[18] | 1 | # The main program
|
---|
| 2 |
|
---|
[36] | 3 | from config import Config
|
---|
[107] | 4 | from i18n import setLanguage
|
---|
[133] | 5 | from sound import initializeSound
|
---|
[27] | 6 |
|
---|
[29] | 7 | import os
|
---|
[36] | 8 | import sys
|
---|
[27] | 9 |
|
---|
[38] | 10 | if os.name=="nt":
|
---|
| 11 | import win32api
|
---|
| 12 |
|
---|
[36] | 13 | #--------------------------------------------------------------------------------------
|
---|
| 14 |
|
---|
| 15 | class StdIOHandler(object):
|
---|
| 16 | """Handler for the standard I/O messages."""
|
---|
| 17 | def __init__(self, gui):
|
---|
| 18 | """Construct the handler."""
|
---|
| 19 | self._gui = gui
|
---|
| 20 |
|
---|
| 21 | def write(self, text):
|
---|
| 22 | """Write the given text into the log."""
|
---|
| 23 | self._gui.writeStdIO(text)
|
---|
| 24 |
|
---|
| 25 | #--------------------------------------------------------------------------------------
|
---|
| 26 |
|
---|
| 27 | def main():
|
---|
[29] | 28 | """The main operation of the program."""
|
---|
[36] | 29 | programDirectory = os.path.dirname(sys.argv[0])
|
---|
| 30 |
|
---|
| 31 | config = Config()
|
---|
[40] | 32 | config.load()
|
---|
[107] | 33 |
|
---|
| 34 | setLanguage(config.getLanguage())
|
---|
[40] | 35 |
|
---|
[123] | 36 | from .gui.gui import GUI
|
---|
[36] | 37 | gui = GUI(programDirectory, config)
|
---|
[38] | 38 |
|
---|
[36] | 39 | sys.stdout = StdIOHandler(gui)
|
---|
| 40 | sys.stderr = StdIOHandler(gui)
|
---|
| 41 |
|
---|
[133] | 42 | initializeSound(os.path.join(programDirectory, "sounds"))
|
---|
| 43 |
|
---|
[38] | 44 | try:
|
---|
| 45 | gui.build(programDirectory)
|
---|
| 46 |
|
---|
| 47 | gui.run()
|
---|
| 48 | finally:
|
---|
| 49 | gui.flushStdIO()
|
---|
| 50 | sys.stdout = sys.__stdout__
|
---|
| 51 | sys.stderr = sys.__stderr__
|
---|
[27] | 52 |
|
---|
[40] | 53 | config.save()
|
---|
| 54 |
|
---|
[38] | 55 | if gui.toRestart:
|
---|
| 56 | programPath = os.path.join(os.path.dirname(sys.argv[0]),
|
---|
| 57 | "runmlx.exe" if os.name=="nt" else "runmlx.sh")
|
---|
| 58 | if os.name=="nt":
|
---|
| 59 | programPath = win32api.GetShortPathName(programPath)
|
---|
| 60 |
|
---|
| 61 | os.execl(programPath, programPath)
|
---|
[27] | 62 |
|
---|
[36] | 63 | #--------------------------------------------------------------------------------------
|
---|
| 64 |
|
---|
[20] | 65 | if __name__ == "__main__":
|
---|
[36] | 66 | main()
|
---|