Changeset 38:08f7e6592452


Ignore:
Timestamp:
03/04/12 09:35:01 (12 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The status icon is now hidden properly when the program quits, and made restarting nicer

Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • src/mlx/gui/gui.py

    r36 r38  
    1313
    1414import time
     15import threading
     16import sys
    1517
    1618acftTypes = [ ("Boeing 737-600", const.AIRCRAFT_B736),
     
    4345        self._flight = None
    4446        self._simulator = None
     47
     48        self._stdioLock = threading.Lock()
     49        self._stdioText = ""
    4550        self._stdioAfterNewLine = True
     51
     52        self.toRestart = False
    4653
    4754    def build(self, iconDirectory):
     
    8491        """Run the GUI."""
    8592        if self._config.autoUpdate:
    86             self._updater = Updater(self._programDirectory,
     93            self._updater = Updater(self,
     94                                    self._programDirectory,
    8795                                    self._config.updateURL,
    8896                                    self._mainWindow)
     
    185193            self.showMainWindow()
    186194
     195    def restart(self):
     196        """Quit and restart the application."""
     197        self.toRestart = True
     198        self._quit()
     199
     200    def flushStdIO(self):
     201        """Flush any text to the standard error that could not be logged."""
     202        if self._stdioText:
     203            sys.__stderr__.write(self._stdioText)
     204           
    187205    def writeStdIO(self, text):
    188206        """Write the given text into standard I/O log."""
    189         gobject.idle_add(self._writeStdIO, text)
    190 
    191     def _writeStdIO(self, text):
     207        with self._stdioLock:
     208            self._stdioText += text
     209
     210        gobject.idle_add(self._writeStdIO)
     211
     212    def _writeStdIO(self):
    192213        """Perform the real writing."""
     214        with self._stdioLock:
     215            text = self._stdioText
     216            self._stdioText = ""
     217        if not text: return
     218           
    193219        lines = text.splitlines()
    194220        if text[-1]=="\n":
     
    335361        self._quitButton.set_tooltip_text("Quit the program.")
    336362       
    337         self._quitButton.connect("clicked", gtk.main_quit)
     363        self._quitButton.connect("clicked", self._quit)
    338364
    339365        setupBox.pack_start(self._quitButton, False, False, 0)
     
    660686        self._logView.scroll_mark_onscreen(buffer.get_insert())
    661687
     688    def _quit(self, what = None):
     689        """Quit from the application."""
     690        self._statusIcon.destroy()
     691        return gtk.main_quit()
     692
    662693class TrackerStatusIcon(gtk.StatusIcon):
    663694        def __init__(self):
  • src/mlx/gui/statusicon.py

    r35 r38  
    8383            self._showHideMenuItem.set_active(True)
    8484
     85    def destroy(self):
     86        """Hide and destroy the status icon."""
     87        if appIndicator:
     88            if pygobject:
     89                self._indicator.set_status(appindicator.IndicatorStatus.PASSIVE)
     90            else:
     91                self._indicator.set_status(appindicator.STATUS_PASSIVE)
     92        else:
     93            self._statusIcon.set_visible(False)
     94       
    8595    def _showHideToggled(self, menuitem):
    8696        """Called when the show/hide menu item is toggled."""
  • src/mlx/gui/update.py

    r37 r38  
    55from mlx.gui.common import *
    66
    7 from mlx.update import update, restart
     7from mlx.update import update
    88
    99import mlx.const as const
     
    9696                                else gtk.WIN_POS_CENTER_ON_PARENT)
    9797
    98     def __init__(self, programDirectory, updateURL, parentWindow):
     98    def __init__(self, gui, programDirectory, updateURL, parentWindow):
    9999        """Construct the updater. If not created yet, the windows used by the
    100100        updater are also created."""
    101101        super(Updater, self).__init__()
     102
     103        self._gui = gui
    102104       
    103105        self._programDirectory = programDirectory
     
    280282        self._progressWindow.hide()
    281283        if self._restart:
    282             restart()
     284            self._gui.restart()
    283285
    284286#-------------------------------------------------------------------------------
  • src/mlx/mlx.py

    r36 r38  
    77import os
    88import sys
     9
     10if os.name=="nt":
     11    import win32api
    912
    1013#--------------------------------------------------------------------------------------
     
    2831    config = Config()
    2932    gui = GUI(programDirectory, config)
    30 
     33   
    3134    sys.stdout = StdIOHandler(gui)
    3235    sys.stderr = StdIOHandler(gui)
    3336
    34     gui.build(programDirectory)
     37    try:
     38        gui.build(programDirectory)
     39       
     40        gui.run()
     41    finally:
     42        gui.flushStdIO()
     43        sys.stdout = sys.__stdout__
     44        sys.stderr = sys.__stderr__
    3545
    36     gui.run()
     46    if gui.toRestart:
     47        programPath = os.path.join(os.path.dirname(sys.argv[0]),
     48                                   "runmlx.exe" if os.name=="nt" else "runmlx.sh")
     49        if os.name=="nt":
     50            programPath = win32api.GetShortPathName(programPath)
     51
     52        os.execl(programPath, programPath)
    3753
    3854#--------------------------------------------------------------------------------------
  • src/mlx/update.py

    r37 r38  
    1212import subprocess
    1313import hashlib
    14 
    15 if os.name=="nt":
    16     import win32api
    1714
    1815#------------------------------------------------------------------------------
     
    501498#------------------------------------------------------------------------------
    502499
    503 def restart():
    504     """Restart the program."""
    505     programPath = os.path.join(os.path.dirname(sys.argv[0]),
    506                                "runmlx.exe" if os.name=="nt" else "runmlx.sh")
    507     if os.name=="nt":
    508         programPath = win32api.GetShortPathName(programPath)
    509     os.execl(programPath, programPath)
    510        
    511 #------------------------------------------------------------------------------
    512 
    513500def updateProcess():
    514501    """This is called in the child process, when we need a child process."""
Note: See TracChangeset for help on using the changeset viewer.