home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from __future__ import with_statement
- import wx
- from common.emailaccount import EmailAccount
- import common.actions as actions
- from gui.textutil import default_font
- from common import pref
- from gui.skin import get as skin
- from gui.skin.skinobjects import SkinColor
- from util import Delegate
- from gui.uberwidgets.uberwidget import UberWidget
- from gui.uberwidgets.umenu import UMenu
- from logging import getLogger
- log = getLogger('accountlist')
- from gui.buddylist.accounttray import should_grey
- from gui.toolbox.refreshtimer import refreshtimer
-
- class AccountList(wx.VListBox, UberWidget):
-
- def __init__(self, parent, accts, infobox, skinkey, onDoubleClick = None, labelCallback = None):
- wx.VListBox.__init__(self, parent)
- self.SetSkinKey(skinkey)
- self._obs_link = None
- self.infobox = infobox
- infobox.Befriend(self)
- self.accts = accts
- self.willreconaccts = set()
- self.itemheight = 0
- self.UpdateSkin()
- Bind = self.Bind
- Bind(wx.EVT_MOTION, self.OnMouseMotion)
- Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseOut)
- Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
- Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDblClick)
- Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
- self.BuildList()
- self.menu = UMenu(self)
- self.OnDoubleClick = None(Delegate if onDoubleClick is not None else [])
- self.labelCallback = labelCallback
- self.BindObservers()
-
-
- def OnClose(self, e = None):
- log.info('OnClose: %r', self)
- self.UnbindObservers()
-
-
- def BindObservers(self):
- self._obs_link = self.accts.add_list_observer(self.BuildList, self.WhenStateChanged, 'state', 'enabled', 'count', 'offline_reason')
-
-
- def UnbindObservers(self):
- if self._obs_link is not None:
- self._obs_link.disconnect()
- self._obs_link = None
-
-
-
- def CalledAfterRefreshLine(self, acct):
-
- try:
- self.RefreshLine(self.active.index(acct))
- except ValueError:
- self.Refresh()
-
-
-
- def WhenStateChanged(self, acct, attr, old, new):
- if attr == 'count':
- wx.CallAfter(self.CalledAfterRefreshLine, acct)
- elif attr == 'enabled':
- wx.CallAfter(self.BuildList)
- elif attr == 'state' or attr == 'offline_reason':
- if acct.offline_reason == acct.Reasons.WILL_RECONNECT:
- self.willreconaccts.add(acct)
- else:
- self.willreconaccts.discard(acct)
- if len(self.willreconaccts):
- refreshtimer().Register(self)
- else:
- refreshtimer().UnRegister(self)
- self.Refresh()
-
-
-
- def OnMouseOut(self, event):
- i = self.Selection
- if i != -1:
- self.RefreshLine(i)
-
- self.Selection = -1
-
-
- def OnMouseMotion(self, event):
- self.Selection = i = self.HitTest(event.Position)
- self.TryShowInfobox(i)
-
-
- def OnLeftDown(self, event):
- self.infobox.quickshow = True
- self.TryShowInfobox(self.Selection)
-
-
- def TryShowInfobox(self, i):
- if pref('infobox.show', True) and i >= 0:
- p = self.Parent
- pl = p.ClientToScreen((0, self.Position.y + self.OnMeasureItem(0) * i))
- pr = pl + (p.Size.width, 0)
- self.infobox.Display(pl, pr, self.active[i])
-
-
-
- def OnLeftDblClick(self, event):
- self.OnDoubleClick(self.active[self.Selection])
- self.infobox.Hide()
-
-
- def OnRightUp(self, event):
- if self.Selection >= 0:
- self.menu.RemoveAllItems()
- acct = self.active[self.Selection]
- if isinstance(acct, EmailAccount):
- actions.menu(wx.FindWindowByName('Buddy List'), acct, menu = self.menu, search_bases = False, cls = EmailAccount)
- else:
- actions.menu(wx.FindWindowByName('Buddy List'), acct, menu = self.menu)
- self.menu.PopupMenu()
-
-
-
- def BuildList(self, *__):
-
- try:
- self._AccountList__i += 1
- except:
- self._AccountList__i = 1
-
- self.active = _[1]
- self.Frozen().__enter__()
-
- try:
- self.ItemCount = len(self.active)
- self.Top.Layout()
- self.Top.Refresh()
- finally:
- pass
-
- self.Refresh()
-
-
- def UpdateSkin(self):
-
- skinget = lambda s, default: skin('%s.%s' % (self.skinkey, s), default)
- self.padding = skinget('padding', (lambda : wx.Point(3, 3)))
- self.Font = skinget('font', default_font)
- self.iconsize = skinget('iconsize', 16)
- self.itemheight = max(self.iconsize, self.Font.LineHeight) + self.padding.y * 2
- default_color = SkinColor(wx.Color(225, 255, 225))
- self.bg = skinget('backgrounds.normal', default_color)
- self.selbg = skinget('backgrounds.hover', default_color)
- self.fontcolor = skinget('fontcolors.normal', wx.BLACK)
- self.selfontcolor = skinget('fontcolors.hover', wx.BLACK)
- self.MinSize = wx.Size(-1, self.itemheight * self.ItemCount)
-
-
- def OnMeasureItem(self, n):
- return self.itemheight
-
-
- def OnDrawBackground(self, dc, rect, n):
- None(getattr, self if self.Selection == n else 'bg').Draw(dc, rect, n)
-
-
- def OnDrawItem(self, dc, rect, n):
- dc.Font = self.Font
- dc.TextForeground = None if n == self.Selection else self.fontcolor
- acct = self.active[n]
- iconsize = self.iconsize
- if hasattr(acct, 'count') or acct.count > 0 or not should_grey(acct):
- icon = acct.icon.Resized(iconsize)
- else:
- icon = acct.icon.Greyed.Resized(iconsize)
- pad = self.padding.x
- dc.DrawBitmap(icon, rect.x + pad, rect.y + self.itemheight / 2 - icon.Height / 2, True)
- textRect = wx.Rect(rect.x + iconsize + 2 * pad, rect.y + self.itemheight / 2 - dc.Font.LineHeight / 2, rect.width - pad * 2, dc.Font.LineHeight)
- dc.DrawTruncatedText(self.labelCallback(acct), textRect)
-
-
-