Python PyQt5.QtWidgets.QMenu() Examples

The following are code examples for showing how to use PyQt5.QtWidgets.QMenu(). They are from open source Python projects. You can vote up the examples you like or vote down the ones you don't like.

Example 1
Project: cct   Author: awacha   File: main.py    BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
def setupUi(self, Form):
        super().setupUi(Form)
        self.recentMenu = QtWidgets.QMenu('Recent projects', self.menubar)
        self.actionRecent_projects.setMenu(self.recentMenu)
        self.actionClose_project.triggered.connect(self.closeProject)
        self.actionFile_list.triggered.connect(self.openFileList)
        self.actionNew_project.triggered.connect(self.createNewProject)
        self.actionPreferences.triggered.connect(self.openPreferences)
        self.actionOpen_project.triggered.connect(self.openProject)
        self.actionSave.triggered.connect(self.save)
        self.actionSave_as.triggered.connect(self.saveAs)
        self.actionQuit.triggered.connect(self.close)
        self.actionProcess.triggered.connect(self.startStopProcessing)
        self.actionReload_headers.triggered.connect(self.startStopReloadHeaders)
        self._actionsNeedingAnOpenProject = [
            self.actionClose_project, self.actionPreferences, self.actionProcess, self.actionReload_headers,
            self.actionSave, self.actionSave_as, self.actionFile_list]
        for a in self._actionsNeedingAnOpenProject:
            a.setEnabled(False)
        self.actionNew_project.trigger()
        self.loadRecentProjectList() 
Example 2
Project: ANGRYsearch   Author: DoTheEvo   File: angrysearch.py    GNU General Public License v2.0 6 votes vote down vote up
def contextMenuEvent(self, event):
        right_click_menu = Qw.QMenu(self)

        act_open = right_click_menu.addAction('Open')
        act_open.triggered.connect(self.parent().parent().right_clk_open)

        act_open_path = right_click_menu.addAction('Open Path')
        act_open_path.triggered.connect(self.parent().parent().right_clk_path)

        right_click_menu.addSeparator()

        act_copy_path = right_click_menu.addAction('Copy Path')
        act_copy_path.triggered.connect(self.parent().parent().right_clk_copy)

        right_click_menu.exec_(event.globalPos())


# THE PRIMARY GUI DEFINING INTERFACE WIDGET, THE WIDGET WITHIN THE MAINWINDOW 
Example 3
Project: idasec   Author: RobinDavid   File: custom_widgets.py    GNU Lesser General Public License v2.1 6 votes vote down vote up
def __init__(self, items, parent=None):
        super(ButtonLineEdit, self).__init__(parent)

        self.menu = QtWidgets.QMenu()
        for i in items:
          self.menu.addAction(i)

        self.button = QtWidgets.QToolButton(self)
        self.button.setStyleSheet('border: 0px; padding: 0px;')
        self.button.setCursor(QtCore.Qt.ArrowCursor)
        self.button.triggered.connect(self.menu_action_triggered)
        self.button.setPopupMode(QtWidgets.QToolButton.InstantPopup)
        self.button.setMenu(self.menu)

        frameWidth = self.style().pixelMetric(QtWidgets.QStyle.PM_DefaultFrameWidth)
        buttonSize = self.button.sizeHint()

        self.setAlignment(QtCore.Qt.Alignment(QtCore.Qt.AlignHCenter))
        self.setStyleSheet('QLineEdit {padding-right: %dpx; }' % (buttonSize.width() + frameWidth + 1))
        self.setMinimumSize(max(self.minimumSizeHint().width(), buttonSize.width() + frameWidth*2 + 2),
                            max(self.minimumSizeHint().height(), buttonSize.height() + frameWidth*2 + 2))
        self.setMaximumWidth(100) 
Example 4
Project: SCGV   Author: KrasnitzLab   File: profiles_window.py    MIT License 6 votes vote down vote up
def on_context_menu(self, pos, *args, **kwargs):
        open_browser = QAction("Open in UCSC Genome Browser", self)
        open_browser.triggered.connect(self.on_open_genome_browser)

        if self.browse_position_region:
            open_browser_region = QAction(
                "Open Region in UCSC Genome Browser End", self)
            open_browser_region.triggered.connect(
                self.on_open_genome_browser_region_end)
        else:
            open_browser_region = QAction(
                "Open Region in UCSC Genome Browser Start", self)
            open_browser_region.triggered.connect(
                self.on_open_genome_browser_region_start)

        context = QMenu(self)
        context.addAction(open_browser_region)
        context.addAction(open_browser)
        context.exec_(self.mapToGlobal(pos)) 
Example 5
Project: MeiTingTrunk   Author: Xunius   File: _MainFrame.py    GNU General Public License v3.0 6 votes vote down vote up
def createAddFolderButton(self):

        button=QtWidgets.QToolButton(self)
        button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

        menu=QtWidgets.QMenu()
        self.create_folder_action=menu.addAction('Create Folder')
        self.create_subfolder_action=menu.addAction('Create Sub Folder')

        button.setDefaultAction(self.create_folder_action)

        button.setText('Create Folder')
        button.setIcon(QIcon.fromTheme('folder-new',
            self.style().standardIcon(QStyle.SP_FileDialogNewFolder)))
        button.setMenu(menu)
        button.setPopupMode(QtWidgets.QToolButton.MenuButtonPopup)

        menu.triggered.connect(self.addFolderButtonClicked)

        return button 
Example 6
Project: MeiTingTrunk   Author: Xunius   File: duplicate_frame.py    GNU General Public License v3.0 6 votes vote down vote up
def docTreeMenu(self,pos):
        '''Right click menu in the document tree'''

        menu=QtWidgets.QMenu()

        foldername,folderid=self.current_folder
        if folderid=='-1':
            menu.addAction('Delete From &Library')
        else:
            menu.addAction('Delete From Current &Folder')

        menu.addAction('&Remove From Duplicate Group')

        action=menu.exec_(QCursor.pos())

        if action:
            action_text=action.text().replace('&','')
            if action_text in ['Delete From Current Folder',
                    'Delete From Library']:
                self.delDocs()
            elif action_text=='Remove From Duplicate Group':
                self.removeFromGroup()

        return 
Example 7
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 6 votes vote down vote up
def buildDiagramMenu(self, diagram):
        """
        Build and return a QMenu instance for the given diagram.
        :type diagram: Diagram
        :rtype: QMenu
        """
        menu = QtWidgets.QMenu()
        if not self.session.clipboard.empty():
            menu.addAction(self.session.action('paste'))
        menu.addAction(self.session.action('select_all'))
        menu.addSeparator()
        menu.addAction(self.session.action('diagram_properties'))
        self.session.action('diagram_properties').setData(diagram)
        return menu

    #############################################
    #   COMPOUND
    ################################# 
