Beispiel #1
0
    def generate_right_click_menu_library(self):
        menu = gtk.Menu()
        accel_group = self.accel_group
        shortcuts_dict = global_gui_config.get_config_value('SHORTCUTS')

        self.insert_show_library_content_in_menu(menu, shortcuts_dict, accel_group)

        self.insert_is_start_state_in_menu(menu, shortcuts_dict, accel_group)

        self.insert_execution_sub_menu_in_menu(menu, shortcuts_dict, accel_group)

        self.insert_copy_cut_paste_in_menu(menu, shortcuts_dict, accel_group, no_paste=True)

        menu.append(create_image_menu_item("Group states", constants.BUTTON_GROUP, self.on_group_states_activate,
                                           accel_code=shortcuts_dict['group'][0], accel_group=accel_group))

        menu.append(create_image_menu_item("Open separately", constants.BUTTON_OPEN,
                                           self.on_open_library_state_separately_activate,
                                           accel_code=shortcuts_dict['open_library_state_separately'][0],
                                           accel_group=accel_group))

        menu.append(create_image_menu_item("Substitute state with library", constants.BUTTON_REFR,
                                           self.on_substitute_state_activate,
                                           accel_code=shortcuts_dict['substitute_state'][0], accel_group=accel_group))

        sub_menu_item, sub_menu = append_sub_menu_to_parent_menu("Substitute library with template", menu,
                                                                 constants.BUTTON_REFR)
        sub_menu.append(create_image_menu_item("Keep state name", constants.BUTTON_LEFTA,
                        partial(self.on_substitute_library_with_template_activate, keep_name=True)))

        sub_menu.append(create_image_menu_item("Take name from library", constants.BUTTON_EXCHANGE,
                        partial(self.on_substitute_library_with_template_activate, keep_name=False)))

        return menu
    def on_mouse_right_click(self, event, state_machine_m, result):

        menu = gtk.Menu()
        for sm_id, sm_m in self.model.state_machines.iteritems():
            menu_item = create_image_menu_item(
                sm_m.root_state.state.name,
                constants.BUTTON_EXCHANGE,
                callback=self.change_selected_state_machine_id,
                callback_args=[sm_id])
            menu.append(menu_item)

        menu_item = create_image_menu_item("New State Machine",
                                           constants.BUTTON_ADD,
                                           callback=add_state_machine,
                                           callback_args=[])
        menu.append(menu_item)

        if self.model.state_machines:
            menu_item = create_image_menu_item(
                "Close State Machine",
                constants.BUTTON_CLOSE,
                callback=self.on_close_clicked,
                callback_args=[state_machine_m, None])
            menu.append(menu_item)

        menu.show_all()
        menu.popup(None, None, None, event.button, event.time)
        return True
Beispiel #3
0
 def insert_copy_cut_paste_in_menu(self, menu, shortcuts_dict, accel_group, no_paste=False):
     menu.append(create_image_menu_item("Copy selection", constants.BUTTON_COPY, self.on_copy_activate,
                                        accel_code=shortcuts_dict['copy'][0], accel_group=accel_group))
     menu.append(create_image_menu_item("Paste selection", constants.BUTTON_PASTE, self.on_paste_activate,
                                        accel_code=shortcuts_dict['paste'][0], accel_group=accel_group))
     if not no_paste:
         menu.append(create_image_menu_item("Cut selection", constants.BUTTON_CUT, self.on_cut_activate,
                                            accel_code=shortcuts_dict['cut'][0], accel_group=accel_group))
Beispiel #4
0
 def insert_execution_sub_menu_in_menu(self, menu, shortcuts_dict, accel_group):
     execution_sub_menu_item, execution_sub_menu = append_sub_menu_to_parent_menu("Execution", menu,
                                                                              constants.BUTTON_EXP)
     execution_sub_menu.append(create_image_menu_item("from here", constants.BUTTON_START_FROM_SELECTED_STATE,
                                                      self.on_run_from_selected_state_activate,
                                                      accel_code=shortcuts_dict['start_from_selected'][0],
                                                      accel_group=accel_group))
     execution_sub_menu.append(create_image_menu_item("stop here", constants.BUTTON_RUN_TO_SELECTED_STATE,
                                                      self.on_run_to_selected_state_activate,
                                                      accel_code=shortcuts_dict['run_to_selected'][0],
                                                      accel_group=accel_group))
