diff options
Diffstat (limited to 'grc')
-rw-r--r-- | grc/core/Param.py | 23 | ||||
-rw-r--r-- | grc/gui/ActionHandler.py | 27 | ||||
-rw-r--r-- | grc/gui/Actions.py | 10 | ||||
-rw-r--r-- | grc/gui/Bars.py | 2 |
4 files changed, 55 insertions, 7 deletions
diff --git a/grc/core/Param.py b/grc/core/Param.py index 26f9d2f451..afa478b3a2 100644 --- a/grc/core/Param.py +++ b/grc/core/Param.py @@ -485,13 +485,20 @@ class Param(Element): # Can python use this as a variable? if not _check_id_matcher.match(v): raise Exception('ID "{0}" must begin with a letter and may contain letters, numbers, and underscores.'.format(v)) - ids = [param.get_value() for param in self.get_all_params(t)] + ids = [param.get_value() for param in self.get_all_params(t, 'id')] - # Id should only appear once, or zero times if block is disabled - if ids.count(v) > 1: - raise Exception('ID "{0}" is not unique.'.format(v)) if v in ID_BLACKLIST: raise Exception('ID "{0}" is blacklisted.'.format(v)) + + if self._key == 'id': + # Id should only appear once, or zero times if block is disabled + if ids.count(v) > 1: + raise Exception('ID "{0}" is not unique.'.format(v)) + else: + # Id should exist to be a reference + if ids.count(v) < 1: + raise Exception('ID "{0}" does not exist.'.format(v)) + return v ######################### @@ -655,17 +662,19 @@ class Param(Element): else: return v - def get_all_params(self, type): + def get_all_params(self, type, key=None): """ - Get all the params from the flowgraph that have the given type. + Get all the params from the flowgraph that have the given type and + optionally a given key Args: type: the specified type + key: the key to match against Returns: a list of params """ - return sum([filter(lambda p: p.get_type() == type, block.get_params()) for block in self.get_parent().get_parent().get_enabled_blocks()], []) + return sum([filter(lambda p: ((p.get_type() == type) and ((key is None) or (p.get_key() == key))), block.get_params()) for block in self.get_parent().get_parent().get_enabled_blocks()], []) def is_enum(self): return self._type == 'enum' diff --git a/grc/gui/ActionHandler.py b/grc/gui/ActionHandler.py index b9f534fdf0..5d48485238 100644 --- a/grc/gui/ActionHandler.py +++ b/grc/gui/ActionHandler.py @@ -131,6 +131,7 @@ class ActionHandler: for action in ( Actions.APPLICATION_QUIT, Actions.FLOW_GRAPH_NEW, Actions.FLOW_GRAPH_OPEN, Actions.FLOW_GRAPH_SAVE_AS, + Actions.FLOW_GRAPH_DUPLICATE, Actions.FLOW_GRAPH_SAVE_A_COPY, Actions.FLOW_GRAPH_CLOSE, Actions.ABOUT_WINDOW_DISPLAY, Actions.FLOW_GRAPH_SCREEN_CAPTURE, Actions.HELP_WINDOW_DISPLAY, Actions.TYPES_WINDOW_DISPLAY, Actions.TOGGLE_BLOCKS_WINDOW, @@ -561,6 +562,32 @@ class ActionHandler: Preferences.add_recent_file(file_path) main.tool_bar.refresh_submenus() main.menu_bar.refresh_submenus() + elif action == Actions.FLOW_GRAPH_SAVE_A_COPY: + try: + if not page.get_file_path(): + Actions.FLOW_GRAPH_SAVE_AS() + else: + dup_file_path = page.get_file_path() + dup_file_name = '.'.join(dup_file_path.split('.')[:-1]) + "_copy" # Assuming .grc extension at the end of file_path + dup_file_path_temp = dup_file_name+'.grc' + count = 1 + while os.path.exists(dup_file_path_temp): + dup_file_path_temp = dup_file_name+'('+str(count)+').grc' + count += 1 + dup_file_path_user = SaveFlowGraphFileDialog(dup_file_path_temp).run() + if dup_file_path_user is not None: + ParseXML.to_file(flow_graph.export_data(), dup_file_path_user) + Messages.send('Saved Copy to: "' + dup_file_path_user + '"\n') + except IOError: + Messages.send_fail_save("Can not create a copy of the flowgraph\n") + elif action == Actions.FLOW_GRAPH_DUPLICATE: + flow_graph = main.get_flow_graph() + main.new_page() + curr_page = main.get_page() + new_flow_graph = main.get_flow_graph() + new_flow_graph.import_data(flow_graph.export_data()) + flow_graph_update(new_flow_graph) + curr_page.set_saved(False) elif action == Actions.FLOW_GRAPH_SCREEN_CAPTURE: file_path, background_transparent = SaveScreenShotDialog(page.get_file_path()).run() if file_path is not None: diff --git a/grc/gui/Actions.py b/grc/gui/Actions.py index 9b2af36b93..6eccab75fb 100644 --- a/grc/gui/Actions.py +++ b/grc/gui/Actions.py @@ -203,6 +203,16 @@ FLOW_GRAPH_SAVE_AS = Action( stock_id=gtk.STOCK_SAVE_AS, keypresses=(gtk.keysyms.s, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK), ) +FLOW_GRAPH_SAVE_A_COPY = Action( + label='Save A Copy', + tooltip='Save the copy of current flowgraph', +) +FLOW_GRAPH_DUPLICATE = Action( + label='_Duplicate', + tooltip='Create a duplicate of current flowgraph', + stock_id=gtk.STOCK_COPY, + keypresses=(gtk.keysyms.d, gtk.gdk.CONTROL_MASK | gtk.gdk.SHIFT_MASK), +) FLOW_GRAPH_CLOSE = Action( label='_Close', tooltip='Close the current flow graph', diff --git a/grc/gui/Bars.py b/grc/gui/Bars.py index a4819b973c..d9bc2aedb7 100644 --- a/grc/gui/Bars.py +++ b/grc/gui/Bars.py @@ -64,11 +64,13 @@ TOOLBAR_LIST = ( MENU_BAR_LIST = ( (gtk.Action('File', '_File', None, None), [ 'flow_graph_new', + Actions.FLOW_GRAPH_DUPLICATE, Actions.FLOW_GRAPH_OPEN, 'flow_graph_recent', None, Actions.FLOW_GRAPH_SAVE, Actions.FLOW_GRAPH_SAVE_AS, + Actions.FLOW_GRAPH_SAVE_A_COPY, None, Actions.FLOW_GRAPH_SCREEN_CAPTURE, None, |