Example 8
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 6 votes vote down vote up
def buildCompoundItemMenu(self, diagram, items):
        """
        Build and return a QMenu instance for the selection of items.
        :type diagram: Diagram
        :type items: T <= list|tuple
        :rtype: QMenu
        """
        menu = QtWidgets.QMenu()
        menu.addAction(self.session.action('delete'))
        menu.addAction(self.session.action('purge'))
        if any([x.isNode() for x in items]):
            menu.addSeparator()
            menu.addAction(self.session.action('bring_to_front'))
            menu.addAction(self.session.action('send_to_back'))
            menu.addSeparator()
            menu.addAction(self.session.action('cut'))
            menu.addAction(self.session.action('copy'))
        return menu

    #############################################
    #   EDGES
    ################################# 
Example 9
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 6 votes vote down vote up
def buildGenericEdgeMenu(self, diagram, edge, pos):
        """
        Build and return a QMenu instance for a generic edge.
        :type diagram: Diagram
        :type edge: AbstractEdge
        :type pos: QPointF
        :rtype: QMenu
        """
        menu = QtWidgets.QMenu()
        breakpoint = edge.breakPointAt(pos)
        if breakpoint is not None:
            action = self.session.action('remove_breakpoint')
            action.setData((edge, breakpoint))
            menu.addAction(action)
        else:
            menu.addAction(self.session.action('delete'))
            menu.addAction(self.session.action('swap_edge'))
            self.session.action('swap_edge').setVisible(edge.isSwapAllowed())
        return menu 
Example 10
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 6 votes vote down vote up
def buildMembershipEdgeMenu(self, diagram, edge, pos):
        """
        Build and return a QMenu instance for InstanceOf edges.
        :type diagram: Diagram
        :type edge: InstanceOfEdge
        :type pos: QPointF
        :rtype: QMenu
        """
        menu = QtWidgets.QMenu()
        breakpoint = edge.breakPointAt(pos)
        if breakpoint is not None:
            action = self.session.action('remove_breakpoint')
            action.setData((edge, breakpoint))
            menu.addAction(action)
        else:
            menu.addAction(self.session.action('delete'))
        return menu 
Example 11
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 6 votes vote down vote up
def buildSameEdgeMenu(self, diagram, edge, pos):
        """
        Build and return a QMenu instance for same edges.
        :type diagram: Diagram
        :type edge: SameEdge
        :type pos: QPointF
        :rtype: QMenu
        """
        menu = QtWidgets.QMenu()
        breakpoint = edge.breakPointAt(pos)
        if breakpoint is not None:
            action = self.session.action('remove_breakpoint')
            action.setData((edge, breakpoint))
            menu.addAction(action)
        else:
            menu.addAction(self.session.action('delete'))
            menu.addAction(self.session.action('switch_same_to_different'))
        return menu 
Example 12
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 6 votes vote down vote up
def buildGenericNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for a generic node.
        :type diagram: Diagram
        :type node: AbstractNode
        :rtype: QMenu
        """
        menu = QtWidgets.QMenu()
        menu.addAction(self.session.action('delete'))
        menu.addAction(self.session.action('purge'))
        menu.addSeparator()
        menu.addAction(self.session.action('cut'))
        menu.addAction(self.session.action('copy'))
        menu.addAction(self.session.action('paste'))
        menu.addSeparator()
        menu.addAction(self.session.action('bring_to_front'))
        menu.addAction(self.session.action('send_to_back'))
        menu.addSeparator()
        menu.addAction(self.session.action('node_properties'))
        menu.addSeparator()
        return menu 
Example 13
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 6 votes vote down vote up
def buildAttributeNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for attribute nodes.
        :type diagram: Diagram
        :type node: AttributeNode
        :rtype: QMenu
        """
        menu = self.buildPredicateNodeMenu(diagram, node)
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('refactor'))
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('brush'))
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('compose_domain_range'))
        if self.project.profile.type() is not OWLProfile.OWL2RL:
            menu.insertMenu(self.session.action('node_properties'), self.session.menu('special'))
        self.insertLabelActions(menu, node)
        menu.insertSeparator(self.session.action('node_properties'))
        self.session.action('refactor_name').setEnabled(node.special() is None)
        return menu 
Example 14
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 6 votes vote down vote up
def buildDomainRestrictionNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for domain restriction nodes.
        :type diagram: Diagram
        :type node: DomainRestrictionNode
        :rtype: QMenu
        """
        menu = self.buildGenericNodeMenu(diagram, node)
        menu.addSeparator()
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('switch_restriction'))
        for action in self.session.action('switch_restriction').actions():
            action.setChecked(node.type() is action.data())
            action.setVisible(True)
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('property_restriction'))
        f1 = lambda x: x.type() is Item.InputEdge
        f2 = lambda x: x.identity() is Identity.Attribute
        qualified = node.isRestrictionQualified()
        attribute = first(node.incomingNodes(filter_on_edges=f1, filter_on_nodes=f2))
        for action in self.session.action('restriction').actions():
            action.setChecked(node.restriction() is action.data())
            action.setVisible(action.data() is not Restriction.Self or not qualified and not attribute)
        menu.insertSeparator(self.session.action('node_properties'))
        self.insertLabelActions(menu, node)
        menu.insertSeparator(self.session.action('node_properties'))
        return menu 
Example 15
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 6 votes vote down vote up
def buildEnumerationNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for enumeration nodes.
        :type diagram: Diagram
        :type node: EnumerationNode
        :rtype: QMenu
        """
        menu = self.buildOperatorNodeMenu(diagram, node)
        if node.edges:
            if node.incomingNodes(filter_on_edges=lambda x: x.type() is Item.InputEdge):
                # If we have input edges targeting the node keep only the Enumeration
                # action active: individuals can be connected only to Enumeration nodes
                # and Property Assertion ones, so switching to another operator is an error.
                for action in self.session.action('switch_operator').actions():
                    action.setVisible(action.isVisible() and action.data() is Item.EnumerationNode)
            elif node.outgoingNodes(filter_on_edges=lambda x: x.type() is Item.InputEdge):
                # We have inclusion edges attached to this edge but no input => allow
                # switching to operators whose identities set intersects the one of this node.
                switch = {Item.DisjointUnionNode, Item.EnumerationNode, Item.IntersectionNode, Item.UnionNode}
                for action in self.session.action('switch_operator').actions():
                    action.setVisible(action.isVisible() and action.data() in switch)
        return menu 
