I'm almost there but I've hit another snag. I am trying to implement
the zoom and drag functionality on my plot like the example in the
wx.lib.plot and I can't get the check functionality working and so it
seems that when I do try to drag, it seems like the zoom functionality
is enabled and so it all goes badly wrong. I've put a sample of code
below, any pointers greatly appreciated.
import wx
import wx.lib.plot
class Plot(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.data = [(1,2), (2,3), (3,5), (4,6), (5,8), (6,8),
(10,10)]
markers = wx.lib.plot.PolyMarker(self.data, legend='',
colour='pink', marker='triangle_down', size=1)
gc = wx.lib.plot.PlotGraphics([markers], 'Scatter Graph', 'X
Axis', 'Y Axis')
client.Draw(gc, xAxis=(0,15), yAxis=(0,15))
client.Bind(wx.EVT_CONTEXT_MENU, self.OnContextMenu)
def OnContextMenu(self, event):
# only do this part the first time so the events are only
bound once
if not hasattr(self, "popupID01"):
self.popupID01 = wx.NewId()
self.popupID02 = wx.NewId()
client.Bind(wx.EVT_MENU, self.OnEnableZoom,
id=self.popupID01)
client.Bind(wx.EVT_MENU, self.OnEnableDrag,
id=self.popupID02)
# make a menu
self.pMenu = wx.Menu()
# add some items
self.pMenu.Append(self.popupID01, 'Enable &Zoom', 'Enable
Mouse Zoom', kind=wx.ITEM_CHECK)
self.pMenu.Append(self.popupID02, 'Enable &Drag', 'Activates
dragging mode', kind=wx.ITEM_CHECK)
# Popup the menu. If an item is selected then its handler
# will be called before PopupMenu returns.
client.PopupMenu(self.pMenu)
self.pMenu.Destroy()
def OnShowPopup(self, event):
pos = event.GetPosition()
pos = client.ScreenToClient(pos)
client.PopupMenu(self.pMenu, pos)
def OnEnableZoom(self, event):
client.SetEnableZoom(event.IsChecked())
self.pMenu.Check(self.popupID01, not event.IsChecked())
def OnEnableDrag(self, event):
client.SetEnableDrag(event.IsChecked())
self.pMenu.Check(self.popupID02, not event.IsChecked())
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Plotting Ex",
size=(500,500))
# Add a panel so it looks correct on all platforms
self.panel = wx.Panel(self, wx.ID_ANY)
global client
client = wx.lib.plot.PlotCanvas(self.panel)
btn6 = wx.Button(self.panel, 1, 'scatter')
btn6.Bind(wx.EVT_BUTTON, self.OnScatter)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(btn6, 0, wx.ALL|wx.CENTER, 5)
sizer.Add(client, 1, wx.EXPAND | wx.ALL, 5)
self.panel.SetSizer(sizer)
def OnScatter(self, event):
myPlot = Plot(self.panel)
# Run the program
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm().Show()
app.MainLoop()
···
--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en