コード例 #1
0
 def contextMenuEvent(self, event):
     self.menu = QMenu(self)
     insertAction = QAction('Insert', self)
     deleteAction = QAction('Delete', self)
     insertAction.triggered.connect(lambda: self.insertSlot(event))
     deleteAction.triggered.connect(lambda: self.deleteSlot(event))
     self.menu.addAction(insertAction)
     self.menu.addAction(deleteAction)
     # add other required actions
     self.menu.exec_(QCursor.pos())
コード例 #2
0
 def handle_context_menu_event(self, event):
     menu = QMenu()
     menu.addAction("Copy states", self.copy_states)
     menu.addAction("Cut states", self.cut_states)
     if self.simgr_viewer.state_clipboard:
         plural = ""
         if len(self.simgr_viewer.state_clipboard) > 1:
             plural += "s"
         menu.addAction("Paste state" + plural, self.paste_states)
     menu.addAction("Delete stash", self.delete_stash)
     menu.exec_(QCursor.pos())
コード例 #3
0
 def contextMenuEvent(self, event: QContextMenuEvent):  # pylint: disable=unused-argument
     """
     Display view context menu.
     """
     mnu = QMenu(self)
     selected_patches = self.get_selected_patches()
     if len(selected_patches) > 0:
         act = QAction('Revert selected patches', mnu)
         act.triggered.connect(self.revert_selected_patches)
         mnu.addAction(act)
     mnu.exec_(QCursor.pos())
コード例 #4
0
    def __create_graphics_node_from(self, node: "Node") -> "GraphicsNode":
        """Creates a new graphics node from the passed node. The GraphicsNode will be
        created on the cursor position."""
        graphics_node = GraphicsNodeFactory(node)

        global_pos = self.mapFromGlobal(QCursor.pos())
        graphics_node.setPos(self.mapToScene(global_pos))

        self.scene().addItem(graphics_node)

        return graphics_node
コード例 #5
0
ファイル: BackupFile.py プロジェクト: BlackC-Y/LearnCode
 def _openDirMenu(self, point):
     ProjectlistMenu = QMenu()
     ProjectlistMenu.addAction(
         QAction(u'打开项目文件夹',
                 self,
                 triggered=lambda *args: self._openDir('project')))
     ProjectlistMenu.addAction(
         QAction(u'打开备份文件夹',
                 self,
                 triggered=lambda *args: self._openDir('backup')))
     ProjectlistMenu.exec_(QCursor.pos())
コード例 #6
0
 def event(self, e):
     if e.type() == QEvent.TabletEnterProximity:
         print('enter', toolbox.window.geometry(), QCursor.pos())
         if not toolbox.overlay_widget.tool:
             return False
         self._grabbing_mouse = True
         if toolbox.window.geometry().contains(QCursor.pos()):
             return False
         w.grabMouse()
         return True
     elif e.type() == QEvent.TabletLeaveProximity:
         print('leave')
         w.releaseMouse()
         self._grabbing_mouse = False
         QCursor.setPos(self._last_cursor_pos)
         return True
     elif e.type() == QEvent.TabletTrackingChange:
         print('track')
         return True
     return False
コード例 #7
0
    def __init__(self, *args):
        super().__init__(*args)
        self._grabbing_mouse = False
        self._last_cursor_pos = QCursor.pos()

        def update_pos():
            if not self._grabbing_mouse:
                self._last_cursor_pos = QCursor.pos()

        self._timer = QTimer()
        self._timer.timeout.connect(update_pos)
        self._timer.start(100)
コード例 #8
0
 def mousePressEvent(self, event):
     event.accept()
     if event.button() == QtCore.Qt.MouseButton.RightButton:
         #self._parent_window.accepted()
         self.capture_complete.emit()
         return
     else:
         self._dragging = True
         orig_pos = self.mapFromGlobal(QCursor.pos())
         scene_pos = self.mapToScene(orig_pos)
         #self.rect_item.show()
         self.start_pos = scene_pos
コード例 #9
0
    def mouseMoveEvent(self, event):
        event.accept()
        if self._dragging:
            orig_pos = self.mapFromGlobal(QCursor.pos())
            now_pos = self.mapToScene(orig_pos)

            s_x = self.start_pos.x()
            s_y = self.start_pos.y()
            n_x = now_pos.x()
            n_y = now_pos.y()

            self.rect_item.setRect(s_x, s_y, max(0, n_x - s_x), n_y - s_y)

            self.rect_item.show()
