Changeset 29:5bcc0ef808c5


Ignore:
Timestamp:
02/25/12 13:40:17 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
hg-Phase:
(<MercurialRepository 1 'hg:/home/ivaradi/mlx/hg' '/'>, 'public')
Message:

The status icon and hiding/showing the window works

Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • runmlx.py

    r27 r29  
    11# Script to run the logger
     2
     3import os
    24
    35if __name__ == "__main__":
    46    import mlx.mlx
    5     mlx.mlx.main()
     7    mlx.mlx.main(os.path.dirname(__file__))
  • runmlx.sh

    r28 r29  
    66export PYTHONPATH
    77
    8 exec python -m mlx.mlx "$@"
     8exec python -m runmlx "$@"
  • src/mlx/acft.py

    r27 r29  
    481481        This implementation checks the RPM values to be 0."""
    482482        for rpm in aircraftState.rpm:
    483             if rpm>0: return
    484         self._setStage(aircraftState, const.STAGE_END)
     483            if rpm>0: return False
     484        return True
    485485
    486486    def logFuel(self, aircraftState):
  • src/mlx/flight.py

    r27 r29  
    2323    It is also the hub for the other main objects participating in the handling of
    2424    the flight."""
    25     def __init__(self, logger):
     25    def __init__(self, logger, gui):
    2626        """Construct the flight."""
    2727        self._stage = None
    2828        self.logger = logger
     29        self._gui = gui
    2930
    3031        self.cruiseAltitude = None
  • src/mlx/gui/common.py

    r28 r29  
    99    pygobject = False
    1010    import pygtk
     11    import gtk.gdk as gdk
    1112    import gtk
    1213    import gobject
     
    1920    print "Using PyGObject"
    2021    pygobject = True
     22    from gi.repository import Gdk as gdk
    2123    from gi.repository import Gtk as gtk
    2224    from gi.repository import GObject as gobject
  • src/mlx/gui/gui.py

    r28 r29  
    11# The main file for the GUI
    22
    3 from common import *
     3from statusicon import StatusIcon
     4from mlx.gui.common import *
    45
    56import mlx.const as const
     
    3233    def __init__(self):
    3334        """Construct the GUI."""
    34 
    3535        gobject.threads_init()
    3636
     
    4141        self._simulator = None
    4242
    43     def build(self):
     43    def build(self, iconDirectory):
    4444        """Build the GUI."""
     45       
    4546        win = gtk.Window()
    4647        win.set_title("MAVA Logger X " + const.VERSION)
    4748        win.set_icon_from_file("logo.ico")
    48         win.connect("delete-event", gtk.main_quit)
     49        win.connect("delete-event", lambda a, b: self.hideMainWindow())
     50        win.connect("window-state-event", self._handleMainWindowState)
    4951
    5052        mainVBox = gtk.VBox()
     
    6264        logFrame.set_border_width(8)
    6365        mainVBox.pack_start(logFrame, True, True, 0)
    64 
     66       
    6567        win.show_all()       
     68
     69        self._mainWindow = win
     70
     71        self._statusIcon = StatusIcon(iconDirectory, self)
    6672
    6773    def run(self):
     
    9399        gobject.idle_add(self._setData, state)
    94100
     101    def _handleMainWindowState(self, window, event):
     102        """Hande a change in the state of the window"""
     103        iconified = gdk.WindowState.ICONIFIED if pygobject \
     104                    else gdk.WINDOW_STATE_ICONIFIED
     105        if (event.changed_mask&iconified)!=0 and (event.new_window_state&iconified)!=0:
     106            self.hideMainWindow()
     107
     108    def hideMainWindow(self):
     109        """Hide the main window and save its position."""
     110        (self._mainWindowX, self._mainWindowY) = \
     111            self._mainWindow.get_window().get_root_origin()
     112        self._mainWindow.hide()
     113        self._statusIcon.mainWindowHidden()
     114        return True
     115
     116    def showMainWindow(self):
     117        """Show the main window at its former position."""
     118        self._mainWindow.move(self._mainWindowX, self._mainWindowY)
     119        self._mainWindow.deiconify()
     120        self._mainWindow.show()
     121        self._statusIcon.mainWindowShown()
     122
     123    def toggleMainWindow(self):
     124        """Toggle the main window."""
     125        if self._mainWindow.get_visible():
     126            self.hideMainWindow()
     127        else:
     128            self.showMainWindow()
     129           
    95130    def _drawConnState(self, connStateArea, eventOrContext):
    96131        """Draw the connection state."""
     
    254289
    255290        setupBox.pack_start(alignment, False, False, 8)
     291
     292        setupBox.pack_start(gtk.VSeparator(), False, False, 8)   
     293
     294        self._quitButton = gtk.Button(label = "Quit")
     295        self._quitButton.set_tooltip_text("Quit the program.")
     296       
     297        self._quitButton.connect("clicked", gtk.main_quit)
     298
     299        setupBox.pack_start(self._quitButton, False, False, 0)
    256300
    257301        return setupFrame
  • src/mlx/mlx.py

    r28 r29  
    22
    33from .gui.gui import GUI
     4from .gui.common import *
    45
    5 def main():
     6import os
     7
     8def main(iconDirectory):
    69    """The main operation of the program."""
    7     # menu = gtk.Menu() 
    8     # item = gtk.MenuItem() 
    9     # item.set_label("Menu Item") 
    10     # item.show() 
    11     # menu.append(item) 
     10    gui = GUI()
    1211
    13     # menu.show() 
     12    gui.build(iconDirectory)
    1413
    15     # if appIndicator:
    16     #     if pygobject:
    17     #         ind = appindicator.Indicator.new ("mava-logger-x",
    18     #                                           "/home/vi/munka/repules/mlx/src/logo.ico",
    19     #                                           #"indicator-messages",
    20     #                                           appindicator.IndicatorCategory.APPLICATION_STATUS)
    21     #         ind.set_status (appindicator.IndicatorStatus.ACTIVE)
    22     #     else:
    23     #         ind = appindicator.Indicator ("mava-logger-x",
    24     #                                       "/home/vi/munka/repules/mlx/src/logo.ico",
    25     #                                       appindicator.CATEGORY_APPLICATION_STATUS)
    26     #         ind.set_status (appindicator.STATUS_ACTIVE)
    27 
    28     #     ind.set_menu(menu)
    29     #     #ind.set_icon("distributor-logo")
    30     # else:
    31     #     def popup_menu(status, button, time):
    32     #         menu.popup(None, None, gtk.status_icon_position_menu,
    33     #                    button, time, status)
    34     #     statusIcon = gtk.StatusIcon()
    35     #     #statusIcon.set_from_stock(gtk.STOCK_FIND)
    36     #     statusIcon.set_from_file("logo.ico")
    37     #     statusIcon.set_tooltip_markup("MAVA Logger X")
    38     #     statusIcon.set_visible(True)
    39     #     statusIcon.connect('popup-menu', popup_menu)
    40 
    41     gui = GUI()
    42     gui.build()
    4314    gui.run()
    4415
    4516if __name__ == "__main__":
    46     main()
     17    main(os.path.dirname(__file__))
    4718
    4819
Note: See TracChangeset for help on using the changeset viewer.