home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- import util.primitives.strings as strings
- DEFAULT_NOICON_OPACITY = 0.4
- import wx
- from wx import ALIGN_LEFT, ALIGN_CENTER_VERTICAL, Font, Rect, ALIGN_BOTTOM, FONTFAMILY_DEFAULT, FONTSTYLE_ITALIC, FONTSTYLE_NORMAL, FONTWEIGHT_BOLD, FONTWEIGHT_NORMAL, SystemSettings_GetColour, Point, ALIGN_RIGHT, ALIGN_CENTER
- lmiddle = ALIGN_LEFT | ALIGN_CENTER_VERTICAL
- LBOTTOM = ALIGN_LEFT | ALIGN_BOTTOM
- RBOTTOM = ALIGN_RIGHT | ALIGN_BOTTOM
- from gui.toolbox import get_wxColor
- from gui.textutil import default_font, TruncateText
- from util import isiterable, do, Storage as S, try_this, nicetimecount, memoize
- from util.lrucache import lru_cache
- from contacts import MetaContact
- from time import time
- from logging import getLogger
- log = getLogger('renderers')
- info = log.info
- from common import pref, prefprop
- from gui import skin
- from gui.skin.skinobjects import SkinColor, Margins
-
- syscol = lambda s: SkinColor(SystemSettings_GetColour(s))
- from wx import Rect
- from PIL import Image
- from os.path import join
- from traceback import print_exc
- import sys
- replace_newlines = lru_cache(100)(strings.replace_newlines)
-
- def get_contact_status(contact):
- msg = contact.stripped_msg
- return None if msg is not None and contact.online else ''
-
- _cached_noicon = None
- from gui.toolbox.imagefx import pil_setalpha
-
- def _load_noicon():
-
- try:
- return skin.get('BuddiesPanel.BuddyIcons.NoIcon').PIL
- except:
- return Image.open(skin.resourcedir() / 'AppDefaults' / 'contact.png')
-
-
-
- def get_no_icon(with_transparency = False):
- global _cached_noicon
-
- try:
- return _cached_noicon[int(with_transparency)]
- except TypeError:
- pass
-
- img = _load_noicon()
- imgnoalpha = img.copy()
-
- try:
- alpha = skin.get('BuddiesPanel.BuddyIcons.NoIconAlpha', '75%').strip().rstrip('%')
- alpha_opacity = float(alpha) / 100
- except:
- alpha_opacity = DEFAULT_NOICON_OPACITY
-
- pil_setalpha(img, alpha_opacity)
- _cached_noicon = (imgnoalpha, img)
- return _cached_noicon[int(with_transparency)]
-
-
- def print_bicon_exc(buddykey):
- print_exc()
-
- if not getattr(sys, 'DEV', False) or True:
- print_bicon_exc = memoize(print_bicon_exc)
-
-
- def _geticon(buddy):
-
- try:
- icon = buddy.icon
- except Exception:
- print_bicon_exc(buddy.info_key)
- return None
-
-
- try:
- if icon is not None:
-
- try:
- extrema = icon._extrema
- except AttributeError:
- extrema = icon._extrema = icon.getextrema()
-
- if extrema != (0, 0) and not all((lambda .0: for e in .0:
- e == (0, 0))(extrema)):
- return icon
-
- except Exception:
- e = None
-
- try:
- print_bicon_exc(buddy.info_key)
- except Exception:
- pass
- except:
- None<EXCEPTION MATCH>Exception
-
-
- None<EXCEPTION MATCH>Exception
-
-
-
- def get_buddy_icon_path(buddy):
- icon = _geticon(buddy)
- if icon is None:
- return skin.get('BuddiesPanel.BuddyIcons.NoIcon').path
- else:
- return buddy.icon_path
-
-
- def get_buddy_icon(buddy, size = None, round_size = 1, grey_offline = True, with_transparency = False):
- icon = _geticon(buddy)
- isno = icon is None
- icon = None if isno else icon
- icon = None if size else icon
- if isno or not round_size:
- i = None if grey_offline and not (buddy.online) else icon.WXB
- else:
- i = icon.Rounded(round_size).WXB
- i = None if grey_offline and not (buddy.online) else i
- return i
-
-
- def get_idle_string(contact):
- idle = getattr(contact, 'idle', None)
- if idle in (True, False, None):
- return ''
- elif isinstance(idle, (int, long)):
- diff = int(time() - idle)
- if diff != 0:
- return _get_idle_string_from_seconds(diff)
- else:
- return ''
- else:
- return ''
-
-
- def _get_idle_string_from_seconds(secs):
- (mins, secs) = divmod(secs, 60)
- (hours, mins) = divmod(mins, 60)
- (days, hours) = divmod(hours, 24)
- timeStr = ''
- if days:
- return '(%dd)' % int(days)
-
- if hours > 0:
- timeStr += '%d' % int(hours) + ':'
- timeStr += '%02d' % int(mins)
- else:
- mins = int(mins)
- if mins < 10:
- timeStr += '%dm' % mins
- else:
- timeStr += '%02dm' % mins
- return None if timeStr else ''
-
- _get_idle_string_from_seconds = lru_cache(100)(_get_idle_string_from_seconds)
-
- def get_prefs():
-
- try:
- profile = profile
- import common
- return profile.prefs
- except ImportError:
- ObservableDict = ObservableDict
- import util.observe
- return ObservableDict()
-
-
-
- def safefont(name, size, bold = False):
- weight = None if bold else FONTWEIGHT_NORMAL
-
- try:
- return Font(size, FONTFAMILY_DEFAULT, FONTSTYLE_NORMAL, weight, False, name)
- except:
- print_exc()
- font = default_font()
- font.SetPointSize(size)
- font.SetWeight(weight)
- return font
-
-
-
- class Renderer(object):
-
- def __init__(self, parent):
- self.parent = parent
- self.prefs = get_prefs()
- self.skin = S(fontcolors = S())
-
-
- def UpdateSkin(self):
- s = self.skin
- g = skin.get
- s.bg = g('BuddiesPanel.Backgrounds.Buddy', (lambda : syscol(wx.SYS_COLOUR_LISTBOX)))
- s.selectedbg = g('BuddiesPanel.Backgrounds.BuddySelected', (lambda : syscol(wx.SYS_COLOUR_HIGHLIGHT)))
- s.hoverbg = g('BuddiesPanel.Backgrounds.BuddyHover', (lambda : syscol(wx.SYS_COLOUR_LISTBOX)))
-
-
- def getpref(self, prefname, default = None):
- return pref('buddylist.layout.%s' % prefname, default)
-
-
- def attrlink(self, attr):
- return self.prefs.link(('buddylist.layout.%s' % attr,), (lambda val: (self.calcsizes(), self.parent.list_changed())), False, obj = self)
-
-
- def draw_background(self, obj, dc, rect, n, selected, hover):
- s = self.skin
- if selected and s.selectedbg:
- s.selectedbg.Draw(dc, rect, n)
- elif hover and s.hoverbg:
- s.hoverbg.Draw(dc, rect, n)
- elif s.bg:
- s.bg.Draw(dc, rect, n)
-
-
-
-
- class GroupCellRenderer(Renderer):
-
- def __init__(self, parent):
- Renderer.__init__(self, parent)
- layout_attrs = '\n name_font_face\n name_font_size\n padding\n '.strip().split()
- (do,)((lambda .0: for attr in .0:
- self.attrlink(attr))(layout_attrs))
- self.UpdateSkin()
-
-
- def UpdateSkin(self):
- Renderer.UpdateSkin(self)
- s = self.skin
- s.margins = skin.get('BuddiesPanel.GroupMargins')
- s.padding = skin.get('BuddiesPanel.GroupPadding', (lambda : Point(4, 4)))
-
- g = lambda k, default = sentinel: skin.get('BuddiesPanel.GroupIcons.' + k, default)
- s.expanded = g('Expanded', (lambda : pass))
- s.expandedhover = g(('ExpandedHover',), (lambda : s.expanded))
- s.expandedselected = g(('ExpandedSelected',), (lambda : s.expanded))
- s.collapsed = g('Collapsed', (lambda : pass))
- s.collapsedhover = g('CollapsedHover', s.collapsed)
- s.collapsedselected = g('CollapsedSelected', s.collapsed)
-
- g = lambda k, default: skin.get('BuddiesPanel.Backgrounds.' + k, default)
- s.bg = g(('Group',), (lambda : g('Buddy')))
- s.hoverbg = g(('GroupHover',), (lambda : g('BuddyHover')))
- s.selectedbg = g(('GroupSelected',), (lambda : g('BuddySelected')))
- f = s.fontcolors
-
- g = lambda k, default: skin.get('BuddiesPanel.FontColors.' + k, default)
- f.group = g(('Group',), (lambda : g('Buddy', (lambda : syscol(wx.SYS_COLOUR_WINDOWTEXT)))
- ))
- f.grouphover = g(('GroupHover',), (lambda : g('BuddyHover', (lambda : syscol(wx.SYS_COLOUR_WINDOWTEXT)))
- ))
- f.groupselected = g(('GroupSelected',), (lambda : g('BuddySelected', (lambda : syscol(wx.SYS_COLOUR_HIGHLIGHTTEXT)))
- ))
- self.calcsizes()
-
-
- def item_height(self, obj):
- return int(self.group_height)
-
-
- def calcsizes(self):
- p = self.getpref
- margins = self.skin.margins
- padding = self.skin.padding
- self.mainfont = safefont(p('name_font_face', None), (try_this,)((lambda : int(p('name_font_size'))), 10))
- self.mainfont_height = self.mainfont.LineHeight
- self.group_height = int(self.mainfont_height) + margins.top + margins.bottom + padding.y * 2
- self.depth_indent = p('indent', 5)
-
- font_face = prefprop('buddylist.layout.name_font_face', None)
- font_size = prefprop('buddylist.layout.name_font_size', None)
- group_indent = prefprop('buddylist.layout.indent', 0)
-
- def Draw(self, dc, rect, selected, obj, depth, expanded, index, hover):
- s = self.skin
- rect = rect.AddMargins(wx.Rect(*s.margins)).AddMargins(wx.Rect(0, s.padding.y, 0, s.padding.y))
- fontface = self.font_face
- font = safefont(fontface, (try_this,)((lambda : int(self.font_size)), 10), bold = True)
- dc.SetFont(font)
- rect = rect.Subtract(left = self.group_indent * depth)
- if isiterable(obj):
- triangle = self.get_expander(selected, expanded, hover)
- if triangle is not None:
- dc.DrawBitmap(triangle, rect.x, rect.VCenter(triangle), True)
- rect = rect.Subtract(left = triangle.Width + s.padding.x)
-
-
- if selected:
- fg = s.fontcolors.groupselected
- elif hover:
- fg = s.fontcolors.grouphover
- else:
- fg = s.fontcolors.group
- dc.SetTextForeground(fg)
- dc.DrawTruncatedText(obj.display_string, rect, alignment = lmiddle)
-
-
- def get_expander(self, selected, expanded, hover):
- iconname = None if expanded else 'collapsed'
- if selected:
- iconname += 'selected'
- elif hover:
- iconname += 'hover'
-
- return getattr(self.skin, iconname, None)
-
-
-
- class ContactCellRenderer(Renderer):
-
- def __init__(self, parent):
- Renderer.__init__(self, parent)
- self._lastcalc = None
- self.layout_attrs = '\n name_font_face\n name_font_size\n show_extra\n extra_info\n extra_font_face\n extra_font_size\n extra_padding\n show_buddy_icon\n buddy_icon_pos\n badge_max_size\n badge_min_size\n show_status_icon\n status_icon_pos\n status_icon_size\n show_service_icon\n service_icon_pos\n badge_ratio\n buddy_icon_size\n service_icon_size\n side_icon_size\n padding\n indent\n grey_offline\n '.strip().split()
- (do,)((lambda .0: for attr in .0:
- self.attrlink(attr))(self.layout_attrs))
- self.UpdateSkin()
-
-
- def UpdateSkin(self):
- Renderer.UpdateSkin(self)
- self.drawseqs = { }
- self._lastcalc = []
- s = self.skin
- g = skin.get
- self.statusicons = g('statusicons')
- s.margins = g('BuddiesPanel.BuddyMargins')
- s.icon_frame = g('BuddiesPanel.BuddyIcons.Frame', None)
- s.icon_frame_size = Margins(g('BuddiesPanel.BuddyIcons.FrameSize', (0, 0, 0, 0)))
- s.round_corners = (try_this,)((lambda : int(g('BuddiesPanel.BuddyIcons.Rounded', 1))), 1)
- f = s.fontcolors
-
- g = lambda k, default: skin.get('BuddiesPanel.FontColors.' + k, default)
- f.buddy = g('Buddy', (lambda : syscol(wx.SYS_COLOUR_WINDOWTEXT)))
- f.buddyoffline = g('BuddyOffline', (lambda : syscol(wx.SYS_COLOUR_GRAYTEXT)))
- f.buddyselected = g('BuddySelected', (lambda : syscol(wx.SYS_COLOUR_HIGHLIGHTTEXT)))
- f.buddyhover = g(('BuddyHover',), (lambda : f.buddy))
- f.status = g(('Status',), (lambda : f.buddy))
- f.statushover = g(('StatusHover',), (lambda : f.buddyhover))
- f.statusselected = g(('StatusSelected',), (lambda : f.buddyselected))
- f.idletime = g('IdleTime', (lambda : syscol(wx.SYS_COLOUR_GRAYTEXT)))
- f.idletimehover = g('IdleTimeHover', (lambda : syscol(wx.SYS_COLOUR_GRAYTEXT)))
- f.idletimeselected = g('IdleTimeSelected', (lambda : syscol(wx.SYS_COLOUR_HIGHLIGHTTEXT)))
- self.icons = [
- 'service_icon',
- 'status_icon',
- 'buddy_icon']
- self.calcsizes()
-
-
- def calcsizes(self):
- p = self.getpref
- s = self.skin
- padding = p('padding', 4)
- (None, do)((lambda .0: for k in .0:
- setattr(self, k.replace('.', '_'), p(k)))(self.layout_attrs))
- sz = int(p('name_font_size', 10))
- self.mainfont = safefont(p('name_font_face', None), sz)
- self.mainfont.Style = FONTSTYLE_NORMAL
- self.mainfont_height = mainfont_height = self.mainfont.LineHeight
- self.extrafont = safefont(p('extra_font_face', None), int(p('extra_font_size', 10)))
- self.extrafont_height = extrafont_height = self.extrafont.LineHeight
- self.depth_indent = p('indent', 5)
- icon_size = p('buddy_icon_size', 0)
- if s.icon_frame_size:
- icon_size += s.icon_frame_size.top + s.icon_frame_size.bottom
-
- show_icon = p('show_buddy_icon', False)
- extraheight = None if p('show_extra', True) and p('extra_info', 'status') in ('status', 'both') else 0
- margins = self.skin.margins
- self.cell_height = None + padding * 2(max if show_icon else 0, mainfont_height + extraheight) + margins.top + margins.bottom
- if self.cell_height < mainfont_height * 1.2:
- self.cell_height = mainfont_height * 1.2
-
- self.drawseqs.clear()
- self._serviceiconcache = { }
- self._lastcalc = None
- return self.cell_height
-
-
- def calcdraw(self, w, h, Rect = Rect):
- if self._lastcalc == (w, h):
- return self._lastseq
-
- s = self.skin
- rect = Rect(0, 0, w, h).AddMargins(wx.Rect(*s.margins))
- icons = (sorted,)((lambda .0: for icon in .0:
- (icon, getattr(self, icon + '_pos')))(self.icons), key = (lambda o: {
- 'f': -1,
- 'b': 1 }.get(o[1][0], 0)))
- seq = []
- last = Rect()
- badge_size = min(self.badge_max_size, max(self.badge_min_size, int(self.buddy_icon_size * self.badge_ratio)))
- frame_size = s.icon_frame_size
- padding = self.padding
- hpadding = 4
- for icon, pos in icons:
- if getattr(self, 'show_' + icon):
- pos = pos.lower()
- size = getattr(self, icon + '_size')
- left = pos.endswith('left')
- iconpos = Point(-size * int(not left), 0)
- if icon == 'buddy_icon':
- iconw = size + frame_size.left + frame_size.right
- frameRect = Rect(0, 0, iconw, size + frame_size.top + frame_size.bottom)
- frameRect.x = rect.Pos(wx.Point(-(frameRect.width) * int(not left), 0))[0]
- frameRect.y = rect.VCenterH(frameRect.height)
- last = Rect(frameRect.x + frame_size.left, frameRect.y + frame_size.top, size, size)
- seq += [
- (getattr(self, 'get_buddy_icon'), last, 0)]
- seq += [
- (getattr(self, 'get_frame_icon'), frameRect, 0)]
- iconw + hpadding[{ } if left else 'right'] = { }
- rect = None(**rect.Subtract)
- bitmap = getattr(self, 'get_' + icon)
- elif not pos.startswith('b'):
- r = Rect(rect.Pos(iconpos)[0], rect.VCenterH(size), size, size)
- size + hpadding[{ } if left else 'right'] = { }
- rect = None(**rect.Subtract)
- last = r
- alignment = ALIGN_CENTER
- bitmap = getattr(self, 'get_' + icon)
- else:
- bp = badge_size
- alignment = None if left else RBOTTOM
- badgepos = None(last.Pos(wx.Point if left else -bp, -bp))
- r = Rect(badgepos[0], badgepos[1], badge_size, badge_size)
-
- bitmap = lambda obj, icon = (None, icon): getattr(self, 'get_' + icon)(obj).ResizedSmaller(badge_size)
- seq.append((bitmap, r, alignment))
- continue
-
- self.inforect = rect
- self._lastcalc = (w, h)
- self._lastseq = seq
- return seq
-
-
- def Draw(self, dc, rect, selected, obj, depth, expanded, index, hover, Rect = Rect):
- DrawBitmap = dc.DrawBitmap
- DrawTruncatedText = dc.DrawTruncatedText
- idle_string = get_idle_string(obj)
- extrafont = self.extrafont
- extra_info = None if self.show_extra else None
- msg = get_contact_status(obj)
- padding = self.padding
- extra_padding = self.extra_padding
- contact_name = obj.alias
- mainfont_height = self.mainfont_height
- for method, r, align in self.calcdraw(rect.width, rect.height):
-
- try:
- b = method(obj)
- except:
- print_exc()
- continue
-
- if b:
- b.Draw(dc, Rect(rect.x + r.x, rect.y + r.y, r.width, r.height), align)
- continue
-
- rect = rect.AddMargins(wx.Rect(*self.skin.margins))
- rect.x = self.inforect.x
- rect.width = self.inforect.width
- if msg and extra_info in ('status', 'both'):
- th = self.mainfont.LineHeight + extra_padding + self.extrafont_height
- rect = Rect(rect.x, rect.VCenterH(th), rect.width, rect.height)
- namerect = Rect(rect.x, rect.y + 1, rect.Width, self.mainfont.LineHeight)
- inforect = Rect(rect.x, rect.y + self.mainfont.LineHeight + extra_padding, rect.Width, self.extrafont_height)
- DrawTruncatedText(self.get_contact_info(obj, dc, selected, expanded, hover), inforect, alignment = lmiddle)
- else:
- namerect = rect
- hpadding = 4
- if idle_string and extra_info in ('idle', 'both'):
- (namew, nameh, namedescent, __) = dc.GetFullTextExtent(contact_name, self.mainfont)
- (w, h, desc, __) = dc.GetFullTextExtent(idle_string, extrafont)
- iy = 3
- diff = namew + w + hpadding - namerect.width
- if diff > 0:
- x = namerect.Pos((-w, 0))[0]
- y = namerect.Y
- r = Rect(x, y, w, namerect.Height)
- namerect = namerect.Subtract(right = w + hpadding)
- else:
- r = Rect(namerect.X + namew + hpadding, namerect.Y, w, namerect.Height)
- self.set_idle_time_dc(obj, dc, selected, expanded, hover)
- dc.DrawLabel(idle_string, r, ALIGN_LEFT | ALIGN_CENTER_VERTICAL)
-
- self.set_contact_name_dc(obj, dc, selected, expanded, hover)
- DrawTruncatedText(contact_name, namerect, alignment = lmiddle)
-
-
- def get_buddy_icon(self, contact, *a):
- return get_buddy_icon(contact, self.buddy_icon_size, self.skin.round_corners, self.grey_offline, with_transparency = True)
-
-
- def get_frame_icon(self, contact, *a):
- return self.skin.icon_frame
-
-
- def get_service_icon(self, contact, *a):
- icon = contact.serviceicon
- if max(icon.Width, icon.Height) > self.service_icon_size:
- icon = icon.Resized(self.service_icon_size)
-
- if self.grey_offline and not (contact.online):
- icon = icon.Greyed
-
- return icon
-
-
- def get_status_icon(self, contact, *a):
- icon = skin.get('statusicons.' + contact.status_orb)
- if max(icon.Width, icon.Height) > self.status_icon_size:
- return icon.Resized(self.status_icon_size)
- else:
- return icon
-
-
- def set_contact_name_dc(self, contact, dc, selected, expanded, hover):
- fontcolors = self.skin.fontcolors
- online = contact.online
- if selected:
- fg = fontcolors.buddyselected
- elif hover:
- fg = fontcolors.buddyhover
- elif not online:
- fg = fontcolors.buddyoffline
- else:
- fg = fontcolors.buddy
- dc.TextForeground = fg
- mainfont = self.mainfont
- None(mainfont.SetStyle if online else FONTSTYLE_ITALIC)
- None(mainfont.SetWeight if getattr(contact, 'entering', False) else FONTWEIGHT_NORMAL)
- dc.SetFont(mainfont)
-
-
- def set_idle_time_dc(self, contact, dc, selected, expanded, hover):
- fontcolors = self.skin.fontcolors
- if selected:
- fg = fontcolors.idletimeselected
- elif hover:
- fg = fontcolors.idletimehover
- else:
- fg = fontcolors.idletime
- dc.TextForeground = fg
- dc.Font = self.extrafont
-
-
- def get_contact_info(self, contact, dc, selected, expanded, hover):
- fontcolors = self.skin.fontcolors
- if selected:
- fg = fontcolors.statusselected
- elif hover:
- fg = fontcolors.statushover
- else:
- fg = fontcolors.status
- dc.TextForeground = fg
- dc.SetFont(self.extrafont)
- return get_contact_status(contact)
-
-
- def item_height(self, obj):
- return int(self.cell_height)
-
-
-
- class MetaContactCellRenderer(ContactCellRenderer):
-
- def __init__(self, parent):
- ContactCellRenderer.__init__(self, parent)
-
-
-