Python PyQt5.QtGui 模块,QKeySequence() 实例源码

我们从Python开源项目中,提取了以下43个代码示例,用于说明如何使用PyQt5.QtGui.QKeySequence()

项目:PyNoder    作者:johnroper100    | 项目源码 | 文件源码
def setGraphView(self, graphView):
        self.graphView = graphView

        # Setup Layout
        layout = QtWidgets.QVBoxLayout(self)
        layout.addWidget(self.graphView)
        self.setLayout(layout)

        # Setup hotkeys for the following actions.
        deleteShortcut = QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Delete), self)
        deleteShortcut.activated.connect(self.graphView.deleteSelectedNodes)

        frameShortcut = QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_F), self)
        frameShortcut.activated.connect(self.graphView.frameSelectedNodes)

        frameShortcut = QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_A), self)
        frameShortcut.activated.connect(self.graphView.frameAllNodes)
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def qui_menu(self, action_list_str, menu_str):
        # qui menu creation
        # syntax: self.qui_menu('right_menu_createFolder_atn;Create Folder,Ctrl+D | right_menu_openFolder_atn;Open Folder', 'right_menu')
        if menu_str not in self.uiList.keys():
            self.uiList[menu_str] = QtWidgets.QMenu()
        create_opt_list = [ x.strip() for x in action_list_str.split('|') ]
        for each_creation in create_opt_list:
            ui_info = [ x.strip() for x in each_creation.split(';') ]
            atn_name = ui_info[0]
            atn_title = ''
            atn_hotkey = ''
            if len(ui_info) > 1:
                options = ui_info[1].split(',')
                atn_title = '' if len(options) < 1 else options[0]
                atn_hotkey = '' if len(options) < 2 else options[1]
            if atn_name != '':
                if atn_name == '_':
                    self.uiList[menu_str].addSeparator()
                else:
                    if atn_name not in self.uiList.keys():
                        self.uiList[atn_name] = QtWidgets.QAction(atn_title, self)
                        if atn_hotkey != '':
                            self.uiList[atn_name].setShortcut(QtGui.QKeySequence(atn_hotkey))
                    self.uiList[menu_str].addAction(self.uiList[atn_name])
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def setupMenu(self):
        self.quickMenu(['file_menu;&File','setting_menu;&Setting','help_menu;&Help'])
        cur_menu = self.uiList['setting_menu']
        self.quickMenuAction('setParaA_atn','Set Parameter &A','A example of tip notice.','setParaA.png', cur_menu)
        self.uiList['setParaA_atn'].setShortcut(QtGui.QKeySequence("Ctrl+R"))
        cur_menu.addSeparator()
        if 'help_menu' in self.uiList.keys():
            # for info review
            cur_menu = self.uiList['help_menu']
            self.quickMenuAction('helpHostMode_atnNone','Host Mode - {}'.format(hostMode),'Host Running.','', cur_menu)
            self.quickMenuAction('helpPyMode_atnNone','Python Mode - {}'.format(pyMode),'Python Library Running.','', cur_menu)
            self.quickMenuAction('helpQtMode_atnNone','Qt Mode - {}'.format(qtModeList[qtMode]),'Qt Library Running.','', cur_menu)
            self.quickMenuAction('helpTemplate_atnNone','Universal Tool Teamplate - {}'.format(tpl_ver),'based on Univeral Tool Template v{0} by Shining Ying - https://github.com/shiningdesign/universal{1}tool{1}template.py'.format(tpl_ver,'_'),'', cur_menu)
            cur_menu.addSeparator()
            self.uiList['helpGuide_msg'] = self.help
            self.quickMenuAction('helpGuide_atnMsg','Usage Guide','How to Usge Guide.','helpGuide.png', cur_menu)
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def __init__(self, mainWindow):
        super().__init__(mainWindow, "choose a dynamic")
        button = QtWidgets.QPushButton("[r] Ramp")
        button.setShortcut(QtGui.QKeySequence("r"))
        self.layout.addWidget(button)
        button.clicked.connect(api.insertDynamicRamp)
        button.clicked.connect(self.done)

        l = [("[{}] {}".format(num+1, keyword), lambda r, keyword=keyword: api.insertDynamicSignature(keyword)) for num, keyword in enumerate(constantsAndConfigs.dynamics)]

        for number, (prettyname, function) in enumerate(l):
            button = QtWidgets.QPushButton(prettyname)
            button.setShortcut(QtGui.QKeySequence(str(number+1)))
            self.layout.addWidget(button)
            button.clicked.connect(function)
            button.clicked.connect(self.done)
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def __setitem__(self, key, menuAction):
        try:
            self[key].setShortcut(QtGui.QKeySequence()) #reset the action that previously had that shortcut
        except AttributeError:
            pass

        if self.mainWindow.settings.contains(menuAction.shortcut().toString()): #"Num+3"
            self.mainWindow.settings.remove(menuAction.shortcut().toString())

        self.mainWindow.settings.remove("Num+"+key) #"Num+3"

        try:
            dict.__setitem__(self, menuAction.shortcut().toString()[-1], None) #-1 is a number as string
        except IndexError:
            pass

        menuAction.setShortcut(QtGui.QKeySequence()) #reset the new action to remove existing shortcuts
        menuAction.setShortcut(QtGui.QKeySequence(self.qShortcuts[key]))
        self.mainWindow.settings.setValue("Num+"+key, menuAction.text())
        dict.__setitem__(self, key, menuAction)
