source: src/mlx/mlx.py@ 799:959b8a49cde5

Last change on this file since 799:959b8a49cde5 was 573:af59e3bbe92e, checked in by István Váradi <ivaradi@…>, 9 years ago

Added function to properly deinitialize sound handling on Linux

File size: 3.1 KB
RevLine 
[18]1
[36]2from config import Config
[107]3from i18n import setLanguage
[573]4from sound import initializeSound, finalizeSound
[373]5from util import secondaryInstallation
[402]6from const import VERSION
[535]7from watchdog import Watchdog
[27]8
[29]9import os
[36]10import sys
[27]11
[36]12#--------------------------------------------------------------------------------------
13
[298]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
[247]23instance = None
24
25#--------------------------------------------------------------------------------------
26
[36]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
[155]39def restart(args = []):
40 """Restart the program with the given arguments."""
[247]41 #print "Restarting with args", args
[155]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
[247]55 instance.close()
[373]56 os.execv(programPath, args)
[155]57
58#--------------------------------------------------------------------------------------
59
[36]60def main():
[29]61 """The main operation of the program."""
[182]62 from singleton import SingleInstance, raiseCallbackWrapper
63
[247]64 global instance
[373]65 instance = SingleInstance("mlx" + ("-secondary" if secondaryInstallation
66 else ""), raiseCallbackWrapper)
[182]67 if not instance: return
68
[36]69 programDirectory = os.path.dirname(sys.argv[0])
70
71 config = Config()
[40]72 config.load()
[107]73
[377]74 secondaryArgs = ["secondary"] if secondaryInstallation else []
75 if "usedeflang" not in sys.argv and config.setupLocale():
76 restart(["usedeflang"] + secondaryArgs)
[155]77
[276]78 setLanguage(programDirectory, config.getLanguage())
[373]79
[123]80 from .gui.gui import GUI
[36]81 gui = GUI(programDirectory, config)
[373]82
[36]83 sys.stdout = StdIOHandler(gui)
84 sys.stderr = StdIOHandler(gui)
85
[402]86 print "MAVA Logger X " + VERSION + " debug log"
87 print "The initial configuration:"
88 config.log()
89
[133]90 initializeSound(os.path.join(programDirectory, "sounds"))
91
[38]92 try:
[535]93 Watchdog().start()
94
[38]95 gui.build(programDirectory)
[160]96
[38]97 gui.run()
[573]98
99 finalizeSound()
[38]100 finally:
101 gui.flushStdIO()
102 sys.stdout = sys.__stdout__
103 sys.stderr = sys.__stderr__
[27]104
[40]105 config.save()
106
[38]107 if gui.toRestart:
[377]108 restart(secondaryArgs)
[27]109
[36]110#--------------------------------------------------------------------------------------
111
[20]112if __name__ == "__main__":
[182]113 if instance:
114 main()
Note: See TracBrowser for help on using the repository browser.