Example 16
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 6 votes vote down vote up
def buildRoleNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for role nodes.
        :type diagram: Diagram
        :type node: RoleNode
        :rtype: QMenu
        """
        menu = self.buildPredicateNodeMenu(diagram, node)
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('refactor'))
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('brush'))
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('compose_domain_range'))
        if self.project.profile.type() is not OWLProfile.OWL2RL:
            menu.insertMenu(self.session.action('node_properties'), self.session.menu('special'))
        menu.insertAction(self.session.action('node_properties'), self.session.action('invert_role'))
        self.insertLabelActions(menu, node)
        menu.insertSeparator(self.session.action('node_properties'))
        self.session.action('refactor_name').setEnabled(node.special() is None)
        return menu 
Example 17
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 6 votes vote down vote up
def buildRoleInverseNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for role inverse nodes.
        :type diagram: Diagram
        :type node: RoleInverseNode
        :rtype: QMenu
        """
        menu = self.buildOperatorNodeMenu(diagram, node)
        if node.edges:
            f1 = lambda x: x.type() is Item.InputEdge
            f2 = lambda x: x.type() is Item.InclusionEdge
            f3 = lambda x: x.type() in {Item.DomainRestrictionNode, Item.RangeRestrictionNode}
            switch = {Item.RoleInverseNode}
            if not node.outgoingNodes(filter_on_edges=f1, filter_on_nodes=f3):
                switch.add(Item.ComplementNode)
            if not node.outgoingNodes(filter_on_edges=f1) and not node.incomingNodes(filter_on_edges=f2):
                switch.add(Item.RoleChainNode)
            for action in self.session.action('switch_operator').actions():
                action.setVisible(action.isVisible() and action.data() in switch)
        return menu 
