-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathWindow.py
More file actions
58 lines (46 loc) · 1.76 KB
/
Copy pathWindow.py
File metadata and controls
58 lines (46 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pygame
from time import sleep
class Window:
def __init__(self, title="Test App", colorRGB=False, customIconPath=False):
pygame.init()
self.screenDims = (800,600)
self.screen = pygame.display.set_mode(self.screenDims, pygame.RESIZABLE)
pygame.display.set_caption(title)
if customIconPath:
icon = pygame.image.load(customIconPath)
pygame.display.set_icon(icon)
self.color = (0, 0, 0)
if customIconPath:
icon = pygame.image.load(customIconPath)
pygame.display.set_icon(icon)
if colorRGB:
self.color = colorRGB
self.screen.fill(self.color)
def setColor(self, colorRGB):
self.screen.fill(colorRGB)
def update(self, screenObj=False):
if screenObj:
self.screen.fill(screenObj.color)
screenObj.display(self.screenDims)
else:
self.screen.fill(self.color)
pygame.display.flip()
if screenObj:
if screenObj.waitForNextFrame:
sleep(screenObj.waitForNextFrame)
screenObj.waitForNextFrame = 0
def checkForInput(self, screen):
#check for inputs
for event in pygame.event.get():
#handle various inputs
##quit type
if event.type == pygame.QUIT:
pygame.quit()
if event.type == pygame.MOUSEBUTTONDOWN:
clickLoc = pygame.mouse.get_pos()
for e in screen.elements[::-1]:
if e.wasClicked(clickLoc):
e.onClick(screen)
return
if event.type == pygame.VIDEORESIZE:
self.screenDims = self.screen.get_size()