Beispiel #5
0
    def _update_recently_opened_state_machines(self):
        """Update the sub menu Open Recent in File menu

        Method clean's first all menu items of the sub menu 'recent open', then insert the user menu item to clean
        recent opened state machine paths and finally insert menu items for all elements in recent opened state machines
        list.
        """
        if not self.registered_view:
            return

        for item in self.view.sub_menu_open_recently.get_children():
            self.view.sub_menu_open_recently.remove(item)

        menu_item = gui_helper_label.create_image_menu_item(
            "remove invalid paths", constants.ICON_ERASE,
            global_runtime_config.clean_recently_opened_state_machines)
        self.view.sub_menu_open_recently.append(menu_item)
        self.view.sub_menu_open_recently.append(gtk.SeparatorMenuItem())

        for sm_path in global_runtime_config.get_config_value(
                "recently_opened_state_machines", []):
            # define label string
            root_state_name = gui_helper_state_machine.get_root_state_name_of_sm_file_system_path(
                sm_path)
            if root_state_name is None and not os.path.isdir(sm_path):
                root_state_name = 'NOT_ACCESSIBLE'
            label_string = "'{0}' in {1}".format(
                root_state_name,
                sm_path) if root_state_name is not None else sm_path

            # define icon of menu item
            is_in_libs = library_manager.is_os_path_within_library_root_paths(
                sm_path)
            button_image = constants.SIGN_LIB if is_in_libs else constants.BUTTON_OPEN

            # prepare state machine open call_back function
            sm_open_function = partial(self.on_open_activate, path=sm_path)

            # create and insert new menu item
            menu_item = gui_helper_label.create_image_menu_item(
                label_string, button_image, sm_open_function)
            self.view.sub_menu_open_recently.append(menu_item)

        self.view.sub_menu_open_recently.show_all()
