-
-
Notifications
You must be signed in to change notification settings - Fork 653
/
app.py
56 lines (39 loc) · 1.62 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
from .libs import Threading, WinForms
from .window import Window
import toga
import sys
class MainWindow(Window):
def on_close(self):
pass
class App:
_MAIN_WINDOW_CLASS = MainWindow
def __init__(self, interface):
self.interface = interface
self.interface._impl = self
def create(self):
self.native = WinForms.Application
self.interface.commands.add(
toga.Command(None, 'About ' + self.interface.name, group=toga.Group.HELP),
toga.Command(None, 'Preferences', group=toga.Group.FILE),
# Quit should always be the last item, in a section on it's own
toga.Command(lambda s: self.exit(), 'Exit ' + self.interface.name, shortcut='q', group=toga.Group.FILE,
section=sys.maxsize),
toga.Command(None, 'Visit homepage', group=toga.Group.HELP)
)
# Call user code to populate the main window
self.interface.startup()
self.interface.main_window._impl.native.Icon = \
self.interface.icon.bind(self.interface.factory).native
def open_document(self, fileURL):
'''Add a new document to this app.'''
print("STUB: If you want to handle opening documents, implement App.open_document(fileURL)")
def run_app(self):
self.create()
self.native.Run(self.interface.main_window._impl.native)
def main_loop(self):
thread = Threading.Thread(Threading.ThreadStart(self.run_app))
thread.SetApartmentState(Threading.ApartmentState.STA)
thread.Start()
thread.Join()
def exit(self):
self.native.Exit()