当前位置: 首页>>代码示例>>Python>>正文


Python QAction.setShortcutContext方法代码示例

本文整理汇总了Python中PyQt5.QtWidgets.QAction.setShortcutContext方法的典型用法代码示例。如果您正苦于以下问题:Python QAction.setShortcutContext方法的具体用法?Python QAction.setShortcutContext怎么用?Python QAction.setShortcutContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtWidgets.QAction的用法示例。


在下文中一共展示了QAction.setShortcutContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_action

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
 def add_action(self, name, shortcut, callback, **kwargs):
     """
     Ajoute une action au context menu et au widget navigation lui même.
     Créer une fonction à la volé pour fournir des arguments aux fonctions
     associé aux actions.
     """
     action = QAction(self.tr(name), self)
     if 'icon' in kwargs:
         action.setIcon(kwargs['icon'])
     if 'checkable' in kwargs and kwargs['checkable']:
         action.setCheckable(True)
         if 'checked' in kwargs:
             checked = True if kwargs['checked'] == 'true' else False
             action.setChecked(
                 checked
             )
     
     action.setShortcut(shortcut)
     action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
     
     if 'wrapped' in kwargs and kwargs['wrapped'] is False:
         action.triggered.connect(callback)
     else:
         action.triggered.connect(self.__wrapper(callback))
     
     self.addAction(action)
     self.menu.addAction(action)
     self.editor_actions[name] = action
开发者ID:FlorianPerrot,项目名称:Mojuru,代码行数:30,代码来源:ace_editor.py

示例2: __init__

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
 def __init__(self, i,parent=None):
     super(TextEdit, self).__init__(parent)
     
     action = QAction('test', self)
     action.setShortcut('ctrl+d')
     action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
     action.triggered.connect(lambda : print('test', i))
     self.addAction(action)
开发者ID:FlorianPerrot,项目名称:Mojuru,代码行数:10,代码来源:test.py

示例3: ProtocolLabelTableView

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
class ProtocolLabelTableView(QTableView):
    def __init__(self, parent=None):
        super().__init__(parent)

        self.delete_action = QAction("Delete selected labels", self)
        self.delete_action.setShortcut(QKeySequence.Delete)
        self.delete_action.setIcon(QIcon.fromTheme("edit-delete"))
        self.delete_action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        self.delete_action.triggered.connect(self.delete_selected_rows)
        self.addAction(self.delete_action)

    @property
    def selected_rows(self) -> list:
        return [i.row() for i in self.selectedIndexes()]

    def model(self) -> PLabelTableModel:
        return super().model()

    def create_context_menu(self):
        menu = QMenu(self)
        if self.model().rowCount() == 0:
            return menu

        if isinstance(self.model(), SimulatorMessageFieldModel):
            value_type_group = QActionGroup(self)
            value_type_menu = menu.addMenu("Set value type")
            labels = [self.model().message_type[i] for i in self.selected_rows
                      if not self.model().message_type[i].is_checksum_label]

            for i, value_type in enumerate(SimulatorProtocolLabel.VALUE_TYPES):
                va = value_type_menu.addAction(value_type)
                va.setCheckable(True)
                va.setActionGroup(value_type_group)
                va.setData(i)

                if all(lbl.value_type_index == i for lbl in labels):
                    va.setChecked(True)

                va.triggered.connect(self.on_set_value_type_action_triggered)

        menu.addAction(self.delete_action)
        return menu

    def contextMenuEvent(self, event):
        self.create_context_menu().exec_(self.mapToGlobal(event.pos()))

    def delete_selected_rows(self):
        for row in sorted(self.selected_rows, reverse=True):
            self.model().remove_label_at(row)

    def on_set_value_type_action_triggered(self):
        assert isinstance(self.model(), SimulatorMessageFieldModel)
        value_type_index = self.sender().data()
        self.model().set_value_type_index(self.selected_rows, value_type_index)
开发者ID:jopohl,项目名称:urh,代码行数:56,代码来源:ProtocolLabelTableView.py

