def _abort(self, *event): if react_to_event(self.view, self.view.textview, event): logger.debug("Abort shortcut pressed {}".format(self.__class__.__name__)) self.cancel_clicked(None) return True else: return False
def paste_action_callback(self, *event): """Add clipboard key value pairs into all selected sub-dictionary""" if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None: _, dict_paths = self.get_view_selection() selected_data_list = rafcon.gui.clipboard.global_clipboard.get_semantic_dictionary_list( ) # enforce paste on root level if semantic data empty or nothing is selected if not dict_paths and not self.model.state.semantic_data: dict_paths = [[]] for target_dict_path_as_list in dict_paths: prev_value = self.model.state.semantic_data value = self.model.state.semantic_data for path_element in target_dict_path_as_list: prev_value = value value = value[path_element] if not isinstance(value, dict) and len( dict_paths) <= 1: # if one selection take parent target_dict_path_as_list.pop(-1) value = prev_value if isinstance(value, dict): for key_to_paste, value_to_add in selected_data_list: self.model.state.add_semantic_data( target_dict_path_as_list, value_to_add, key_to_paste) self.reload_tree_store_data()
def add_action_callback(self, key_value, modifier_mask, a_dict=False): """Callback method for add action""" if react_to_event( self.view, self.tree_view, event=(key_value, modifier_mask)) and self.active_entry_widget is None: self.on_add(None, a_dict) return True
def _redo(self, *event): if not self.view: return buffer = self.view.textview.get_buffer() if react_to_event(self.view, self.view.textview, event) and hasattr(buffer, 'can_redo') and buffer.can_redo(): logger.debug('Run redo on {}'.format(self.__class__.__name__)) return buffer.redo() return False
def _add_new_state(self, *event, **kwargs): """Triggered when shortcut keys for adding a new state are pressed, or Menu Bar "Edit, Add State" is clicked. Adds a new state only if the the state machine tree is in focus. """ if react_to_event(self.view, self.view['state_machine_tree_view'], event): state_type = StateType.EXECUTION if 'state_type' not in kwargs else kwargs['state_type'] gui_helper_state_machine.add_new_state(self._selected_sm_model, state_type) return True
def cut_action_callback(self, *event): """Callback method for copy action""" if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None: sm_selection, sm_selected_model_list = self.get_state_machine_selection() # only list specific elements are cut by widget if sm_selection is not None: sm_selection.set(sm_selected_model_list) global_clipboard.cut(sm_selection) return True
def paste_action_callback(self, *event): """Callback method for paste action""" if react_to_event(self.view, self.tree_view, event): sm_selection, _ = self.get_state_machine_selection() # only list specific elements are cut by widget if len(sm_selection.states) == 1: global_clipboard.paste(sm_selection.get_selected_state(), limited=['states', 'transitions', 'data_flows']) else: logger.warning("Please select only one state to paste.") return True
def remove_action_callback(self, *event): """Callback method for remove action The method checks whether a shortcut ('Delete') is in the gui config model which shadow the delete functionality of maybe active a entry widget. If a entry widget is active the remove callback return with None. """ if react_to_event(self.view, self.tree_view, event) and \ not (self.active_entry_widget and not is_event_of_key_string(event, 'Delete')): self.on_remove(None) return True
def _apply(self, *event): if react_to_event(self.view, self.view.textview, event): logger.debug("Apply short-cut pressed {}".format(self.__class__.__name__)) if self.source_text == self.view.get_text(): logger.debug("Nothing to apply {}".format(self.__class__.__name__)) else: self.apply_clicked(None) return True return False
def redo(self, key_value, modifier_mask): """Redo for selected state-machine if no state-source-editor is open and focused in states-editor-controller. :return: True if a redo was performed, False if focus on source-editor. :rtype: bool """ # TODO re-organize as request to controller which holds source-editor-view or any parent to it for key, tab in gui_singletons.main_window_controller.get_controller('states_editor_ctrl').tabs.items(): if tab['controller'].get_controller('source_ctrl') is not None and \ react_to_event(self.view, tab['controller'].get_controller('source_ctrl').view.textview, (key_value, modifier_mask)) or \ tab['controller'].get_controller('description_ctrl') is not None and \ react_to_event(self.view, tab['controller'].get_controller('description_ctrl').view.textview, (key_value, modifier_mask)): return False if self._selected_sm_model is not None: self._selected_sm_model.history.redo() return True else: logger.debug("Redo is not possible now as long as no state_machine is selected.")
def copy_action_callback(self, *event): """Add a copy of all selected row dict value pairs to the clipboard""" if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None: _, dict_paths = self.get_view_selection() selected_data_list = [] for dict_path_as_list in dict_paths: value = self.model.state.semantic_data for path_element in dict_path_as_list: value = value[path_element] selected_data_list.append((path_element, value)) rafcon.gui.clipboard.global_clipboard.set_semantic_dictionary_list(selected_data_list)
def _on_add_library(self, *event): """Callback method handling the addition of a new library """ self.view['library_tree_view'].grab_focus() if react_to_event(self.view, self.view['library_tree_view'], event): temp_library_name = "<LIB_NAME_%s>" % self._lib_counter self._lib_counter += 1 library_config = self.core_config_model.get_current_config_value( "LIBRARY_PATHS", use_preliminary=True, default={}) library_config[temp_library_name] = "<LIB_PATH>" self.core_config_model.set_preliminary_config_value( "LIBRARY_PATHS", library_config) self._select_row_by_column_value(self.view['library_tree_view'], self.library_list_store, 0, temp_library_name) return True
def _on_remove_library(self, *event): """Callback method handling the removal of an existing library """ self.view['library_tree_view'].grab_focus() if react_to_event(self.view, self.view['library_tree_view'], event): path = self.view["library_tree_view"].get_cursor()[0] if path is not None: library_name = self.library_list_store[int(path[0])][0] library_config = self.core_config_model.get_current_config_value( "LIBRARY_PATHS", use_preliminary=True, default={}) del library_config[library_name] self.core_config_model.set_preliminary_config_value( "LIBRARY_PATHS", library_config) if len(self.library_list_store) > 0: self.view['library_tree_view'].set_cursor( min(path[0], len(self.library_list_store) - 1)) return True
def _open_external_editor(self, *event, **kwargs): if react_to_event(self.view, self.view.textview, event): self.view['open_external_button'].set_active(True) return True return False
def _delete_selection(self, *event): if react_to_event(self.view, self.view['state_machine_tree_view'], event): return gui_helper_state_machine.delete_selected_elements( self._selected_sm_model)
def add_action_callback(self, *event): """Callback method for add action""" if react_to_event(self.view, self.tree_view, event) and self.active_entry_widget is None: self.on_add(None) return True