Exemplo n.º 1
0
    def _right_click_variables(self, point):
        ''' construct and show an operations operations_menu when the user right clicks the variable selector '''
        operations_menu = QtGui.QMenu(self)
        add_variable_menu = self._create_add_variable_menu()
        add_variable_menu.setTitle('Add a variable')
        add_variable_menu.setIcon(IconLibrary.icon('add'))
        operations_menu.addMenu(add_variable_menu)

        index_under_cursor = self.table_selected_variables.indexAt(point)
        if index_under_cursor.isValid():
            row = index_under_cursor.row()
            variable_node = self.selector_table_model.get_variable(row)
            self.table_selected_variables.selectRow(row)
            action = create_qt_action(
                None, 'Remove %s' % get_variable_name(variable_node),
                self._remove_selected_variables, self.table_selected_variables)
            action.setIcon(IconLibrary.icon('delete'))
            operations_menu.addAction(action)
        else:
            # if the index is not valid -- assume that the user clicked the "white space" of the table
            pass
        operations_menu.exec_(QtGui.QCursor.pos())
    def _right_click_variables(self, point):
        ''' construct and show an operations operations_menu when the user right clicks the variable selector '''
        operations_menu = QtGui.QMenu(self)
        add_variable_menu = self._create_add_variable_menu()
        add_variable_menu.setTitle('Add a variable')
        add_variable_menu.setIcon(IconLibrary.icon('add'))
        operations_menu.addMenu(add_variable_menu)

        index_under_cursor = self.table_selected_variables.indexAt(point)
        if index_under_cursor.isValid():
            row = index_under_cursor.row()
            variable_node = self.selector_table_model.get_variable(row)
            self.table_selected_variables.selectRow(row)
            action = create_qt_action(None, 'Remove %s' % get_variable_name(variable_node),
                                      self._remove_selected_variables,
                                      self.table_selected_variables)
            action.setIcon(IconLibrary.icon('delete'))
            operations_menu.addAction(action)
        else:
            # if the index is not valid -- assume that the user clicked the "white space" of the table
            pass
        operations_menu.exec_(QtGui.QCursor.pos())
Exemplo n.º 3
0
 def create_action(self, icon_name, text, callback):
     return create_qt_action(icon_name, text, callback, self.view)
Exemplo n.º 4
0
    def _show_right_click_menu(self, point):
        ''' handler for the when users right click on table variables_table '''
        index = self.variables_table.indexAt(point)
        if not index.isValid:
            return
        self.variables_table.setCurrentIndex(index)
        var = self.model.variables[index.row()]
        menu = QMenu(self.variables_table)

        # Edit variable action
        p = ('edit', 'Edit %s' % var['name'],
             lambda x=var: self._edit_variable(x), self)
        edit_action = create_qt_action(*p)
        font = QFont()
        font.setBold(True)
        edit_action.setFont(font)
        # Clone variable action
        p = ('clone', 'Create new variable based on this',
             lambda x=var: self._add_variable(x), self)
        clone_action = create_qt_action(*p)

        def make_local(var=var):
            if var['inherited']:
                var['dirty'] = True
                var['inherited'] = None
                self.model.dirty = True
            self._update_apply_button()

        def delete_var(var=var):
            self.model.delete_variable(var)
            self._update_apply_button()

        p = ('make_local', 'Make local', make_local, self)
        make_local_action = create_qt_action(*p)
        p = ('delete', 'Delete %s' % var['name'], delete_var, self)
        delete_action = create_qt_action(*p)
        p = ('revert', 'Revert %s to inherited' % var['name'], delete_var,
             self)
        revert_action = create_qt_action(*p)

        # check to see if we have graphviz installed
        p = ('zoom', 'View dependencies',
             lambda x=var: self._view_dependencies(x), self)
        view_dependencies_action = create_qt_action(*p)

        if var['inherited']:
            #            menu.addAction(edit_action)
            menu.addAction(make_local_action)
            menu.addAction(clone_action)
            menu.addSeparator()
            menu.addAction(view_dependencies_action)
        else:
            menu.addAction(edit_action)
            menu.addAction(clone_action)
            menu.addSeparator()
            # if the node in the table is local, but the original is inherited OR
            # if the original node is shadowing an inherited node, allow user to 'revert'
            # instead of 'delete'. Read more about prototype nodes in opus_project.py.
            if var['originalnode'] is None:
                menu.addAction(delete_action)
            else:
                prototype_node = self.project.get_prototype_node(
                    var['originalnode'])
                if var['originalnode'].get('inherited') or \
                    (prototype_node is not None and prototype_node.get('inherited')):
                    # This action will revert the node to the parent state. Show the values
                    # that it will revert to
                    tt = ('Revert %s to Name: %s, Definition: %s' %
                          (var['name'], prototype_node.get('name'),
                           prototype_node.text))
                    revert_action.setToolTip(tt)
                    menu.addAction(revert_action)
                else:
                    menu.addAction(delete_action)
            menu.addAction(view_dependencies_action)

        # Menu constructed, present to user
        if not menu.isEmpty():
            menu.exec_(QCursor.pos())
 def create_action(self, icon_name, text, callback):
     return create_qt_action(icon_name, text, callback, self.view)