示例4: _createAction

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
    def _createAction(self, widget, iconFileName, text, shortcut, slot):
        """Create QAction with given parameters and add to the widget
        """
        icon = QIcon(qutepart.getIconPath(iconFileName))
        action = QAction(icon, text, widget)
        action.setShortcut(QKeySequence(shortcut))
        action.setShortcutContext(Qt.WidgetShortcut)
        action.triggered.connect(slot)

        widget.addAction(action)

        return action
开发者ID:Aldenis2112,项目名称:qutepart,代码行数:14,代码来源:bookmarks.py

示例5: menu_add_action

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
 def menu_add_action(self, name, callback, data=None, shortcut=None, icon=None):
     action = QAction(name, self)
     if icon:
         action.setIcon(icon)
     if shortcut:
         action.setShortcut(shortcut)
         action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
     if data:
         action.setData(data)
     action.triggered.connect(callback)
     self.addAction(action)
     self.menu.addAction(action)
开发者ID:lheido,项目名称:Mojuru,代码行数:14,代码来源:navigation.py

示例6: add_action

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
 def add_action(self, name, shortcut, callback, icon = None):
     """
     Ajoute une action au context menu et au widget lui même.
     Créer une fonction à la volé pour fournir des arguments aux fonctions
     associé aux actions.
     """
     action = QAction(name, self)
     if icon:
         action.setIcon(icon)
     action.setShortcut(shortcut)
     action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
     action.triggered.connect(self.__wrapper(callback))
     self.addAction(action)
     self.menu.addAction(action)
开发者ID:lheido,项目名称:Mojuru,代码行数:16,代码来源:tab_widget.py

示例7: add_action

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
 def add_action(self, name, callback, **kwargs):
     """
     Ajoute une action au context menu et au widget lui même.
     Créer une fonction à la volé pour fournir des arguments aux fonctions
     de rappel.
     """
     action = QAction(name, self)
     if 'icon' in kwargs:
         action.setIcon(kwargs['icon'])
     if 'shortcut' in kwargs:
         action.setShortcut(kwargs['shortcut'])
     action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
     action.triggered.connect(self.__wrapper(callback, **kwargs))
     self.addAction(action)
     if 'menu' in kwargs:
         kwargs['menu'].addAction(action)
开发者ID:lheido,项目名称:Mojuru,代码行数:18,代码来源:main_window.py

示例8: create_action

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
def create_action(parent, text, shortcut=None, icon=None, tip=None,
                  triggered=None, toggled=None, context=Qt.WindowShortcut):
    """Create a QAction with the given attributes."""
    action = QAction(text, parent)
    if triggered is not None:
        action.triggered.connect(triggered)
    if toggled is not None:
        action.toggled.connect(toggled)
        action.setCheckable(True)
    if icon is not None:
        action.setIcon( icon )
    if shortcut is not None:
        action.setShortcut(shortcut)
    if tip is not None:
        action.setToolTip(tip)
        action.setStatusTip(tip)
    action.setShortcutContext(context)
    return action
开发者ID:Ilias95,项目名称:FF-Multi-Converter,代码行数:20,代码来源:utils.py

示例9: action

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
 def action(self, parent):
     """Create a ``QAction`` from this item."""
     checkable = self.checked is not None
     action = QAction(self.label, parent, checkable=checkable)
     if self.shortcut is not None:
         action.setShortcut(self.shortcut)
         action.setShortcutContext(Qt.ApplicationShortcut)
     if self.description is not None:
         action.setStatusTip(self.description)
     if self.callback is not None:
         action.triggered.connect(self.callback)
     if self.icon is not None:
         if isinstance(self.icon, QStyle.StandardPixmap):
             icon = parent.style().standardIcon(self.icon)
         elif isinstance(self.icon, str):
             icon = QIcon.fromTheme(self.icon)
         else:
             icon = self.icon
         action.setIcon(icon)
     _set_from(action.setEnabled, self.enabled)
     _set_from(action.setChecked, self.checked)
     return action
