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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. from gui.uberwidgets.uberwidget import UberWidget
  6. from gui.textutil import CopyFont, default_font, GetTextWidth
  7. from gui.skin.skinobjects import SkinColor
  8. from gui import skin
  9. from gui.toolbox.refreshtimer import refreshtimer
  10.  
  11. class ErrorPanel(wx.Panel, UberWidget):
  12.     
  13.     def __init__(self, parent):
  14.         wx.Panel.__init__(self, parent, -1)
  15.         self.link = ''
  16.         self.linkhovered = False
  17.         self.linkdown = False
  18.         self.message = None
  19.         self.UpdateSkin()
  20.         self.Bind(wx.EVT_PAINT, self.OnPaint)
  21.         self.Bind(wx.EVT_ERASE_BACKGROUND, (lambda e: pass))
  22.         self.Bind(wx.EVT_SIZE, self.OnSize)
  23.         self.Bind(wx.EVT_ENTER_WINDOW, self.OnMouseIn)
  24.         self.Bind(wx.EVT_LEAVE_WINDOW, self.OnMouseOut)
  25.         self.Bind(wx.EVT_MOTION, self.OnMouseMotion)
  26.         self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
  27.         self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
  28.         self.Bind((wx.EVT_LEFT_DCLICK,), (lambda e: (self.OnLeftDown(e), self.OnLeftUp(e))))
  29.         self.Show(False)
  30.  
  31.     
  32.     def OnSize(self, event):
  33.         if self.link:
  34.             linksize = self.linkrect.Size
  35.             if self.link:
  36.                 self.linkrect = wx.Rect(self.Size.width - linksize.width - self.padding.x, self.Size.height - linksize.height - self.padding.y, *linksize)
  37.             
  38.         
  39.         self.Refresh(False)
  40.  
  41.     
  42.     def UpdateSkin(self):
  43.         key = 'infobox'
  44.         if skin.get(key, False):
  45.             
  46.             s = lambda k, d: skin.get('%s.%s' % (key, k), d)
  47.         else:
  48.             
  49.             s = lambda k, d: d
  50.         self.padding = s('padding', (lambda : wx.Point(2, 2)))
  51.         self.labelf = s('fonts.title', (lambda : default_font()))
  52.         self.labelfc = s('fontcolors.title', wx.BLACK)
  53.         self.linkf = CopyFont(s('fonts.link', (lambda : default_font())), underline = True)
  54.         self.linkfc = s('fontcolors.link', wx.BLUE)
  55.         self.bg = s('backgrounds.email', (lambda : SkinColor(wx.WHITE)))
  56.  
  57.     
  58.     def OnPaint(self, event):
  59.         dc = wx.BufferedPaintDC(self)
  60.         rect = wx.RectS(self.Size)
  61.         dc.Font = self.labelf
  62.         dc.TextForeground = self.labelfc
  63.         self.bg.Draw(dc, rect)
  64.         rect2 = None(wx.Rect, 0, 0, self.Size.width - self.Size.height if self.link else 0)
  65.         message = self.message
  66.         None(dc.DrawLabel if callable(message) else message, rect2, wx.ALIGN_CENTER)
  67.         if self.link:
  68.             dc.Font = self.linkf
  69.             dc.TextForeground = self.linkfc
  70.             dc.DrawLabel(self.link, self.linkrect)
  71.         
  72.  
  73.     
  74.     def Error(self, message = None, link = None, callback = None):
  75.         self.message = message
  76.         self.link = ''
  77.         if message:
  78.             if link and callback:
  79.                 
  80.                 self.linkcb = lambda *a: (wx.GetTopLevelParent(self).Hide(), callback(*a))
  81.                 self.link = link
  82.                 linksize = wx.Size(GetTextWidth(link, self.linkf), self.linkf.Height)
  83.                 self.linkrect = wx.Rect(self.Size.width - linksize.width - self.padding.x, self.Size.height - linksize.height - self.padding.y, *linksize)
  84.             
  85.             self.Show(True)
  86.             self.MinSize = wx.Size(-1, 5 * max(self.labelf.Height, self.linkf.Height))
  87.             self.GrandParent.DoSizeMagic()
  88.             self.Refresh()
  89.         else:
  90.             self.Show(False)
  91.         if callable(message):
  92.             refreshtimer().Register(self)
  93.         else:
  94.             refreshtimer().UnRegister(self)
  95.  
  96.     
  97.     def SkimIt(self, height):
  98.         return height
  99.  
  100.     
  101.     def OnLeftDown(self, event):
  102.         if self.linkhovered:
  103.             self.linkdown = True
  104.         
  105.  
  106.     
  107.     def OnLeftUp(self, event):
  108.         if self.linkdown:
  109.             if self.linkhovered:
  110.                 self.linkcb()
  111.             
  112.             self.linkdown = False
  113.         
  114.         self.OnMouseMotion(event)
  115.         self.Refresh()
  116.  
  117.     
  118.     def OnMouseMotion(self, event):
  119.         if not event.LeftIsDown():
  120.             mouseisin = wx.FindWindowAtPointer() is self
  121.             if mouseisin and not self.HasCapture():
  122.                 self.OnMouseIn(event)
  123.             elif not mouseisin and self.HasCapture():
  124.                 self.OnMouseOut(event)
  125.             
  126.         
  127.         if self.link:
  128.             mouseinl = self.linkhovered = self.linkrect.Contains(event.Position)
  129.             None(self.SetCursor(wx.StockCursor if mouseinl else wx.CURSOR_DEFAULT))
  130.         
  131.  
  132.     
  133.     def OnMouseIn(self, event):
  134.         if not self.HasCapture() and not event.LeftIsDown():
  135.             self.CaptureMouse()
  136.         
  137.  
  138.     
  139.     def OnMouseOut(self, event):
  140.         if not event.LeftIsDown():
  141.             while self.HasCapture():
  142.                 self.ReleaseMouse()
  143.         
  144.  
  145.  
  146.