source: src/mlx/mlx.py@ 374:a505684c3723

Last change on this file since 374:a505684c3723 was 373:cf2b6b8a3973, checked in by István Váradi <ivaradi@…>, 12 years ago

Added support for a secondary instance (#157)

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