source: src/mlx/mlx.py@ 618:3745c38783d9

Last change on this file since 618:3745c38783d9 was 573:af59e3bbe92e, checked in by István Váradi <ivaradi@…>, 10 years ago

Added function to properly deinitialize sound handling on Linux

File size: 3.1 KB
Line 
1
2from config import Config
3from i18n import setLanguage
4from sound import 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 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
99 finalizeSound()
100 finally:
101 gui.flushStdIO()
102 sys.stdout = sys.__stdout__
103 sys.stderr = sys.__stderr__
104
105 config.save()
106
107 if gui.toRestart:
108 restart(secondaryArgs)
109
110#--------------------------------------------------------------------------------------
111
112if __name__ == "__main__":
113 if instance:
114 main()
Note: See TracBrowser for help on using the repository browser.