Example 18
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 6 votes vote down vote up
def buildRoleChainNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for role chain nodes.
        :type diagram: Diagram
        :type node: RoleChainNode
        :rtype: QMenu
        """
        menu = self.buildOperatorNodeMenu(diagram, node)
        if node.edges:
            switch = {Item.RoleChainNode}
            if len(node.incomingNodes(filter_on_edges=lambda x: x.type() is Item.InputEdge)) <= 1:
                switch.add(Item.ComplementNode)
                switch.add(Item.RoleInverseNode)
            for action in self.session.action('switch_operator').actions():
                action.setVisible(action.isVisible() and action.data() in switch)
        return menu 
Example 19
Project: screenrulerzoom   Author: ElMoribond   File: screenrulerzoom.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent):
            super().__init__(parent)
            self.parent, unitMeasure, rulerSize, colors, zoom= parent, QMenu(gettext("Unit Measure"), self), QMenu(gettext("Ruler Size"), self), QMenu(gettext("Colors"), self), QMenu(gettext("Zoom"), self)
            self.addAction(QAction(parent.orientation[1 if not parent.oH else 0], self, triggered= partial(parent.changeOrientation, 1 if not parent.oH else 0)))
            for menu in [ [ zoom, parent.zooms, parent.changeMode, parent.zoom ], [ unitMeasure, parent.unitMeasure, parent.changeUnitMeasure, parent.cUM ], [ rulerSize, parent.rulerSize, parent.changeRulerSize, parent.sXY ], [ colors, parent.colors, parent.changeRulerColor, parent.defaultColors ] ]:
                for i, item in enumerate(menu[1]):
                    item= QAction(item[0][0], self, triggered= partial(menu[2], i))
                    if type(menu[3]) == type(list()) and i == len(menu[1]) - 1:
                        menu[0].addSeparator()
                        item.setEnabled(False if menu[1] == menu[3] else True)
                    else:
                        item.setCheckable(True)
                        item.setChecked(True if i == menu[3] else False)
                        item.setEnabled(not item.isChecked())
                    menu[0].addAction(item)
                if menu[0] in [ unitMeasure, colors ]:
                    menu[0].setEnabled(not bool(parent.zoom))
                self.addMenu(menu[0])
            self.addSeparator()
            self.addAction(QAction(parent.about, self, triggered= self.AboutDialog(parent).exec_))
            self.addSeparator()
            self.addAction(QAction(gettext("Exit"), self, triggered= parent.close)) 
Example 20
Project: persepolis   Author: persepolisdm   File: mainwindow_ui.py    GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent):
        super().__init__()

        # set ui direction
        ui_direction = parent.persepolis_setting.value('ui_direction')

        if ui_direction == 'rtl':
            self.setLayoutDirection(Qt.RightToLeft)

        elif ui_direction in 'ltr':
            self.setLayoutDirection(Qt.LeftToRight)

        # creating context menu
        self.category_tree_menu = QMenu(self)

        # connecting activation  event
        self.activated.connect(parent.categoryTreeSelected)
        self.pressed.connect(parent.categoryTreeSelected) 
Example 21
Project: XulDebugTool   Author: starcor-company   File: FavoriteTreeView.py    GNU Lesser General Public License v3.0 6 votes vote down vote up
def menuBatchOperation(self,list):
        itemList = []
        #标记本次批量操作所有记录的类别是否一致,如果不一致就不进行右键批量操作
        itemTpye = None;
        for modelIndex in list:
            item = self.treeModel.itemFromIndex(modelIndex)
            if itemTpye != None:
                if itemTpye != item.type:
                    return
            itemTpye = item.type
            itemList.append(item)

        menu = QMenu()
        if itemTpye == ITEM_TYPE_HISTORY:
            deleteAction = QAction(IconTool.buildQIcon('clear.png'), '&Delete', self,triggered=lambda: self.deleteHistoryBatch(itemList))
            deleteAction.setShortcut('Ctrl+D')
            menu.addAction(deleteAction)

        if itemTpye == ITEM_TYPE_FAVORITES:
            deleteAction = QAction(IconTool.buildQIcon('clear.png'), '&Delete', self,triggered=lambda: self.deleteFavoritesBatch(itemList))
            deleteAction.setShortcut('Ctrl+D')
            menu.addAction(deleteAction)

        menu.exec_(QCursor.pos()) 
Example 22
Project: FIRST-plugin-ida   Author: vrtadmin   File: first.py    GNU General Public License v2.0 6 votes vote down vote up
def applied_custom_menu(self, point):
        index = self.applied_tree_view.indexAt(point)
        address = index.data(FIRSTUI.ROLE_ADDRESS)
        if not address:
            return

        menu = QtWidgets.QMenu(self.applied_tree_view)
        goto_action = QtWidgets.QAction('&Go to Function', self.applied_tree_view)
        goto_action.triggered.connect(lambda:IDAW.Jump(address))
        menu.addAction(goto_action)

        metadata_id = index.data(FIRSTUI.ROLE_ID)
        if metadata_id:
            history_action = QtWidgets.QAction('View &History', self.applied_tree_view)
            history_action.triggered.connect(lambda:self._metadata_history(metadata_id))
            menu.addAction(history_action)

        menu.exec_(QtGui.QCursor.pos()) 
Example 23
Project: FIRST-plugin-ida   Author: vrtadmin   File: first.py    GNU General Public License v2.0 6 votes vote down vote up
def custom_menu(self, point):
            index = self.tree_view.indexAt(point)
            address = index.data(FIRSTUI.ROLE_ADDRESS)
            if not address:
                return

            menu = QtWidgets.QMenu(self.tree_view)
            goto_action = QtWidgets.QAction('&Go to Function', self.tree_view)
            goto_action.triggered.connect(lambda:IDAW.Jump(address))
            menu.addAction(goto_action)

            metadata_id = index.data(FIRSTUI.ROLE_ID)
            if metadata_id:
                history_action = QtWidgets.QAction('View &History', self.tree_view)
                history_action.triggered.connect(lambda:self.metadata_history(metadata_id))
                menu.addAction(history_action)

            menu.exec_(QtGui.QCursor.pos()) 
Example 24
Project: ocelot   Author: ocelot-collab   File: ocl_table.py    GNU General Public License v3.0 6 votes vote down vote up
def contextMenuEvent(self, event):
        if self.selectionModel().selection().indexes():
            rows = []
            cols = []
            for i in self.selectionModel().selection().indexes():
                row, column = i.row(), i.column()
                rows.append(row)
                cols.append(column)
            self.menu = QMenu(self)

            #deleteAction = QAction('Delete', self)
            checkAction = QAction('Check', self)
            uncheckAction = QAction('Uncheck', self)
            #deleteAction.triggered.connect(lambda: self.deleteSlot(rows))
            checkAction.triggered.connect(lambda: self.checkSlot())
            uncheckAction.triggered.connect(lambda: self.uncheckSlot())
            self.menu.addAction(checkAction)
            self.menu.addAction(uncheckAction)
            #editAction = QtGui.QAction('Edit', self)
            #self.menu.addAction(editAction)
            # add other required actions
            self.menu.popup(QtGui.QCursor.pos()) 
Example 25
Project: EGTR-FutureRestore   Author: M4cs   File: PySimpleGUIQt.py    GNU General Public License v3.0 6 votes vote down vote up
def Update(self, menu_definition=None, visible=None):
        if menu_definition is not None:
            menu_def = menu_definition
            self.MenuDefinition = menu_def
            self.QT_QMenuBar = QMenuBar(self.ParentForm.QT_QMainWindow)

            for menu_entry in menu_def:
                # print(f'Adding a Menubar ENTRY {menu_entry}')
                baritem = QMenu(self.QT_QMenuBar)
                if menu_entry[0][0] == MENU_DISABLED_CHARACTER:
                    baritem.setDisabled(True)
                    baritem.setTitle(menu_entry[0][1:])
                else:
                    baritem.setTitle(menu_entry[0])
                self.QT_QMenuBar.addAction(baritem.menuAction())
                AddMenuItem(baritem, menu_entry[1], self)

            self.ParentForm.QT_QMainWindow.setMenuBar(self.QT_QMenuBar)
        super().Update(self.QT_QMenuBar, visible=visible) 
Example 26
Project: chinese-support-redux   Author: luoliyan   File: gui.py    GNU General Public License v3.0 6 votes vote down vote up
def add_menu(path):
    if not hasattr(mw, 'custom_menus'):
        mw.custom_menus = {}

    if len(path.split('::')) == 2:
        parent_path, child_path = path.split('::')
        has_child = True
    else:
        parent_path = path
        has_child = False

    if parent_path not in mw.custom_menus:
        parent = QMenu('&' + parent_path, mw)
        mw.custom_menus[parent_path] = parent
        mw.form.menubar.insertMenu(mw.form.menuTools.menuAction(), parent)

    if has_child and (path not in mw.custom_menus):
        child = QMenu('&' + child_path, mw)
        mw.custom_menus[path] = child
        mw.custom_menus[parent_path].addMenu(child) 
Example 27
Project: r2dwarf   Author: iGio90   File: decompiler.py    GNU General Public License v3.0 5 votes vote down vote up
def handle_offset_click(self, mouse_btn, offset_link):
        if mouse_btn == Qt.LeftButton:
            _offset = offset_link.split(':')
            line = self._debug_panel.disassembly_panel.get_line_for_address(_offset[1])
            self._debug_panel.disassembly_panel.verticalScrollBar().setValue(line)
            self._debug_panel.disassembly_panel._current_line = line
        elif mouse_btn == Qt.RightButton:
            _offset = offset_link.split(':')
            _offset = _offset[1]
            menu = QMenu()
            menu.addAction('Copy Offset', lambda: utils.copy_hex_to_clipboard(_offset))
            menu.exec_(QCursor.pos()) 
Example 28
Project: ANGRYsearch   Author: DoTheEvo   File: angrysearch.py    GNU General Public License v2.0 5 votes vote down vote up
def make_sys_tray(self):
        if Qw.QSystemTrayIcon.isSystemTrayAvailable():
            menu = Qw.QMenu()
            menu.addAction('v1.0.1')
            menu.addSeparator()
            exitAction = menu.addAction('Quit')
            exitAction.triggered.connect(self.close)

            self.tray_icon = Qw.QSystemTrayIcon()
            self.tray_icon.setIcon(self.icon)
            self.tray_icon.setContextMenu(menu)
            self.tray_icon.show()
            self.tray_icon.setToolTip('ANGRYsearch')
            self.tray_icon.activated.connect(self.sys_tray_clicking) 
Example 29
Project: dcc   Author: amimo   File: sourcewindow.py    Apache License 2.0 5 votes vote down vote up
def CustomContextMenuHandler(self, pos):
        menu = QtWidgets.QMenu(self)
        menu.addAction(QtWidgets.QAction(
            "Xref ...",
            self,
            statusTip="List the references where this element is used",
            triggered=self.actionXref))
        menu.addAction(QtWidgets.QAction("&Goto",
                                         self,
                                         statusTip="Go to element definition",
                                         triggered=self.actionGoto))
        menu.addAction(
            QtWidgets.QAction("Rename...",
                              self,
                              statusTip="Rename an element (class, method, ...)",
                              triggered=self.actionRename))
        menu.addAction(QtWidgets.QAction(
            "&Info",
            self,
            statusTip=
            "Display info of an element (anything useful in the document)",
            triggered=self.actionInfo))
        menu.addAction(QtWidgets.QAction(
            "&Reload sources",
            self,
            statusTip=
            "Reload sources (needed when renaming changed other tabs)",
            triggered=self.reload_java_sources))
        menu.addAction(QtWidgets.QAction("&Copy",
                                         self,
                                         shortcut=QtGui.QKeySequence.Copy,
                                         statusTip="Copy the current selection's contents to the clipboard",
                                         triggered=self.actionCopy))
        menu.exec_(QtGui.QCursor.pos()) 
Example 30
Project: dcc   Author: amimo   File: treewindow.py    Apache License 2.0 5 votes vote down vote up
def contextMenuEvent(self, event):
        menu = QtWidgets.QMenu(self)
        menu.addAction(self.xrefAct)
        menu.addAction(self.expandAct)
        menu.addAction(self.collapseAct)
        menu.exec_(event.globalPos()) 
Example 31
Project: dcc   Author: amimo   File: mainwindow.py    Apache License 2.0 5 votes vote down vote up
def contextMenuEvent(self, event):
        menu = QtWidgets.QMenu(self)
        menu.addAction(self.closeAllTabs)
        menu.addAction(self.closeOtherTabs)
        menu.addAction(self.closeLeftTabs)
        menu.addAction(self.closeRightTabs)
        menu.exec_(event.globalPos()) 
Example 32
Project: kucher   Author: Zubax   File: tool_window_manager.py    GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent_window: QMainWindow):
        self._parent_window: QMainWindow = parent_window

        self._children: typing.List[ToolWindow] = []
        self._menu: QMenu = None
        self._arrangement_rules: typing.List[_ArrangementRule] = []
        self._title_to_icon_mapping: typing.Dict[str, QIcon] = {}

        self._tool_window_resize_event = Event()
        self._new_tool_window_event = Event()
        self._tool_window_removed_event = Event()

        self._parent_window.tabifiedDockWidgetActivated.connect(self._reiconize)

        # Set up the appearance
        self._parent_window.setTabPosition(Qt.TopDockWidgetArea,    QTabWidget.North)
        self._parent_window.setTabPosition(Qt.BottomDockWidgetArea, QTabWidget.South)
        self._parent_window.setTabPosition(Qt.LeftDockWidgetArea,   QTabWidget.South)
        self._parent_window.setTabPosition(Qt.RightDockWidgetArea,  QTabWidget.South)

        # Now, most screens are wide but not very tall; we need to optimize the layout for that
        # More info (this is for Qt4 but works for Qt5 as well): https://doc.qt.io/archives/4.6/qt4-mainwindow.html
        self._parent_window.setCorner(Qt.TopLeftCorner,     Qt.LeftDockWidgetArea)
        self._parent_window.setCorner(Qt.BottomLeftCorner,  Qt.LeftDockWidgetArea)
        self._parent_window.setCorner(Qt.TopRightCorner,    Qt.RightDockWidgetArea)
        self._parent_window.setCorner(Qt.BottomRightCorner, Qt.RightDockWidgetArea)

        # http://doc.qt.io/qt-5/qmainwindow.html#DockOption-enum
        dock_options = self._parent_window.AnimatedDocks | self._parent_window.AllowTabbedDocks
        if not is_small_screen():
            dock_options |= self._parent_window.AllowNestedDocks    # This won't work well on small screens

        self._parent_window.setDockOptions(dock_options) 
Example 33
Project: straditize   Author: Chilipp   File: progress_widget.py    GNU General Public License v3.0 5 votes vote down vote up
def setup_menu(self):
        """Set up the context menu"""
        self.menu = menu = QtWidgets.QMenu(self)
        self._done_action = menu.addAction(
            'Mark as done', self.toggle_done_by_user)
        menu.addAction('Show docs', lambda: self.show_rst(
            self.progress_list.selectedItems()[0])) 
Example 34
Project: QuantStudio   Author: Scorpi000   File: DateTimeSetup.py    GNU General Public License v3.0 5 votes vote down vote up
def setDateListWidgetMenu(self):
        # 设置 DateListWidget 的弹出菜单
        self.DateListWidget.setContextMenuPolicy(Qt.CustomContextMenu)
        self.DateListWidget.customContextMenuRequested.connect(self.showDateListWidgetMenu)
        self.DateListWidget.ContextMenu = {"主菜单": QMenu(parent=self.DateListWidget)}
        self.DateListWidget.ContextMenu["主菜单"].addAction("删除选中项").triggered.connect(self.deleteItems)
        self.DateListWidget.ContextMenu["主菜单"].addAction("清空").triggered.connect(self.clearList)
        self.DateListWidget.ContextMenu["日期变换"] = {"主菜单": QMenu("日期变换", parent=self.DateListWidget.ContextMenu["主菜单"])}
        self.DateListWidget.ContextMenu["日期变换"]["主菜单"].addAction("转月底").triggered.connect(self.toMonthLastDay)
        self.DateListWidget.ContextMenu["日期变换"]["主菜单"].addAction("转月中").triggered.connect(self.toMonthMiddleDay)
        self.DateListWidget.ContextMenu["日期变换"]["主菜单"].addAction("转月初").triggered.connect(self.toMonthFirstDay)
        self.DateListWidget.ContextMenu["日期变换"]["主菜单"].addAction("转周末").triggered.connect(self.toWeekLastDay)
        self.DateListWidget.ContextMenu["日期变换"]["主菜单"].addAction("转周初").triggered.connect(self.toWeekFirstDay)
        self.DateListWidget.ContextMenu["日期变换"]["主菜单"].addAction("转年末").triggered.connect(self.toYearLastDay)
        self.DateListWidget.ContextMenu["日期变换"]["主菜单"].addAction("转年初").triggered.connect(self.toYearFirstDay)
        self.DateListWidget.ContextMenu["日期变换"]["主菜单"].addAction("转季末").triggered.connect(self.toQuarterLastDay)
        self.DateListWidget.ContextMenu["日期变换"]["主菜单"].addAction("转季初").triggered.connect(self.toQuarterFirstDay)
        self.DateListWidget.ContextMenu["日期变换"]["主菜单"].addAction("转财报季末").triggered.connect(self.toFinancialQuarterLastDay)
        self.DateListWidget.ContextMenu["日期变换"]["主菜单"].addAction("转财报季初").triggered.connect(self.toFinancialQuarterFirstDay)
        self.DateListWidget.ContextMenu["日期变换"]["主菜单"].addAction("等间隔抽样").triggered.connect(self.sampleData)
        self.DateListWidget.ContextMenu["主菜单"].addMenu(self.DateListWidget.ContextMenu["日期变换"]["主菜单"])
        self.DateListWidget.ContextMenu["导入导出"] = {"主菜单": QMenu("导入导出", parent=self.DateListWidget.ContextMenu["主菜单"])}
        self.DateListWidget.ContextMenu["导入导出"]["主菜单"].addAction("导入日期").triggered.connect(self.importData)
        self.DateListWidget.ContextMenu["导入导出"]["主菜单"].addAction("导出日期").triggered.connect(self.exportData)
        self.DateListWidget.ContextMenu["主菜单"].addMenu(self.DateListWidget.ContextMenu["导入导出"]["主菜单"])
        return 0 
Example 35
Project: QuantStudio   Author: Scorpi000   File: DateTimeSetup.py    GNU General Public License v3.0 5 votes vote down vote up
def setTimeListWidgetMenu(self):
        # 设置 TimeListWidget 的弹出菜单
        self.TimeListWidget.setContextMenuPolicy(Qt.CustomContextMenu)
        self.TimeListWidget.customContextMenuRequested.connect(self.showTimeListWidgetMenu)
        self.TimeListWidget.ContextMenu = {"主菜单": QMenu(parent=self.TimeListWidget)}
        self.TimeListWidget.ContextMenu["主菜单"].addAction("删除选中项").triggered.connect(self.deleteItems)
        self.TimeListWidget.ContextMenu["主菜单"].addAction("清空").triggered.connect(self.clearList)
        self.TimeListWidget.ContextMenu["时间变换"] = {"主菜单": QMenu("时间变换", parent=self.TimeListWidget.ContextMenu["主菜单"])}
        self.TimeListWidget.ContextMenu["时间变换"]["主菜单"].addAction("等间隔抽样").triggered.connect(self.sampleData)
        self.TimeListWidget.ContextMenu["主菜单"].addMenu(self.TimeListWidget.ContextMenu["时间变换"]["主菜单"])
        self.TimeListWidget.ContextMenu["导入导出"] = {"主菜单": QMenu("导入导出", parent=self.TimeListWidget.ContextMenu["主菜单"])}
        self.TimeListWidget.ContextMenu["导入导出"]["主菜单"].addAction("导入时间").triggered.connect(self.importData)
        self.TimeListWidget.ContextMenu["导入导出"]["主菜单"].addAction("导出时间").triggered.connect(self.exportData)
        self.TimeListWidget.ContextMenu["主菜单"].addMenu(self.TimeListWidget.ContextMenu["导入导出"]["主菜单"])
        return 0 
Example 36
Project: QuantStudio   Author: Scorpi000   File: DateTimeSetup.py    GNU General Public License v3.0 5 votes vote down vote up
def setDateTimeListWidgetMenu(self):
        # 设置 DateTimeListWidget 的弹出菜单
        self.DateTimeListWidget.setContextMenuPolicy(Qt.CustomContextMenu)
        self.DateTimeListWidget.customContextMenuRequested.connect(self.showDateTimeListWidgetMenu)
        self.DateTimeListWidget.ContextMenu = {"主菜单": QMenu(parent=self.DateTimeListWidget)}
        self.DateTimeListWidget.ContextMenu["主菜单"].addAction("删除选中项").triggered.connect(self.deleteItems)
        self.DateTimeListWidget.ContextMenu["主菜单"].addAction("清空").triggered.connect(self.clearList)
        self.DateTimeListWidget.ContextMenu["时点变换"] = {"主菜单": QMenu("时点变换", parent=self.DateTimeListWidget.ContextMenu["主菜单"])}
        self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"].addAction("转月底").triggered.connect(self.toMonthLastDay)
        self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"].addAction("转月中").triggered.connect(self.toMonthMiddleDay)
        self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"].addAction("转月初").triggered.connect(self.toMonthFirstDay)
        self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"].addAction("转周末").triggered.connect(self.toWeekLastDay)
        self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"].addAction("转周初").triggered.connect(self.toWeekFirstDay)
        self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"].addAction("转年末").triggered.connect(self.toYearLastDay)
        self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"].addAction("转年初").triggered.connect(self.toYearFirstDay)
        self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"].addAction("转季末").triggered.connect(self.toQuarterLastDay)
        self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"].addAction("转季初").triggered.connect(self.toQuarterFirstDay)
        self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"].addAction("转财报季末").triggered.connect(self.toFinancialQuarterLastDay)
        self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"].addAction("转财报季初").triggered.connect(self.toFinancialQuarterFirstDay)
        self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"].addAction("等间隔抽样").triggered.connect(self.sampleData)
        self.DateTimeListWidget.ContextMenu["主菜单"].addMenu(self.DateTimeListWidget.ContextMenu["时点变换"]["主菜单"])
        self.DateTimeListWidget.ContextMenu["导入导出"] = {"主菜单": QMenu("导入导出", parent=self.DateTimeListWidget.ContextMenu["主菜单"])}
        self.DateTimeListWidget.ContextMenu["导入导出"]["主菜单"].addAction("导入时点").triggered.connect(self.importData)
        self.DateTimeListWidget.ContextMenu["导入导出"]["主菜单"].addAction("导出时点").triggered.connect(self.exportData)
        self.DateTimeListWidget.ContextMenu["主菜单"].addMenu(self.DateTimeListWidget.ContextMenu["导入导出"]["主菜单"])
        return 0 
Example 37
Project: QuantStudio   Author: Scorpi000   File: IDSetup.py    GNU General Public License v3.0 5 votes vote down vote up
def setIDListWidgetMenu(self):
        # 设置 IDListWidget 的弹出菜单
        self.IDListWidget.setContextMenuPolicy(Qt.CustomContextMenu)
        self.IDListWidget.customContextMenuRequested.connect(self.showIDListWidgetMenu)
        self.IDListWidget.ContextMenu = {"主菜单": QMenu(parent=self.IDListWidget)}
        self.IDListWidget.ContextMenu["主菜单"].addAction("删除选中项").triggered.connect(self.deleteIDListItems)
        self.IDListWidget.ContextMenu["主菜单"].addAction("清空").triggered.connect(self.clearIDList)
        self.IDListWidget.ContextMenu["导入导出"] = {"主菜单": QMenu("导入导出", parent=self.IDListWidget.ContextMenu["主菜单"])}
        self.IDListWidget.ContextMenu["导入导出"]["主菜单"].addAction("导入 ID").triggered.connect(self.importData)
        self.IDListWidget.ContextMenu["导入导出"]["主菜单"].addAction("导出 ID").triggered.connect(self.exportData)
        self.IDListWidget.ContextMenu["主菜单"].addMenu(self.IDListWidget.ContextMenu["导入导出"]["主菜单"])
        return 0 
Example 38
Project: cct   Author: awacha   File: motorview.py    BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def onTreeViewContextMenuRequested(self, pos: QtCore.QPoint):
        if self._popupmenu is not None:
            try:
                self._popupmenu.close()
            except RuntimeError:
                pass
            self._popupmenu = None
            self._motor_for_popupmenu = None
        index = self.treeView.indexAt(pos)
        motor = self.credo.motors[sorted(self.credo.motors.keys())[index.row()]]
        assert isinstance(motor, Motor)
        self._popupmenu = QtWidgets.QMenu('Operations with motor {}'.format(motor.name))
        self._motor_for_popupmenu = motor
        if MoveMotor.testRequirements(self.credo):
            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap(":/icons/motor.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self._popupmenu.addAction(icon, 'Move {}'.format(motor.name), self.onMoveMotorRequestedFromContextMenu)
        if MotorConfig.testRequirements(self.credo):
            icon = QtGui.QIcon()
            icon.addPixmap(QtGui.QPixmap(":/icons/editconfig.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
            self._popupmenu.addAction(icon, 'Configure {}'.format(motor.name),
                                      self.onConfigureMotorRequestedFromContextMenu)
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(":/icons/calibration.svg"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self._popupmenu.addAction(icon, 'Calibrate {}'.format(motor.name),
                                  self.onCalibrateMotorRequestedFromContextMenu)
        self._popupmenu.popup(QtGui.QCursor.pos()) 
Example 39
Project: PyLSS   Author: gmrandazzo   File: chromanalyzer.py    GNU Lesser General Public License v3.0 5 votes vote down vote up
def openTableMenu(self, position):
        """ context menu event """
        menu = QtWidgets.QMenu(self)
        exportAction = menu.addAction("Export table as CSV")
        action = menu.exec_(self.tableView.viewport().mapToGlobal(position))
        if action == exportAction:
            fname, _ = QtWidgets.QFileDialog.getSaveFileName(self, "Save File", "CSV (*.csv)");
            self.tablemodel.SaveTable(fname)
        else:
            return
        return 
Example 40
Project: Lector   Author: BasioMeusPuga   File: dockwidgets.py    GNU General Public License v3.0 5 votes vote down vote up
def generate_bookmark_context_menu(self, position):
        index = self.bookmarkTreeView.indexAt(position)
        if not index.isValid():
            return

        is_parent = self.parent.bookmarkProxyModel.data(
            index, QtCore.Qt.UserRole + 10)
        if is_parent:
            return

        bookmarkMenu = QtWidgets.QMenu()
        editAction = bookmarkMenu.addAction(
            self.parentTab.main_window.QImageFactory.get_image('edit-rename'),
            self._translate('Tab', 'Edit'))
        deleteAction = bookmarkMenu.addAction(
            self.parentTab.main_window.QImageFactory.get_image('trash-empty'),
            self._translate('Tab', 'Delete'))

        action = bookmarkMenu.exec_(
            self.bookmarkTreeView.mapToGlobal(position))

        if action == editAction:
            self.bookmarkTreeView.edit(index)

        if action == deleteAction:
            child_index = self.parent.bookmarkProxyModel.mapToSource(index)
            parent_index = child_index.parent()
            child_rows = self.parent.bookmarkModel.itemFromIndex(
                parent_index).rowCount()
            delete_uuid = self.parent.bookmarkModel.data(
                child_index, QtCore.Qt.UserRole + 2)

            self.parentTab.metadata['bookmarks'].pop(delete_uuid)

            self.parent.bookmarkModel.removeRow(
                child_index.row(), child_index.parent())
            if child_rows == 1:
                self.parent.bookmarkModel.removeRow(parent_index.row()) 
Example 41
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 5 votes vote down vote up
def buildComplementNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for complement nodes.
        :type diagram: Diagram
        :type node: ComplementNode
        :rtype: QMenu
        """
        menu = self.buildOperatorNodeMenu(diagram, node)
        if node.edges:
            switch = {Item.ComplementNode}
            if node.identity() in {Identity.Concept, Identity.ValueDomain}:
                switch.add(Item.DisjointUnionNode)
                switch.add(Item.IntersectionNode)
                switch.add(Item.UnionNode)
            elif node.identity() is Identity.Role:
                switch.add(Item.RoleInverseNode)
                if not node.incomingNodes(filter_on_edges=lambda x: x.type() is Item.InclusionEdge):
                    switch.add(Item.RoleChainNode)
            elif node.identity() is Identity.Neutral:
                switch.add(Item.DisjointUnionNode)
                switch.add(Item.EnumerationNode)
                switch.add(Item.IntersectionNode)
                switch.add(Item.RoleChainNode)
                switch.add(Item.RoleInverseNode)
                switch.add(Item.UnionNode)
            for action in self.session.action('switch_operator').actions():
                action.setVisible(action.isVisible() and action.data() in switch)
        return menu 
