source: src/mlx/mlx.py@ 247:12a62baf908f

Last change on this file since 247:12a62baf908f was 247:12a62baf908f, checked in by István Váradi <ivaradi@…>, 12 years ago

Hopefully fixed the problem of not restarting properly

File size: 2.5 KB
RevLine 
[18]1# The main program
2
[36]3from config import Config
[107]4from i18n import setLanguage
[133]5from sound import initializeSound
[27]6
[29]7import os
[36]8import sys
[27]9
[36]10#--------------------------------------------------------------------------------------
11
[247]12instance = None
13
14#--------------------------------------------------------------------------------------
15
[36]16class StdIOHandler(object):
17 """Handler for the standard I/O messages."""
18 def __init__(self, gui):
19 """Construct the handler."""
20 self._gui = gui
21
22 def write(self, text):
23 """Write the given text into the log."""
24 self._gui.writeStdIO(text)
25
26#--------------------------------------------------------------------------------------
27
[155]28def restart(args = []):
29 """Restart the program with the given arguments."""
[247]30 #print "Restarting with args", args
[155]31 programPath = os.path.join(os.path.dirname(sys.argv[0]),
32 "runmlx.exe" if os.name=="nt" else "runmlx.sh")
33 if os.name=="nt":
34 import win32api
35 try:
36 programPath = win32api.GetShortPathName(programPath)
37 except:
38 programPath = os.path.join(os.path.dirname(sys.argv[0]),
39 "runmlx.bat")
40 programPath = win32api.GetShortPathName(programPath)
41
42 args = [programPath] + args
43
[247]44 instance.close()
[155]45 os.execv(programPath, args)
46
47#--------------------------------------------------------------------------------------
48
[36]49def main():
[29]50 """The main operation of the program."""
[182]51 from singleton import SingleInstance, raiseCallbackWrapper
52
[247]53 global instance
[182]54 instance = SingleInstance("mlx", raiseCallbackWrapper)
55 if not instance: return
56
[36]57 programDirectory = os.path.dirname(sys.argv[0])
58
59 config = Config()
[40]60 config.load()
[107]61
[155]62 if (len(sys.argv)<=1 or sys.argv[1]!="usedeflang") and config.setupLocale():
63 restart(["usedeflang"])
64
[107]65 setLanguage(config.getLanguage())
[40]66
[123]67 from .gui.gui import GUI
[36]68 gui = GUI(programDirectory, config)
[38]69
[36]70 sys.stdout = StdIOHandler(gui)
71 sys.stderr = StdIOHandler(gui)
72
[133]73 initializeSound(os.path.join(programDirectory, "sounds"))
74
[38]75 try:
76 gui.build(programDirectory)
[160]77
[38]78 gui.run()
79 finally:
80 gui.flushStdIO()
81 sys.stdout = sys.__stdout__
82 sys.stderr = sys.__stderr__
[27]83
[40]84 config.save()
85
[38]86 if gui.toRestart:
[155]87 restart()
[27]88
[36]89#--------------------------------------------------------------------------------------
90
[20]91if __name__ == "__main__":
[182]92 if instance:
93 main()
Note: See TracBrowser for help on using the repository browser.