source: src/mlx/mlx.py@ 435:54d318811885

Last change on this file since 435:54d318811885 was 402:b668511b4ac8, checked in by István Váradi <ivaradi@…>, 11 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
RevLine 
[18]1
[36]2from config import Config
[107]3from i18n import setLanguage
[133]4from sound import initializeSound
[373]5from util import secondaryInstallation
[402]6from const import VERSION
[27]7
[29]8import os
[36]9import sys
[27]10
[36]11#--------------------------------------------------------------------------------------
12
[298]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
[247]22instance = None
23
24#--------------------------------------------------------------------------------------
25
[36]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
[155]38def restart(args = []):
39 """Restart the program with the given arguments."""
[247]40 #print "Restarting with args", args
[155]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
[247]54 instance.close()
[373]55 os.execv(programPath, args)
[155]56
57#--------------------------------------------------------------------------------------
58
[36]59def main():
[29]60 """The main operation of the program."""
[182]61 from singleton import SingleInstance, raiseCallbackWrapper
62
[247]63 global instance
[373]64 instance = SingleInstance("mlx" + ("-secondary" if secondaryInstallation
65 else ""), raiseCallbackWrapper)
[182]66 if not instance: return
67
[36]68 programDirectory = os.path.dirname(sys.argv[0])
69
70 config = Config()
[40]71 config.load()
[107]72
[377]73 secondaryArgs = ["secondary"] if secondaryInstallation else []
74 if "usedeflang" not in sys.argv and config.setupLocale():
75 restart(["usedeflang"] + secondaryArgs)
[155]76
[276]77 setLanguage(programDirectory, config.getLanguage())
[373]78
[123]79 from .gui.gui import GUI
[36]80 gui = GUI(programDirectory, config)
[373]81
[36]82 sys.stdout = StdIOHandler(gui)
83 sys.stderr = StdIOHandler(gui)
84
[402]85 print "MAVA Logger X " + VERSION + " debug log"
86 print "The initial configuration:"
87 config.log()
88
[133]89 initializeSound(os.path.join(programDirectory, "sounds"))
90
[38]91 try:
92 gui.build(programDirectory)
[160]93
[38]94 gui.run()
95 finally:
96 gui.flushStdIO()
97 sys.stdout = sys.__stdout__
98 sys.stderr = sys.__stderr__
[27]99
[40]100 config.save()
101
[38]102 if gui.toRestart:
[377]103 restart(secondaryArgs)
[27]104
[36]105#--------------------------------------------------------------------------------------
106
[20]107if __name__ == "__main__":
[182]108 if instance:
109 main()
Note: See TracBrowser for help on using the repository browser.