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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. from wx import Rect, DCClipper, Brush, RectS, BufferedPaintDC
  5. import wx
  6. from logging import getLogger
  7. log = getLogger('skinvlist')
  8. from traceback import print_exc
  9.  
  10. class SkinVListBox(wx.VListBox):
  11.     
  12.     def __init__(self, parent, id = -1, style = 0):
  13.         wx.VListBox.__init__(self, parent, id = id, style = style)
  14.         self.Bind(wx.EVT_PAINT, self.paint)
  15.         self.Bind(wx.EVT_ERASE_BACKGROUND, (lambda e: pass))
  16.         self.Bind(wx.EVT_KEY_DOWN, self._SkinVListBox__keydown)
  17.         self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
  18.         self.bg = None
  19.         self._refreshOnScroll = False
  20.  
  21.     
  22.     def GetItemY(self, i):
  23.         measure = self.OnMeasureItem
  24.         first = self.GetFirstVisibleLine()
  25.         last = self.GetLastVisibleLine()
  26.         if i >= 0 and i >= first and i <= last:
  27.             
  28.             try:
  29.                 return (sum,)((lambda .0: for x in .0:
  30. measure(x))(xrange(first, i)))
  31.             except TypeError:
  32.                 pass
  33.             except:
  34.                 None<EXCEPTION MATCH>TypeError
  35.             
  36.  
  37.         None<EXCEPTION MATCH>TypeError
  38.         return -1
  39.  
  40.     
  41.     def SetBackground(self, background_brush):
  42.         self.bg = background_brush
  43.         if not (background_brush.ytile) and not (self._refreshOnScroll):
  44.             self._refreshOnScroll = True
  45.             self.Bind(wx.EVT_SCROLLWIN, self._onScroll)
  46.         elif background_brush.ytile and self._refreshOnScroll:
  47.             self._refreshOnScroll = False
  48.             self.Unbind(wx.EVT_SCROLLWIN)
  49.         
  50.  
  51.     
  52.     def _onScroll(self, e):
  53.         e.Skip()
  54.         self.RefreshAll()
  55.  
  56.     
  57.     def GetBackground(self):
  58.         return self.bg
  59.  
  60.     Background = property(GetBackground, SetBackground)
  61.     
  62.     def PaintMoreBackground(self, dc, rect):
  63.         pass
  64.  
  65.     
  66.     def __keydown(self, e):
  67.         e.Skip()
  68.         scrollPos = self.GetScrollPos(wx.VERTICAL)
  69.         
  70.         def later():
  71.             if scrollPos != self.GetScrollPos(wx.VERTICAL):
  72.                 self.RefreshAll()
  73.             
  74.  
  75.         wx.CallAfter(later)
  76.  
  77.     
  78.     def paint(self, e):
  79.         clientSize = self.ClientSize
  80.         dc = BufferedPaintDC(self)
  81.         rectUpdate = self.GetUpdateClientRect()
  82.         crect = self.ClientRect
  83.         if self.bg is not None:
  84.             self.bg.Draw(dc, crect)
  85.         else:
  86.             dc.Brush = Brush(self.BackgroundColour)
  87.             dc.Pen = wx.TRANSPARENT_PEN
  88.             dc.DrawRectangleRect(RectS(self.Size))
  89.         self.PaintMoreBackground(dc, crect)
  90.         rectLine = Rect(0, 0, clientSize.x, 0)
  91.         lineMax = self.GetVisibleEnd()
  92.         lineh = self.OnMeasureItem
  93.         drawbg = self.OnDrawBackground
  94.         drawsep = self.OnDrawSeparator
  95.         drawitem = self.OnDrawItem
  96.         margins = self.GetMargins()
  97.         for line in xrange(self.GetFirstVisibleLine(), lineMax):
  98.             
  99.             try:
  100.                 hLine = lineh(line)
  101.             except TypeError:
  102.                 log.critical('self.OnMeasureItem was None, returning')
  103.                 del dc
  104.                 return None
  105.  
  106.             rectLine.height = hLine
  107.             if rectLine.Intersects(rectUpdate):
  108.                 clip = DCClipper(dc, rectLine)
  109.                 rect = Rect(*rectLine)
  110.                 
  111.                 try:
  112.                     drawbg(dc, Rect(*rect), line)
  113.                 except Exception:
  114.                     print_exc()
  115.  
  116.                 
  117.                 try:
  118.                     drawsep(dc, Rect(*rect), line)
  119.                 except Exception:
  120.                     print_exc()
  121.  
  122.                 rect.Deflate(margins.x, margins.y)
  123.                 
  124.                 try:
  125.                     drawitem(dc, rect, line)
  126.                 except Exception:
  127.                     print_exc()
  128.  
  129.                 del clip
  130.             elif rectLine.Top > rectUpdate.Bottom:
  131.                 break
  132.             
  133.             rectLine.y += hLine
  134.         
  135.         return dc
  136.  
  137.     
  138.     def _emit_lbox_selection(self, i):
  139.         evt = wx.CommandEvent(wx.wxEVT_COMMAND_LISTBOX_SELECTED, self.Id)
  140.         evt.SetInt(i)
  141.         self.AddPendingEvent(evt)
  142.  
  143.  
  144. if __name__ == '__main__':
  145.     
  146.     class MyList(SkinVListBox):
  147.         
  148.         def __init__(self, parent):
  149.             SkinVListBox.__init__(self, parent)
  150.  
  151.         
  152.         def OnGetLineHeight(self, i):
  153.             return 20
  154.  
  155.         
  156.         def OnDrawItem(self, dc, rect, n):
  157.             dc.SetBrush(wx.RED_BRUSH)
  158.             dc.DrawRectangleRect(rect)
  159.  
  160.         
  161.         def OnDrawBackground(self, dc, rect, n):
  162.             pass
  163.  
  164.  
  165.     a = wx.PySimpleApp()
  166.     f = wx.Frame(None)
  167.     l = MyList(f)
  168.     l.SetItemCount(10)
  169.     f.Show()
  170.     a.MainLoop()
  171.  
  172.