Line | |
---|
1 | # The main program
|
---|
2 |
|
---|
3 | from .gui.gui import GUI
|
---|
4 |
|
---|
5 | from config import Config
|
---|
6 |
|
---|
7 | import os
|
---|
8 | import sys
|
---|
9 |
|
---|
10 | if os.name=="nt":
|
---|
11 | import win32api
|
---|
12 |
|
---|
13 | #--------------------------------------------------------------------------------------
|
---|
14 |
|
---|
15 | class StdIOHandler(object):
|
---|
16 | """Handler for the standard I/O messages."""
|
---|
17 | def __init__(self, gui):
|
---|
18 | """Construct the handler."""
|
---|
19 | self._gui = gui
|
---|
20 |
|
---|
21 | def write(self, text):
|
---|
22 | """Write the given text into the log."""
|
---|
23 | self._gui.writeStdIO(text)
|
---|
24 |
|
---|
25 | #--------------------------------------------------------------------------------------
|
---|
26 |
|
---|
27 | def main():
|
---|
28 | """The main operation of the program."""
|
---|
29 | programDirectory = os.path.dirname(sys.argv[0])
|
---|
30 |
|
---|
31 | config = Config()
|
---|
32 | config.load()
|
---|
33 |
|
---|
34 | gui = GUI(programDirectory, config)
|
---|
35 |
|
---|
36 | sys.stdout = StdIOHandler(gui)
|
---|
37 | sys.stderr = StdIOHandler(gui)
|
---|
38 |
|
---|
39 | try:
|
---|
40 | gui.build(programDirectory)
|
---|
41 |
|
---|
42 | gui.run()
|
---|
43 | finally:
|
---|
44 | gui.flushStdIO()
|
---|
45 | sys.stdout = sys.__stdout__
|
---|
46 | sys.stderr = sys.__stderr__
|
---|
47 |
|
---|
48 | config.save()
|
---|
49 |
|
---|
50 | if gui.toRestart:
|
---|
51 | programPath = os.path.join(os.path.dirname(sys.argv[0]),
|
---|
52 | "runmlx.exe" if os.name=="nt" else "runmlx.sh")
|
---|
53 | if os.name=="nt":
|
---|
54 | programPath = win32api.GetShortPathName(programPath)
|
---|
55 |
|
---|
56 | os.execl(programPath, programPath)
|
---|
57 |
|
---|
58 | #--------------------------------------------------------------------------------------
|
---|
59 |
|
---|
60 | if __name__ == "__main__":
|
---|
61 | main()
|
---|
Note:
See
TracBrowser
for help on using the repository browser.