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