source: src/mlx/mlx.py@ 531:f8ffb59d8112

Last change on this file since 531:f8ffb59d8112 was 402:b668511b4ac8, checked in by István Váradi <ivaradi@…>, 12 years ago

Made the debug logging more detailed by adding the printout of the configuration and a few other stuff (re #170)

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