source: src/mlx/mlx.py@ 156:fc2987b14e61

Last change on this file since 156:fc2987b14e61 was 155:08f1f0a4dd9a, checked in by István Váradi <ivaradi@…>, 12 years ago

Enhanced language handling to run the program in the proper environment for gettext

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