source: src/mlx/mlx.py@ 1000:64355debf74a

python3
Last change on this file since 1000:64355debf74a was 919:2ce8ca39525b, checked in by István Váradi <ivaradi@…>, 6 years ago

Ran 2to3

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