Beispiel #6
0
    def generate_right_click_menu_state(self):
        menu = gtk.Menu()
        accel_group = self.accel_group
        shortcuts_dict = global_gui_config.get_config_value('SHORTCUTS')

        self.insert_is_start_state_in_menu(menu, shortcuts_dict, accel_group)

        self.insert_execution_sub_menu_in_menu(menu, shortcuts_dict, accel_group)

        menu.append(gtk.SeparatorMenuItem())

        add_sub_menu_item, add_sub_menu = append_sub_menu_to_parent_menu("Add", menu, constants.BUTTON_ADD)

        add_state_sub_menu_item, add_state_sub_menu = append_sub_menu_to_parent_menu("State", add_sub_menu,
                                                                                     constants.BUTTON_ADD)

        add_state_sub_menu.append(create_image_menu_item("Execution State", constants.BUTTON_ADD,
                                                         self.on_add_execution_state_activate,
                                                         accel_code=shortcuts_dict['add_execution_state'][0],
                                                         accel_group=accel_group))
        add_state_sub_menu.append(create_image_menu_item("Hierarchy State", constants.BUTTON_ADD,
                                                         self.on_add_hierarchy_state_activate,
                                                         accel_code=shortcuts_dict['add_hierarchy_state'][0],
                                                         accel_group=accel_group))
        add_state_sub_menu.append(create_image_menu_item("Preemptive State", constants.BUTTON_ADD,
                                                         self.on_add_preemptive_state_activate,
                                                         accel_code=shortcuts_dict['add_preemptive_state'][0],
                                                         accel_group=accel_group))
        add_state_sub_menu.append(create_image_menu_item("Barrier State", constants.BUTTON_ADD,
                                                         self.on_add_barrier_state_activate,
                                                         accel_code=shortcuts_dict['add_barrier_state'][0],
                                                         accel_group=accel_group))

        add_sub_menu.append(gtk.SeparatorMenuItem())

        add_sub_menu.append(create_image_menu_item("Outcome", constants.BUTTON_ADD, self.on_add_outcome,
                                                   accel_code=shortcuts_dict['add_outcome'][0], accel_group=accel_group))
        add_sub_menu.append(create_image_menu_item("Output Port", constants.BUTTON_ADD, self.on_add_output,
                                                   accel_code=shortcuts_dict['add_output'][0], accel_group=accel_group))
        add_sub_menu.append(create_image_menu_item("Input Port", constants.BUTTON_ADD, self.on_add_input,
                                                   accel_code=shortcuts_dict['add_input'][0], accel_group=accel_group))
        add_sub_menu.append(create_image_menu_item("Scoped Variable", constants.BUTTON_ADD, self.on_add_scoped_variable,
                                                   accel_code=shortcuts_dict['add_scoped_variable'][0],
                                                   accel_group=accel_group))
        menu.append(gtk.SeparatorMenuItem())

        self.insert_copy_cut_paste_in_menu(menu, shortcuts_dict, accel_group)

        from rafcon.core.states.barrier_concurrency_state import DeciderState
        selection = gui_singletons.state_machine_manager_model.get_selected_state_machine_model().selection
        selected_state_m = selection.get_selected_state()
        all_m_list = gui_singletons.state_machine_manager_model.get_selected_state_machine_model().selection.get_all()
        # logger.info("Element in selection: " + str(selected_state_m) + " : " + str([elem for elem in all_m_list]))
        if any([isinstance(elem, (AbstractStateModel, ScopedVariableModel)) for elem in all_m_list]) and \
                all([isinstance(elem, (AbstractStateModel, ScopedVariableModel, TransitionModel, DataFlowModel))
                     for elem in all_m_list]) and \
                all([not state_m.state.is_root_state for state_m in selection.states]):
            menu.append(create_image_menu_item("Group states", constants.BUTTON_GROUP, self.on_group_states_activate,
                                               accel_code=shortcuts_dict['group'][0], accel_group=accel_group))
        if len(selection.states) == 1:
            if isinstance(selected_state_m, ContainerStateModel) and not selected_state_m.state.is_root_state:
                menu.append(create_image_menu_item("Ungroup states", constants.BUTTON_UNGR,
                                                   self.on_ungroup_state_activate,
                                                   accel_code=shortcuts_dict['ungroup'][0], accel_group=accel_group))
            if not isinstance(selected_state_m.state, DeciderState) and not selected_state_m.state.is_root_state:
                menu.append(create_image_menu_item("Substitute state", constants.BUTTON_REFR,
                                                   self.on_substitute_state_activate,
                                                   accel_code=shortcuts_dict['substitute_state'][0],
                                                   accel_group=accel_group))

            from rafcon.gui.controllers.state_editor.overview import StateOverviewController
            state_type_class_dict = StateOverviewController.change_state_type_class_dict(selected_state_m.state)
            if len(state_type_class_dict) > 1:
                change_type_sub_menu_item, change_type_sub_menu = append_sub_menu_to_parent_menu("Change state type",
                                                                                                 menu,
                                                                                                 constants.BUTTON_EXCHANGE)
                for class_key, item in state_type_class_dict.iteritems():
                    class_item = create_image_menu_item(class_key, constants.SIGN_LIB,
                                                        partial(self.on_type_change_activate,
                                                                target_class=item['class']),
                                                                accel_code=None,
                                                                accel_group=accel_group)
                    if isinstance(selected_state_m.state, item['class']):
                        class_item.set_sensitive(False)
                    change_type_sub_menu.append(class_item)
        menu.append(gtk.SeparatorMenuItem())

        # save state as but not for root state, therefore the user should use save state machine as
        if len(selection.states) == 1 and not selected_state_m.state.is_root_state:
            save_as_sub_menu_item, save_as_sub_menu = append_sub_menu_to_parent_menu("Save state as", menu,
                                                                                     constants.BUTTON_SAVE)
            callback_function = partial(self.on_save_as_activate,
                                        save_as_function=gui_helper_state_machine.save_selected_state_as)
            save_as_sub_menu.append(create_image_menu_item("State machine", constants.BUTTON_SAVE,
                                                           callback_function,
                                                           accel_code=shortcuts_dict['save_state_as'][0],
                                                           accel_group=accel_group))
            save_as_library_sub_menu_item, save_as_library_sub_menu = append_sub_menu_to_parent_menu("Library",
                                                                                                     save_as_sub_menu,
                                                                                                     constants.SIGN_LIB)
            library_root_paths = core_singletons.library_manager.library_root_paths
            for library_root_key in library_root_paths.iterkeys():
                callback_function = partial(self.on_save_as_activate,
                                            path=library_root_paths[library_root_key],
                                            save_as_function=gui_helper_state_machine.save_selected_state_as)
                save_as_library_sub_menu.append(create_image_menu_item(library_root_key, constants.SIGN_LIB,
                                                                       callback_function,
                                                                       accel_code=None, accel_group=accel_group))
        else:
            save_as_sub_menu_item, save_as_sub_menu = append_sub_menu_to_parent_menu("Save state machine as", menu,
                                                                                     constants.BUTTON_SAVE)

            callback_function = partial(self.on_save_as_activate,
                                        save_as_function=gui_helper_state_machine.save_state_machine_as)
            save_as_sub_menu.append(create_image_menu_item("State machine", constants.BUTTON_SAVE,
                                                           callback_function,
                                                           accel_code=shortcuts_dict['save_as'][0],
                                                           accel_group=accel_group))
            save_as_library_sub_menu_item, save_as_library_sub_menu = append_sub_menu_to_parent_menu("Library",
                                                                                                     save_as_sub_menu,
                                                                                                     constants.SIGN_LIB)
            library_root_paths = core_singletons.library_manager.library_root_paths
            for library_root_key in library_root_paths.iterkeys():
                callback_function = partial(self.on_save_as_activate,
                                            path=library_root_paths[library_root_key],
                                            save_as_function=gui_helper_state_machine.save_state_machine_as)
                save_as_library_sub_menu.append(create_image_menu_item(library_root_key, constants.SIGN_LIB,
                                                                       callback_function,
                                                                       accel_code=None, accel_group=accel_group))

        return menu