开发者ID:hibtc,项目名称:madgui,代码行数:24,代码来源:menu.py

示例10: ZoomableGraphicView

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
class ZoomableGraphicView(SelectableGraphicView):

    # argument is x zoom factor
    # if argument is -1, then show_full_scene was triggered during zoom
    zoomed = pyqtSignal(float)

    def __init__(self, parent=None):
        super().__init__(parent)

        self.zoom_in_action = QAction(self.tr("Zoom in"), self)
        self.zoom_in_action.setShortcut(QKeySequence.ZoomIn)
        self.zoom_in_action.triggered.connect(self.on_zoom_in_action_triggered)
        self.zoom_in_action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        self.zoom_in_action.setIcon(QIcon.fromTheme("zoom-in"))
        self.addAction(self.zoom_in_action)

        self.zoom_out_action = QAction(self.tr("Zoom out"), self)
        self.zoom_out_action.setShortcut(QKeySequence.ZoomOut)
        self.zoom_out_action.triggered.connect(self.on_zoom_out_action_triggered)
        self.zoom_out_action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        self.zoom_out_action.setIcon(QIcon.fromTheme("zoom-out"))
        self.addAction(self.zoom_out_action)

        self.redraw_timer = QTimer()
        self.redraw_timer.setSingleShot(True)
        self.redraw_timer.timeout.connect(self.redraw_view)

        self.zoomed.connect(self.on_signal_zoomed)

        self.scene_y_min = float("nan")  # NaN = AutoDetect
        self.scene_y_max = float("nan")  # NaN = AutoDetect

        self.scene_x_zoom_stretch = 1

    @property
    def y_center(self):
        if not hasattr(self, "scene_type") or self.scene_type == 0:
            # Normal scene
            return 0
        else:
            return -self.signal.qad_center

    @property
    def scene_type(self):
        return 0  # gets overwritten in Epic Graphic View

    def scrollContentsBy(self, dx: int, dy: int):
        try:
            super().scrollContentsBy(dx, dy)
            self.redraw_timer.start(0)
        except RuntimeError as e:
            logger.warning("Graphic View already closed: " + str(e))

    def zoom(self, factor, zoom_to_mouse_cursor=True, cursor_pos=None):
        if factor > 1 and self.view_rect().width() / factor < 300:
            factor = self.view_rect().width() / 300

        if zoom_to_mouse_cursor:
            pos = self.mapFromGlobal(QCursor.pos()) if cursor_pos is None else cursor_pos
        else:
            pos = None
        old_pos = self.mapToScene(pos) if pos is not None else None

        show_full = False
        if self.view_rect().width() / factor > self.sceneRect().width():
            self.show_full_scene()
            factor = 1
            show_full = True

        self.scale(factor, 1)
        if show_full:
            self.zoomed.emit(-1)
        else:
            self.zoomed.emit(factor)

        if pos is not None:
            move = self.mapToScene(pos) - old_pos
            self.translate(move.x(), 0)

    def wheelEvent(self, event: QWheelEvent):
        zoom_factor = 1.001 ** event.angleDelta().y()
        self.zoom(zoom_factor, cursor_pos=event.pos())

    def resizeEvent(self, event):
        if self.sceneRect().width() == 0:
            return

        self.auto_fit_view()

    def auto_fit_view(self):
        h_tar = self.sceneRect().height()
        h_view = self.view_rect().height()

        if abs(h_tar) > 0:
            self.scale(1, h_view / h_tar)
        self.centerOn(self.view_rect().x() + self.view_rect().width() / 2, self.y_center)

    def show_full_scene(self, reinitialize=False):
        y_factor = self.transform().m22()
        self.resetTransform()
#.........这里部分代码省略.........
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:103,代码来源:ZoomableGraphicView.py

