mailr13941 - in /branches/gui_testing/gui: icons.py relax_gui.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on July 28, 2011 - 09:36:
Author: bugman
Date: Thu Jul 28 09:36:14 2011
New Revision: 13941

URL: http://svn.gna.org/viewcvs/relax?rev=13941&view=rev
Log:
Created a task bar icon for Mac OS X.


Modified:
    branches/gui_testing/gui/icons.py
    branches/gui_testing/gui/relax_gui.py

Modified: branches/gui_testing/gui/icons.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/icons.py?rev=13941&r1=13940&r2=13941&view=diff
==============================================================================
--- branches/gui_testing/gui/icons.py (original)
+++ branches/gui_testing/gui/icons.py Thu Jul 28 09:36:14 2011
@@ -43,6 +43,84 @@
             self.AddIconFromFile(status.install_path + sep + 'graphics' + 
sep + 'ulysses.ico', wx.BITMAP_TYPE_ANY)
 
 
+class Relax_task_bar_icon(wx.TaskBarIcon):
+    """The icon for the Mac OS X task bar."""
+
+    # Set up some ID numbers for the menu entries.
+    TBMENU_RESTORE = wx.NewId()
+    TBMENU_CLOSE   = wx.NewId()
+
+    def __init__(self, gui):
+        """Set up the task bar icon.
+
+        @param gui:     The GUI object.
+        @type gui:      wx.Frame instance
+        """
+
+        # Store the args.
+        self.gui = gui
+
+        # Initilise the base class.
+        wx.TaskBarIcon.__init__(self)
+
+        # Set the task bar icon.
+        self.SetIcon(wx.Icon(status.install_path + sep + 'graphics' + sep + 
'ulysses_shadowless_trans_128x128.png', wx.BITMAP_TYPE_ANY))
+
+        # Bind mouse events.
+        self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.restore)
+
+
+    def CreatePopupMenu(self):
+        """Create and return the task bar menu.
+
+        @return:    The pop up menu.
+        @rtype:     wx.Menu instance
+        """
+
+        # Initialise the menu.
+        popup = wx.Menu()
+
+        # Add some menu entries.
+        popup.Append(self.TBMENU_RESTORE, "Restore relax")
+        popup.Append(self.TBMENU_CLOSE,   "Exit relax")
+
+        # Bind the menu events.
+        self.Bind(wx.EVT_MENU, self.restore, id=self.TBMENU_RESTORE)
+        self.Bind(wx.EVT_MENU, self.exit, id=self.TBMENU_CLOSE)
+
+        # Return the menu.
+        return popup
+
+
+    def exit(self, evt):
+        """Exit relax from the task bar.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        """
+
+        # Exit relax.
+        wx.CallAfter(self.gui.exit_gui)
+
+
+    def restore(self, event):
+        """Restore relax from the task bar.
+
+        @param event:   The wx event.
+        @type event:    wx event
+        """
+
+        # Show relax.
+        if not self.gui.IsShown():
+            self.gui.Show(True)
+
+        # De-iconise relax.
+        if self.gui.IsIconized():
+            self.gui.Iconize(False)
+
+        # Raise relax to the top of the window hierarchy.
+        self.gui.Raise()
+
 
 # Set up the main set of icons for relax.
 relax_icons = Relax_icons()

Modified: branches/gui_testing/gui/relax_gui.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/relax_gui.py?rev=13941&r1=13940&r2=13941&view=diff
==============================================================================
--- branches/gui_testing/gui/relax_gui.py (original)
+++ branches/gui_testing/gui/relax_gui.py Thu Jul 28 09:36:14 2011
@@ -55,7 +55,7 @@
 from gui.controller import Controller
 from gui.filedialog import opendir, openfile, savefile
 from gui.fonts import font
-from gui.icons import relax_icons
+from gui.icons import Relax_task_bar_icon, relax_icons
 from gui.menu import Menu
 from gui.message import dir_message, error_message, question
 from gui import paths
@@ -85,6 +85,10 @@
         relax_icons.setup()
         self.SetIcons(relax_icons)
 
+        # Set up the Mac OS X task bar icon.
+        if not 'darwin' in sys.platform:
+            self.taskbar_icon = Relax_task_bar_icon(self)
+
         # Initialise some variables for the GUI.
         self.launch_dir = getcwd()
 
@@ -128,7 +132,7 @@
         # Add the start screen.
         self.add_start_screen()
 
-        # Close Box event
+        # Close Box event.
         self.Bind(wx.EVT_CLOSE, self.exit_gui)
 
         # Load a copy of the relax interpreter.
@@ -274,6 +278,10 @@
             text = text + '\n'
             sys.__stdout__.write(text)
 
+            # Remove the Mac OS X task bar icon.
+            if hasattr(self, 'taskbar_icon'):
+                self.taskbar_icon.Destroy()
+
             # End application.
             sys.exit()
 




Related Messages


Powered by MHonArc, Updated Thu Jul 28 10:00:02 2011