Beispiel #7
0
    def generate_right_click_menu(self, kind='library'):
        menu = gtk.Menu()
        if kind == 'library':
            menu.append(create_image_menu_item("Add as library (link)", constants.BUTTON_ADD,
                                               partial(self.insert_button_clicked, as_template=False)))
            menu.append(create_image_menu_item("Add as template (copy)", constants.BUTTON_COPY,
                                               partial(self.insert_button_clicked, as_template=True)))
            menu.append(gtk.SeparatorMenuItem())
            menu.append(create_image_menu_item("Open", constants.BUTTON_OPEN, self.open_button_clicked))
            menu.append(create_image_menu_item("Open and run", constants.BUTTON_START, self.open_run_button_clicked))
            menu.append(gtk.SeparatorMenuItem())
            menu.append(create_image_menu_item("Remove library", constants.BUTTON_DEL, self.delete_button_clicked))

            sub_menu_item, sub_menu = append_sub_menu_to_parent_menu("Substitute as library", menu,
                                                                     constants.BUTTON_REFR)

            sub_menu.append(create_image_menu_item("Keep state name", constants.BUTTON_LEFTA,
                            partial(self.substitute_as_library_clicked, keep_name=True)))
            sub_menu.append(create_image_menu_item("Take name from Library", constants.BUTTON_EXCHANGE,
                            partial(self.substitute_as_library_clicked, keep_name=False)))

            sub_menu_item, sub_menu = append_sub_menu_to_parent_menu("Substitute as template", menu,
                                                                     constants.BUTTON_REFR)

            sub_menu.append(create_image_menu_item("Keep state name", constants.BUTTON_LEFTA,
                            partial(self.substitute_as_template_clicked, keep_name=True)))
            sub_menu.append(create_image_menu_item("Take name from Library", constants.BUTTON_EXCHANGE,
                            partial(self.substitute_as_template_clicked, keep_name=False)))
        elif kind == 'library root':
            menu.append(create_image_menu_item("Add library root", constants.BUTTON_DEL, self.add_button_clicked))
            menu.append(create_image_menu_item("Remove library root", constants.BUTTON_DEL, self.delete_button_clicked))
        elif kind == 'libraries':
            menu.append(create_image_menu_item("Remove libraries", constants.BUTTON_DEL, self.delete_button_clicked))
        elif kind == 'library tree':
            menu.append(create_image_menu_item("Add library root", constants.BUTTON_DEL, self.add_button_clicked))

        return menu