项目:urh    作者:jopohl    | 项目源码 | 文件源码
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)
项目:lxa5    作者:linguistica-uchicago    | 项目源码 | 文件源码
def create_action(self, text=None, slot=None, tip=None, shortcut=None):
        """
        This create actions for the File menu, things like
        Read Corpus, Rerun Corpus etc
        """
        action = QAction(text, self)
        if shortcut:
            action.setShortcut(shortcut)
        if tip:
            action.setToolTip(tip)
            action.setStatusTip(tip)
        if slot:
            # noinspection PyUnresolvedReferences
            action.triggered.connect(slot)
        if shortcut:
            # noinspection PyUnresolvedReferences
            QShortcut(QKeySequence(shortcut), self).activated.connect(slot)
        return action
项目:uPyLoader    作者:BetaRavener    | 项目源码 | 文件源码
def __init__(self):
        self.version = 100  # Assume oldest config
        self.root_dir = QDir().currentPath()
        self.send_sleep = 0.1
        self.read_sleep = 0.1
        self.use_transfer_scripts = True
        self.external_transfer_scripts_folder = None
        self.wifi_presets = []
        self.python_flash_executable = None
        self.last_firmware_directory = None
        self.debug_mode = False
        self._geometries = {}
        self.external_editor_path = None
        self.external_editor_args = None
        self.new_line_key = QKeySequence(Qt.SHIFT + Qt.Key_Return, Qt.SHIFT + Qt.Key_Enter)
        self.send_key = QKeySequence(Qt.Key_Return, Qt.Key_Enter)
        self.terminal_tab_spaces = 4
        self.mpy_cross_path = None
        self.preferred_port = None
        self.auto_transfer = False

        if not self.load():
            if not self.load_old():
                # No config found, init at newest version
                self.version = Settings.newest_version
                return

        self._update_config()
项目:uPyLoader    作者:BetaRavener    | 项目源码 | 文件源码
def serialize(self):
        serialized = {}
        for key, val in self.__dict__.items():
            if isinstance(val, QKeySequence):
                val = val.toString()

            serialized[key] = val

        return serialized
项目:uPyLoader    作者:BetaRavener    | 项目源码 | 文件源码
def deserialize(self, serialized):
        deserialized = {}
        for key, val in serialized.items():
            if key == "new_line_key" or key == "send_key":
                val = QKeySequence(val)

            deserialized[key] = val

        return deserialized
项目:uPyLoader    作者:BetaRavener    | 项目源码 | 文件源码
def key_event_sequence(event):
        val = event.key()
        mod = event.modifiers()
        if mod & Qt.ShiftModifier:
            val += Qt.SHIFT
        if mod & Qt.ControlModifier:
            val += Qt.CTRL
        if mod & Qt.AltModifier:
            val += Qt.ALT
        if mod & Qt.MetaModifier:
            val += Qt.META
        return QKeySequence(val)
项目:QtPropertyBrowserV2.6-for-pyqt5    作者:theall    | 项目源码 | 文件源码
def _slotValueChanged(self, property, val):
        if type(val)==QKeySequence:
            raise NotImplementedError
        self._valueChanged(property, QVariant(val))
项目:EMFT    作者:132nd-etcher    | 项目源码 | 文件源码
def __init__(self):
        # Fucking QMainWindow calls a general super().__init__ on every parent class, don't call them here !
        flags = Qt.WindowTitleHint | Qt.WindowSystemMenuHint | Qt.WindowCloseButtonHint
        flags = flags | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint

        self.helpers = {}

        QMainWindow.__init__(
            self,
            flags=flags
        )

        self.resize(1024, 768)

        self.tabs = TabWidget()

        layout = VLayout(
            [
                self.tabs
            ]
        )

        layout.setContentsMargins(10, 10, 10, 10)

        window = Widget()
        window.setLayout(layout)

        self.setCentralWidget(window)

        self.setWindowIcon(QIcon(constant.DEFAULT_ICON))

        self.exit_shortcut = Shortcut(QKeySequence(Qt.Key_Escape), self, self.exit)

        self.setWindowTitle(
            '{} v{} - {}'.format(constant.APP_SHORT_NAME,
                                 __version__,
                                 constant.APP_RELEASE_NAME))
项目:EMFT    作者:132nd-etcher    | 项目源码 | 文件源码
def __init__(self, key_sequence: QKeySequence, parent: QWidget, func: callable):
        QShortcut.__init__(self, key_sequence, parent)
        # noinspection PyUnresolvedReferences
        self.activated.connect(func)
