source: src/mlx/mlx.py@ 138:bc4d9d192a7b

Last change on this file since 138:bc4d9d192a7b was 133:dcbe33497899, checked in by István Váradi <ivaradi@…>, 13 years ago

The general message sending works and the most important messages are sent

File size: 1.6 KB
Line 
1# The main program
2
3from config import Config
4from i18n import setLanguage
5from sound import initializeSound
6
7import os
8import sys
9
10if os.name=="nt":
11 import win32api
12
13#--------------------------------------------------------------------------------------
14
15class 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
27def 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 setLanguage(config.getLanguage())
35
36 from .gui.gui import GUI
37 gui = GUI(programDirectory, config)
38
39 sys.stdout = StdIOHandler(gui)
40 sys.stderr = StdIOHandler(gui)
41
42 initializeSound(os.path.join(programDirectory, "sounds"))
43
44 try:
45 gui.build(programDirectory)
46
47 gui.run()
48 finally:
49 gui.flushStdIO()
50 sys.stdout = sys.__stdout__
51 sys.stderr = sys.__stderr__
52
53 config.save()
54
55 if gui.toRestart:
56 programPath = os.path.join(os.path.dirname(sys.argv[0]),
57 "runmlx.exe" if os.name=="nt" else "runmlx.sh")
58 if os.name=="nt":
59 programPath = win32api.GetShortPathName(programPath)
60
61 os.execl(programPath, programPath)
62
63#--------------------------------------------------------------------------------------
64
65if __name__ == "__main__":
66 main()
Note: See TracBrowser for help on using the repository browser.