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

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. from wx import HORIZONTAL, VERTICAL, Point, Rect
  6. lineSize = Point(10, 10)
  7.  
  8. class ScrollWindow(wx.Window):
  9.     
  10.     def __init__(self, parent, id = -1, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.HSCROLL | wx.VSCROLL | wx.FULL_REPAINT_ON_RESIZE, name = 'ScrollWindow'):
  11.         wx.Window.__init__(self, parent, id, pos, size, style, name)
  12.         evts = 'top bottom lineup linedown pageup pagedown thumbtrack thumbrelease'.split()
  13.         for e in evts:
  14.             self.Bind(getattr(wx, 'EVT_SCROLLWIN_' + e.upper()), (lambda evt, e = (e,): self._scroll(evt, e)))
  15.         
  16.         self.Bind(wx.EVT_SIZE, self._size)
  17.  
  18.     
  19.     def SetVirtualSize(self, size):
  20.         wx.Window.SetVirtualSize(self, size)
  21.         print size
  22.         self.AdjustScrollbars()
  23.         self.Refresh()
  24.  
  25.     
  26.     def _scroll(self, e, name):
  27.         e.Skip()
  28.         clientRect = self.ClientRect
  29.         virtual = self.VirtualSize
  30.         scrollType = e.EventType
  31.         orientation = e.Orientation
  32.         o_idx = None if orientation == HORIZONTAL else 1
  33.         x = self.GetScrollPos(HORIZONTAL)
  34.         y = self.GetScrollPos(VERTICAL)
  35.         newPos = Point(x, y)
  36.         setScrollbars = True
  37.         if scrollType == wx.wxEVT_SCROLLWIN_THUMBTRACK:
  38.             newPos[o_idx] = e.Position
  39.         elif scrollType == wx.wxEVT_SCROLLWIN_THUMBRELEASE:
  40.             newPos[o_idx] = e.Position
  41.         elif scrollType == wx.wxEVT_SCROLLWIN_LINEDOWN:
  42.             newPos[o_idx] = newPos[o_idx] + lineSize[o_idx]
  43.         elif scrollType == wx.wxEVT_SCROLLWIN_LINEUP:
  44.             newPos[o_idx] = newPos[o_idx] - lineSize[o_idx]
  45.         elif scrollType == wx.wxEVT_SCROLLWIN_PAGEDOWN:
  46.             newPos[o_idx] = newPos[o_idx] + clientRect[2 + o_idx]
  47.         elif scrollType == wx.wxEVT_SCROLLWIN_PAGEUP:
  48.             newPos[o_idx] = newPos[o_idx] - clientRect[2 + o_idx]
  49.         
  50.         newPos[0] = max(min(newPos[0], virtual.width - clientRect.width), 0)
  51.         newPos[1] = max(min(newPos[1], virtual.height - clientRect.height), 0)
  52.         self.ScrollWindow(-(newPos.x - x), -(newPos.y - y))
  53.         if setScrollbars:
  54.             self.AdjustScrollbars(*newPos)
  55.         
  56.  
  57.     
  58.     def _size(self, e):
  59.         self.AdjustScrollbars()
  60.  
  61.     
  62.     def AdjustScrollbars(self, x = -1, y = -1):
  63.         r = self.Rect
  64.         virtual = self.VirtualSize
  65.         if x == -1:
  66.             x = self.GetScrollPos(HORIZONTAL)
  67.         
  68.         if y == -1:
  69.             y = self.GetScrollPos(VERTICAL)
  70.         
  71.         self.SetScrollbar(HORIZONTAL, x, r.Width, virtual.width)
  72.         self.SetScrollbar(VERTICAL, y, r.Height, virtual.height)
  73.  
  74.     
  75.     def PrepareDC(self, dc):
  76.         pt = dc.GetDeviceOrigin()
  77.         x = self.GetScrollPos(HORIZONTAL)
  78.         y = self.GetScrollPos(VERTICAL)
  79.         dc.SetDeviceOrigin(pt.x - x, pt.y - y)
  80.  
  81.  
  82. if __name__ == '__main__':
  83.     
  84.     def bindPaint(w, paint = None):
  85.         w.Bind(wx.EVT_ERASE_BACKGROUND, (lambda e: pass))
  86.         f.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
  87.         if paint is not None:
  88.             w.Bind(wx.EVT_PAINT, paint)
  89.         
  90.  
  91.     a = wx.PySimpleApp()
  92.     f = wx.Frame(None, title = 'scroll area')
  93.     bindPaint(f)
  94.     f.Bind(wx.EVT_CLOSE, (lambda e: a.ExitMainLoop()))
  95.     f2 = wx.Frame(None, pos = f.Position + tuple(f.Size), size = f.ClientSize, title = 'virtual area', style = wx.DEFAULT_FRAME_STYLE | wx.FULL_REPAINT_ON_RESIZE)
  96.     f2.Bind(wx.EVT_SIZE, (lambda e: s.SetVirtualSize(f2.Size)))
  97.     s = ScrollWindow(f)
  98.     
  99.     def paint(ctrl, e):
  100.         dc = wx.BufferedPaintDC(ctrl)
  101.         
  102.         try:
  103.             ctrl.PrepareDC(dc)
  104.         except AttributeError:
  105.             pass
  106.  
  107.         dc.Brush = wx.WHITE_BRUSH
  108.         dc.Clear()
  109.         p = wx.BLACK_DASHED_PEN
  110.         p.SetWidth(10)
  111.         dc.Pen = p
  112.         gc = wx.GraphicsContext.Create(dc)
  113.         r = Rect(0, 0, *f2.Size)
  114.         b = gc.CreateLinearGradientBrush(r.x, r.y, r.width, r.height, wx.WHITE, wx.BLACK)
  115.         gc.SetBrush(b)
  116.         gc.DrawRectangle(*r)
  117.  
  118.     bindPaint(s, (lambda e: paint(s, e)))
  119.     bindPaint(f2, (lambda e: paint(f2, e)))
  120.     f.Show()
  121.     f2.Show()
  122.     a.MainLoop()
  123.  
  124.