def on_delete_check_sm_modified(self): if state_machine_manager.has_dirty_state_machine(): message_string = "Are you sure you want to exit RAFCON?\n\n" \ "The following state machines have been modified and not saved. " \ "These changes will get lost:" for sm_id, sm in state_machine_manager.state_machines.iteritems(): if sm.marked_dirty: message_string = "%s\n#%s: %s " % ( message_string, str(sm_id), sm.root_state.name) dialog = RAFCONButtonDialog(message_string, ["Close without saving", "Cancel"], message_type=gtk.MESSAGE_WARNING, parent=self.get_root_window()) response_id = dialog.run() dialog.destroy() if response_id == 1: # Close without saving - button pressed if not self.state_machine_execution_engine.finished_or_stopped( ): self.on_delete_check_sm_running() else: gui_singletons.main_window_controller.prepare_destruction() self.on_destroy(None) elif response_id == 2: # Cancel - button pressed logger.debug("Close main window canceled") return True return False
def execute(self, inputs, outputs, gvm): self.logger.debug("Creating button dialog") if len(inputs['buttons']) != 2: self.logger.error("Please specify exactly two buttons as a list") return "aborted" dialog_window = RAFCONButtonDialog(markup_text=inputs['message_text'], button_texts=inputs['buttons']) abort = inputs['abort_on_quit'] response_id = dialog_window.run() dialog_window.destroy() if response_id == 1: return 0 elif response_id == 2: return 1 if abort: return "aborted" else: return 1
def menu_item_remove_libraries_or_root_clicked(self, menu_item): """Removes library from hard drive after request second confirmation""" menu_item_text = self.get_menu_item_text(menu_item) logger.info("Delete item '{0}' pressed.".format(menu_item_text)) model, path = self.view.get_selection().get_selected() if path: # Second confirmation to delete library tree_m_row = self.filter[path] library_os_path, library_path, library_name, item_key = self.extract_library_properties_from_selected_row() library_file_system_path = library_os_path if "root" in menu_item_text: button_texts = [menu_item_text + "from tree and config", "Cancel"] partial_message = "This will remove the library root from your configuration (config.yaml)." else: button_texts = [menu_item_text, "Cancel"] partial_message = "This folder will be removed from your hard drive! Do you really want to do that?" message_string = "You have chosen to {2} with " \ "\n\nlibrary tree path: {0}" \ "\n\nphysical path: {1}\n\n\n" \ "{3}" \ "".format(os.path.join(self.convert_if_human_readable(tree_m_row[self.LIB_PATH_STORAGE_ID]), item_key), library_file_system_path, menu_item_text.lower(), partial_message) width = 8*len("physical path: " + library_file_system_path) dialog = RAFCONButtonDialog(message_string, button_texts, message_type=Gtk.MessageType.QUESTION, parent=self.get_root_window(), width=min(width, 1400)) response_id = dialog.run() dialog.destroy() if response_id == 1: if "root" in menu_item_text: logger.info("Remove library root key '{0}' from config.".format(item_key)) from rafcon.gui.singleton import global_config library_paths = global_config.get_config_value('LIBRARY_PATHS') del library_paths[tree_m_row[self.LIB_KEY_STORAGE_ID]] global_config.save_configuration() self.model.library_manager.refresh_libraries() elif "libraries" in menu_item_text: logger.debug("Remove of all libraries in {} is triggered.".format(library_os_path)) import shutil shutil.rmtree(library_os_path) self.model.library_manager.refresh_libraries() else: logger.debug("Remove of Library {} is triggered.".format(library_os_path)) self.model.library_manager.remove_library_from_file_system(library_path, library_name) elif response_id in [2, -4]: pass else: logger.warning("Response id: {} is not considered".format(response_id)) return True return False
def run_dialog(event, result, logger): dialog_window = RAFCONButtonDialog(markup_text=inputs['message_text'], button_texts=inputs['buttons'], flags=Gtk.DialogFlags.MODAL, parent=get_root_window()) result[1] = dialog_window result[0] = dialog_window.run() dialog_window.destroy() event.set()
def __init__(self, text, subtext, options, key_mapping, logger): subtext = subtext or text RAFCONButtonDialog.__init__(self, message_type=Gtk.MessageType.INFO, flags=Gtk.DialogFlags.MODAL, parent=get_root_window(), title=text, markup_text=subtext, button_texts=options) if key_mapping: self.connect('key-press-event', self.on_dialog_key_press, key_mapping, options)
def on_delete_check_sm_running(self): if not self.state_machine_execution_engine.finished_or_stopped(): message_string = "The state machine is still running. Do you want to stop the execution before closing?" dialog = RAFCONButtonDialog(message_string, ["Stop execution", "Keep running"], message_type=gtk.MESSAGE_QUESTION, parent=self.get_root_window()) response_id = dialog.run() dialog.destroy() if response_id == 1: # Stop execution self.state_machine_execution_engine.stop() elif response_id == 2: # Keep running logger.debug("State machine will stay running!") gui_singletons.main_window_controller.prepare_destruction() self.on_destroy(None) return True return False
def push_sm_dirty_dialog(): sm_id = state_machine_m.state_machine.state_machine_id root_state_name = state_machine_m.root_state.state.name message_string = "There are unsaved changes in the state machine '{0}' with id {1}. Do you want to close " \ "the state machine anyway?".format(root_state_name, sm_id) dialog = RAFCONButtonDialog(message_string, ["Close without saving", "Cancel"], message_type=Gtk.MessageType.QUESTION, parent=self.get_root_window()) response_id = dialog.run() dialog.destroy() if response_id == 1: # Close without saving pressed remove_state_machine_m() return True else: logger.debug("Closing of state machine canceled") return False
def on_delete_check_sm_running(self): if not self.state_machine_execution_engine.finished_or_stopped(): message_string = "The state machine is still running. Do you want to stop the execution before closing?" dialog = RAFCONButtonDialog(message_string, ["Stop execution", "Keep running"], message_type=Gtk.MessageType.QUESTION, parent=self.get_root_window()) response_id = dialog.run() dialog.destroy() if response_id == 1: # Stop execution self.state_machine_execution_engine.stop() return False elif response_id == 2: # Keep running logger.debug("State machine will keep running!") return True else: return False
def execute(self, inputs, outputs, gvm): self.logger.debug("Creating a generic button dialog") dialog_window = RAFCONButtonDialog(markup_text=inputs['message_text'], button_texts=inputs['buttons']) response_id = dialog_window.run() dialog_window.destroy() outputs['response_id'] = response_id if response_id >= 1: return 0 if inputs['abort_on_quit']: return "aborted" else: return 1
def push_sm_running_dialog(): message_string = "The state machine is still running. Are you sure you want to close?" dialog = RAFCONButtonDialog(message_string, ["Stop and close", "Cancel"], message_type=gtk.MESSAGE_QUESTION, parent=self.get_root_window()) response_id = dialog.run() dialog.destroy() if response_id == 1: logger.debug("State machine execution is being stopped") state_machine_execution_engine.stop() remove_state_machine_m() return True elif response_id == 2: logger.debug("State machine execution will keep running") return False
def push_sm_running_dialog(): message_string = "The state machine is still running. Are you sure you want to close?" dialog = RAFCONButtonDialog(message_string, ["Stop and close", "Cancel"], message_type=Gtk.MessageType.QUESTION, parent=self.get_root_window()) response_id = dialog.run() dialog.destroy() if response_id == 1: logger.debug("State machine execution is being stopped") state_machine_execution_engine.stop() state_machine_execution_engine.join() # wait for gui is needed; otherwise the signals related to the execution engine cannot # be processed properly by the state machine under destruction rafcon.gui.utils.wait_for_gui() remove_state_machine_m() return True elif response_id == 2: logger.debug("State machine execution will keep running") return False
def on_delete_check_sm_modified(self): if state_machine_manager.has_dirty_state_machine(): message_string = "Are you sure you want to exit RAFCON?\n\n" \ "The following state machines have been modified and not saved. " \ "These changes will get lost:" for sm_id, sm in state_machine_manager.state_machines.items(): if sm.marked_dirty: message_string = "%s\n#%s: %s " % ( message_string, str(sm_id), sm.root_state.name) dialog = RAFCONButtonDialog(message_string, ["Close without saving", "Cancel"], message_type=Gtk.MessageType.WARNING, parent=self.get_root_window()) response_id = dialog.run() dialog.destroy() if response_id == 1: # Close without saving - button pressed return False elif response_id == 2: # Cancel - button pressed logger.debug("Close main window canceled") return True else: return False
def apply_clicked(self, button): """Triggered when the Apply button in the source editor is clicked. """ if isinstance(self.model.state, LibraryState): logger.warn("It is not allowed to modify libraries.") self.view.set_text("") return # Ugly workaround to give user at least some feedback about the parser # Without the loop, this function would block the GTK main loop and the log message would appear after the # function has finished # TODO: run parser in separate thread while gtk.events_pending(): gtk.main_iteration_do() # get script current_text = self.view.get_text() # Directly apply script if linter was deactivated if not self.view['pylint_check_button'].get_active(): self.set_script_text(current_text) return logger.debug("Parsing execute script...") with open(self.tmp_file, "w") as text_file: text_file.write(current_text) # clear astroid module cache, see http://stackoverflow.com/questions/22241435/pylint-discard-cached-file-state MANAGER.astroid_cache.clear() lint_config_file = resource_filename(rafcon.__name__, "pylintrc") args = ["--rcfile={}".format(lint_config_file)] # put your own here with contextlib.closing(StringIO()) as dummy_buffer: json_report = JSONReporter(dummy_buffer) try: lint.Run([self.tmp_file] + args, reporter=json_report, exit=False) except: logger.exception("Could not run linter to check script") os.remove(self.tmp_file) if json_report.messages: def on_message_dialog_response_signal(widget, response_id): if response_id == 1: self.set_script_text(current_text) else: logger.debug("The script was not saved") widget.destroy() message_string = "Are you sure that you want to save this file?\n\nThe following errors were found:" line = None for message in json_report.messages: (error_string, line) = self.format_error_string(message) message_string += "\n\n" + error_string # focus line of error if line: tbuffer = self.view.get_buffer() start_iter = tbuffer.get_start_iter() start_iter.set_line(int(line) - 1) tbuffer.place_cursor(start_iter) message_string += "\n\nThe line was focused in the source editor." self.view.scroll_to_cursor_onscreen() # select state to show source editor sm_m = state_machine_manager_model.get_state_machine_model( self.model) if sm_m.selection.get_selected_state() is not self.model: sm_m.selection.set(self.model) RAFCONButtonDialog(message_string, ["Save with errors", "Do not save"], on_message_dialog_response_signal, message_type=gtk.MESSAGE_WARNING, parent=self.get_root_window()) else: self.set_script_text(current_text)
def delete_button_clicked(self, widget): """Removes library from hard drive after request second confirmation""" logger.info("delete library" + str(widget) + str(widget.get_label())) model, path = self.view.get_selection().get_selected() if path: # Second confirmation to delete library tree_m_row = self.tree_store[path] # assert isinstance(tree_m_row[self.ITEM_STORAGE_ID], str) library_file_system_path = tree_m_row[self.OS_PATH_STORAGE_ID] if "root" in widget.get_label(): button_texts = [ widget.get_label() + "from tree and config", "Cancel" ] partial_message = "This will remove the library root from your configuration (config.yaml)." else: button_texts = [widget.get_label(), "Cancel"] partial_message = "This folder will be removed from hard drive! You really wanna do that?" message_string = "You choose to {2} with " \ "\n\nlibrary tree path: {0}" \ "\n\nphysical path: {1}.\n\n\n"\ "{3}" \ "".format(os.path.join(self.convert_if_human_readable(tree_m_row[self.LIB_PATH_STORAGE_ID]), tree_m_row[self.ID_STORAGE_ID]), library_file_system_path, widget.get_label().lower(), partial_message) width = 8 * len("physical path: " + library_file_system_path) dialog = RAFCONButtonDialog(message_string, button_texts, message_type=gtk.MESSAGE_QUESTION, parent=self.get_root_window(), width=min(width, 1400)) response_id = dialog.run() dialog.destroy() if response_id == 1: if "root" in widget.get_label(): logger.info( "Remove library root key '{0}' from config.".format( tree_m_row[self.ID_STORAGE_ID])) from rafcon.gui.singleton import global_config library_paths = global_config.get_config_value( 'LIBRARY_PATHS') del library_paths[tree_m_row[self.LIB_KEY_STORAGE_ID]] global_config.save_configuration() self.model.library_manager.refresh_libraries() elif "libraries" in widget.get_label(): logger.debug( "Remove of all libraries in {} is triggered.".format( tree_m_row[self.OS_PATH_STORAGE_ID])) import shutil shutil.rmtree(tree_m_row[self.OS_PATH_STORAGE_ID]) self.model.library_manager.refresh_libraries() else: logger.debug("Remove of Library {} is triggered.".format( tree_m_row[self.ITEM_STORAGE_ID])) self.model.library_manager.remove_library_from_file_system( tree_m_row[self.LIB_PATH_STORAGE_ID], tree_m_row[self.ID_STORAGE_ID]) elif response_id in [2, -4]: pass else: logger.warning( "Response id: {} is not considered".format(response_id)) return True return False