项目:Dragonfly    作者:duaneloh    | 项目源码 | 文件源码
def keyPressEvent(self, event):
        k = event.key()
        m = int(event.modifiers())

        if QtGui.QKeySequence(m+k) == QtGui.QKeySequence('Ctrl+N'):
            self.frame_panel.next_frame()
        elif QtGui.QKeySequence(m+k) == QtGui.QKeySequence('Ctrl+P'):
            self.frame_panel.prev_frame()
        elif QtGui.QKeySequence(m+k) == QtGui.QKeySequence('Ctrl+R'):
            self.frame_panel.rand_frame()
        elif QtGui.QKeySequence(m+k) == QtGui.QKeySequence('Ctrl+Q'):
            self.close()
        else:
            event.ignore()
项目:Dragonfly    作者:duaneloh    | 项目源码 | 文件源码
def keyPressEvent(self, event):
        k = event.key()
        m = int(event.modifiers())

        if QtGui.QKeySequence(m+k) == QtGui.QKeySequence('Ctrl+N'):
            self.frame_panel.next_frame()
        elif QtGui.QKeySequence(m+k) == QtGui.QKeySequence('Ctrl+P'):
            self.frame_panel.prev_frame()
        elif QtGui.QKeySequence(m+k) == QtGui.QKeySequence('Ctrl+R'):
            self.frame_panel.rand_frame()
        elif QtGui.QKeySequence(m+k) == QtGui.QKeySequence('Ctrl+Q'):
            self.close()
        else:
            event.ignore()
