Editting the context menu

955 views
Skip to first unread message

Nathaniel Saul

unread,
Jan 29, 2014, 8:59:33 PM1/29/14
to pyqt...@googlegroups.com
I would like to trim down the right click menu as a lot of the items on it will not be useful in my application.  How would I go about doing this? 
Specifically, I don't want 'plot options' and 'export' to show up.  I do not want the user to be able to export from the right click as it kills some of the threads that are running.  The plot options is mostly useless for my application.

Is there a way to override this?  I have looked through the viewBox and the viewBoxMenu but haven't found any good way to do this. 

Thanks,
Nathaniel Saul

Luke Campagnola

unread,
Jan 30, 2014, 11:32:23 AM1/30/14
to pyqt...@googlegroups.com
On Wed, Jan 29, 2014 at 8:59 PM, Nathaniel Saul <saul...@gmail.com> wrote:
I would like to trim down the right click menu as a lot of the items on it will not be useful in my application.  How would I go about doing this? 
Specifically, I don't want 'plot options' and 'export' to show up.  I do not want the user to be able to export from the right click as it kills some of the threads that are running.

That's interesting.. can you explain what you mean by "kills some of the treads" ? This should not happen.
 
  The plot options is mostly useless for my application.

Is there a way to override this?  I have looked through the viewBox and the viewBoxMenu but haven't found any good way to do this. 


The comtext menu you see is constructed from 3 separate menus: the ViewBox generates the topmost entries (View all ... Mouse Mode), PlotItem adds the "Plot Options" entry, and the scene adds the "Export" entry. So to get rid of the last two entries, try this:

    >>> import pyqtgraph as pg
    >>> plt = pg.plot();
    >>> plt.plotItem.ctrlMenu = None  # get rid of 'Plot Options'
    >>> plt.scene().contextMenu = None  # get rid of 'Export'

If you want to modify the other entries selectively, you can access ViewBox.menu directly (see QMenu.removeAction)


Luke

Nathaniel Saul

unread,
Jan 30, 2014, 9:01:42 PM1/30/14
to pyqt...@googlegroups.com
I'm exactly sure what is going on.   I'll try to explain it as best I can. 
My plots are updated regularly, about 5x per second.  To do this in a way that I can change the update rate, I made an update thread that emits a signal periodically.  The plot's update method is connected to this signal and every time it receives the signal, it refreshes itself.  When I use the right click->export, all of the updating stops, and not just for this plot.  Even when I open new plots they do not update.  So I assume that the update thread has been killed.  I'm still a novice, so there is probably more going on than meets my I, and I haven't bothered to track the issue down.

Here's the error message I receive:
udp_read_packet -- select:: Interrupted system call
udp_read_packet -- select:: Interrupted system call
udp_read_packet -- select:: Interrupted system call
udp_read_packet -- select:: Interrupted system call
Traceback (most recent call last):
  File "/home/sauln/Projects/LCM Graphing Utility/lcmThread.py", line 57, in run
    self.lc.handle()            
IOError: [Errno 4] Interrupted system call


Regardless, thanks you,
These 2 lines did exactly what I needed:


    >>> plt.plotItem.ctrlMenu = None  # get rid of 'Plot Options'
    >>> plt.scene().contextMenu = None  # get rid of 'Export'

--
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyqtgraph/h-dyr0l6yZU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/CACZXET_d21Y%2BrFOJtFC%2BPQrSkRz3hP_JZBbH9r1z3WA4CZKN3A%40mail.gmail.com.

For more options, visit https://groups.google.com/groups/opt_out.

Luke Campagnola

unread,
Jan 30, 2014, 9:47:50 PM1/30/14
to pyqt...@googlegroups.com
On Thu, Jan 30, 2014 at 9:01 PM, Nathaniel Saul <saul...@gmail.com> wrote:
I'm exactly sure what is going on.   I'll try to explain it as best I can. 
My plots are updated regularly, about 5x per second.  To do this in a way that I can change the update rate, I made an update thread that emits a signal periodically.  The plot's update method is connected to this signal and every time it receives the signal, it refreshes itself.  When I use the right click->export, all of the updating stops, and not just for this plot.  Even when I open new plots they do not update.  So I assume that the update thread has been killed.  I'm still a novice, so there is probably more going on than meets my I, and I haven't bothered to track the issue down.

Here's the error message I receive:
udp_read_packet -- select:: Interrupted system call
udp_read_packet -- select:: Interrupted system call
udp_read_packet -- select:: Interrupted system call
udp_read_packet -- select:: Interrupted system call
Traceback (most recent call last):
  File "/home/sauln/Projects/LCM Graphing Utility/lcmThread.py", line 57, in run
    self.lc.handle()            
IOError: [Errno 4] Interrupted system call


I have no idea where this thread communication issue is coming from, but I recommend avoiding threads if possible. If all you need is a periodic signal, use QTimer.
 
Reply all
Reply to author
Forward
0 new messages