-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
76 lines (58 loc) · 2.15 KB
/
app.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
from pyglet.window import mouse,Window,key
from pyglet import clock
from .space import Space
from .utils import load_config,get_config
from .ui import UI
from .views import Tip,Grid,History,Viewport,Point,Size
class App(Window):
def __init__(self):
self._case_idx=0
self._demo_names=load_config()
cfg=get_config(self._demo_names[0])
w,h=cfg['WIDTH'],cfg['HEIGHT']
super().__init__(w,h , cfg['TITLE'], resizable=False)
self.set_vsync(False)
clock.schedule_interval(self.update, 1/cfg['FPS'])
self.reset()
def on_draw(self):
self.clear()
for v in self._views:
v.render()
self._UI.render()
def on_key_press(self, symbol, modifiers):
super().on_key_press(symbol, modifiers)
flag=False
if symbol==key.LEFT or symbol==key.UP :
self._case_idx+=len(self._demo_names)-1
flag=True
elif symbol==key.RIGHT or symbol==key.DOWN:
self._case_idx+=1
flag=True
if flag:
self._case_idx%= len(self._demo_names)
self.reset()
def on_mouse_press(self,x, y, button, modifiers):
if button & mouse.RIGHT:
self._views[0].on_click(x,y)
def reset(self):
self.reload=False
cfg=get_config(self._demo_names[self._case_idx])
self._cfg=cfg
space=Space(cfg)
self._space=space
self._views=[Grid(space),Tip(space)]
trajectory=cfg.get('trajectory',False)
if trajectory:
w,h=cfg['WIDTH'],cfg['HEIGHT']
self._views.append(History(space,viewPort=Viewport(Point(w/2,0),Size(w/2,h/2))))
self._UI = UI(self, cfg,'Setup')
def update(self, dt):
if self.reload:
self.reset()
return
self._space.update()
for key,_ in self._cfg.args.items():
if self._UI.settings.get_changed(key):
self._cfg.args[key][1]=self._UI.settings.get_value(key)
self.reload=True
#print(self._UI.settings.get_value(key))