示例11: LabelValueTableView

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
class LabelValueTableView(QTableView):
    edit_label_action_triggered = pyqtSignal()
    configure_field_types_action_triggered = pyqtSignal()

    def __init__(self, parent=None):
        super().__init__(parent)
        self.setItemDelegateForColumn(1, ComboBoxDelegate([""] * len(constants.LABEL_COLORS),
                                                          colors=constants.LABEL_COLORS,
                                                          parent=self))
        self.setItemDelegateForColumn(2, ComboBoxDelegate(ProtocolLabel.DISPLAY_FORMATS, parent=self))

        orders = OrderedDict([("Big Endian (BE)", [bo + "/BE" for bo in ProtocolLabel.DISPLAY_BIT_ORDERS]),
                              ("Little Endian (LE)", [bo + "/LE" for bo in ProtocolLabel.DISPLAY_BIT_ORDERS])])

        self.setItemDelegateForColumn(3, SectionComboBoxDelegate(orders, parent=self))

        self.del_rows_action = QAction("Delete selected labels", self)
        self.del_rows_action.setShortcut(QKeySequence.Delete)
        self.del_rows_action.setIcon(QIcon.fromTheme("edit-delete"))
        self.del_rows_action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        self.del_rows_action.triggered.connect(self.delete_rows)

        self.addAction(self.del_rows_action)

    @property
    def selected_min_max_row(self):
        selected = self.selectionModel().selection()
        if selected.isEmpty():
            return -1, -1
        min_row = min(rng.top() for rng in selected)
        max_row = max(rng.bottom() for rng in selected)
        return min_row, max_row

    def create_context_menu(self):
        menu = QMenu()
        min_row, max_row = self.selected_min_max_row
        if self.model().rowCount() > 0 and min_row > -1:
            edit_label_action = menu.addAction(self.tr("Edit..."))
            edit_label_action.setIcon(QIcon.fromTheme("configure"))
            edit_label_action.triggered.connect(self.on_edit_label_action_triggered)

            if len(self.model().controller.proto_analyzer.message_types) > 1:
                msg_type_menu = menu.addMenu("Copy to message type")
                for i, message_type in enumerate(self.model().controller.proto_analyzer.message_types):
                    if message_type != self.model().controller.active_message_type:
                        msg_type_action = msg_type_menu.addAction(message_type.name)
                        msg_type_action.setData(i)
                        msg_type_action.triggered.connect(self.on_copy_to_msg_type_action_triggered)

            menu.addAction(self.del_rows_action)
        menu.addSeparator()
        configure_field_types_action = menu.addAction("Configure field types...")
        configure_field_types_action.triggered.connect(self.configure_field_types_action_triggered.emit)

        return menu

    def contextMenuEvent(self, event: QContextMenuEvent):
        menu = self.create_context_menu()
        menu.exec_(self.mapToGlobal(event.pos()))

    def model(self) -> LabelValueTableModel:
        return super().model()

    def delete_rows(self):
        min_row, max_row = self.selected_min_max_row
        if min_row > -1:
            self.model().delete_labels_at(min_row, max_row)

    @pyqtSlot()
    def on_edit_label_action_triggered(self):
        self.edit_label_action_triggered.emit()

    @pyqtSlot()
    def on_copy_to_msg_type_action_triggered(self):
        min_row, max_row = self.selected_min_max_row
        self.model().add_labels_to_message_type(min_row, max_row, int(self.sender().data()))
开发者ID:jopohl,项目名称:urh,代码行数:78,代码来源:LabelValueTableView.py

