home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.5)
-
- from wx import Rect, DCClipper, Brush, RectS, BufferedPaintDC
- import wx
- from logging import getLogger
- log = getLogger('skinvlist')
- from traceback import print_exc
-
- class SkinVListBox(wx.VListBox):
-
- def __init__(self, parent, id = -1, style = 0):
- wx.VListBox.__init__(self, parent, id = id, style = style)
- self.Bind(wx.EVT_PAINT, self.paint)
- self.Bind(wx.EVT_ERASE_BACKGROUND, (lambda e: pass))
- self.Bind(wx.EVT_KEY_DOWN, self._SkinVListBox__keydown)
- self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
- self.bg = None
- self._refreshOnScroll = False
-
-
- def GetItemY(self, i):
- measure = self.OnMeasureItem
- first = self.GetFirstVisibleLine()
- last = self.GetLastVisibleLine()
- if i >= 0 and i >= first and i <= last:
-
- try:
- return (sum,)((lambda .0: for x in .0:
- measure(x))(xrange(first, i)))
- except TypeError:
- pass
- except:
- None<EXCEPTION MATCH>TypeError
-
-
- None<EXCEPTION MATCH>TypeError
- return -1
-
-
- def SetBackground(self, background_brush):
- self.bg = background_brush
- if not (background_brush.ytile) and not (self._refreshOnScroll):
- self._refreshOnScroll = True
- self.Bind(wx.EVT_SCROLLWIN, self._onScroll)
- elif background_brush.ytile and self._refreshOnScroll:
- self._refreshOnScroll = False
- self.Unbind(wx.EVT_SCROLLWIN)
-
-
-
- def _onScroll(self, e):
- e.Skip()
- self.RefreshAll()
-
-
- def GetBackground(self):
- return self.bg
-
- Background = property(GetBackground, SetBackground)
-
- def PaintMoreBackground(self, dc, rect):
- pass
-
-
- def __keydown(self, e):
- e.Skip()
- scrollPos = self.GetScrollPos(wx.VERTICAL)
-
- def later():
- if scrollPos != self.GetScrollPos(wx.VERTICAL):
- self.RefreshAll()
-
-
- wx.CallAfter(later)
-
-
- def paint(self, e):
- clientSize = self.ClientSize
- dc = BufferedPaintDC(self)
- rectUpdate = self.GetUpdateClientRect()
- crect = self.ClientRect
- if self.bg is not None:
- self.bg.Draw(dc, crect)
- else:
- dc.Brush = Brush(self.BackgroundColour)
- dc.Pen = wx.TRANSPARENT_PEN
- dc.DrawRectangleRect(RectS(self.Size))
- self.PaintMoreBackground(dc, crect)
- rectLine = Rect(0, 0, clientSize.x, 0)
- lineMax = self.GetVisibleEnd()
- lineh = self.OnMeasureItem
- drawbg = self.OnDrawBackground
- drawsep = self.OnDrawSeparator
- drawitem = self.OnDrawItem
- margins = self.GetMargins()
- for line in xrange(self.GetFirstVisibleLine(), lineMax):
-
- try:
- hLine = lineh(line)
- except TypeError:
- log.critical('self.OnMeasureItem was None, returning')
- del dc
- return None
-
- rectLine.height = hLine
- if rectLine.Intersects(rectUpdate):
- clip = DCClipper(dc, rectLine)
- rect = Rect(*rectLine)
-
- try:
- drawbg(dc, Rect(*rect), line)
- except Exception:
- print_exc()
-
-
- try:
- drawsep(dc, Rect(*rect), line)
- except Exception:
- print_exc()
-
- rect.Deflate(margins.x, margins.y)
-
- try:
- drawitem(dc, rect, line)
- except Exception:
- print_exc()
-
- del clip
- elif rectLine.Top > rectUpdate.Bottom:
- break
-
- rectLine.y += hLine
-
- return dc
-
-
- def _emit_lbox_selection(self, i):
- evt = wx.CommandEvent(wx.wxEVT_COMMAND_LISTBOX_SELECTED, self.Id)
- evt.SetInt(i)
- self.AddPendingEvent(evt)
-
-
- if __name__ == '__main__':
-
- class MyList(SkinVListBox):
-
- def __init__(self, parent):
- SkinVListBox.__init__(self, parent)
-
-
- def OnGetLineHeight(self, i):
- return 20
-
-
- def OnDrawItem(self, dc, rect, n):
- dc.SetBrush(wx.RED_BRUSH)
- dc.DrawRectangleRect(rect)
-
-
- def OnDrawBackground(self, dc, rect, n):
- pass
-
-
- a = wx.PySimpleApp()
- f = wx.Frame(None)
- l = MyList(f)
- l.SetItemCount(10)
- f.Show()
- a.MainLoop()
-
-