Popup menu in plot

Is it possible to produce a popup menu when using wx.lib.plot instead
of a traditional menu? I'd like to be able to right click and select
from there.

Thanks

···

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

You should be able to bind a handler for EVT_CONTEXT_MENU and pop up your own menu from there.

···

On 5/19/10 9:19 AM, ytzsch wrote:

Is it possible to produce a popup menu when using wx.lib.plot instead
of a traditional menu? I'd like to be able to right click and select
from there.

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Nice one Robin. I've got it working thanks.

···

On May 20, 7:34 am, Robin Dunn <ro...@alldunn.com> wrote:

On 5/19/10 9:19 AM, ytzsch wrote:

> Is it possible to produce a popup menu when using wx.lib.plot instead
> of a traditional menu? I'd like to be able to right click and select
> from there.

You should be able to bind a handler for EVT_CONTEXT_MENU and pop up
your own menu from there.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visithttp://groups.google.com/group/wxPython-users?hl=en

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

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

Since you need to create the popup menu each time you use it you will need to do the Check() of the checkable items to show the current state before you do the popup.

···

On 5/23/10 6:30 AM, ytzsch wrote:

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.

--
Robin Dunn
Software Craftsman

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Finally figured it out. Got the checks working and also fixed the drag
issue that was fixed by the following line:

client.Draw(gc, xAxis=(0,15), yAxis=(0,15)

becomes:

client.Draw(gc, xAxis=(0.0,15.0), yAxis=(0.0,15.0))

but it took a lot of finding.

···

On May 24, 10:32 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 5/23/10 6:30 AM, ytzsch wrote:

> 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.

Since you need to create thepopupmenu each time you use it you will
need to do the Check() of the checkable items to show the current state
before you do thepopup.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visithttp://groups.google.com/group/wxPython-users?hl=en