示例12: MainController

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
class MainController(QMainWindow):
    def __init__(self, *args):
        super().__init__(*args)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        util.set_splitter_stylesheet(self.ui.splitter)

        OptionsDialog.write_default_options()

        self.project_save_timer = QTimer()
        self.project_manager = ProjectManager(self)
        self.plugin_manager = PluginManager()
        self.signal_tab_controller = SignalTabController(self.project_manager,
                                                         parent=self.ui.tab_interpretation)
        self.ui.tab_interpretation.layout().addWidget(self.signal_tab_controller)
        self.compare_frame_controller = CompareFrameController(parent=self.ui.tab_protocol,
                                                               plugin_manager=self.plugin_manager,
                                                               project_manager=self.project_manager)
        self.compare_frame_controller.ui.splitter.setSizes([1, 1000000])

        self.ui.tab_protocol.layout().addWidget(self.compare_frame_controller)

        self.generator_tab_controller = GeneratorTabController(self.compare_frame_controller,
                                                               self.project_manager,
                                                               parent=self.ui.tab_generator)

        self.simulator_tab_controller = SimulatorTabController(parent=self.ui.tab_simulator,
                                                               compare_frame_controller=self.compare_frame_controller,
                                                               generator_tab_controller=self.generator_tab_controller,
                                                               project_manager=self.project_manager)

        self.ui.tab_simulator.layout().addWidget(self.simulator_tab_controller)

        self.undo_group = QUndoGroup()
        self.undo_group.addStack(self.signal_tab_controller.signal_undo_stack)
        self.undo_group.addStack(self.compare_frame_controller.protocol_undo_stack)
        self.undo_group.addStack(self.generator_tab_controller.generator_undo_stack)
        self.undo_group.setActiveStack(self.signal_tab_controller.signal_undo_stack)

        self.cancel_action = QAction(self.tr("Cancel"), self)
        self.cancel_action.setShortcut(QKeySequence.Cancel if hasattr(QKeySequence, "Cancel") else "Esc")
        self.cancel_action.triggered.connect(self.on_cancel_triggered)
        self.cancel_action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        self.cancel_action.setIcon(QIcon.fromTheme("dialog-cancel"))
        self.addAction(self.cancel_action)

        self.ui.actionAuto_detect_new_signals.setChecked(constants.SETTINGS.value("auto_detect_new_signals",
                                                                                  True, bool))

        self.participant_legend_model = ParticipantLegendListModel(self.project_manager.participants)
        self.ui.listViewParticipants.setModel(self.participant_legend_model)

        gtc = self.generator_tab_controller
        gtc.ui.splitter.setSizes([gtc.width() / 0.7, gtc.width() / 0.3])

        self.ui.tab_generator.layout().addWidget(self.generator_tab_controller)

        self.signal_protocol_dict = {}  # type: dict[SignalFrame, ProtocolAnalyzer]

        self.ui.lnEdtTreeFilter.setClearButtonEnabled(True)

        group = QActionGroup(self)
        self.ui.actionFSK.setActionGroup(group)
        self.ui.actionOOK.setActionGroup(group)
        self.ui.actionNone.setActionGroup(group)
        self.ui.actionPSK.setActionGroup(group)

        self.recentFileActionList = []
        self.create_connects()
        self.init_recent_file_action_list(constants.SETTINGS.value("recentFiles", []))

        self.filemodel = FileSystemModel(self)
        path = QDir.homePath()

        self.filemodel.setIconProvider(FileIconProvider())
        self.filemodel.setRootPath(path)
        self.file_proxy_model = FileFilterProxyModel(self)
        self.file_proxy_model.setSourceModel(self.filemodel)
        self.ui.fileTree.setModel(self.file_proxy_model)

        self.ui.fileTree.setRootIndex(self.file_proxy_model.mapFromSource(self.filemodel.index(path)))
        self.ui.fileTree.setToolTip(path)
        self.ui.fileTree.header().setSectionResizeMode(0, QHeaderView.ResizeToContents)
        self.ui.fileTree.header().setSectionResizeMode(1, QHeaderView.Stretch)
        self.ui.fileTree.setFocus()

        self.generator_tab_controller.table_model.cfc = self.compare_frame_controller

        self.ui.actionConvert_Folder_to_Project.setEnabled(False)

        undo_action = self.undo_group.createUndoAction(self)
        undo_action.setIcon(QIcon.fromTheme("edit-undo"))
        undo_action.setShortcut(QKeySequence.Undo)
        self.ui.menuEdit.insertAction(self.ui.actionDecoding, undo_action)

        redo_action = self.undo_group.createRedoAction(self)
        redo_action.setIcon(QIcon.fromTheme("edit-redo"))
        redo_action.setShortcut(QKeySequence.Redo)
        self.ui.menuEdit.insertAction(self.ui.actionDecoding, redo_action)
