python类QKeySequence()的实例源码

submenus.py 文件源码 项目:Laborejo 作者: hilbrichtsoftware 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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)
submenus.py 文件源码 项目:Laborejo 作者: hilbrichtsoftware 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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)
submenus.py 文件源码 项目:Laborejo 作者: hilbrichtsoftware 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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)
submenus.py 文件源码 项目:Laborejo 作者: hilbrichtsoftware 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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)
main.py 文件源码 项目:PointlessMaker 作者: aboood40091 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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'])
ShortcutUtility.py 文件源码 项目:ezdmb 作者: angryrancor 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def setEscKey(window):
    window.shortcut = QShortcut(QKeySequence(Qt.Key_Escape), window)
    window.shortcut.activated.connect(lambda: QApplication.quit())
my_dialog.py 文件源码 项目:copa 作者: komradz 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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.py 文件源码 项目:notepad 作者: lfsando 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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()
_inspector.py 文件源码 项目:qt_style_sheet_inspector 作者: ESSS 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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()
breathing_phrase_list_wt.py 文件源码 项目:mindfulness-at-the-computer 作者: SunyataZero 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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
main_window.py 文件源码 项目:bubblesub 作者: rr- 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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)
notepad_menubar.py 文件源码 项目:OpenTutorials_PyQt 作者: RavenKyu 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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)
notepad_menubar.py 文件源码 项目:OpenTutorials_PyQt 作者: RavenKyu 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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)


问题


面经


文章

微信
公众号

扫码关注公众号