diff --git a/src/damaris/gui/DamarisGUI.py b/src/damaris/gui/DamarisGUI.py index 8069159..62f8395 100644 --- a/src/damaris/gui/DamarisGUI.py +++ b/src/damaris/gui/DamarisGUI.py @@ -2278,9 +2278,8 @@ class MonitorWidgets: # add figure to canvas self.matplot_canvas = FigureCanvas( self.matplot_figure ) - # add right-click context menu to canva - # disable right lcikc for now - #self.matplot_canvas.connect("button-press-event", self.on_canvas_button_press) + # add ctrl + right-click context menu to canvas + self.matplot_canvas.connect("button-press-event", self.on_canvas_button_press) self.display_table = self.xml_gui.get_object( "display_table" ) self.display_table.attach( self.matplot_canvas, 0, 6, 0, 1, gtk.AttachOptions.EXPAND | gtk.AttachOptions.FILL, gtk.AttachOptions.EXPAND | gtk.AttachOptions.FILL, 0, 0 ) @@ -2293,17 +2292,17 @@ class MonitorWidgets: #self.matplot_toolbar.remove(self.matplot_toolbar.get_nth_item(3)) self.matplot_toolbar.remove(self.matplot_toolbar.get_nth_item(6)) # now let's add a button to the toolbar - button = gtk.ToggleButton(label='') + self.matplot_cursor_button = gtk.ToggleButton(label='') try: image = gtk.Image.new_from_file("/usr/share/icons/breeze/actions/24/crosshairs-symbolic.svg") - button.set_image(image) + self.matplot_cursor_button.set_image(image) except: pass - button.set_tooltip_text('Enable Crosshairs') - button.show() - button.connect('toggled', self.toggle_cursor) + self.matplot_cursor_button.set_tooltip_text('Enable Crosshairs') + self.matplot_cursor_button.show() + self.matplot_cursor_button.connect('toggled', self.toggle_cursor) toolitem = gtk.ToolItem() - toolitem.add(button) + toolitem.add(self.matplot_cursor_button) self.matplot_toolbar.insert(toolitem, 5) # Make cursor position text bigger and bold - access message label directly @@ -2745,16 +2744,27 @@ class MonitorWidgets: def toggle_cursor(self, widget): """Toggle matplotlib crosshair cursor""" if widget.get_active(): - self.matplot_cursor = matplotlib.widgets.Cursor(self.matplot_axes, useblit=False, color='red', linewidth=1) + # Activate cursor + if not hasattr(self, 'matplot_cursor') or self.matplot_cursor is None: + self.matplot_cursor = matplotlib.widgets.Cursor(self.matplot_axes, + useblit=False, color='red', linewidth=1) + self.matplot_canvas.draw() + else: - if hasattr(self, 'matplot_cursor'): + # Deactivate cursor + if hasattr(self, 'matplot_cursor') and self.matplot_cursor is not None: + self.matplot_cursor.disconnect_events() + # Remove the lines from the plot + if hasattr(self.matplot_cursor, 'lineh'): + self.matplot_cursor.lineh.remove() + if hasattr(self.matplot_cursor, 'linev'): + self.matplot_cursor.linev.remove() self.matplot_cursor = None - self.matplot_canvas.draw_idle() + self.matplot_canvas.draw() def on_canvas_button_press(self, widget, event): """Handle button press events on matplotlib canvas""" - - if event.button == 3: # Right click + if event.button == 2: # middle click self.show_canvas_context_menu(event) return True return False @@ -2770,7 +2780,7 @@ class MonitorWidgets: toggle_cursor.set_active(True) else: toggle_cursor.set_active(False) - toggle_cursor.connect("toggled", self.toggle_cursor) + toggle_cursor.connect("toggled", lambda w: self.matplot_cursor_button.set_active(w.get_active())) menu.append(toggle_cursor) # Copy as PNG