#.........这里部分代码省略.........
开发者ID:jopohl,项目名称:urh,代码行数:103,代码来源:MainController.py

示例13: SelectableGraphicView

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
class SelectableGraphicView(QGraphicsView):
    sep_area_moving = pyqtSignal(float)
    sep_area_changed = pyqtSignal(float)
    selection_width_changed = pyqtSignal(int)
    selection_height_changed = pyqtSignal(int)
    sel_area_start_end_changed = pyqtSignal(int, int)

    def __init__(self, parent=None):
        super().__init__(parent)

        self.setResizeAnchor(QGraphicsView.NoAnchor)
        self.setTransformationAnchor(QGraphicsView.NoAnchor)
        self.setRenderHints(QPainter.Antialiasing)

        self.scene_manager = None  # type: SceneManager
        self.mouse_press_pos = None  # type: QPoint
        self.mouse_pos = None  # type: QPoint
        self.grab_start = None  # type: QPoint

        self.move_y_with_drag = False

        self.xmove = 0

        self.separation_area_moving = False

        self.shift_mode = False  # Shift Key currently pressed?

        self.select_all_action = QAction(self.tr("Select all"), self)
        self.select_all_action.setShortcut(QKeySequence.SelectAll)
        self.select_all_action.triggered.connect(self.select_all)
        self.select_all_action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        self.select_all_action.setIcon(QIcon.fromTheme("edit-select-all"))
        self.addAction(self.select_all_action)

    def scene(self) -> ZoomableScene:
        return super().scene()

    @property
    def selection_area(self) -> HorizontalSelection:
        return self.scene().selection_area

    @selection_area.setter
    def selection_area(self, value):
        self.scene().selection_area = value

    @property
    def has_horizontal_selection(self) -> bool:
        return isinstance(self.scene().selection_area, HorizontalSelection)

    @property
    def hold_shift_to_drag(self) -> bool:
        return constants.SETTINGS.value('hold_shift_to_drag', True, type=bool)

    @property
    def something_is_selected(self) -> bool:
        return hasattr(self, "selection_area") and self.selection_area is not None and not self.selection_area.is_empty

    def is_pos_in_separea(self, pos: QPoint):
        """
        GraphicViews can override this, if they need a seperation area.
        E.g. EpicGraphic View will do for Demodulated View

        :param pos:
        :return:
        """

        return False

    def keyPressEvent(self, event: QKeyEvent):
        if event.key() == Qt.Key_Shift:
            self.shift_mode = True

            if self.hold_shift_to_drag:
                self.setCursor(Qt.OpenHandCursor)
            else:
                self.unsetCursor()
                self.grab_start = None

        super().keyPressEvent(event)

    def keyReleaseEvent(self, event: QKeyEvent):
        if event.key() == Qt.Key_Shift:
            self.shift_mode = False

            if self.hold_shift_to_drag:
                self.unsetCursor()
                self.grab_start = None
            else:
                self.setCursor(Qt.OpenHandCursor)

        super().keyPressEvent(event)

    def mousePressEvent(self, event: QMouseEvent):
        if self.scene() is None:
            return

        cursor = self.cursor().shape()
        has_shift_modifier = event.modifiers() == Qt.ShiftModifier
        is_in_shift_mode = (has_shift_modifier and self.hold_shift_to_drag) \
                           or (not has_shift_modifier and not self.hold_shift_to_drag) \
#.........这里部分代码省略.........
开发者ID:jopohl,项目名称:urh,代码行数:103,代码来源:SelectableGraphicView.py

