home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 February / maximum-cd-2011-02.iso / DiscContents / digsby_setup85.exe / lib / gui / taskbar.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-11-24  |  4.9 KB  |  153 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import wx
  5. from gui.toolbox import to_icon
  6. from logging import getLogger
  7. log = getLogger('taskbar')
  8. import config
  9. from gui.animation import Animation
  10. DEFAULT_TASKBAR_ID = 99
  11.  
  12. class TaskBarIconBase(wx.TaskBarIcon):
  13.     
  14.     def __init__(self, id = DEFAULT_TASKBAR_ID):
  15.         
  16.         try:
  17.             wx.TaskBarIcon.__init__(self, id)
  18.         except TypeError:
  19.             wx.TaskBarIcon.__init__(self)
  20.  
  21.         if config.platform != 'mac':
  22.             self.Bind(wx.EVT_TASKBAR_RIGHT_UP, self.OnRightUp)
  23.         
  24.  
  25.     
  26.     def _IconSize(self):
  27.         return native_taskbar_icon_size()
  28.  
  29.     _IconSize = property(_IconSize)
  30.     
  31.     def Destroy(self):
  32.         if getattr(self, '_icon_destroyed', False):
  33.             return log.critical('destroyed %r already. not destroying it again', self)
  34.         log.info('Destroying %r', self)
  35.         self._icon_destroyed = True
  36.         wx.TaskBarIcon.Destroy(self)
  37.  
  38.     
  39.     def OnRightUp(self, e):
  40.         menu = self.CreatePopupMenu()
  41.         if menu is not None:
  42.             menu.PopupMenu()
  43.         
  44.  
  45.     
  46.     def CreatePopupMenu(self):
  47.         return self.Menu
  48.  
  49.     
  50.     def SetMenu(self, menu):
  51.         self._menu = menu
  52.         menu.Windowless = True
  53.  
  54.     
  55.     def GetMenu(self):
  56.         return getattr(self, '_menu', None)
  57.  
  58.     Menu = property(GetMenu, SetMenu)
  59.     
  60.     def Refresh(self):
  61.         if not wx.IsDestroyed(self):
  62.             self.SetIcon(self.GetIcon(), self._tooltip)
  63.         
  64.  
  65.  
  66.  
  67. class AnimatedTaskBarIcon(TaskBarIconBase):
  68.     
  69.     def __init__(self, id = DEFAULT_TASKBAR_ID):
  70.         TaskBarIconBase.__init__(self, id)
  71.         self.icons = [
  72.             None]
  73.         self.delays = [
  74.             1000]
  75.         self.animation = Animation()
  76.         self.animation.add_listener(self._update_tray)
  77.         self._tooltip = ''
  78.  
  79.     
  80.     def SetTooltip(self, tooltip):
  81.         if tooltip != self._tooltip:
  82.             self._tooltip = tooltip
  83.             self._update_tray()
  84.         
  85.  
  86.     
  87.     def UpdateAnimation(self, tooltip = None):
  88.         if tooltip is not None:
  89.             self._tooltip = tooltip
  90.         
  91.         self.animation.set_frames(self.icons, self.delays)
  92.  
  93.     
  94.     def _update_tray(self):
  95.         if not wx.IsDestroyed(self):
  96.             self._icon = self.animation.current_frame
  97.             self.SetIcon(self._icon, self._tooltip)
  98.         
  99.  
  100.     
  101.     def GetIcon(self):
  102.         return self._icon
  103.  
  104.  
  105.  
  106. class DigsbyTaskBarIcon(TaskBarIconBase):
  107.     
  108.     def __init__(self, icon, menu = None, tooltip = None, id = DEFAULT_TASKBAR_ID):
  109.         TaskBarIconBase.__init__(self, id)
  110.         if isinstance(icon, wx.WindowClass):
  111.             raise TypeError
  112.         isinstance(icon, wx.WindowClass)
  113.         self._tooltip = ''
  114.         if icon is not None:
  115.             self.SetIcon(icon, tooltip)
  116.         
  117.         if menu is not None:
  118.             self.Menu = menu
  119.         
  120.  
  121.     
  122.     def SetIcon(self, icon_or_bitmap, tooltip = None):
  123.         size = self._IconSize
  124.         self._icon = to_icon(icon_or_bitmap.PIL.ResizedSmaller(size).ResizeCanvas(size, size))
  125.         if tooltip is None:
  126.             tooltip = self._tooltip
  127.         else:
  128.             self._tooltip = tooltip
  129.         wx.TaskBarIcon.SetIcon(self, self._icon, tooltip)
  130.  
  131.     
  132.     def GetIcon(self):
  133.         return self._icon
  134.  
  135.     Icon = property(GetIcon, SetIcon)
  136.  
  137. if config.platform == 'mac':
  138.     
  139.     def native_taskbar_icon_size():
  140.         return 128
  141.  
  142. elif config.platform == 'gtk':
  143.     
  144.     def native_taskbar_icon_size():
  145.         return 20
  146.  
  147. else:
  148.     GetMetric = wx.SystemSettings.GetMetric
  149.     
  150.     def native_taskbar_icon_size():
  151.         return GetMetric(wx.SYS_SMALLICON_X)
  152.  
  153.