Ignore:
Timestamp:
02/25/12 13:40:17 (13 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

The status icon and hiding/showing the window works

Location:
src/mlx/gui
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.