项目:Dragonfly    作者:duaneloh    | 项目源码 | 文件源码
def keyPressEvent(self, event):
        k = event.key()
        m = int(event.modifiers())

        if k == QtCore.Qt.Key_Return or k == QtCore.Qt.Key_Enter:
            self.parse_and_plot()
        elif QtGui.QKeySequence(m+k) == QtGui.QKeySequence('Ctrl+Q'):
            self.close()
        elif QtGui.QKeySequence(m+k) == QtGui.QKeySequence('Ctrl+S'):
            self.save_plot()
        else:
            event.ignore()
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def qui_atn(self, ui_name, title, tip=None, icon=None, parent=None, key=None):
        self.uiList[ui_name] = QtWidgets.QAction(title, self)
        if icon!=None:
            self.uiList[ui_name].setIcon(QtGui.QIcon(icon))
        if tip !=None:
            self.uiList[ui_name].setStatusTip(tip)
        if key != None:
            self.uiList[ui_name].setShortcut(QtGui.QKeySequence(key))
        if parent !=None:
            if isinstance(parent, (str, unicode)) and parent in self.uiList.keys():
                self.uiList[parent].addAction(self.uiList[ui_name])
            elif isinstance(parent, QtWidgets.QMenu):
                parent.addAction(self.uiList[ui_name])
        return ui_name
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def qui_key(self, key_name, key_combo, func):
        self.hotkey[key_name] = QtWidgets.QShortcut(QtGui.QKeySequence(key_combo), self)
        self.hotkey[key_name].activated.connect( func )
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def setupMenu(self):
        self.quickMenu('file_menu;&File | setting_menu;&Setting | help_menu;&Help')
        cur_menu = self.uiList['setting_menu']
        for info in ['export', 'import','user']:
            title = info.title()
            self.quickMenuAction('{0}Config_atn'.format(info),'{0} Config (&{1})'.format(title,title[0]),'{0} Setting and Configuration.'.format(title),'{0}Config.png'.format(info), cur_menu)
            self.uiList['{0}Config_atn'.format(info)].setShortcut(QtGui.QKeySequence("Ctrl+{0}".format(title[0])))
        cur_menu.addSeparator()
        super(self.__class__,self).setupMenu()
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def Establish_Connections(self):
        super(self.__class__,self).Establish_Connections()
        # custom ui response
        # shortcut connection
        self.hotkey = {}
        # self.hotkey['my_key'] = QtWidgets.QShortcut(QtGui.QKeySequence( "Ctrl+1" ), self)
        # self.hotkey['my_key'].activated.connect(self.my_key_func)
    # ---- user response list ----
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def setupMenu(self):
        self.quickMenu('file_menu;&File | setting_menu;&Setting | help_menu;&Help')
        cur_menu = self.uiList['setting_menu']
        for info in ['export', 'import']:
            title = info.title()
            self.quickMenuAction('{0}Config_atn'.format(info),'{0} Config (&{1})'.format(title,title[0]),'{0} Setting and Configuration.'.format(title),'{0}Config.png'.format(info), cur_menu)
            self.uiList['{0}Config_atn'.format(info)].setShortcut(QtGui.QKeySequence("Ctrl+{0}".format(title[0])))
        cur_menu.addSeparator()
        super(self.__class__,self).setupMenu()
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def Establish_Connections(self):
        super(self.__class__,self).Establish_Connections()
        # custom ui response
        # shortcut connection
        self.hotkey = {}
        # self.hotkey['my_key'] = QtWidgets.QShortcut(QtGui.QKeySequence( "Ctrl+1" ), self)
        # self.hotkey['my_key'].activated.connect(self.my_key_func)
    # ---- user response list ----
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def setupMenu(self):
        self.quickMenu(['file_menu;&File','setting_menu;&Setting','help_menu;&Help'])
        cur_menu = self.uiList['setting_menu']
        self.quickMenuAction('setParaA_atn','Set Parameter &A','A example of tip notice.','setParaA.png', cur_menu)
        self.uiList['setParaA_atn'].setShortcut(QtGui.QKeySequence("Ctrl+R"))
        cur_menu.addSeparator()
        super(self.__class__,self).setupMenu()
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def Establish_Connections(self):
        super(self.__class__,self).Establish_Connections()
        # custom ui response
        # shortcut connection
        self.hotkey = {}
        # self.hotkey['my_key'] = QtWidgets.QShortcut(QtGui.QKeySequence( "Ctrl+1" ), self)
        # self.hotkey['my_key'].activated.connect(self.my_key_func)


    # ---- user response list ----
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def setupMenu(self):
        self.quickMenu('file_menu;&File | setting_menu;&Setting | help_menu;&Help')
        cur_menu = self.uiList['setting_menu']
        for info in ['export', 'import']:
            title = info.title()
            self.quickMenuAction('{0}Config_atn'.format(info),'{0} Config (&{1})'.format(title,title[0]),'{0} Setting and Configuration.'.format(title),'{0}Config.png'.format(info), cur_menu)
            self.uiList['{0}Config_atn'.format(info)].setShortcut(QtGui.QKeySequence("Ctrl+{0}".format(title[0])))
        cur_menu.addSeparator()
        super(self.__class__,self).setupMenu()
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def setupMenu(self):
        self.quickMenu(['file_menu;&File','setting_menu;&Setting','help_menu;&Help'])
        cur_menu = self.uiList['setting_menu']
        self.quickMenuAction('setParaA_atn','Set Parameter &A','A example of tip notice.','setParaA.png', cur_menu)
        self.uiList['setParaA_atn'].setShortcut(QtGui.QKeySequence("Ctrl+R"))
        cur_menu.addSeparator()
        super(self.__class__,self).setupMenu()
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def setupMenu(self):
        self.quickMenu(['file_menu;&File','setting_menu;&Setting','help_menu;&Help'])
        cur_menu = self.uiList['setting_menu']
        self.quickMenuAction('setParaA_atn','Set Parameter &A','A example of tip notice.','setParaA.png', cur_menu)
        self.uiList['setParaA_atn'].setShortcut(QtGui.QKeySequence("Ctrl+R"))
        cur_menu.addSeparator()
        # for info review
        cur_menu = self.uiList['help_menu']
        self.quickMenuAction('helpHostMode_atnNone','Host Mode - {}'.format(hostMode),'Host Running.','', cur_menu)
        self.quickMenuAction('helpPyMode_atnNone','Python Mode - {}'.format(pyMode),'Python Library Running.','', cur_menu)
        self.quickMenuAction('helpQtMode_atnNone','Qt Mode - {}'.format(qtModeList[qtMode]),'Qt Library Running.','', cur_menu)
        self.quickMenuAction('helpTemplate_atnNone','Universal Tool Teamplate - {}'.format(tpl_ver),'based on Univeral Tool Template v{} by Shining Ying - https://github.com/shiningdesign/universal_tool_template.py'.format(tpl_ver),'', cur_menu)
        cur_menu.addSeparator()
        self.uiList['helpGuide_msg'] = "How to Use:\n1. Put source info in\n2. Click Process button\n3. Check result output\n4. Save memory info into a file."
        self.quickMenuAction('helpGuide_atnMsg','Usage Guide','How to Usge Guide.','helpGuide.png', cur_menu)
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def setupMenu(self):
        self.quickMenu('file_menu;&File | setting_menu;&Setting | help_menu;&Help')
        cur_menu = self.uiList['setting_menu']
        for info in ['export', 'import']:
            title = info.title()
            self.quickMenuAction('{0}Config_atn'.format(info),'{0} Config (&{1})'.format(title,title[0]),'{0} Setting and Configuration.'.format(title),'{0}Config.png'.format(info), cur_menu)
            self.uiList['{0}Config_atn'.format(info)].setShortcut(QtGui.QKeySequence("Ctrl+{0}".format(title[0])))
        cur_menu.addSeparator()
        super(self.__class__,self).setupMenu()