Example 42
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 5 votes vote down vote up
def buildConceptNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for concept nodes.
        :type diagram: Diagram
        :type node: ConceptNode
        :rtype: QMenu
        """
        menu = self.buildPredicateNodeMenu(diagram, node)
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('refactor'))
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('brush'))
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('special'))
        self.insertLabelActions(menu, node)
        menu.insertSeparator(self.session.action('node_properties'))
        self.session.action('refactor_name').setEnabled(node.special() is None)
        return menu 
Example 43
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 5 votes vote down vote up
def buildDatatypeRestrictionNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for datatype restriction nodes.
        :type diagram: Diagram
        :type node: DatatypeRestrictionNode
        :rtype: QMenu
        """
        return self.buildOperatorNodeMenu(diagram, node) 
Example 44
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 5 votes vote down vote up
def buildFacetNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for facet nodes.
        :type diagram: Diagram
        :type node: FacetNode
        :rtype: QMenu
        """
        menu = self.buildGenericNodeMenu(diagram, node)
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('facet'))
        menu.insertSeparator(self.session.action('node_properties'))

        #############################################
        # BEGIN CONSTRAIN FACET SWITCH
        #################################

        f1 = lambda x: x.type() is Item.InputEdge
        f2 = lambda x: x.type() is Item.DatatypeRestrictionNode
        f3 = lambda x: x.type() is Item.ValueDomainNode
        facet = node.facet
        admissible = [x for x in Facet]
        restriction = first(node.outgoingNodes(filter_on_edges=f1, filter_on_nodes=f2))
        if restriction:
            valuedomain = first(restriction.incomingNodes(filter_on_edges=f1, filter_on_nodes=f3))
            if valuedomain:
                admissible = Facet.forDatatype(valuedomain.datatype)
        for action in self.session.action('facet').actions():
            action.setChecked(action.data() is facet)
            action.setVisible(action.data() in admissible)

        #############################################
        # END CONSTRAIN FACET SWITCH
        #################################

        return menu 
Example 45
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 5 votes vote down vote up
def buildIntersectionNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for intersection nodes.
        :type diagram: Diagram
        :type node: IntersectionNode
        :rtype: QMenu
        """
        menu = self.buildOperatorNodeMenu(diagram, node)
        if node.edges:
            switch = {Item.DisjointUnionNode, Item.IntersectionNode, Item.UnionNode}
            for action in self.session.action('switch_operator').actions():
                action.setVisible(action.isVisible() and action.data() in switch)
        return menu 