Exemplo n.º 6
0
    def _show_right_click_menu(self, point):
        ''' handler for the when users right click on table variables_table '''
        index = self.variables_table.indexAt(point)
        if not index.isValid:
            return
        self.variables_table.setCurrentIndex(index)
        var = self.model.variables[index.row()]
        menu = QMenu(self.variables_table)

        # Edit variable action
        p = ('edit', 'Edit %s' % var['name'], lambda x=var: self._edit_variable(x), self)
        edit_action = create_qt_action(*p)
        font = QFont()
        font.setBold(True)
        edit_action.setFont(font)
        # Clone variable action
        p = ('clone', 'Create new variable based on this', lambda x=var: self._add_variable(x), self)
        clone_action = create_qt_action(*p)
        def make_local(var = var):
            if var['inherited']:
                var['dirty'] = True
                var['inherited'] = None
                self.model.dirty = True
            self._update_apply_button()
        def delete_var(var = var):
            self.model.delete_variable(var)
            self._update_apply_button()
        p = ('make_local', 'Make local', make_local, self)
        make_local_action = create_qt_action(*p)
        p = ('delete', 'Delete %s' % var['name'], delete_var, self)
        delete_action = create_qt_action(*p)
        p = ('revert', 'Revert %s to inherited' % var['name'], delete_var, self)
        revert_action = create_qt_action(*p)

        # check to see if we have graphviz installed
        p = ('zoom', 'View dependencies', lambda x=var: self._view_dependencies(x), self)
        view_dependencies_action = create_qt_action(*p)

        if var['inherited']:
#            menu.addAction(edit_action)
            menu.addAction(make_local_action)
            menu.addAction(clone_action)
            menu.addSeparator()
            menu.addAction(view_dependencies_action)
        else:
            menu.addAction(edit_action)
            menu.addAction(clone_action)
            menu.addSeparator()
            # if the node in the table is local, but the original is inherited OR
            # if the original node is shadowing an inherited node, allow user to 'revert'
            # instead of 'delete'. Read more about prototype nodes in opus_project.py.
            if var['originalnode'] is None:
                menu.addAction(delete_action)
            else:
                prototype_node = self.project.get_prototype_node(var['originalnode'])
                if var['originalnode'].get('inherited') or \
                    (prototype_node is not None and prototype_node.get('inherited')):
                    # This action will revert the node to the parent state. Show the values
                    # that it will revert to
                    tt = ('Revert %s to Name: %s, Definition: %s' % (var['name'],
                                                                     prototype_node.get('name'),
                                                                     prototype_node.text))
                    revert_action.setToolTip(tt)
                    menu.addAction(revert_action)
                else:
                    menu.addAction(delete_action)
            menu.addAction(view_dependencies_action)

        # Menu constructed, present to user
        if not menu.isEmpty():
            menu.exec_(QCursor.pos())