项目:universal_tool_template.py    作者:shiningdesign    | 项目源码 | 文件源码
def Establish_Connections(self):
        super(self.__class__,self).Establish_Connections()
        # custom ui response
        # shortcut connection
        self.hotkey = {}
        # self.hotkey['my_key'] = QtWidgets.QShortcut(QtGui.QKeySequence( "Ctrl+1" ), self)
        # self.hotkey['my_key'].activated.connect(self.my_key_func)
    # ---- user response list ----
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def __init__(self, mainWindow):
        super().__init__(mainWindow, "choose a clef")

        for number, (prettyname, function) in enumerate(SecondaryClefMenu.clefs):
            button = QtWidgets.QPushButton(prettyname)
            button.setShortcut(QtGui.QKeySequence(str(number+1)))
            self.layout.addWidget(button)
            button.clicked.connect(function)
            button.clicked.connect(self.done)
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def __init__(self, mainWindow):
        super().__init__(mainWindow, "split chord in")

        for number, (prettyname, function) in enumerate(SecondarySplitMenu.splits):
            button = QtWidgets.QPushButton(prettyname)
            button.setShortcut(QtGui.QKeySequence(str(number+2))) #+1 for enumerate from 0, +2 we start at 2.
            self.layout.addWidget(button)
            button.clicked.connect(function)
            button.clicked.connect(self.done)
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def __init__(self, mainWindow):
        super().__init__(mainWindow, "root note is the cursor position")
        l = [("[{}] {}".format(num+1, modeString.title()), lambda r, modeString=modeString: api.insertCursorCommonKeySignature(modeString)) for num, modeString in enumerate(api.commonKeySignaturesAsList())]

        for number, (prettyname, function) in enumerate(l):
            button = QtWidgets.QPushButton(prettyname)
            button.setShortcut(QtGui.QKeySequence(str(number+1)))
            self.layout.addWidget(button)
            button.clicked.connect(function)
            button.clicked.connect(self.done)
项目:Laborejo    作者:hilbrichtsoftware    | 项目源码 | 文件源码
def __init__(self, mainWindow):
        super().__init__(mainWindow, "choose a metrical instruction")

        l = [("[{}] {}".format(num+1, modeString), lambda r, modeString=modeString: api.insertCommonMetricalInstrucions(modeString)) for num, modeString in enumerate(api.commonMetricalInstructionsAsList())]

        for number, (prettyname, function) in enumerate(l):
            button = QtWidgets.QPushButton(prettyname)
            button.setShortcut(QtGui.QKeySequence(str(number+1)))
            self.layout.addWidget(button)
            button.clicked.connect(function)
            button.clicked.connect(self.done)
项目:PointlessMaker    作者:aboood40091    | 项目源码 | 文件源码
def createMenubar(self):
        self.CreateAction('openfromfile', self.HandleOpenFromFile, None,
                          'Open Level by File...', 'Open a level based on its filename',
                          QtGui.QKeySequence('Ctrl+Shift+O'))
        self.CreateAction('save', self.HandleSaveAs, None, 'Save Level As',
                          'Save the level with a new filename', QtGui.QKeySequence.Save)


        menubar = QtWidgets.QMenuBar()
        self.setMenuBar(menubar)

        fmenu = menubar.addMenu('&File')
        fmenu.addAction(self.actions['openfromfile'])
        fmenu.addSeparator()
        fmenu.addAction(self.actions['save'])
项目:ezdmb    作者:angryrancor    | 项目源码 | 文件源码
def setEscKey(window):
    window.shortcut = QShortcut(QKeySequence(Qt.Key_Escape), window)
    window.shortcut.activated.connect(lambda: QApplication.quit())
项目:copa    作者:komradz    | 项目源码 | 文件源码
def setupUi(self):
        self.setObjectName("Dialog")
        self.resize(355, 76)
        self.buttonBox = QtWidgets.QDialogButtonBox(self)
        self.buttonBox.setGeometry(QtCore.QRect(0, 40, 341, 32))
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        font8 = QtGui.QFont('Courier New',8)
        self.buttonBox.addButton('Find (Enter)',QtWidgets.QDialogButtonBox.AcceptRole)
        self.findnext_Btn = self.buttonBox.addButton('Find next (F3)',QtWidgets.QDialogButtonBox.ApplyRole)
        self.buttonBox.addButton('Cancel',QtWidgets.QDialogButtonBox.RejectRole)
        self.buttonBox.setObjectName("buttonBox")
        self.lineEdit_search = QtWidgets.QLineEdit(self)
        self.lineEdit_search.setGeometry(QtCore.QRect(100, 10, 221, 20))
        self.lineEdit_search.setObjectName("lineEdit_search")
        self.lineEdit_search.setFont(font8)
        self.lineEdit_search.setClearButtonEnabled(True)
        self.label = QtWidgets.QLabel(self)
        self.label.setGeometry(QtCore.QRect(10, 10, 71, 16))
        self.label.setObjectName("label")

        self.lineEdit_search.setText('search here')
        self.retranslateUi()
        #button clicks events
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)
        self.findnext_Btn.clicked.connect(self.acceptNext)

        # shortcut = QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_F3), self)
        # # shortcut = QtWidgets.QShortcut(QtGui.QKeySequence(QtCore.Qt.Key_F3), self, QtCore.SLOT(self.acceptNext))
        # self.setShortcutEnabled(shortcut.id(),True)
        # findNext_ = QtWidgets.QAction('&FindNext', self)
        # findNext_.setShortcut(QtGui.QKeySequence(QtCore.Qt.Key_F3))
        # findNext_.triggered.connect(self.acceptNext)

        find_ = QtWidgets.QAction('&Find', self)
        find_.setShortcut(self.tr("Enter"))
        find_.triggered.connect(self.accept)

        QtCore.QMetaObject.connectSlotsByName(self)
        self.setTabOrder(self.lineEdit_search, self.findnext_Btn)
        self.setTabOrder(self.findnext_Btn, self.buttonBox)
    # def exec(self):
    #     return 1
