source: src/mlx/mlx.py@ 359:fa4e93edd48b

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

Documented the non-GUI modules

File size: 2.7 KB
RevLine 
[18]1
[36]2from config import Config
[107]3from i18n import setLanguage
[133]4from sound import initializeSound
[27]5
[29]6import os
[36]7import sys
[27]8
[36]9#--------------------------------------------------------------------------------------
10
[298]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
[247]20instance = None
21
22#--------------------------------------------------------------------------------------
23
[36]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
[155]36def restart(args = []):
37 """Restart the program with the given arguments."""
[247]38 #print "Restarting with args", args
[155]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
[247]52 instance.close()
[155]53 os.execv(programPath, args)
54
55#--------------------------------------------------------------------------------------
56
[36]57def main():
[29]58 """The main operation of the program."""
[182]59 from singleton import SingleInstance, raiseCallbackWrapper
60
[247]61 global instance
[182]62 instance = SingleInstance("mlx", raiseCallbackWrapper)
63 if not instance: return
64
[36]65 programDirectory = os.path.dirname(sys.argv[0])
66
67 config = Config()
[40]68 config.load()
[107]69
[155]70 if (len(sys.argv)<=1 or sys.argv[1]!="usedeflang") and config.setupLocale():
71 restart(["usedeflang"])
72
[276]73 setLanguage(programDirectory, config.getLanguage())
[40]74
[123]75 from .gui.gui import GUI
[36]76 gui = GUI(programDirectory, config)
[38]77
[36]78 sys.stdout = StdIOHandler(gui)
79 sys.stderr = StdIOHandler(gui)
80
[133]81 initializeSound(os.path.join(programDirectory, "sounds"))
82
[38]83 try:
84 gui.build(programDirectory)
[160]85
[38]86 gui.run()
87 finally:
88 gui.flushStdIO()
89 sys.stdout = sys.__stdout__
90 sys.stderr = sys.__stderr__
[27]91
[40]92 config.save()
93
[38]94 if gui.toRestart:
[155]95 restart()
[27]96
[36]97#--------------------------------------------------------------------------------------
98
[20]99if __name__ == "__main__":
[182]100 if instance:
101 main()
Note: See TracBrowser for help on using the repository browser.