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