示例14: ProtocolTableView

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
class ProtocolTableView(TableView):
    show_interpretation_clicked = pyqtSignal(int, int, int, int)
    selection_changed = pyqtSignal()
    protocol_view_change_clicked = pyqtSignal(int)
    row_visibility_changed = pyqtSignal()
    writeable_changed = pyqtSignal(bool)
    crop_sync_clicked = pyqtSignal()
    revert_sync_cropping_wanted = pyqtSignal()
    edit_label_clicked = pyqtSignal(ProtocolLabel)
    files_dropped = pyqtSignal(list)
    participant_changed = pyqtSignal()
    new_messagetype_clicked = pyqtSignal(list)  # list of protocol messages
    messagetype_selected = pyqtSignal(MessageType, list)

    def __init__(self, parent=None):
        super().__init__(parent)

        self.verticalHeader().setSectionResizeMode(QHeaderView.Fixed)
        self.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed)

        self.ref_message_action = QAction(self.tr("Mark as reference message"), self)
        self.ref_message_action.setShortcut(QKeySequence("R"))
        self.ref_message_action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        self.ref_message_action.triggered.connect(self.set_ref_message)

        self.hide_row_action = QAction("Hide selected rows", self)
        self.hide_row_action.setShortcut(QKeySequence("H"))
        self.hide_row_action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
        self.hide_row_action.triggered.connect(self.hide_row)

        self.addAction(self.ref_message_action)
        self.addAction(self.hide_row_action)

    def model(self) -> ProtocolTableModel:
        return super().model()

    @property
    def selected_messages(self):
        messages = self.model().protocol.messages
        rows = set(i.row() for i in self.selectionModel().selectedIndexes())
        return [messages[i] for i in rows]

    def selectionChanged(self, selection_1: QItemSelection, selection_2: QItemSelection):
        self.selection_changed.emit()
        super().selectionChanged(selection_1, selection_2)

    def dragMoveEvent(self, event):
        event.accept()

    def dragEnterEvent(self, event):
        event.acceptProposedAction()

    def dropEvent(self, event: QDropEvent):
        if len(event.mimeData().urls()) > 0:
            self.files_dropped.emit(event.mimeData().urls())

    def create_context_menu(self):
        menu = QMenu()
        row = self.rowAt(self.context_menu_pos.y())
        cols = [index.column() for index in self.selectionModel().selectedIndexes() if index.row() == row]
        cols.sort()

        pos = self.context_menu_pos
        row = self.rowAt(pos.y())
        selected_messages = self.selected_messages
        self.participant_actions = {}

        if len(selected_messages) == 0:
            selected_participant = -1
            selected_message_type = -1
        else:
            selected_participant = selected_messages[0].participant
            selected_message_type = selected_messages[0].message_type
            for message in selected_messages:
                if selected_participant != message.participant:
                    selected_participant = -1
                if selected_message_type != message.message_type:
                    selected_message_type = -1
                if selected_message_type == -1 and selected_participant == -1:
                    break

        message_type_menu_str = self.tr("Message type")
        if selected_message_type != -1:
            message_type_menu_str += self.tr(" ("+selected_message_type.name+")")
        message_type_menu = menu.addMenu(message_type_menu_str)
        message_type_group = QActionGroup(self)
        self.message_type_actions = {}

        for message_type in self.model().protocol.message_types:
            action = message_type_menu.addAction(message_type.name)
            action.setCheckable(True)
            action.setActionGroup(message_type_group)

            if selected_message_type == message_type:
                action.setChecked(True)

            self.message_type_actions[action] = message_type
            action.triggered.connect(self.on_message_type_action_triggered)

        new_message_type_action = message_type_menu.addAction("Create new")
#.........这里部分代码省略.........
开发者ID:Cyber-Forensic,项目名称:urh,代码行数:103,代码来源:ProtocolTableView.py

示例15: act

# 需要导入模块: from PyQt5.QtWidgets import QAction [as 别名]
# 或者: from PyQt5.QtWidgets.QAction import setShortcutContext [as 别名]
 def act(slot, icon=None):
     a = QAction(self, triggered=slot)
     self.addAction(a)
     a.setShortcutContext(Qt.WidgetWithChildrenShortcut)
     icon and a.setIcon(icons.get(icon))
     return a
开发者ID:AlexSchr,项目名称:frescobaldi,代码行数:8,代码来源:widget.py


注:本文中的PyQt5.QtWidgets.QAction.setShortcutContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。