コード例 #10
0
ファイル: Sherlock.py プロジェクト: bakhyeonjae/Sherlock
 def wheelEvent (self, eventQWheelEvent):
     oldscale = self.scale
     self.scale += eventQWheelEvent.delta() / 1200.0
     if (self.scale < 0.1):
         self.scale = oldscale
     screenpoint = self.mapFromGlobal(QCursor.pos())
     dx, dy = screenpoint.x(), screenpoint.y()
     oldpoint = (screenpoint.x() + self.position[0], screenpoint.y() + self.position[1])
     newpoint = (oldpoint[0] * (self.scale/oldscale), oldpoint[1] * (self.scale/oldscale))
     self.position = (newpoint[0] - dx, newpoint[1] - dy)
     print(self.position[0])
     print(self.position[1])
     print("  ")
     self.update()
コード例 #11
0
ファイル: main.py プロジェクト: tidyx/MagnetSearcher
 def connect(self):
     """槽连接"""
     # 搜索框和按钮
     self.window.search_button.clicked.connect(self.search)
     self.window.input_box.returnPressed.connect(self.search)
     # 磁力搜索线程
     self.spider.status_change.connect(self.searchStatusChange)
     self.spider.result_add.connect(self.outputBoxAdd)
     # 右键菜单
     action = self.rightMenu.addAction("复制")
     action.triggered.connect(self.rightCopy)
     self.window.search_out.setContextMenuPolicy(Qt.CustomContextMenu)
     self.window.search_out.customContextMenuRequested.connect(
         lambda: self.rightMenu.exec_(QCursor.pos()))
コード例 #12
0
    def paintEvent(self, event: QPaintEvent):
        self.painter = QPainter(self)
        pen = QPen(Qt.black, 2)
        self.painter.setPen(pen)

        pos = self.mapFromGlobal(QCursor.pos())
        mouse = (pos.x(), pos.y())

        if self.isDragging:
            w = mouse[0] - self.topleft[0]
            h = mouse[1] - self.topleft[1]

            self.painter.drawRect(self.topleft[0], self.topleft[1], w, h)
        self.painter.end()
コード例 #13
0
ファイル: api.py プロジェクト: schoentoon/runekit
    def get_mouse_position(self):
        if not self.app.has_permission("gamestate"):
            return 0

        value = QCursor.pos()
        pos = self._game_position

        if not pos.contains(value, True) or not self._game_active:
            # Cursor is out of game
            return 0

        x = value.x() - pos.x()
        y = value.y() - pos.y()
        return encode_mouse(x, y)
コード例 #14
0
    def index_under_mouse(self):
        """Returns the index under the mouse cursor, or None if the cursor isn't over the tab bar.
        Used to check for drop targets.

        Returns:
            int or NoneType
        """
        pos = self.mapFromGlobal(QCursor.pos())
        if not self.geometry().contains(pos):
            return None
        index = self.tabAt(pos)
        if index == -1:
            index = self.count()
        return index
コード例 #15
0
    def contextMenuEvent(self, event):
        """context menu to interact with process items - delete item"""
        # prevent context menu of scene not in draft mode
        if not self.draft_mode:
            return

        if self._edit_mode == SelectConnect.SELECT:
            # open context menu only for process items
            self._clicked_item = self.itemAt(event.scenePos(), QTransform())
            if self._clicked_item:
                if isinstance(self._clicked_item, ProcessItem):
                    menu = QMenu()
                    delete_action = QAction("Delete", None)
                    delete_action.triggered.connect(
                        lambda: self.delete_process(self._clicked_item))
                    menu.addAction(delete_action)
                    menu.exec_(event.screenPos())
                    self._clicked_item = None
        else:
            # open context menu for commodities of other sections
            menu = QMenu()
            section_list = [
                item for item in OverviewSelection if item is not self._section
                and item is not OverviewSelection.OVERVIEW
            ]
            for section in section_list:
                submenu = QMenu(section.name)
                section_coms = [
                    commodity for commodity in self._model.commodity_list
                    if section in commodity.connection_count.keys()
                ]
                for commodity in section_coms:
                    action = submenu.addAction(str(commodity))
                    action.setData(commodity)

                # only add sub menu if commodities are available
                if section_coms:
                    menu.addMenu(submenu)

            # execute menu
            action = menu.exec_(QCursor.pos())
            if action:
                # start connection
                line_pen = QPen(Qt.lightGray, 1, Qt.DashLine)
                line = QLineF(event.scenePos(), event.scenePos())
                self._connect_line = self.addLine(line, line_pen)
                self._connect_line.setData(0, None)
                self._connect_line.setData(1, action.data())
                self.views()[1].setMouseTracking(True)
