summaryrefslogtreecommitdiff
path: root/grc/gui/canvas/flowgraph.py
diff options
context:
space:
mode:
authorBrennan Ashton <bashton@brennanashton.com>2018-10-29 13:57:43 -0700
committerMarcus Müller <marcus@hostalia.de>2018-11-02 00:08:15 +0100
commitcaa9ded4bbb11a65ea60e3df0e239a771f8ca1fc (patch)
treeaa5868d33cc77adca3776889183d29301acbfb9e /grc/gui/canvas/flowgraph.py
parenta1dcad241e0531bf0ad3c7fc2da418015ac2a04b (diff)
grc: Restore right click menu. Fixes #2062
Diffstat (limited to 'grc/gui/canvas/flowgraph.py')
-rw-r--r--grc/gui/canvas/flowgraph.py36
1 files changed, 32 insertions, 4 deletions
diff --git a/grc/gui/canvas/flowgraph.py b/grc/gui/canvas/flowgraph.py
index 3e0fd83dad..ca27406e0e 100644
--- a/grc/gui/canvas/flowgraph.py
+++ b/grc/gui/canvas/flowgraph.py
@@ -26,18 +26,36 @@ from distutils.spawn import find_executable
from itertools import count
import six
-from gi.repository import GLib
+from gi.repository import GLib, Gtk
from six.moves import filter
from . import colors
from .drawable import Drawable
from .connection import DummyConnection
-from .. import Actions, Constants, Utils, Bars, Dialogs
+from .. import Actions, Constants, Utils, Bars, Dialogs, MainWindow
from ..external_editor import ExternalEditor
from ...core import Messages
from ...core.FlowGraph import FlowGraph as CoreFlowgraph
+class _ContextMenu(object):
+ """
+ Help with drawing the right click context menu
+ """
+
+ def __init__(self, main_window):
+ self._menu = Gtk.Menu.new_from_model(Bars.ContextMenu())
+ self._menu.attach_to_widget(main_window)
+
+ # In GTK 3.22 Menu.popup was deprecated, we want to popup at the
+ # pointer, so use that new function instead if we can.
+ if Gtk.check_version(3,22,0) is None:
+ self.popup = self._menu.popup_at_pointer
+
+ def popup(self, event):
+ self._menu.popup(None, None, None, None, event.button, event.time)
+
+
class FlowGraph(CoreFlowgraph, Drawable):
"""
FlowGraph is the data structure to store graphical signal blocks,
@@ -52,6 +70,16 @@ class FlowGraph(CoreFlowgraph, Drawable):
"""
super(self.__class__, self).__init__(parent, **kwargs)
Drawable.__init__(self)
+
+ # We need to get the main window object so the context menu can be to the
+ # registered actions
+ app = Gtk.Application.get_default()
+ main_window = None
+ for window in app.get_windows():
+ if isinstance(window, MainWindow.MainWindow):
+ main_window = window
+ break
+
self.drawing_area = None
# important vars dealing with mouse event tracking
self.element_moved = False
@@ -64,7 +92,7 @@ class FlowGraph(CoreFlowgraph, Drawable):
# current mouse hover element
self.element_under_mouse = None
# context menu
- self._context_menu = Bars.ContextMenu()
+ self._context_menu = _ContextMenu(main_window)
self.get_context_menu = lambda: self._context_menu
self._new_connection = None
@@ -661,7 +689,7 @@ class FlowGraph(CoreFlowgraph, Drawable):
if self._new_connection:
self._new_connection = None
self.drawing_area.queue_draw()
- self._context_menu.popup(None, None, None, None, event.button, event.time)
+ self._context_menu.popup(event)
def handle_mouse_selector_press(self, double_click, coordinate):
"""