项目:notepad    作者:lfsando    | 项目源码 | 文件源码
def __init__(self, window_width=1000, window_height=950):
        super().__init__()

        # Initialize Plain Text Widget

        self.text_widget = QtWidgets.QPlainTextEdit()

        # Default Mode to Insertion

        self.insert = True

        # EventFilter FocusOut

        self._filter = Filter()

        # Setup Shortcuts

        self.shift_tab = QtWidgets.QShortcut(QtGui.QKeySequence('Shift+Tab'), self)
        #self.shift_tab.activated.setFocus()

        # Default start up File

        self.file_name = 'Untitled.txt'
        self.file_path = ['/', '']
        self.file_type = self.file_name.split('.')[-1]
        self.syntax = highlighter.PythonHighlighter(self.text_widget.document())
        self.assign_syntax_def()

        # Initialize Menus

        self.menu_bar = self.menuBar()
        self.file_menu()
        self.edit_menu()
        self.format_menu()
        self.preferences_menu()
        self.finder_toolbar()

        # Set Default Pallete

        self.default_visual()

        # Initialize UI Related Properties

        self.notepad_ui()

        self.setCentralWidget(self.text_widget)
        self.setWindowIcon(QtGui.QIcon('assets/icons/notepad.png'))
        self.resize(window_width, window_height)

        # Center the main window to the screen
        self.center()
        self.show()
项目:qt_style_sheet_inspector    作者:ESSS    | 项目源码 | 文件源码
def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.tape = []
        self.tape_pos = -1

        self.style_sheet = None

        self.search_bar = QLineEdit(self)
        self.search_bar.textChanged.connect(self.onSearchTextChanged)

        self.style_text_edit = QTextEdit(self)
        self.style_text_edit.textChanged.connect(self.onStyleTextChanged)
        # To prevent messing with contents when pasted from an IDE, for
        # instance.
        self.style_text_edit.setAcceptRichText(False)

        self.apply_button = QPushButton('Apply', self)
        self.apply_button.clicked.connect(self.onApplyButton)

        layout = QVBoxLayout(self)
        layout.addWidget(self.search_bar)
        layout.addWidget(self.style_text_edit)
        layout.addWidget(self.apply_button)
        self.setLayout(layout)

        next_hit_shortcut = QShortcut(QKeySequence(Qt.Key_F3), self)
        next_hit_shortcut.activated.connect(self.onNextSearchHit)

        search_shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_F), self)
        search_shortcut.activated.connect(self.onFocusSearchBar)

        apply_shortcut = QShortcut(QKeySequence(Qt.CTRL + Qt.Key_S), self)
        apply_shortcut.activated.connect(self.applyStyleSheet)

        undo_shortcut = QShortcut(
            QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_Z), self)
        undo_shortcut.activated.connect(self.onUndo)

        redo_shortcut = QShortcut(
            QKeySequence(Qt.CTRL + Qt.ALT + Qt.Key_Y), self)
        redo_shortcut.activated.connect(self.onRedo)

        help_shortcut = QShortcut(
            QKeySequence(Qt.Key_F1), self)
        help_shortcut.activated.connect(self.onHelp)

        self.loadStyleSheet()
