Niels et al:
Christopher Barker wrote:
For your purposes, take a look at the GUIMode.GUIMove class. You
essentially want to make a class just like that, but with "left" changed
to "right" everywhere.
I've done that. It's enclosed, and also in SVN under "Tests".
At this point, it starts out in "right move mode" -- grabbing with the
right button will move it -- but I haven't messed the the toolbar, so as
soon as you click a tool, it goes back to the old ones. I'll leave it as
an exercise for the reader to figure out how to derive from NavCanvas
(or make your own toolbar, etc) to change this.
This requires the latest SVN FloatCanvas to work -- I made a few changed
to make it cleaner.
Also you'll want to put in whatever else you want
for the other mouse events.
That's another exercise for the reader.
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
[EMAIL PROTECTED]
#!/usr/bin/env python
"""
A small demo to show how to make a new GUIMode that allows panning the
image with the right mouse button.
"""
import wx
import numpy as N
## import the installed version
#from wx.lib.floatcanvas import NavCanvas, FloatCanvas
## import a local version
import sys
sys.path.append("..")
from floatcanvas import NavCanvas, FloatCanvas
## A new GUI Mode:
from floatcanvas.GUIMode import GUIMove
class GUIRightMove(GUIMove):
## rename these methods from GUIMMove
OnRightDown = GUIMove.OnLeftDown
def OnLeftDown(self, event):
## you'll probably want to do something else with this.
pass
OnRightUp = GUIMove.OnLeftUp
def OnLeftUp(self, event):
## you'll probably want to do something else with this.
pass
def OnMove(self, event):
# Allways raise the Move event.
self.Canvas._RaiseMouseEvent(event,FloatCanvas.EVT_FC_MOTION)
if event.Dragging() and event.RightIsDown() and not self.StartMove is None:
self.MoveImage(event)
class DrawFrame(wx.Frame):
"""
A frame used for the FloatCanvas Demo
"""
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.CreateStatusBar()
# Add the Canvas
Canvas = NavCanvas.NavCanvas(self,-1,
size = (500,500),
ProjectionFun = None,
Debug = 0,
BackgroundColor = "DARK SLATE BLUE",
).Canvas
self.Canvas = Canvas
FloatCanvas.EVT_MOTION(self.Canvas, self.OnMove )
Point = (45,40)
Box = Canvas.AddScaledTextBox("A Two Line\nString",
Point,
2,
Color = "Black",
BackgroundColor = None,
LineColor = "Red",
LineStyle = "Solid",
LineWidth = 1,
Width = None,
PadSize = 5,
Family = wx.ROMAN,
Style = wx.NORMAL,
Weight = wx.NORMAL,
Underlined = False,
Position = 'br',
Alignment = "left",
InForeground = False)
Box.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.Binding)
self.Show()
Canvas.ZoomToBB()
self.GUIRightMove = GUIRightMove(Canvas)
Canvas.SetMode(self.GUIRightMove)
def OnMove(self, event):
"""
Updates the status bar with the world coordinates
"""
self.SetStatusText("%.2f, %.2f"%tuple(event.Coords))
def Binding(self, event):
print "Writing a png file:"
self.Canvas.SaveAsImage("junk.png")
print "Writing a jpeg file:"
self.Canvas.SaveAsImage("junk.jpg",wx.BITMAP_TYPE_JPEG)
if __name__ == "__main__":
app = wx.App(False)
F = DrawFrame(None, title="FloatCanvas Demo App", size=(700,700) )
app.MainLoop()
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas