def OnDrawItem(self,dc,rect,n): 'Draws the foreground of each item.' curser = Point(rect.x, rect.y) + (self.padding.x, 0) if self.items[n].id==-1: return self.DrawSeparator(dc, rect, n) if self.items[n].font: font = self.items[n].font else: font = self.Font dc.Font=font dc.TextForeground=(self.selfc if self.Selection==n else self.normalfc) if self.items[n].menu: dc.Brush=wx.BLACK_BRUSH dc.Pen=wx.TRANSPARENT_PEN smi=self.submenuiconhot if self.Selection==n else self.submenuicon # if isinstance(smi,wx.Mask): # acolor = self.selfc if self.Selection==n else self.normalfc # arrow = wx.EmptyBitmap(10,10) # arrow.SetMask(smi) # mdc2 = wx.MemoryDC() # mdc2.SelectObject(arrow) # mdc2.Brush = wx.Brush(acolor) # mdc2.FloodFill(0,0,wx.BLACK) # mdc2.SelectObject(wx.NullBitmap) # dc.DrawBitmap(arrow,rect.Width-self.padding.x-arrow.Width,rect.Y+(rect.Height/2)-arrow.Height/2,True) # endcap=arrow.Width+self.padding.x # else: dc.DrawBitmap(smi,rect.Width-self.padding.x-smi.Width,rect.Y+(rect.Height/2)-smi.Height/2,True) endcap=smi.Width+self.padding.x else: endcap=0 padx = self.padding.x txtext = dc.Font.Height txtext_pad = Point(txtext + padx, 0) for i in self.items[n].content: if type(i) is Bitmap: curser.y = rect.Y + (rect.height / 2 - i.Height / 2) imgpad = (self.bitmapwidth - i.Width)//2 if self.bitmapwidth else 0 try: dc.DrawBitmapPoint(i, (curser.x + imgpad, curser.y), True) except Exception: traceback.print_exc_once() try: log.error("Failed drawing bitmap: %r", getattr(i, 'path', None)) except Exception: pass curser += Point(max(self.bitmapwidth, i.Width) + padx, 0) elif isinstance(i, basestring): curser.y = rect.Y + (rect.height / 2 - txtext / 2) text_rect = RectPS(curser, Size(rect.width - curser.x - padx - endcap, txtext)) dc.DrawTruncatedText(i, text_rect, alignment = wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL) curser += txtext_pad
def chat_icon(self): try: bitmap = self.convo.protocol.serviceicon.ResizedSmaller((16,16)) except Exception: traceback.print_exc_once() from gui import skin bitmap = skin.get('actionsbar.icons.roomlist').Resized((16,16)) return bitmap
def go(): try: os.startfile(url) except WindowsError: if hasattr(traceback, 'print_exc_once'): traceback.print_exc_once() else: traceback.print_exc() log.error('could not open browser for url: %r', url) _fire_browser_error_popup()
def buddy_lookup(buddy, name): protocol = getattr(buddy, 'protocol', None) # protocol might be offline, or missing a buddies dictionary. if protocol is not None and hasattr(protocol, 'buddies') and protocol.buddies: try: buddy = buddy.protocol.get_buddy(name) except Exception: import traceback traceback.print_exc_once() return buddy
def __repr__(self): try: return u'<%s %r %s>' % (type(self).__name__, getattr(self, 'name', '<no name>'), list.__repr__(self)) except: try: traceback.print_exc_once() except: return '<DGroup (print_exc error)>' try: return '<%s %r ???>' % (type(self).__name__, self.name,) except: return '<DGroup ????>'
def FullscreenAppLog(): try: from gui.native.win import winfullscreen except ImportError: traceback.print_exc_once() else: if winfullscreen.enabled: try: return log.debug('fullscreen (notification state) is %s ', winfullscreen.last_state) except Exception: traceback.print_exc() winfullscreen.enabled = False log.info('fullscreen was computed')
def __repr__(self): try: return u'<%s %r %s>' % (type(self).__name__, getattr(self, 'name', '<no name>'), list.__repr__(self)) except: try: traceback.print_exc_once() except: return '<DGroup (print_exc error)>' try: return '<%s %r ???>' % ( type(self).__name__, self.name, ) except: return '<DGroup ????>'
def urls_have_same_domain(a, b): try: return UrlQuery.parse(a).netloc == UrlQuery.parse(b).netloc except Exception: traceback.print_exc_once() return a == b
def OnDrawItem(self, dc, rect, n): 'Draws the foreground of each item.' curser = Point(rect.x, rect.y) + (self.padding.x, 0) if self.items[n].id == -1: return self.DrawSeparator(dc, rect, n) if self.items[n].font: font = self.items[n].font else: font = self.Font dc.Font = font dc.TextForeground = (self.selfc if self.Selection == n else self.normalfc) if self.items[n].menu: dc.Brush = wx.BLACK_BRUSH dc.Pen = wx.TRANSPARENT_PEN smi = self.submenuiconhot if self.Selection == n else self.submenuicon # if isinstance(smi,wx.Mask): # acolor = self.selfc if self.Selection==n else self.normalfc # arrow = wx.EmptyBitmap(10,10) # arrow.SetMask(smi) # mdc2 = wx.MemoryDC() # mdc2.SelectObject(arrow) # mdc2.Brush = wx.Brush(acolor) # mdc2.FloodFill(0,0,wx.BLACK) # mdc2.SelectObject(wx.NullBitmap) # dc.DrawBitmap(arrow,rect.Width-self.padding.x-arrow.Width,rect.Y+(rect.Height/2)-arrow.Height/2,True) # endcap=arrow.Width+self.padding.x # else: dc.DrawBitmap(smi, rect.Width - self.padding.x - smi.Width, rect.Y + (rect.Height / 2) - smi.Height / 2, True) endcap = smi.Width + self.padding.x else: endcap = 0 padx = self.padding.x txtext = dc.Font.Height txtext_pad = Point(txtext + padx, 0) for i in self.items[n].content: if type(i) is Bitmap: curser.y = rect.Y + (rect.height / 2 - i.Height / 2) imgpad = (self.bitmapwidth - i.Width) // 2 if self.bitmapwidth else 0 try: dc.DrawBitmapPoint(i, (curser.x + imgpad, curser.y), True) except Exception: traceback.print_exc_once() try: log.error("Failed drawing bitmap: %r", getattr(i, 'path', None)) except Exception: pass curser += Point(max(self.bitmapwidth, i.Width) + padx, 0) elif isinstance(i, basestring): curser.y = rect.Y + (rect.height / 2 - txtext / 2) text_rect = RectPS( curser, Size(rect.width - curser.x - padx - endcap, txtext)) dc.DrawTruncatedText(i, text_rect, alignment=wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL) curser += txtext_pad
def OnDrawItem(self, dc, rect, n): """ Draws the content for the item, and positions the links for selection """ issel = n == self.Selection email = self.emails[n] pad = self.padding sendtime = getattr(email, 'sendtime', None) if hasattr(sendtime, 'strftime'): strf = sendtime.strftime try: # Generate a timestamp for the email -- may raise an exception # if the date is < 1900 iscurdate = strf('%b %d %y') == datetime.now().strftime( '%b %d %y') date = strf('%b %d') time = strf('%I:%M %p') if time[0] == '0': time = time[1:] if iscurdate and getattr(self.account, 'timestamp_is_time', lambda t: True)(sendtime): timestamp = time else: timestamp = date except Exception: traceback.print_exc_once() timestamp = None else: timestamp = sendtime if timestamp is None: timestamp = '' curserx = rect.x + pad.x cursery = rect.y + pad.y # Draw the favicon. from common.favicons import favicon d = email.domain icon = favicon(d) if d is not None else None iconsize = 16 if icon is None: icon = skin.get('emailpanel.miscicons.defaulticon', None) if icon is not None: icon = icon.Resized(iconsize) dc.DrawBitmap(icon, curserx, cursery, True) curserx += iconsize + pad.x #draw the timestamp dc.Font = self.minorfont dc.TextForeground = self.hoverminorfc if issel else self.minorfc tste = dc.GetFullTextExtent(timestamp) tsrect = wx.Rect(rect.x + rect.width - tste[0] - pad.x, cursery, tste[0], tste[1] + tste[2] + tste[3]) dc.DrawTruncatedText(timestamp, tsrect) # draw attachment icon if email.attachments: atticon = skin.get('emailpanel.miscicons.attachmenticon', None) if atticon is not None: count = len(email.attachments) if count > 1: atticon = add_image_text(atticon, str(count)) dc.DrawBitmap(atticon, tsrect.X - atticon.Width - pad.x, tsrect.Y, True) # draw the sender name or email dc.Font = self.titlefont dc.TextForeground = self.hovertitlefc if issel else self.titlefc dc.DrawTruncatedText( u'%s' % (email.fromname or email.fromemail), Rect(curserx, cursery, rect.Width - (curserx + pad.x) - tsrect.width, dc.Font.Height)) cursery += dc.Font.Height + self.padding.y # Draw the subject dc.Font = self.majorfont dc.TextForeground = self.hovermajorfc if issel else self.majorfc dc.DrawTruncatedText( email.subject or _('(No Subject)'), Rect(curserx, cursery, rect.Width - (curserx + pad.x), dc.Font.Height)) # Draw the preview line if applicable if self.account.can_has_preview: cursery += dc.Font.Height + pad.y dc.Font = self.minorfont dc.TextForeground = self.hoverminorfc if issel else self.minorfc self.preview_rect = wx.Rect( curserx, cursery, rect.Width - (curserx + pad.x), GetFontHeight(dc.Font, line_height=True)) if dc.DrawTruncatedTextInfo( email.content[self.preview_offset:] or _('(No Preview)'), self.preview_rect): self.marquee_timer.Stop() # draw separator if there is one and not last email if self.sep and n < len(self.emails) - 1: self.sep.Draw( dc, wx.RectPS( rect.Position + (2, rect.height - self.sep.Size.height), (rect.width - 4, self.sep.Size.height))) # place links if selection if issel: cursery += dc.Font.Height + pad.y self.linkage.SetPosition((curserx, cursery))
def OnDrawItem(self, dc, rect, n): """ Draws the content for the item, and positions the links for selection """ issel = n == self.Selection email = self.emails[n] pad = self.padding sendtime = getattr(email, 'sendtime', None) if hasattr(sendtime, 'strftime'): strf = sendtime.strftime try: # Generate a timestamp for the email -- may raise an exception # if the date is < 1900 iscurdate = strf('%b %d %y') == datetime.now().strftime('%b %d %y') date = strf('%b %d') time = strf('%I:%M %p') if time[0] == '0': time = time[1:] if iscurdate and getattr(self.account, 'timestamp_is_time', lambda t: True)(sendtime): timestamp = time else: timestamp = date except Exception: traceback.print_exc_once() timestamp = None else: timestamp = sendtime if timestamp is None: timestamp = '' curserx = rect.x + pad.x cursery = rect.y + pad.y # Draw the favicon. from common.favicons import favicon d = email.domain icon = favicon(d) if d is not None else None iconsize = 16 if icon is None: icon = skin.get('emailpanel.miscicons.defaulticon', None) if icon is not None: icon = icon.Resized(iconsize) dc.DrawBitmap(icon, curserx, cursery, True) curserx += iconsize + pad.x #draw the timestamp dc.Font = self.minorfont dc.TextForeground = self.hoverminorfc if issel else self.minorfc tste = dc.GetFullTextExtent(timestamp) tsrect = wx.Rect(rect.x+rect.width-tste[0] - pad.x, cursery, tste[0], tste[1] + tste[2] + tste[3]) dc.DrawTruncatedText(timestamp, tsrect) # draw attachment icon if email.attachments: atticon = skin.get('emailpanel.miscicons.attachmenticon', None) if atticon is not None: count = len(email.attachments) if count > 1: atticon = add_image_text(atticon, str(count)) dc.DrawBitmap(atticon, tsrect.X - atticon.Width - pad.x, tsrect.Y, True) # draw the sender name or email dc.Font = self.titlefont dc.TextForeground = self.hovertitlefc if issel else self.titlefc dc.DrawTruncatedText(u'%s' % (email.fromname or email.fromemail), Rect(curserx, cursery, rect.Width-(curserx + pad.x) - tsrect.width, dc.Font.Height)) cursery+=dc.Font.Height + self.padding.y # Draw the subject dc.Font = self.majorfont dc.TextForeground = self.hovermajorfc if issel else self.majorfc dc.DrawTruncatedText(email.subject or _('(No Subject)'), Rect(curserx, cursery, rect.Width-(curserx+pad.x), dc.Font.Height)) # Draw the preview line if applicable if self.account.can_has_preview: cursery += dc.Font.Height + pad.y dc.Font = self.minorfont dc.TextForeground = self.hoverminorfc if issel else self.minorfc self.preview_rect = wx.Rect(curserx, cursery, rect.Width-(curserx + pad.x), GetFontHeight(dc.Font, line_height=True)) if dc.DrawTruncatedTextInfo(email.content[self.preview_offset:] or _('(No Preview)'), self.preview_rect): self.marquee_timer.Stop() # draw separator if there is one and not last email if self.sep and n < len(self.emails)-1: self.sep.Draw(dc, wx.RectPS(rect.Position + (2, rect.height-self.sep.Size.height), (rect.width-4, self.sep.Size.height))) # place links if selection if issel: cursery += dc.Font.Height + pad.y self.linkage.SetPosition((curserx, cursery))