]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/dragscroller.py
1 #-----------------------------------------------------------------------------
2 # Name: dragscroller.py
3 # Purpose: Scrolls a wx.ScrollWindow by dragging
5 # Author: Riaan Booysen
10 #-----------------------------------------------------------------------------
15 """ Scrolls a wx.ScrollWindow in the direction and speed of a mouse drag.
17 Call Start with the position of the drag start.
18 Call Stop on the drag release. """
20 def __init__(self
, scrollwin
, rate
=30, sensitivity
=0.75):
21 self
.scrollwin
= scrollwin
23 self
.sensitivity
= sensitivity
28 def GetScrollWindow(self
):
30 def SetScrollWindow(self
, scrollwin
):
31 self
.scrollwin
= scrollwin
33 def GetUpdateRate(self
):
35 def SetUpdateRate(self
, rate
):
38 def GetSensitivity(self
):
39 return self
.sensitivity
40 def SetSensitivity(self
, sensitivity
):
41 self
.sensitivity
= sensitivity
44 """ Start a drag scroll operation """
45 if not self
.scrollwin
:
46 raise Exception, 'No ScrollWindow defined'
49 self
.scrollwin
.SetCursor(wx
.StockCursor(wx
.CURSOR_SIZING
))
50 self
.scrollwin
.CaptureMouse()
52 self
.timer
= wx
.Timer(self
.scrollwin
)
53 self
.scrollwin
.Bind(wx
.EVT_TIMER
, self
.OnTimerDoScroll
, id=self
.timer
.GetId())
54 self
.timer
.Start(self
.rate
)
57 """ Stops a drag scroll operation """
58 if self
.timer
and self
.scrollwin
:
60 self
.scrollwin
.Disconnect(self
.timer
.GetId())
64 self
.scrollwin
.SetCursor(wx
.STANDARD_CURSOR
)
65 self
.scrollwin
.ReleaseMouse()
67 def OnTimerDoScroll(self
, event
):
68 if self
.pos
is None or not self
.timer
or not self
.scrollwin
:
71 new
= self
.scrollwin
.ScreenToClient(wx
.GetMousePosition())
72 dx
= int((new
.x
-self
.pos
.x
)*self
.sensitivity
)
73 dy
= int((new
.y
-self
.pos
.y
)*self
.sensitivity
)
74 spx
= self
.scrollwin
.GetScrollPos(wx
.HORIZONTAL
)
75 spy
= self
.scrollwin
.GetScrollPos(wx
.VERTICAL
)
77 self
.scrollwin
.Scroll(spx
+dx
, spy
+dy
)