home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 June / maximum-cd-2009-06.iso / DiscContents / digsby_setup.exe / lib / gui / buddylist / accountlist.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-02-26  |  7.9 KB  |  190 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import with_statement
  5. import wx
  6. from common.emailaccount import EmailAccount
  7. import common.actions as actions
  8. from gui.textutil import default_font
  9. from common import pref
  10. from gui.skin import get as skin
  11. from gui.skin.skinobjects import SkinColor
  12. from util import Delegate
  13. from gui.uberwidgets.uberwidget import UberWidget
  14. from gui.uberwidgets.umenu import UMenu
  15. from logging import getLogger
  16. log = getLogger('accountlist')
  17. from gui.buddylist.accounttray import should_grey
  18. from gui.toolbox.refreshtimer import refreshtimer
  19.  
  20. class AccountList(wx.VListBox, UberWidget):
  21.     
  22.     def __init__(self, parent, accts, infobox, skinkey, onDoubleClick = None, labelCallback = None):
  23.         wx.VListBox.__init__(self, parent)
  24.         self.SetSkinKey(skinkey)
  25.         self._obs_link = None
  26.         self.infobox = infobox
  27.         infobox.Befriend(self)
  28.         self.accts = accts
  29.         self.willreconaccts = set()
  30.         self.itemheight = 0
  31.         self.UpdateSkin()
  32.         Bind = self.Bind
  33.         Bind(wx.EVT_MOTION, self.OnMouseMotion)
  34.         Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseOut)
  35.         Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
  36.         Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDblClick)
  37.         Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
  38.         self.BuildList()
  39.         self.menu = UMenu(self)
  40.         self.OnDoubleClick = None(Delegate if onDoubleClick is not None else [])
  41.         self.labelCallback = labelCallback
  42.         self.BindObservers()
  43.  
  44.     
  45.     def OnClose(self, e = None):
  46.         log.info('OnClose: %r', self)
  47.         self.UnbindObservers()
  48.  
  49.     
  50.     def BindObservers(self):
  51.         self._obs_link = self.accts.add_list_observer(self.BuildList, self.WhenStateChanged, 'state', 'enabled', 'count', 'offline_reason')
  52.  
  53.     
  54.     def UnbindObservers(self):
  55.         if self._obs_link is not None:
  56.             self._obs_link.disconnect()
  57.             self._obs_link = None
  58.         
  59.  
  60.     
  61.     def CalledAfterRefreshLine(self, acct):
  62.         
  63.         try:
  64.             self.RefreshLine(self.active.index(acct))
  65.         except ValueError:
  66.             self.Refresh()
  67.  
  68.  
  69.     
  70.     def WhenStateChanged(self, acct, attr, old, new):
  71.         if attr == 'count':
  72.             wx.CallAfter(self.CalledAfterRefreshLine, acct)
  73.         elif attr == 'enabled':
  74.             wx.CallAfter(self.BuildList)
  75.         elif attr == 'state' or attr == 'offline_reason':
  76.             if acct.offline_reason == acct.Reasons.WILL_RECONNECT:
  77.                 self.willreconaccts.add(acct)
  78.             else:
  79.                 self.willreconaccts.discard(acct)
  80.             if len(self.willreconaccts):
  81.                 refreshtimer().Register(self)
  82.             else:
  83.                 refreshtimer().UnRegister(self)
  84.             self.Refresh()
  85.         
  86.  
  87.     
  88.     def OnMouseOut(self, event):
  89.         i = self.Selection
  90.         if i != -1:
  91.             self.RefreshLine(i)
  92.         
  93.         self.Selection = -1
  94.  
  95.     
  96.     def OnMouseMotion(self, event):
  97.         self.Selection = i = self.HitTest(event.Position)
  98.         self.TryShowInfobox(i)
  99.  
  100.     
  101.     def OnLeftDown(self, event):
  102.         self.infobox.quickshow = True
  103.         self.TryShowInfobox(self.Selection)
  104.  
  105.     
  106.     def TryShowInfobox(self, i):
  107.         if pref('infobox.show', True) and i >= 0:
  108.             p = self.Parent
  109.             pl = p.ClientToScreen((0, self.Position.y + self.OnMeasureItem(0) * i))
  110.             pr = pl + (p.Size.width, 0)
  111.             self.infobox.Display(pl, pr, self.active[i])
  112.         
  113.  
  114.     
  115.     def OnLeftDblClick(self, event):
  116.         self.OnDoubleClick(self.active[self.Selection])
  117.         self.infobox.Hide()
  118.  
  119.     
  120.     def OnRightUp(self, event):
  121.         if self.Selection >= 0:
  122.             self.menu.RemoveAllItems()
  123.             acct = self.active[self.Selection]
  124.             if isinstance(acct, EmailAccount):
  125.                 actions.menu(wx.FindWindowByName('Buddy List'), acct, menu = self.menu, search_bases = False, cls = EmailAccount)
  126.             else:
  127.                 actions.menu(wx.FindWindowByName('Buddy List'), acct, menu = self.menu)
  128.             self.menu.PopupMenu()
  129.         
  130.  
  131.     
  132.     def BuildList(self, *__):
  133.         
  134.         try:
  135.             self._AccountList__i += 1
  136.         except:
  137.             self._AccountList__i = 1
  138.  
  139.         self.active = _[1]
  140.         self.Frozen().__enter__()
  141.         
  142.         try:
  143.             self.ItemCount = len(self.active)
  144.             self.Top.Layout()
  145.             self.Top.Refresh()
  146.         finally:
  147.             pass
  148.  
  149.         self.Refresh()
  150.  
  151.     
  152.     def UpdateSkin(self):
  153.         
  154.         skinget = lambda s, default: skin('%s.%s' % (self.skinkey, s), default)
  155.         self.padding = skinget('padding', (lambda : wx.Point(3, 3)))
  156.         self.Font = skinget('font', default_font)
  157.         self.iconsize = skinget('iconsize', 16)
  158.         self.itemheight = max(self.iconsize, self.Font.LineHeight) + self.padding.y * 2
  159.         default_color = SkinColor(wx.Color(225, 255, 225))
  160.         self.bg = skinget('backgrounds.normal', default_color)
  161.         self.selbg = skinget('backgrounds.hover', default_color)
  162.         self.fontcolor = skinget('fontcolors.normal', wx.BLACK)
  163.         self.selfontcolor = skinget('fontcolors.hover', wx.BLACK)
  164.         self.MinSize = wx.Size(-1, self.itemheight * self.ItemCount)
  165.  
  166.     
  167.     def OnMeasureItem(self, n):
  168.         return self.itemheight
  169.  
  170.     
  171.     def OnDrawBackground(self, dc, rect, n):
  172.         None(getattr, self if self.Selection == n else 'bg').Draw(dc, rect, n)
  173.  
  174.     
  175.     def OnDrawItem(self, dc, rect, n):
  176.         dc.Font = self.Font
  177.         dc.TextForeground = None if n == self.Selection else self.fontcolor
  178.         acct = self.active[n]
  179.         iconsize = self.iconsize
  180.         if hasattr(acct, 'count') or acct.count > 0 or not should_grey(acct):
  181.             icon = acct.icon.Resized(iconsize)
  182.         else:
  183.             icon = acct.icon.Greyed.Resized(iconsize)
  184.         pad = self.padding.x
  185.         dc.DrawBitmap(icon, rect.x + pad, rect.y + self.itemheight / 2 - icon.Height / 2, True)
  186.         textRect = wx.Rect(rect.x + iconsize + 2 * pad, rect.y + self.itemheight / 2 - dc.Font.LineHeight / 2, rect.width - pad * 2, dc.Font.LineHeight)
  187.         dc.DrawTruncatedText(self.labelCallback(acct), textRect)
  188.  
  189.  
  190.