source: src/mlx/mlx.py@ 129:dcca616a78ca

Last change on this file since 129:dcca616a78ca was 123:3b181cd0ab99, checked in by István Váradi <ivaradi@…>, 13 years ago

The Preferences dialog works

File size: 1.5 KB
Line 
1# The main program
2
3from config import Config
4from i18n import setLanguage
5
6import os
7import sys
8
9if os.name=="nt":
10 import win32api
11
12#--------------------------------------------------------------------------------------
13
14class 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
26def 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
62if __name__ == "__main__":
63 main()
Note: See TracBrowser for help on using the repository browser.