コード例 #16
0
    def set_cross_hairs_items(self, relationship_class, cross_hairs_items):
        """Sets 'cross_hairs' items for relationship creation.

        Args:
            relationship_class (dict)
            cross_hairs_items (list(QGraphicsItems))
        """
        self.relationship_class = relationship_class
        self.cross_hairs_items = cross_hairs_items
        for item in cross_hairs_items:
            self.scene().addItem(item)
            item.apply_zoom(self.zoom_factor)
        cursor_pos = self.mapFromGlobal(QCursor.pos())
        self._update_cross_hairs_pos(cursor_pos)
        self.viewport().setCursor(Qt.BlankCursor)
コード例 #17
0
ファイル: QCanvas.py プロジェクト: Bernardrouhi/PuppetMaster
    def add_node(self):
        '''
        Add a new PickNode to the scene.
        '''
        # Cursor Position on Scene
        globPosition = self.mapFromGlobal(QCursor.pos())
        scenePosition = self.mapToScene(globPosition)

        self.create_node(text=self._defaultText,
                         size=self._defaultTextSize,
                         textColor=self._defaultTextColor,
                         bgColor=self._defaultColor,
                         position=scenePosition,
                         items=getActiveItems(),
                         shape=PickShape.SQUARE)
コード例 #18
0
    def showColorValue(self) -> None:
        if not self.pressed: return

        x: int = QCursor.pos().x()
        y: int = QCursor.pos().y()
        self.txtPoint.setText("x:%d  y:%d" % (x, y))

        screen: QScreen = QApplication.primaryScreen()
        pixmap: QPixmap = screen.grabWindow(QApplication.desktop().winId(), x, y, 2, 2)

        red: int = 0
        green: int = 0
        blue: int = 0
        strDecimalValue: str = ''
        strHex: str = ''
        if not pixmap.isNull():
            image: QImage = pixmap.toImage()
            if not image.isNull():
                if image.valid(0, 0):
                    color: QColor = QColor(image.pixel(0, 0))
                    red = color.red()
                    green = color.green()
                    blue = color.blue()

                    strDecimalValue = "%d, %d, %d" % (red, green, blue)
                    strHex = "#%02X%02X%02X" % (red, green, blue)

        # 根据背景色自动计算合适的前景色
        color: QColor = QColor(red, green, blue)
        gray: float = (0.299 * color.red() + 0.587 * color.green() + 0.114 * color.blue()) / 255
        textColor: QColor = QColor(Qt.black) if gray > 0.5 else QColor(Qt.white)

        value = "background:rgb(%s);color:%s" % (strDecimalValue, textColor.name())
        self.labColor.setStyleSheet(value)
        self.txtRgb.setText(strDecimalValue)
        self.txtWeb.setText(strHex)
コード例 #19
0
    def handleItemEntered(self, index):
        """Process event when mouse enters an item and
        create a `QTooltip` which describes the category, with a timer

        Parameter:
            index: a `QModelIndex` instance
        """
        if index.isValid():
            row = index.row()
        else:
            return
        idExp = str(self.proxyModel.sibling(row, 0, index).data())
        try:
            self.timer.stop()
            QToolTip.showText(QCursor.pos(), "", self.tableview.viewport())
        except AttributeError:
            pass
        try:
            expData = pBDB.exps.getByID(idExp)[0]
        except IndexError:
            pBGUILogger.exception(ewstr.failedFind)
            return
        self.timer = QTimer(self)
        self.timer.setSingleShot(True)
        self.timer.timeout.connect(
            lambda: QToolTip.showText(
                QCursor.pos(),
                ewstr.expId.format(idE=idExp, exp=expData["name"])
                + ewstr.entriesCorrespondent.format(en=pBDB.bibExp.countByExp(idExp))
                + ewstr.catsAssociated.format(ca=pBDB.catExp.countByExp(idExp)),
                self.tableview.viewport(),
                self.tableview.visualRect(index),
                3000,
            )
        )
        self.timer.start(500)
コード例 #20
0
 def timerEvent(self, event):
     """Performs the drag, i.e., moves the window with the mouse cursor.
     As soon as the mouse hovers the tab bar of another MultiSpineDBEditor, reattaches it.
     """
     self.move(QCursor.pos() - self._hot_spot -
               QPoint(0, self._frame_height()))
     for other in self._others:
         index = other.tab_bar.index_under_mouse()
         if index is not None:
             db_editor = self.tab_widget.widget(0)
             text = self.tab_widget.tabText(0)
             self.tab_widget.remove_disconnect_tab(0)
             self.close()
             other.reattach(index, db_editor, text)
             break