项目:mindfulness-at-the-computer    作者:SunyataZero    | 项目源码 | 文件源码
def __init__(self):
        super().__init__()
        vbox = QtWidgets.QVBoxLayout()
        self.setLayout(vbox)
        # self.setMinimumWidth(180)

        self.updating_gui_bool = False

        self.list_widget = QtWidgets.QListWidget()
        # self.list_widget.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        vbox.addWidget(self.list_widget)
        self.list_widget.itemSelectionChanged.connect(self.on_selection_changed)

        hbox = QtWidgets.QHBoxLayout()
        vbox.addLayout(hbox)
        self.add_to_list_qle = QtWidgets.QLineEdit()
        hbox.addWidget(self.add_to_list_qle)
        self.add_to_list_qle.setPlaceholderText("New item")
        QtWidgets.QShortcut(
            QtGui.QKeySequence(QtCore.Qt.Key_Return),
            self.add_to_list_qle,
            member=self.add_new_phrase_button_clicked,
            context=QtCore.Qt.WidgetShortcut
        )
        self.add_new_phrase_qpb = QtWidgets.QPushButton("Add")
        self.add_new_phrase_qpb.clicked.connect(self.add_new_phrase_button_clicked)
        hbox.addWidget(self.add_new_phrase_qpb)

        hbox = QtWidgets.QHBoxLayout()
        vbox.addLayout(hbox)

        self.edit_texts_qpb = QtWidgets.QPushButton()
        hbox.addWidget(self.edit_texts_qpb)
        self.edit_texts_qpb.setIcon(QtGui.QIcon(mc.mc_global.get_icon_path("pencil-2x.png")))
        self.edit_texts_qpb.clicked.connect(self.on_edit_texts_clicked)
        self.move_to_top_qpb = QtWidgets.QPushButton()
        hbox.addWidget(self.move_to_top_qpb)
        self.move_to_top_qpb.setIcon(QtGui.QIcon(mc.mc_global.get_icon_path("data-transfer-upload-2x.png")))
        self.move_to_top_qpb.clicked.connect(self.on_move_to_top_clicked)
        self.move_up_qpb = QtWidgets.QPushButton()
        hbox.addWidget(self.move_up_qpb)
        self.move_up_qpb.setIcon(QtGui.QIcon(mc.mc_global.get_icon_path("arrow-top-2x.png")))
        self.move_up_qpb.clicked.connect(self.on_move_up_clicked)
        self.move_down_qpb = QtWidgets.QPushButton()
        hbox.addWidget(self.move_down_qpb)
        self.move_down_qpb.setIcon(QtGui.QIcon(mc.mc_global.get_icon_path("arrow-bottom-2x.png")))
        self.move_down_qpb.clicked.connect(self.on_move_down_clicked)

        hbox.addStretch(1)

        self.delete_phrase_qpb = QtWidgets.QPushButton()
        hbox.addWidget(self.delete_phrase_qpb)
        self.delete_phrase_qpb.setIcon(QtGui.QIcon(mc.mc_global.get_icon_path("trash-2x.png")))
        self.delete_phrase_qpb.clicked.connect(self.on_delete_clicked)

        self.update_gui()

        self.list_widget.setCurrentRow(0)  # -the first row
项目:bubblesub    作者:rr-    | 项目源码 | 文件源码
def _setup_hotkeys(self, action_map):
        shortcuts = {}

        def resolve_ambiguity(keys):
            widget = QtWidgets.QApplication.focusWidget()
            while widget:
                if widget == self.audio:
                    shortcuts[keys].activated.emit()
                widget = widget.parent()

        for context, items in self._api.opt.hotkeys.items():
            for item in items:
                keys, cmd_name, *cmd_args = item

                action = action_map.get((cmd_name, *cmd_args))
                if action and context == 'global':
                    # add shortcut hint text to the buttons in the menu
                    action.setShortcut(QtGui.QKeySequence(keys))
                    # prevent the action from triggering any signal on pressing
                    # its shortcut. (the action is parent of the main window,
                    # and the main window widget can never have focus by
                    # itself.)
                    # basically, all hotkey triggers are to be handled by the
                    # QShortcut below.
                    action.setShortcutContext(QtCore.Qt.WidgetShortcut)

                shortcut = QtWidgets.QShortcut(QtGui.QKeySequence(keys), self)
                shortcuts[keys] = shortcut

                shortcut.setContext(QtCore.Qt.WidgetWithChildrenShortcut)
                shortcut.activated.connect(functools.partial(
                    self._api.cmd.run,
                    self._api.cmd.get(cmd_name, cmd_args)))
                if context == 'audio':
                    shortcut.setParent(self.audio)
                elif context != 'global':
                    raise RuntimeError('Invalid shortcut context')

                # when the user focuses some widget X or its child, and presses
                # a hotkey that's defined both for widget X and for the window,
                # qt doesn't know whether the user meant to use global hotkey
                # or the widget X hotkey since the focused widget is a
                # descendant of both the widget X and the main window.
                #
                # in case a shortcut is ambiguous, qt invokes the ambiguous
                # signals in turns each time user presses given shortcut.
                if context == 'global':
                    # since ambiguous keypress happens only if user has
                    # actually focused an ambiguous widget X, in case when it
                    # is the main window that receives ambiguous trigger, the
                    # main window must pass the event to the widget X.
                    shortcut.activatedAmbiguously.connect(
                        functools.partial(resolve_ambiguity, keys))
                else:
                    # in case where it is the ambiguous widget X that receives
                    # ambiguous trigger, it can just carry on with execution.
                    shortcut.activatedAmbiguously.connect(
                        shortcut.activated.emit)
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def init_menu_file(self):
        # Action ??
        # ? ??
        self.act_new_file = QAction(self)
        self.act_new_file.setShortcut(QKeySequence('Ctrl+N'))
        self.act_new_file.triggered.connect(lambda : self.sig_new_file.emit())
        # self.act_new_file.triggered.emmit(self.slot_new)
        # ??
        self.act_open_file = QAction(self)
        self.act_open_file.setShortcut(QKeySequence('Ctrl+O'))
        self.act_open_file.triggered.connect(lambda : self.sig_open_file.emit())
        # ??
        self.act_save_file = QAction(self)
        self.act_save_file.setShortcut(QKeySequence('Ctrl+S'))
        self.act_save_file.triggered.connect(lambda : self.sig_save_file.emit())
        # ?? ???? ??
        self.act_save_as_file = QAction(self)
        self.act_save_as_file.triggered.connect(self.slot_save_as)
        # ??? ??
        self.act_page_setup = QAction(self)
        self.act_page_setup.setShortcut(QKeySequence('Ctrl+S'))
        self.act_page_setup.triggered.connect(lambda : self.sig_page_setup.emit())
        # ???
        self.act_print = QAction(self)
        self.act_print.setShortcut(QKeySequence('Ctrl+P'))
        self.act_print.triggered.connect(lambda : self.sig_print.emit())
        # ???
        self.act_quit = QAction(self.tr('Exit') + "(&X)", self)
        self.act_quit.triggered.connect(lambda : self.sig_exit.emit())
        # ??? ?? ? ?? ??
        # addAction? ??? ??

        self.menu_file = self.addMenu(self.tr("File") + "(&F)")
        self.menu_file.addAction(self.act_new_file)
        self.menu_file.addAction(self.act_open_file)
        self.menu_file.addAction(self.act_save_file)
        self.menu_file.addAction(self.act_save_as_file)
        self.menu_file.addSeparator()
        self.menu_file.addAction(self.act_page_setup)
        self.menu_file.addAction(self.act_print)
        self.menu_file.addSeparator()
        self.menu_file.addAction(self.act_quit)
