Package gui :: Module icons
[hide private]
[frames] | no frames]

Source Code for Module gui.icons

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2011 Edward d'Auvergne                                        # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  # Module docstring. 
 24  """All of the icons for relax.""" 
 25   
 26  # Python module imports. 
 27  from os import sep 
 28  import sys 
 29  import wx 
 30   
 31  # relax module imports. 
 32  from status import Status; status = Status() 
 33   
 34   
35 -class Relax_icons(wx.IconBundle):
36 """The icon bundle class of the main relax icons.""" 37
38 - def setup(self):
39 """Set up the icons after the main app is created.""" 40 41 # This is disabled on Macs. 42 if not 'darwin' in sys.platform: 43 self.AddIconFromFile(status.install_path + sep + 'graphics' + sep + 'ulysses.ico', wx.BITMAP_TYPE_ANY)
44 45
46 -class Relax_task_bar_icon(wx.TaskBarIcon):
47 """The icon for the Mac OS X task bar.""" 48 49 # Set up some ID numbers for the menu entries. 50 TBMENU_RESTORE = wx.NewId() 51 TBMENU_CLOSE = wx.NewId() 52
53 - def __init__(self, gui):
54 """Set up the task bar icon. 55 56 @param gui: The GUI object. 57 @type gui: wx.Frame instance 58 """ 59 60 # Store the args. 61 self.gui = gui 62 63 # Initilise the base class. 64 wx.TaskBarIcon.__init__(self) 65 66 # Set the task bar icon. 67 self.SetIcon(wx.Icon(status.install_path + sep + 'graphics' + sep + 'ulysses_shadowless_trans_128x128.png', wx.BITMAP_TYPE_ANY)) 68 69 # Bind mouse events. 70 self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.restore)
71 72
73 - def CreatePopupMenu(self):
74 """Create and return the task bar menu. 75 76 @return: The pop up menu. 77 @rtype: wx.Menu instance 78 """ 79 80 # Initialise the menu. 81 popup = wx.Menu() 82 83 # Add some menu entries. 84 popup.Append(self.TBMENU_RESTORE, "Restore relax") 85 popup.Append(self.TBMENU_CLOSE, "Exit relax") 86 87 # Bind the menu events. 88 self.Bind(wx.EVT_MENU, self.restore, id=self.TBMENU_RESTORE) 89 self.Bind(wx.EVT_MENU, self.exit, id=self.TBMENU_CLOSE) 90 91 # Return the menu. 92 return popup
93 94
95 - def exit(self, event):
96 """Exit relax from the task bar. 97 98 @param event: The wx event. 99 @type event: wx event 100 """ 101 102 # Exit relax. 103 wx.CallAfter(self.gui.exit_gui)
104 105
106 - def restore(self, event):
107 """Restore relax from the task bar. 108 109 @param event: The wx event. 110 @type event: wx event 111 """ 112 113 # Show relax. 114 if status.show_gui and not self.gui.IsShown(): 115 self.gui.Show(True) 116 117 # De-iconise relax. 118 if self.gui.IsIconized(): 119 self.gui.Iconize(False) 120 121 # Raise relax to the top of the window hierarchy. 122 self.gui.Raise()
123 124 125 # Set up the main set of icons for relax. 126 relax_icons = Relax_icons() 127