-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
75 lines (58 loc) · 1.91 KB
/
main.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import sys
import time
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
import pygame
from config import Config
from screen import Screen
from utils import *
class RetroComputer():
def __init__(self):
make_sure_basic_folder_exist()
pygame.init()
self._config = Config()
if self._config.win_pos_x is not None and self._config.win_pos_y is not None:
os.environ['SDL_VIDEO_WINDOW_POS'] = "%d,%d" % (self._config.win_pos_x, self._config.win_pos_y)
self._surface = pygame.display.set_mode((self._config.win_width, self._config.win_height), pygame.NOFRAME)
self._clock = pygame.time.Clock()
if not self._config.show_cursor:
pygame.mouse.set_visible(False)
self.__font = pygame.font.Font('fonts/graph-35-pix-clone.ttf', 48)
self._screen = Screen(self)
def run(self):
try:
while True:
self._update()
for e in pygame.event.get():
if e.type == pygame.QUIT:
raise StopIteration
if e.type == pygame.KEYDOWN:
self._key_down(e)
self._paint()
pygame.display.flip()
self._clock.tick(self._config.fps)
except StopIteration:
self.quit()
def quit(self):
self._do_quit()
def _do_quit(self):
self._screen.end()
#self._config.save_config_file()
pygame.quit()
sys.exit()
def _update(self):
self._screen.update()
def _paint(self):
self._screen.paint()
def _key_down(self, event):
self._screen.key_down(event)
@property
def font(self):
return self.__font
@property
def surface(self):
return self._surface
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
c = RetroComputer()
c.run()