Example 46
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 5 votes vote down vote up
def buildOperatorNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for operator nodes.
        :type diagram: Diagram
        :type node: OperatorNode
        :rtype: QMenu
        """
        menu = self.buildGenericNodeMenu(diagram, node)
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('switch_operator'))
        menu.insertSeparator(self.session.action('node_properties'))
        # Initialize switch action set.
        for action in self.session.action('switch_operator').actions():
            action.setChecked(node.type() is action.data())
            action.setVisible(True)
        # Add OWL 2 QL switch constraints.
        if self.project.profile.type() is OWLProfile.OWL2QL:
            for action in self.session.action('switch_operator').actions():
                action.setVisible(action.data() not in {Item.DatatypeRestrictionNode,
                    Item.DisjointUnionNode, Item.EnumerationNode, Item.RoleChainNode,
                    Item.UnionNode})
        # Add OWL 2 RL switch constraints.
        if self.project.profile.type() is OWLProfile.OWL2RL:
            for action in self.session.action('switch_operator').actions():
                action.setVisible(action.data() is not Item.DatatypeRestrictionNode)

        return menu 
Example 47
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 5 votes vote down vote up
def buildRangeRestrictionNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for range restriction nodes.
        :type diagram: Diagram
        :type node: RangeRestrictionNode
        :rtype: QMenu
        """
        f1 = lambda x: x.type() is Item.InputEdge
        f2 = lambda x: x.identity() is Identity.Attribute
        f3 = lambda x: x.type() is Item.InclusionEdge
        f4 = lambda x: x.identity() is Identity.ValueDomain
        attribute_in_input = first(node.incomingNodes(filter_on_edges=f1, filter_on_nodes=f2))
        valuedomain_in_isa = first(node.outgoingNodes(filter_on_edges=f3, filter_on_nodes=f4))
        menu = self.buildGenericNodeMenu(diagram, node)
        menu.addSeparator()
        menu.insertMenu(self.session.action('node_properties'), self.session.menu('switch_restriction'))
        for action in self.session.action('switch_restriction').actions():
            action.setChecked(node.type() is action.data())
            action.setVisible(node.type() is action.data() or not attribute_in_input and not valuedomain_in_isa)
        if not attribute_in_input and not valuedomain_in_isa:
            qualified = node.isRestrictionQualified()
            menu.insertMenu(self.session.action('node_properties'), self.session.menu('property_restriction'))
            for action in self.session.action('restriction').actions():
                action.setChecked(node.restriction() is action.data())
                action.setVisible(action.data() is not Restriction.Self or not qualified)
        menu.insertSeparator(self.session.action('node_properties'))
        self.insertLabelActions(menu, node)
        menu.insertSeparator(self.session.action('node_properties'))
        return menu 
