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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from __future__ import with_statement
  5. import sys
  6. import wx
  7. from wx import Rect, RectS, BLACK
  8. from datetime import datetime
  9. from gui import skin
  10. from gui.textutil import default_font, CopyFont
  11. from gui.skin.skinobjects import SkinColor
  12. from gui.toolbox import add_image_text
  13. from gui.uberwidgets.pseudosizer import PseudoSizer
  14. from gui.uberwidgets.clearlink import ClearLink
  15. from cgui import SimplePanel
  16. from common import actions
  17. link_style = wx.NO_BORDER | wx.HL_ALIGN_LEFT | wx.TRANSPARENT_WINDOW
  18.  
  19. class Header(SimplePanel):
  20.     
  21.     def __init__(self, parent):
  22.         SimplePanel.__init__(self, parent)
  23.         self.account = None
  24.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  25.         self.linkage = PseudoSizer()
  26.         self.UpdateSkin()
  27.  
  28.     
  29.     def SetAccount(self, account):
  30.         if account is self.account:
  31.             return None
  32.         
  33.         if self.account is not None:
  34.             
  35.             try:
  36.                 self.account.unobserve_count(self.Refreshxor)
  37.             except NotImplementedError:
  38.                 pass
  39.  
  40.             
  41.             try:
  42.                 self.account.unobserve_state(self.Refreshxor)
  43.             except NotImplementedError:
  44.                 pass
  45.             except:
  46.                 None<EXCEPTION MATCH>NotImplementedError
  47.             
  48.  
  49.         None<EXCEPTION MATCH>NotImplementedError
  50.         self.account = account
  51.         self.icon = account.icon.Resized(16)
  52.         self.linkage.Clear(True)
  53.         for linkfunc in account.header_funcs:
  54.             link = ClearLink(self, -1, linkfunc[0], (lambda l = (linkfunc,): self.do_link(l)), style = link_style, pos = (-400, -400))
  55.             link.NormalColour = link.HoverColour = link.VisitedColour = self.linkfc
  56.             link.Font = self.linkfont
  57.             self.linkage.Add(link)
  58.         
  59.         self.linkage.Layout()
  60.         
  61.         try:
  62.             account.observe_count(self.Refreshxor)
  63.         except NotImplementedError:
  64.             pass
  65.  
  66.         
  67.         try:
  68.             account.observe_state(self.Refreshxor)
  69.         except NotImplementedError:
  70.             pass
  71.  
  72.         self.Refresh(False)
  73.  
  74.     
  75.     def do_link(self, link):
  76.         if len(link) > 2:
  77.             if link[2]:
  78.                 wx.GetTopLevelParent(self).Hide()
  79.             
  80.         else:
  81.             wx.GetTopLevelParent(self).Hide()
  82.         if callable(link[1]):
  83.             link[1]()
  84.         else:
  85.             wx.LaunchDefaultBrowser(link[1])
  86.  
  87.     
  88.     def Refreshxor(self, *a):
  89.         self.Refresh(False)
  90.  
  91.     
  92.     def UpdateSkin(self):
  93.         self.padding = wx.Point(4, 4)
  94.         self.headerfont = skin.get('infobox.fonts.header', (lambda : default_font()))
  95.         self.linkfont = CopyFont(skin.get('infobox.fonts.link', (lambda : default_font())), underline = True)
  96.         self.headerfc = skin.get('infobox.fontcolors.navbarheader', (lambda : wx.BLACK))
  97.         self.linkfc = skin.get('infobox.fontcolors.navbarlink', (lambda : wx.BLUE))
  98.         linkposy = self.headerfont.Height + 2 * self.padding[1]
  99.         linkposx = self.padding[0] * 2 + 16
  100.         self.linkage.SetPosition((linkposx, linkposy))
  101.         for link in self.linkage:
  102.             link.NormalColour = link.HoverColour = link.VisitedColour = self.linkfc
  103.             link.Font = self.linkfont
  104.         
  105.         self.linkage.Layout()
  106.         self.bg = skin.get('infobox.backgrounds.header', (lambda : SkinColor(wx.Color(225, 255, 225))))
  107.         self.Size = self.MinSize = wx.Size(-1, self.headerfont.Height + self.linkfont.Height + self.padding.y * 4)
  108.  
  109.     
  110.     def OnPaint(self, event):
  111.         dc = wx.BufferedPaintDC(self)
  112.         rect = RectS(self.Size)
  113.         (padx, pady) = self.padding
  114.         self.bg.Draw(dc, rect)
  115.         dc.Font = self.headerfont
  116.         font_height = self.headerfont.Height
  117.         dc.TextForeground = self.headerfc
  118.         dc.DrawBitmap(self.icon, padx, padx + font_height // 2 - self.icon.Height // 2, True)
  119.         printable = rect.width - padx
  120.         curserx = rect.x + 2 * padx + self.icon.Width
  121.         cursery = rect.y + pady
  122.         dc.DrawLabel(self.account.display_name, wx.Rect(curserx, cursery, printable - curserx, font_height))
  123.         curserx += dc.GetTextExtent(self.account.display_name + ' ')[0]
  124.         if getattr(self.account, 'service', None) != 'twitter':
  125.             None(dc.DrawLabel if not hasattr(self.account, 'count') else '(' + str(self.account.count) + ')', Rect(curserx, cursery, printable - curserx, dc.Font.Height))
  126.         
  127.  
  128.  
  129.  
  130. class EmailList(wx.VListBox):
  131.     
  132.     def __init__(self, parent):
  133.         wx.VListBox.__init__(self, parent)
  134.         import common.favicons as common
  135.         common.favicons.on_icon += self.OnFaviconReceived
  136.         self.emails = []
  137.         self.account = None
  138.         self.itemheight = 0
  139.         self.SetItemCount(len(self.emails))
  140.         self.linkage = PseudoSizer()
  141.         self.linkage.Show(False)
  142.         self.errorlink = None
  143.         self.UpdateSkin()
  144.         links = [
  145.             ('olink', 'Open', 'OnClickEmail'),
  146.             ('rlink', 'Mark as Read', 'markAsRead'),
  147.             ('alink', 'Archive', 'archive'),
  148.             ('dlink', 'Delete', 'delete'),
  149.             ('slink', 'Report Spam', 'reportSpam')]
  150.         for attr, text, method in links:
  151.             link = ClearLink(self, -1, text, method, style = wx.NO_BORDER | wx.HL_ALIGN_CENTRE)
  152.             link.Font = self.linkfont
  153.             setattr(self, attr, link)
  154.             self.linkage.Add(link)
  155.         
  156.         self.BBind(HYPERLINK = self.OnLink, MOTION = self.OnMouseMotion, LEFT_DCLICK = self.OnDblClick, LEAVE_WINDOW = self.OnMouseOut, MOUSEWHEEL = self.OnMouseWheel, PAINT = self.OnPaint, SHOW = self.OnShow)
  157.         self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
  158.  
  159.     
  160.     def OnFaviconReceived(self, domain):
  161.         get_icon_domain = get_icon_domain
  162.         import common.favicons
  163.         for i, email in enumerate(self.emails):
  164.             if not email.domain:
  165.                 continue
  166.             
  167.             if domain == get_icon_domain(email.domain):
  168.                 self.RefreshLine(i)
  169.                 continue
  170.         
  171.  
  172.     
  173.     def OnMouseWheel(self, event):
  174.         self.ScrollLines(-(event.WheelRotation) // abs(event.WheelRotation))
  175.  
  176.     
  177.     def OnDblClick(self, event):
  178.         self.account.OnClickEmail(self.account.emails[self.Selection])
  179.  
  180.     
  181.     def OnMouseOut(self, event):
  182.         if not self.linkage.Rect.Contains(event.Position) and self.Selection != -1:
  183.             self.RefreshLine(self.Selection)
  184.             self.Selection = -1
  185.             self.linkage.Show(False)
  186.         
  187.  
  188.     
  189.     def OnMouseMotion(self, event):
  190.         i = self.HitTest(event.Position)
  191.         if self.Selection != i:
  192.             oldSelection = self.Selection
  193.             self.Selection = i
  194.             if self.Selection == -1:
  195.                 self.linkage.Show(False)
  196.             else:
  197.                 self.linkage.Show(True)
  198.             if oldSelection >= 0:
  199.                 self.RefreshLine(oldSelection)
  200.             
  201.             if self.Selection >= 0:
  202.                 self.RefreshLine(self.Selection)
  203.             
  204.         
  205.  
  206.     
  207.     def OnShow(self, event):
  208.         event.Skip()
  209.         if wx.IsDestroyed(self):
  210.             print >>sys.stderr, 'WARNING: emailpanels.py OnShow called, but is destroyed'
  211.             return None
  212.         
  213.         if not (self.Shown) and self.account is not None:
  214.             self.account.emails.remove_observer(self.ListChanged)
  215.         
  216.         self.Selection = -1
  217.         self.linkage.Show(False)
  218.         self.Refresh(False)
  219.  
  220.     
  221.     def SetAccount(self, account):
  222.         self.ScrollToLine(0)
  223.         self.Selection = -1
  224.         self.linkage.Show(False)
  225.         if self.account is not None:
  226.             self.account.emails.remove_observer(self.ListChanged)
  227.         
  228.         self.account = account
  229.         self.account.emails.add_observer(self.ListChanged)
  230.         self.ListChanged()
  231.         acts = actions.forclass(account)
  232.         fnames = [ _[1] if not isinstance(act, basestring) else None for act in acts ]
  233.         self.olink.Show('open' in fnames)
  234.         self.rlink.Show('markAsRead' in fnames)
  235.         self.alink.Show('archive' in fnames)
  236.         self.dlink.Show('delete' in fnames)
  237.         self.slink.Show('reportSpam' in fnames)
  238.         self.linkage.Layout()
  239.         self.itemheight = [] + self.padding.y * 4 + self.titlefont.Height + self.majorfont.Height + self.linkfont.Height if self.sep else 0
  240.         if account.can_has_preview:
  241.             self.itemheight += self.minorfont.Height + self.padding.y
  242.         
  243.         self.RefreshAll()
  244.         self.Show(True)
  245.         self.Frozen().__enter__()
  246.         
  247.         try:
  248.             self.GrandParent.DoSizeMagic()
  249.         finally:
  250.             pass
  251.  
  252.  
  253.     
  254.     def ListChanged(self, *args, **kwargs):
  255.         i = self.GetFirstVisibleLine()
  256.         
  257.         try:
  258.             topemail = self.emails[i]
  259.         except IndexError:
  260.             topemail = None
  261.  
  262.         self.emails = self.account.emails
  263.         self.Frozen().__enter__()
  264.         
  265.         try:
  266.             self.SetItemCount(len(self.emails))
  267.             self.GrandParent.DoSizeMagic()
  268.             if topemail is not None:
  269.                 
  270.                 try:
  271.                     i = self.emails.index(topemail)
  272.                 except ValueError:
  273.                     self.Frozen()
  274.                     self.Frozen()
  275.                 except:
  276.                     self.Frozen()<EXCEPTION MATCH>ValueError
  277.                 
  278.  
  279.             self.Frozen()
  280.             self.ScrollLines(i)
  281.         finally:
  282.             pass
  283.  
  284.         self.Parent.Refresh(False)
  285.  
  286.     
  287.     def UpdateSkin(self):
  288.         s = skin.get
  289.         self.padding = s('infobox.padding', (lambda : wx.Point(4, 4)))
  290.         self.headerfont = s('infobox.fonts.header', default_font)
  291.         self.titlefont = s('infobox.fonts.title', default_font)
  292.         self.majorfont = s('infobox.fonts.major', default_font)
  293.         self.minorfont = s('infobox.fonts.minor', default_font)
  294.         self.linkfont = CopyFont(s('infobox.fonts.link', default_font), underline = True)
  295.         fc = s('infobox.fontcolors')
  296.         g = fc.get
  297.         self.titlefc = g('title', BLACK)
  298.         self.majorfc = g('major', wx.BLACK)
  299.         self.minorfc = g('minor', wx.Color(128, 128, 128))
  300.         self.linkfc = g('link', wx.BLUE)
  301.         self.hovertitlefc = g('emailhovertitle', self.titlefc)
  302.         self.hovermajorfc = g('emailhovermajor', self.majorfc)
  303.         self.hoverminorfc = g('emailhoverminor', self.minorfc)
  304.         self.hoverlinkfc = g('emailhoverlink', self.linkfc)
  305.         for link in self.linkage:
  306.             link.NormalColour = link.HoverColour = link.VisitedColour = self.hoverlinkfc
  307.             link.Font = self.linkfont
  308.         
  309.         self.linkage.Layout()
  310.         if self.errorlink:
  311.             self.errorlink.Font = self.Parent.Font
  312.             self.errorlink.VisitedColour = self.errorlink.HoverColour = self.errorlink.NormalColour = s('infobox.linkcolor', (lambda : wx.BLUE))
  313.         
  314.         self.bg = s('infobox.backgrounds.email', (lambda : SkinColor(wx.WHITE)))
  315.         self.selbg = s('infobox.backgrounds.emailhover', (lambda : SkinColor(wx.Color(225, 255, 225))))
  316.         self.sep = s('infobox.shortseparatorimage', None)
  317.  
  318.     
  319.     def GetFullHeight(self):
  320.         if not self.ItemCount:
  321.             pass
  322.         return 1 * self.OnMeasureItem(0)
  323.  
  324.     
  325.     def SkimIt(self, it):
  326.         if self.ItemCount:
  327.             h = self.OnMeasureItem(0)
  328.             r = (it // h) * h
  329.             return r
  330.         
  331.         return self.OnMeasureItem(0)
  332.  
  333.     
  334.     def OnMeasureItem(self, n):
  335.         return self.itemheight
  336.  
  337.     
  338.     def OnDrawBackground(self, dc, rect, n):
  339.         if self.Selection == n:
  340.             self.selbg.Draw(dc, rect, n)
  341.         else:
  342.             self.bg.Draw(dc, rect, n)
  343.  
  344.     
  345.     def OnPaint(self, event):
  346.         if self.ItemCount:
  347.             event.Skip()
  348.             return None
  349.         
  350.         dc = wx.BufferedPaintDC(self)
  351.         rect = RectS(self.Size)
  352.         self.OnDrawBackground(dc, rect, 0)
  353.         dc.Font = self.titlefont
  354.         None(dc.DrawLabel if self.account.count else 'No New Email', rect, wx.ALIGN_CENTER)
  355.  
  356.     
  357.     def OnDrawItem(self, dc, rect, n):
  358.         issel = n == self.Selection
  359.         email = self.emails[n]
  360.         pad = self.padding
  361.         sendtime = getattr(email, 'sendtime', None)
  362.         if hasattr(sendtime, 'strftime'):
  363.             strf = sendtime.strftime
  364.             iscurdate = strf('%b %d %y') == datetime.now().strftime('%b %d %y')
  365.             date = strf('%b %d')
  366.             time = strf('%I:%M %p')
  367.             if time[0] == '0':
  368.                 time = time[1:]
  369.             
  370.             if iscurdate and getattr(self.account, 'timestamp_is_time', (lambda t: True))(sendtime):
  371.                 timestamp = time
  372.             else:
  373.                 timestamp = date
  374.         else:
  375.             timestamp = sendtime
  376.         if timestamp is None:
  377.             timestamp = ''
  378.         
  379.         curserx = rect.x + pad.x
  380.         cursery = rect.y + pad.y
  381.         favicon = favicon
  382.         import common.favicons
  383.         d = email.domain
  384.         icon = None if d is not None else None
  385.         iconsize = 16
  386.         if icon is None:
  387.             icon = skin.get('emailpanel.miscicons.defaulticon', None)
  388.         
  389.         if icon is not None:
  390.             icon = icon.Resized(iconsize)
  391.             dc.DrawBitmap(icon, curserx, cursery, True)
  392.         
  393.         curserx += iconsize + pad.x
  394.         dc.Font = self.minorfont
  395.         dc.TextForeground = None if issel else self.minorfc
  396.         tste = dc.GetFullTextExtent(timestamp)
  397.         tsrect = wx.Rect(rect.x + rect.width - tste[0] - pad.x, cursery, tste[0], tste[1] + tste[2] + tste[3])
  398.         dc.DrawTruncatedText(timestamp, tsrect)
  399.         if email.attachments:
  400.             atticon = skin.get('emailpanel.miscicons.attachmenticon', None)
  401.             if atticon is not None:
  402.                 count = len(email.attachments)
  403.                 if count > 1:
  404.                     atticon = add_image_text(atticon, str(count))
  405.                 
  406.                 dc.DrawBitmap(atticon, tsrect.X - atticon.Width - pad.x, tsrect.Y, True)
  407.             
  408.         
  409.         dc.Font = self.titlefont
  410.         dc.TextForeground = None if issel else self.titlefc
  411.         if not email.fromname:
  412.             pass
  413.         dc.DrawTruncatedText(u'%s' % email.fromemail, Rect(curserx, cursery, rect.Width - (curserx + pad.x) - tsrect.width, dc.Font.Height))
  414.         cursery += dc.Font.Height + self.padding.y
  415.         dc.Font = self.majorfont
  416.         dc.TextForeground = None if issel else self.majorfc
  417.         if not email.subject:
  418.             pass
  419.         dc.DrawTruncatedText(_('(No Subject)'), Rect(curserx, cursery, rect.Width - (curserx + pad.x), dc.Font.Height))
  420.         if self.account.can_has_preview:
  421.             cursery += dc.Font.Height + pad.y
  422.             dc.Font = self.minorfont
  423.             dc.TextForeground = None if issel else self.minorfc
  424.             if not email.content:
  425.                 pass
  426.             dc.DrawTruncatedText(_('(No Preview)'), wx.Rect(curserx, cursery, rect.Width - (curserx + pad.x), dc.Font.Height))
  427.         
  428.         if self.sep and n < len(self.emails) - 1:
  429.             self.sep.Draw(dc, wx.RectPS(rect.Position + (2, rect.height - self.sep.Size.height), (rect.width - 4, self.sep.Size.height)))
  430.         
  431.         if issel:
  432.             cursery += dc.Font.Height + pad.y
  433.             self.linkage.SetPosition((curserx, cursery))
  434.         
  435.  
  436.     
  437.     def OnLink(self, event):
  438.         if event.URL == 'OnClickEmail':
  439.             wx.GetTopLevelParent(self).Hide()
  440.         
  441.         getattr(self.account, event.URL)(self.account.emails[self.Selection])
  442.         self.Selection = -1
  443.         self.linkage.Show(False)
  444.  
  445.  
  446.