diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2015-04-02 13:20:19 +0200 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2015-04-02 13:20:19 +0200 |
commit | a601b909daabe84c1a3c31ba13456e48c3871e46 (patch) | |
tree | 27003ad191368168e0ae15ec05c2ff79f6a5b47c /grc | |
parent | ffb28308cefc7cf588da745508670122319c690f (diff) |
grc: move context def into Bars.py and add submenu
Diffstat (limited to 'grc')
-rw-r--r-- | grc/gui/Bars.py | 53 | ||||
-rw-r--r-- | grc/gui/FlowGraph.py | 21 |
2 files changed, 52 insertions, 22 deletions
diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py index 5041a28f14..6ce614bc99 100644 --- a/grc/gui/Bars.py +++ b/grc/gui/Bars.py @@ -121,6 +121,30 @@ MENU_BAR_LIST = ( Actions.ABOUT_WINDOW_DISPLAY, ]), ) + + +CONTEXT_MENU_LIST = [ + Actions.BLOCK_CUT, + Actions.BLOCK_COPY, + Actions.BLOCK_PASTE, + Actions.ELEMENT_DELETE, + None, + Actions.BLOCK_ROTATE_CCW, + Actions.BLOCK_ROTATE_CW, + Actions.BLOCK_ENABLE, + Actions.BLOCK_DISABLE, + None, + (gtk.Action('More', '_More', None, None), [ + Actions.BLOCK_CREATE_HIER, + Actions.OPEN_HIER, + None, + Actions.BUSSIFY_SOURCES, + Actions.BUSSIFY_SINKS, + ]), + Actions.BLOCK_PARAM_MODIFY +] + + class Toolbar(gtk.Toolbar): """The gtk toolbar with actions added from the toolbar list.""" @@ -138,6 +162,7 @@ class Toolbar(gtk.Toolbar): action.set_property('tooltip', action.get_property('tooltip')) else: self.add(gtk.SeparatorToolItem()) + class MenuBar(gtk.MenuBar): """The gtk menu bar with actions added from the menu bar list.""" @@ -157,7 +182,29 @@ class MenuBar(gtk.MenuBar): main_menu = gtk.Menu() main_menu_item.set_submenu(main_menu) for action in actions: - if action: #append a menu item - main_menu.append(action.create_menu_item()) - else: main_menu.append(gtk.SeparatorMenuItem()) + main_menu.append(action.create_menu_item() if action else + gtk.SeparatorMenuItem()) main_menu.show_all() #this show all is required for the separators to show + + +class ContextMenu(gtk.Menu): + """The gtk menu with actions added from the context menu list.""" + + def __init__(self): + gtk.Menu.__init__(self) + for action in CONTEXT_MENU_LIST: + if isinstance(action, tuple): + action, sub_menu_action_list = action + item = action.create_menu_item() + self.append(item) + sub_menu = gtk.Menu() + item.set_submenu(sub_menu) + for action in sub_menu_action_list: + sub_menu.append(action.create_menu_item() if action else + gtk.SeparatorMenuItem()) + sub_menu.show_all() + + else: + self.append(action.create_menu_item() if action else + gtk.SeparatorMenuItem()) + self.show_all() diff --git a/grc/gui/FlowGraph.py b/grc/gui/FlowGraph.py index 794d992e4e..f8be2f6cc3 100644 --- a/grc/gui/FlowGraph.py +++ b/grc/gui/FlowGraph.py @@ -27,6 +27,7 @@ pygtk.require('2.0') import gtk import random import Messages +import Bars class FlowGraph(Element): """ @@ -54,25 +55,7 @@ class FlowGraph(Element): # current mouse hover element self.element_under_mouse = None #context menu - self._context_menu = gtk.Menu() - for action in [ - Actions.BLOCK_CUT, - Actions.BLOCK_COPY, - Actions.BLOCK_PASTE, - Actions.ELEMENT_DELETE, - None, - Actions.BLOCK_ROTATE_CCW, - Actions.BLOCK_ROTATE_CW, - Actions.BLOCK_ENABLE, - Actions.BLOCK_DISABLE, - None, - Actions.BLOCK_CREATE_HIER, - Actions.OPEN_HIER, - Actions.BUSSIFY_SOURCES, - Actions.BUSSIFY_SINKS, - None, - Actions.BLOCK_PARAM_MODIFY - ]: self._context_menu.append(action.create_menu_item() if action else gtk.SeparatorMenuItem()) + self._context_menu = Bars.ContextMenu() self.get_context_menu = lambda: self._context_menu ########################################################################### |