Esempio n. 1
0
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
Esempio n. 2
0
    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
Esempio n. 3
0
    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
Esempio n. 4
0
    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()
Esempio n. 5
0
    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
Esempio n. 7
0
 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
Esempio n. 8
0
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
Esempio n. 9
0
        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
Esempio n. 11
0
 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
Esempio n. 12
0
    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