1 |
|
---|
2 | from config import Config
|
---|
3 | from i18n import setLanguage
|
---|
4 | from sound import initializeSound
|
---|
5 | from util import secondaryInstallation
|
---|
6 | from const import VERSION
|
---|
7 | from watchdog import Watchdog
|
---|
8 |
|
---|
9 | import os
|
---|
10 | import 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 |
|
---|
23 | instance = None
|
---|
24 |
|
---|
25 | #--------------------------------------------------------------------------------------
|
---|
26 |
|
---|
27 | class 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 |
|
---|
39 | def 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 |
|
---|
60 | def 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 | from .gui.gui import GUI
|
---|
81 | gui = GUI(programDirectory, config)
|
---|
82 |
|
---|
83 | sys.stdout = StdIOHandler(gui)
|
---|
84 | sys.stderr = StdIOHandler(gui)
|
---|
85 |
|
---|
86 | print "MAVA Logger X " + VERSION + " debug log"
|
---|
87 | print "The initial configuration:"
|
---|
88 | config.log()
|
---|
89 |
|
---|
90 | initializeSound(os.path.join(programDirectory, "sounds"))
|
---|
91 |
|
---|
92 | try:
|
---|
93 | Watchdog().start()
|
---|
94 |
|
---|
95 | gui.build(programDirectory)
|
---|
96 |
|
---|
97 | gui.run()
|
---|
98 | finally:
|
---|
99 | gui.flushStdIO()
|
---|
100 | sys.stdout = sys.__stdout__
|
---|
101 | sys.stderr = sys.__stderr__
|
---|
102 |
|
---|
103 | config.save()
|
---|
104 |
|
---|
105 | if gui.toRestart:
|
---|
106 | restart(secondaryArgs)
|
---|
107 |
|
---|
108 | #--------------------------------------------------------------------------------------
|
---|
109 |
|
---|
110 | if __name__ == "__main__":
|
---|
111 | if instance:
|
---|
112 | main()
|
---|