-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.py
executable file
·52 lines (42 loc) · 1.32 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
#!/usr/bin/env python3
import kivy
import can
import datetime
import time
import threading
import sched
import yaml
import importlib
from functools import partial
from kivy.app import App
from kivy.lang.builder import Builder
from kivy.clock import Clock
from can_runner import CanRunner
class PeugeotSim(App):
def build(self):
return Builder.load_file('main.kv')
def on_start(self):
# Get tabs id
tabs = self.root.ids['modules']
tabs.clear_widgets()
with open('config.yml', 'r') as conf_file:
self.conf = yaml.load(conf_file, Loader=yaml.FullLoader)
# Init CAN runner
self.can_runner = CanRunner()
self.can_runner.run()
# Init modules
self.modules = {}
for name in self.conf['modules']:
module = importlib.import_module(f'modules.{name}')
self.modules[name] = getattr(module, module._modname)(self.can_runner)
if not tabs.tab_list:
tabs.add_widget(self.modules[name])
Clock.schedule_once(partial(tabs.switch_to, self.modules[name]))
else:
tabs.add_widget(self.modules[name])
def on_stop(self):
print('closing app')
self.can_runner.stop()
self.thread_exit = True
if __name__ == '__main__':
PeugeotSim().run()