コード例 #21
0
 def add_marker_fn(self, line):
     self.current_line = line + 1
     if self.current_line not in self._valid_line:
         return
     menu = QMenu()
     menu.addAction("Add Find", self.add_find)
     menu.addAction("Add Avoid", self.add_avoid)
     address_list = self.viewer.main.line_to_addr[(self.file.path,
                                                   self.current_line)]
     if address_list:
         jump_menu = menu.addMenu("Jump to")
         for addr in address_list:
             jump_menu.addAction("0x%x" % addr,
                                 lambda addr=addr: self.jump_to(addr))
     menu.exec_(QCursor.pos())
コード例 #22
0
    def show_context_menu(self, pos):
        """
        Method which displays context menu
        under right mouse click

        Args:
            pos (index): position at which context should be shown
        """
        item = self.itemAt(pos)
        assert(item.columnCount() >= 1)

        menu = QMenu()
        menu.addAction(
            QAction('Refresh', self, triggered=lambda: self.menu_refresh_callback(item)))
        menu.exec_(QCursor.pos())
コード例 #23
0
ファイル: QCanvas.py プロジェクト: Bernardrouhi/PuppetMaster
 def add_commands(self):
     '''
     Create a new ButtonNode with Commands.
     '''
     globPosition = self.mapFromGlobal(QCursor.pos())
     scenePosition = self.mapToScene(globPosition)
     self.newCommand = CommandDialog()
     if self.newCommand.exec_() == QDialog.Accepted:
         data = self.newCommand.Raw
         self.create_button(position=scenePosition,
                            text=data[PIIButton.TEXT],
                            size=self._defaultTextSize,
                            textColor=self._defaultTextColor,
                            bgColor=self._defaultColor,
                            cmd=data[PIIButton.COMMAND],
                            cmdType=data[PIIButton.COMMANDTYPE])