Example 48
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 5 votes vote down vote up
def buildUnionNodeMenu(self, diagram, node):
        """
        Build and return a QMenu instance for union nodes.
        :type diagram: Diagram
        :type node: UnionNode
        :rtype: QMenu
        """
        menu = self.buildOperatorNodeMenu(diagram, node)
        if node.edges:
            switch = {Item.DisjointUnionNode, Item.IntersectionNode, Item.UnionNode}
            for action in self.session.action('switch_operator').actions():
                action.setVisible(action.isVisible() and action.data() in switch)
        return menu 
Example 49
Project: eddy   Author: obdasystems   File: factory.py    GNU General Public License v3.0 5 votes vote down vote up
def insertLabelActions(self, menu, node):
        """
        Insert label specific actions in the given menu.
        :type menu: QtWidgets.QMenu
        :type node: AbstractNode
        """
        if node.label.isMovable() and node.label.isMoved():
            menu.insertAction(self.session.action('node_properties'), self.session.action('relocate_label'))

    #############################################
    #   FACTORY
    ################################# 
Example 50
Project: eddy   Author: obdasystems   File: project_explorer.py    GNU General Public License v3.0 5 votes vote down vote up
def mouseReleaseEvent(self, mouseEvent):
        """
        Executed when the mouse is released from the tree view.
        :type mouseEvent: QMouseEvent
        """
        if mouseEvent.button() == QtCore.Qt.RightButton:
            index = first(self.selectedIndexes())
            if index:
                model = self.model().sourceModel()
                index = self.model().mapToSource(index)
                item = model.itemFromIndex(index)
                diagram = item.data()
                if diagram:
                    menu = QtWidgets.QMenu()
                    menu.addAction(self.session.action('new_diagram'))
                    menu.addSeparator()
                    menu.addAction(self.session.action('rename_diagram'))
                    menu.addAction(self.session.action('remove_diagram'))
                    menu.addSeparator()
                    menu.addAction(self.session.action('diagram_properties'))
                    self.session.action('rename_diagram').setData(diagram)
                    self.session.action('remove_diagram').setData(diagram)
                    self.session.action('diagram_properties').setData(diagram)
                    menu.exec_(mouseEvent.screenPos().toPoint())

        super().mouseReleaseEvent(mouseEvent)

    #############################################
    #   INTERFACE
    #################################