source: src/mlx/mlx.py@ 353:f3c95dc2eaea

Last change on this file since 353:f3c95dc2eaea was 298:24c67ec5cdca, checked in by István Váradi <ivaradi@…>, 12 years ago

Documented the non-GUI modules

File size: 2.7 KB
Line 
1
2from config import Config
3from i18n import setLanguage
4from sound import initializeSound
5
6import os
7import sys
8
9#--------------------------------------------------------------------------------------
10
11## @package mlx.mlx
12#
13# The main program.
14#
15# This module contains the main program of the logger as well as the \ref
16# restart "restart" handling.
17
18#--------------------------------------------------------------------------------------
19
20instance = None
21
22#--------------------------------------------------------------------------------------
23
24class StdIOHandler(object):
25 """Handler for the standard I/O messages."""
26 def __init__(self, gui):
27 """Construct the handler."""
28 self._gui = gui
29
30 def write(self, text):
31 """Write the given text into the log."""
32 self._gui.writeStdIO(text)
33
34#--------------------------------------------------------------------------------------
35
36def restart(args = []):
37 """Restart the program with the given arguments."""
38 #print "Restarting with args", args
39 programPath = os.path.join(os.path.dirname(sys.argv[0]),
40 "runmlx.exe" if os.name=="nt" else "runmlx.sh")
41 if os.name=="nt":
42 import win32api
43 try:
44 programPath = win32api.GetShortPathName(programPath)
45 except:
46 programPath = os.path.join(os.path.dirname(sys.argv[0]),
47 "runmlx.bat")
48 programPath = win32api.GetShortPathName(programPath)
49
50 args = [programPath] + args
51
52 instance.close()
53 os.execv(programPath, args)
54
55#--------------------------------------------------------------------------------------
56
57def main():
58 """The main operation of the program."""
59 from singleton import SingleInstance, raiseCallbackWrapper
60
61 global instance
62 instance = SingleInstance("mlx", raiseCallbackWrapper)
63 if not instance: return
64
65 programDirectory = os.path.dirname(sys.argv[0])
66
67 config = Config()
68 config.load()
69
70 if (len(sys.argv)<=1 or sys.argv[1]!="usedeflang") and config.setupLocale():
71 restart(["usedeflang"])
72
73 setLanguage(programDirectory, config.getLanguage())
74
75 from .gui.gui import GUI
76 gui = GUI(programDirectory, config)
77
78 sys.stdout = StdIOHandler(gui)
79 sys.stderr = StdIOHandler(gui)
80
81 initializeSound(os.path.join(programDirectory, "sounds"))
82
83 try:
84 gui.build(programDirectory)
85
86 gui.run()
87 finally:
88 gui.flushStdIO()
89 sys.stdout = sys.__stdout__
90 sys.stderr = sys.__stderr__
91
92 config.save()
93
94 if gui.toRestart:
95 restart()
96
97#--------------------------------------------------------------------------------------
98
99if __name__ == "__main__":
100 if instance:
101 main()
Note: See TracBrowser for help on using the repository browser.