项目:OpenTutorials_PyQt    作者:RavenKyu    | 项目源码 | 文件源码
def init_menu_edit(self):
        # ????
        self.act_undo = QAction(self)
        self.act_undo.setShortcut(QKeySequence('Ctrl+Z'))
        self.act_undo.triggered.connect(self.slot_undo)
        # ????
        self.act_cut = QAction(self)
        self.act_cut.setShortcut(QKeySequence('Ctrl+X'))
        self.act_cut.triggered.connect(self.slot_cut)
        # ??
        self.act_copy = QAction(self)
        self.act_copy.setShortcut(QKeySequence('Ctrl+C'))
        self.act_copy.triggered.connect(self.slot_copy)
        # ????
        self.act_paste = QAction(self)
        self.act_paste.setShortcut(QKeySequence('Ctrl+V'))
        self.act_paste.triggered.connect(self.slot_paste)
        # ??
        self.act_del = QAction(self)
        self.act_del.setShortcut(QKeySequence('Del'))
        self.act_del.triggered.connect(self.slot_del)
        # ??
        self.act_find = QAction(self)
        self.act_find.setShortcut(QKeySequence('Ctrl+F'))
        self.act_find.triggered.connect(self.slot_find)
        # ????
        self.act_find_next = QAction(self)
        self.act_find_next.setShortcut(QKeySequence('F3'))
        self.act_find_next.triggered.connect(self.slot_find_next)
        # ???
        self.act_replace = QAction(self)
        self.act_replace.setShortcut(QKeySequence('Ctrl+H'))
        self.act_replace.triggered.connect(self.slot_replace)
        # ??
        self.act_go_to = QAction(self)
        self.act_go_to.setShortcut(QKeySequence('Ctrl+G'))
        self.act_go_to.triggered.connect(self.slot_go_to)
        # ????
        self.act_select_all = QAction(self)
        self.act_select_all.setShortcut(QKeySequence('Ctrl+A'))
        self.act_select_all.triggered.connect(self.slot_select_all)
        # ????
        self.act_time_date = QAction(self)
        self.act_time_date.setShortcut(QKeySequence('F5'))
        self.act_time_date.triggered.connect(self.slot_time_date)

        self.menu_edit = self.addMenu(self.tr('Edit') + "(&E)")
        self.menu_edit.addAction(self.act_undo)
        self.menu_edit.addSeparator()
        self.menu_edit.addAction(self.act_cut)
        self.menu_edit.addAction(self.act_copy)
        self.menu_edit.addAction(self.act_paste)
        self.menu_edit.addAction(self.act_del)
        self.menu_edit.addSeparator()
        self.menu_edit.addAction(self.act_find)
        self.menu_edit.addAction(self.act_find_next)
        self.menu_edit.addAction(self.act_replace)
        self.menu_edit.addAction(self.act_go_to)
        self.menu_edit.addSeparator()
        self.menu_edit.addAction(self.act_select_all)
        self.menu_edit.addAction(self.act_time_date)