Added wx.lib.dragscroller from Riaan Booysen.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41027 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
57
wxPython/demo/DragScroller.py
Normal file
57
wxPython/demo/DragScroller.py
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import wx
|
||||||
|
import wx.lib.dragscroller
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def runTest(frame, nb, log):
|
||||||
|
win = DragScrollerExample(nb, -1)
|
||||||
|
return win
|
||||||
|
|
||||||
|
class DragScrollerExample(wx.ScrolledWindow):
|
||||||
|
def __init__(self, parent, id=-1):
|
||||||
|
wx.ScrolledWindow.__init__(self, parent, id)
|
||||||
|
self.Bind(wx.EVT_PAINT, self.OnPaint)
|
||||||
|
self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
|
||||||
|
self.Bind(wx.EVT_RIGHT_UP, self.OnRightUp)
|
||||||
|
|
||||||
|
self.SetScrollbars(1, 1, 2000, 2000, 0, 0)
|
||||||
|
|
||||||
|
self.scroller = wx.lib.dragscroller.DragScroller(self)
|
||||||
|
|
||||||
|
def OnPaint(self, event):
|
||||||
|
dc = wx.PaintDC(self)
|
||||||
|
self.DoPrepareDC(dc)
|
||||||
|
|
||||||
|
pen = wx.Pen(wx.BLACK, 5)
|
||||||
|
dc.SetPen(pen)
|
||||||
|
|
||||||
|
for y in range(10):
|
||||||
|
for x in range(10):
|
||||||
|
dc.DrawCircle(x*400+20, y*400+20, 200)
|
||||||
|
|
||||||
|
dc.DrawText('Right click and drag in the direction you want to scroll.',
|
||||||
|
20, 20)
|
||||||
|
dc.DrawText('The distance from the start of the drag determines the speed.',
|
||||||
|
20, 50)
|
||||||
|
|
||||||
|
def OnRightDown(self, event):
|
||||||
|
self.scroller.Start(event.GetPosition())
|
||||||
|
|
||||||
|
def OnRightUp(self, event):
|
||||||
|
self.scroller.Stop()
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
overview = """<html><body>
|
||||||
|
<h2>DragScroller</h2>
|
||||||
|
<p>
|
||||||
|
A helper class that adds scrolling to a wx.ScrolledWindow in the direction
|
||||||
|
of the drag.
|
||||||
|
</body></html>
|
||||||
|
"""
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys,os
|
||||||
|
import run
|
||||||
|
run.main(['', os.path.basename(sys.argv[0])])
|
@@ -59,6 +59,7 @@ _treeList = [
|
|||||||
'Toolbook',
|
'Toolbook',
|
||||||
'BitmapFromBuffer',
|
'BitmapFromBuffer',
|
||||||
'RawBitmapAccess',
|
'RawBitmapAccess',
|
||||||
|
'DragScroller',
|
||||||
]),
|
]),
|
||||||
|
|
||||||
# managed windows == things with a (optional) caption you can close
|
# managed windows == things with a (optional) caption you can close
|
||||||
@@ -248,6 +249,7 @@ _treeList = [
|
|||||||
('Miscellaneous', [
|
('Miscellaneous', [
|
||||||
'ColourDB',
|
'ColourDB',
|
||||||
##'DialogUnits', # needs more explanations
|
##'DialogUnits', # needs more explanations
|
||||||
|
'DragScroller',
|
||||||
'DrawXXXList',
|
'DrawXXXList',
|
||||||
'FileHistory',
|
'FileHistory',
|
||||||
'FontEnumerator',
|
'FontEnumerator',
|
||||||
|
@@ -216,6 +216,10 @@ to the platform specific pixel buffer inside of a wx.Bitmap object.
|
|||||||
The beginnings of support for RTL languages has been added, thanks to
|
The beginnings of support for RTL languages has been added, thanks to
|
||||||
a Google SoC project.
|
a Google SoC project.
|
||||||
|
|
||||||
|
Added wx.lib.dragscroller from Riaan Booysen. It provides a helper
|
||||||
|
class that can used to scroll a wx.ScrolledWindow in response to a
|
||||||
|
mouse drag.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
77
wxPython/wx/lib/dragscroller.py
Normal file
77
wxPython/wx/lib/dragscroller.py
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Name: dragscroller.py
|
||||||
|
# Purpose: Scrolls a wx.ScrollWindow by dragging
|
||||||
|
#
|
||||||
|
# Author: Riaan Booysen
|
||||||
|
#
|
||||||
|
# Created: 2006/09/05
|
||||||
|
# Copyright: (c) 2006
|
||||||
|
# Licence: wxPython
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
import wx
|
||||||
|
|
||||||
|
class DragScroller:
|
||||||
|
""" Scrolls a wx.ScrollWindow in the direction and speed of a mouse drag.
|
||||||
|
|
||||||
|
Call Start with the position of the drag start.
|
||||||
|
Call Stop on the drag release. """
|
||||||
|
|
||||||
|
def __init__(self, scrollwin, rate=30, sensitivity=0.75):
|
||||||
|
self.scrollwin = scrollwin
|
||||||
|
self.rate = rate
|
||||||
|
self.sensitivity = sensitivity
|
||||||
|
|
||||||
|
self.pos = None
|
||||||
|
self.timer = None
|
||||||
|
|
||||||
|
def GetScrollWindow(self):
|
||||||
|
return self.scrollwin
|
||||||
|
def SetScrollWindow(self, scrollwin):
|
||||||
|
self.scrollwin = scrollwin
|
||||||
|
|
||||||
|
def GetUpdateRate(self):
|
||||||
|
return self.rate
|
||||||
|
def SetUpdateRate(self, rate):
|
||||||
|
self.rate = rate
|
||||||
|
|
||||||
|
def GetSensitivity(self):
|
||||||
|
return self.sensitivity
|
||||||
|
def SetSensitivity(self, sensitivity):
|
||||||
|
self.sensitivity = sensitivity
|
||||||
|
|
||||||
|
def Start(self, pos):
|
||||||
|
""" Start a drag scroll operation """
|
||||||
|
if not self.scrollwin:
|
||||||
|
raise Exception, 'No ScrollWindow defined'
|
||||||
|
|
||||||
|
self.pos = pos
|
||||||
|
self.scrollwin.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
|
||||||
|
self.scrollwin.CaptureMouse()
|
||||||
|
|
||||||
|
self.timer = wx.Timer(self.scrollwin)
|
||||||
|
self.scrollwin.Bind(wx.EVT_TIMER, self.OnTimerDoScroll, id=self.timer.GetId())
|
||||||
|
self.timer.Start(self.rate)
|
||||||
|
|
||||||
|
def Stop(self):
|
||||||
|
""" Stops a drag scroll operation """
|
||||||
|
if self.timer and self.scrollwin:
|
||||||
|
self.timer.Stop()
|
||||||
|
self.scrollwin.Disconnect(self.timer.GetId())
|
||||||
|
self.timer.Destroy()
|
||||||
|
self.timer = None
|
||||||
|
|
||||||
|
self.scrollwin.SetCursor(wx.STANDARD_CURSOR)
|
||||||
|
self.scrollwin.ReleaseMouse()
|
||||||
|
|
||||||
|
def OnTimerDoScroll(self, event):
|
||||||
|
if self.pos is None or not self.timer or not self.scrollwin:
|
||||||
|
return
|
||||||
|
|
||||||
|
new = self.scrollwin.ScreenToClient(wx.GetMousePosition())
|
||||||
|
dx = int((new.x-self.pos.x)*self.sensitivity)
|
||||||
|
dy = int((new.y-self.pos.y)*self.sensitivity)
|
||||||
|
spx = self.scrollwin.GetScrollPos(wx.HORIZONTAL)
|
||||||
|
spy = self.scrollwin.GetScrollPos(wx.VERTICAL)
|
||||||
|
|
||||||
|
self.scrollwin.Scroll(spx+dx, spy+dy)
|
Reference in New Issue
Block a user