コード例 #24
0
    def start_dragging(self, index):
        """Stars dragging the given index. This happens when a detached tab is reattached to this bar.

        Args:
            index (int)
        """
        self.drag_index = index
        press_pos = self.tabRect(self.drag_index).center()
        press_event = QMouseEvent(QEvent.MouseButtonPress, press_pos, Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
        QApplication.sendEvent(self, press_event)
        QApplication.processEvents()
        move_pos = self.mapFromGlobal(QCursor.pos())
        if self.geometry().contains(move_pos):
            move_event = QMouseEvent(QEvent.MouseMove, move_pos, Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
            QApplication.sendEvent(self, move_event)
        self.grabMouse()
コード例 #25
0
 def hoizontalMenu(self, event):
     menu = QMenu(self)
     actionAddColRight = QAction("Add column to the right", self)
     actionAddColLeft = QAction("Add column to the left ", self)
     menu.addAction(actionAddColRight)
     menu.addAction(actionAddColLeft)
     menu.popup(QCursor.pos())
     _col = self.ui.tb_DataFrame.horizontalHeader().logicalIndexAt(event)
     action = menu.exec_()
     # action = menu.exec_()
     if action == actionAddColRight:
         self.OnNewVar(_col + 1)
         return
     if action == actionAddColLeft:
         self.OnNewVar(_col)
         return
コード例 #26
0
ファイル: Sherlock.py プロジェクト: bakhyeonjae/Sherlock
 def wheelEvent(self, eventQWheelEvent):
     oldscale = self.scale
     self.scale += eventQWheelEvent.delta() / 1200.0
     if (self.scale < 0.1):
         self.scale = oldscale
     screenpoint = self.mapFromGlobal(QCursor.pos())
     dx, dy = screenpoint.x(), screenpoint.y()
     oldpoint = (screenpoint.x() + self.position[0],
                 screenpoint.y() + self.position[1])
     newpoint = (oldpoint[0] * (self.scale / oldscale),
                 oldpoint[1] * (self.scale / oldscale))
     self.position = (newpoint[0] - dx, newpoint[1] - dy)
     print(self.position[0])
     print(self.position[1])
     print("  ")
     self.update()
コード例 #27
0
 def selectMietobjekt(self) -> str:
     dlg = MietobjektAuswahldialog()
     crsr = QCursor.pos()
     dlg.move(crsr.x(), crsr.y())
     itemtext_list, mobj_list = BusinessLogic.inst().getAllMietobjekte()
     dlg.appendItemList(itemtext_list)
     if dlg.exec_() == QDialog.Accepted:
         auswahl: List[Tuple] = dlg.getSelection()
         itemtext = auswahl[0][0]
         mobj_id = ""
         for n in range(len(itemtext_list)):
             if itemtext_list[n] == itemtext:
                 mobj_id = mobj_list[n]
                 return mobj_id
         raise Exception(
             "MietobjektAuswahl.selectMietobjekt: interner Fehler")
     return ""
コード例 #28
0
    def SelectMenu(self, pos):
        index = self.tableWidget.indexAt(pos)
        if index.isValid():
            selected = self.tableWidget.selectedIndexes()
            selectRows = set()
            for index in selected:
                selectRows.add(index.row())
            if not selectRows:
                return
            if len(selectRows) == 1:
                # 单选
                row = selectRows.pop()
                col = 0
                bookId = self.tableWidget.item(row, col).text()
                task = self.downloadDict.get(bookId)
                if not task:
                    return

                menu = QMenu(self.tableWidget)

                menu.addAction(self.openDirAction)
                menu.addAction(self.selectEpsAction)
                assert isinstance(task, DownloadInfo)
                if task.status in [DownloadInfo.Pause, DownloadInfo.Error]:
                    menu.addAction(self.startAction)
                elif task.status in [
                        DownloadInfo.Downloading, DownloadInfo.Waiting,
                        DownloadInfo.Reading, DownloadInfo.ReadingPicture,
                        DownloadInfo.ReadingEps
                ]:
                    menu.addAction(self.pauseAction)
                else:
                    if task.convertStatus in [DownloadInfo.Converting]:
                        menu.addAction(self.pauseConvertAction)
                    elif task.convertStatus in [
                            DownloadInfo.Pause, DownloadInfo.Error,
                            DownloadInfo.NotFound
                    ]:
                        menu.addAction(self.startConvertAction)
            else:
                menu = QMenu(self.tableWidget)

            menu.addAction(self.removeAction)
            menu.addAction(self.removeFileAction)
            menu.exec_(QCursor.pos())
        pass
コード例 #29
0
 def mousePressEvent(self, event: QGraphicsSceneMouseEvent):
     if event.button() == Qt.LeftButton and QApplication.keyboardModifiers() in (Qt.NoModifier, Qt.ControlModifier):
         # toggle selection
         self.infodock.toggle_instruction_selection(
             self.addr,
             insn_pos=self.scenePos(),
             unique=QApplication.keyboardModifiers() != Qt.ControlModifier)
         event.accept()
     elif event.button() == Qt.RightButton and QApplication.keyboardModifiers() == Qt.NoModifier:
         if self.addr not in self.infodock.selected_insns:
             self.infodock.toggle_instruction_selection(self.addr, insn_pos=self.scenePos(), unique=True)
         self.disasm_view.instruction_context_menu(self.insn, QCursor.pos())
         event.accept()
     elif self.workspace.plugins.handle_click_insn(self, event):
         event.accept()
     else:
         super().mousePressEvent(event)
コード例 #30
0
 def menu_show(self, _):
     flag = self.client.list[self.file_list.currentRow()][3]
     self.retr_rest.setVisible(False)
     self.upload_appe.setVisible(False)
     if self.file_list.currentRow() >= 0:
         self.open.setVisible(True)
         if flag:  # 选中文件夹显示为 打开
             self.open.setText(u'打开')
         else:  # 选中文件显示 下载、继续上传、继续下载
             self.open.setText(u'下载')
             self.retr_rest.setVisible(True)
             self.upload_appe.setVisible(True)
     else:
         self.open.setVisible(False)
     self.rmd.setVisible(self.file_list.currentRow() >= 0)
     self.rename.setVisible(self.file_list.currentRow() >= 0)
     self.table_menu.exec_(QCursor.pos())
コード例 #31
0
 def object_context_menu(self):
     """
     Context menu when the object tree is right clicked
     """
     selected_items = self.selectedItems()
     if self.accept_drop and selected_items:
         menu = QMenu(self)
         # copy_action = menu.addAction("Copy")
         download_action = menu.addAction("Download")
         rename_action = menu.addAction("Rename")
         if len(selected_items) > 1:
             rename_action.setEnabled(False)
         rename_action.triggered.connect(self.rename_object)
         delete_action = menu.addAction("Delete")
         delete_action.triggered.connect(self.delete_objects)
         download_action.triggered.connect(self.download_objects)
         menu.exec_(QCursor.pos())
コード例 #32
0
ファイル: qtgui.py プロジェクト: davethecipo/polibeepsync
 def _activate_traymenu(self, reason):
     if reason == QSystemTrayIcon.ActivationReason.DoubleClick:
         self.restore_window()
     else:
         self.trayIconMenu.activateWindow()
         self.trayIconMenu.popup(QCursor.pos())