Python PyQt5.QtCore.Qt 模块,Key_S() 实例源码

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

项目:thegame    作者:afg984    | 项目源码 | 文件源码
def __init__(self):
        super().__init__()
        self.width = 5000
        self.height = 4000
        self.margin = 10

        self.keys = {
            Qt.Key_W: False,
            Qt.Key_A: False,
            Qt.Key_S: False,
            Qt.Key_D: False,
        }  # This will be modified by View, and be read by GuiClient
        self.mouseDown = False
        self.mousePos = QPoint()
        self.decaying = []
        self.setSceneRect(5, 5, self.width, self.height)
        self.polygons = ObjectTracker()
        self.heroes = ObjectTracker()
        self.bullets = ObjectTracker()
        self.experienceBar = ExperienceBar()
        self.addItem(self.experienceBar)
        self.scoreboard = Scoreboard()
        self.addItem(self.scoreboard)
项目:thegame    作者:afg984    | 项目源码 | 文件源码
def action(self, **kwds):
        x = y = 0
        if self.scene.keys[Qt.Key_W]:
            y -= 1
        if self.scene.keys[Qt.Key_A]:
            x -= 1
        if self.scene.keys[Qt.Key_S]:
            y += 1
        if self.scene.keys[Qt.Key_D]:
            x += 1
        if x or y:
            self.accelerate(math.atan2(y, x))
        mpos = self.scene.views()[0].mapToScene(self.scene.mousePos)
        self.shoot_at(
            mpos.x(), mpos.y(),
            rotate_only=not self.scene.mouseDown)
        try:
            while True:
                self.level_up(self.to_level_up.pop())
        except IndexError:
            pass
项目:pyree-old    作者:DrLuke    | 项目源码 | 文件源码
def keyPressEvent(self, QKeyEvent):
        if QKeyEvent.key() == Qt.Key_S and QKeyEvent.modifiers() == Qt.ControlModifier:
            self.saveProjectDialog()
        else:
            super(PyreeMainWindow, self).keyPressEvent(QKeyEvent)
项目:SiebenApp    作者:ahitrin    | 项目源码 | 文件源码
def keyPressEvent(self, event):
        key_handlers = {
            Qt.Key_1: self.select_number(1),
            Qt.Key_2: self.select_number(2),
            Qt.Key_3: self.select_number(3),
            Qt.Key_4: self.select_number(4),
            Qt.Key_5: self.select_number(5),
            Qt.Key_6: self.select_number(6),
            Qt.Key_7: self.select_number(7),
            Qt.Key_8: self.select_number(8),
            Qt.Key_9: self.select_number(9),
            Qt.Key_0: self.select_number(0),
            Qt.Key_A: self.start_edit(self.goals.add, 'Add new goal'),
            Qt.Key_C: self.with_refresh(self.goals.toggle_close),
            Qt.Key_D: self.with_refresh(self.goals.delete),
            Qt.Key_I: self.start_edit(self.goals.insert, 'Insert new goal'),
            Qt.Key_L: self.with_refresh(self.goals.toggle_link),
            Qt.Key_Q: self.quit_app.emit,
            Qt.Key_R: self.start_edit(self.goals.rename, 'Rename goal'),
            Qt.Key_S: self.with_refresh(self.goals.swap_goals),
            Qt.Key_V: self.toggle_view,
            Qt.Key_Z: self.toggle_zoom,
            Qt.Key_Escape: self.cancel_edit,
            Qt.Key_Space: self.with_refresh(self.goals.hold_select),
        }
        if event.key() in key_handlers:
            key_handlers[event.key()]()
        else:
            super().keyPressEvent(event)
项目:pyqt5    作者:yurisnm    | 项目源码 | 文件源码
def set_up_keyboard_keys(self):

        row_1 = [Qt.Key_Q, Qt.Key_W, Qt.Key_E, Qt.Key_R, Qt.Key_T, Qt.Key_Y,
                 Qt.Key_Y, Qt.Key_I, Qt.Key_O, Qt.Key_P, Qt.Key_Backspace]
        row_2 = [Qt.Key_A, Qt.Key_S, Qt.Key_D, Qt.Key_F, Qt.Key_G, Qt.Key_H,
                 Qt.Key_J, Qt.Key_K, Qt.Key_L, Qt.Key_Ccedilla, Qt.Key_Return]
        row_3 = [Qt.Key_Aring, Qt.Key_Z, Qt.Key_X, Qt.Key_C, Qt.Key_V,
                 Qt.Key_B, Qt.Key_N, Qt.Key_M, Qt.Key_Comma, Qt.Key_Period,
                 Qt.Key_Question, Qt.Key_Aring]
        row_4 = [Qt.Key_Aring, Qt.Key_Space,
                 Qt.Key_Left, Qt.Key_Right, Qt.Key_Aring]
        self.keyboard_keys = [row_1, row_2, row_3, row_4]
项目:SunFounder_PiCar-V    作者:sunfounder    | 项目源码 | 文件源码
def keyPressEvent(self, event):
        """Keyboard press event

        Effective key: W, A, S, D, ?,  ?,  ?,  ?
        Press a key on keyboard, the function will get an event, if the condition is met, call the function 
        run_action(). 

        Args:
            event, this argument will get when an event of keyboard pressed occured

        """
        key_press = event.key()

        # don't need autorepeat, while haven't released, just run once
        if not event.isAutoRepeat():
            if key_press == Qt.Key_Up:          # up 
                run_action('camup')
            elif key_press == Qt.Key_Right:     # right
                run_action('camright')
            elif key_press == Qt.Key_Down:      # down
                run_action('camdown')
            elif key_press == Qt.Key_Left:      # left
                run_action('camleft')
            elif key_press == Qt.Key_W:         # W
                run_action('forward')
            elif key_press == Qt.Key_A:         # A
                run_action('fwleft')
            elif key_press == Qt.Key_S:         # S
                run_action('backward')
            elif key_press == Qt.Key_D:         # D
                run_action('fwright')
项目:SunFounder_PiCar-V    作者:sunfounder    | 项目源码 | 文件源码
def keyReleaseEvent(self, event):
        """Keyboard released event

        Effective key: W,A,S,D, ?,  ?,  ?,  ?
        Release a key on keyboard, the function will get an event, if the condition is met, call the function 
        run_action(). 

        Args:
            event, this argument will get when an event of keyboard release occured

        """
        # don't need autorepeat, while haven't pressed, just run once
        key_release = event.key()
        if not event.isAutoRepeat():
            if key_release == Qt.Key_Up:        # up
                run_action('camready')
            elif key_release == Qt.Key_Right:   # right
                run_action('camready')
            elif key_release == Qt.Key_Down:    # down
                run_action('camready')
            elif key_release == Qt.Key_Left:    # left
                run_action('camready')
            elif key_release == Qt.Key_W:       # W
                run_action('stop')
            elif key_release == Qt.Key_A:       # A
                run_action('fwstraight')
            elif key_release == Qt.Key_S:       # S
                run_action('stop')
            elif key_release == Qt.Key_D:       # D
                run_action('fwstraight')
项目: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()
项目:SunFounder_PiCar-V    作者:sunfounder    | 项目源码 | 文件源码
def keyPressEvent(self, event):
        """Keyboard press event

        Press a key on keyboard, the function will get an event, if the condition is met, call the function 
        run_action(). 
        In camera calibration mode, Effective key: W,A,S,D, ?,  ?,  ?,  ?, ESC
        In front wheel calibration mode, Effective key: A, D, ?,  ?, ESC
        In back wheel calibration mode, Effective key: A, D, ?,  ?, ESC

        Args:
            event, this argument will get when an event of keyboard pressed occured

        """
        key_press = event.key()

        if key_press in (Qt.Key_Up, Qt.Key_W):      # UP
            if   self.calibration_status == 1:
                cali_action('camcaliup')
            elif self.calibration_status == 2:
                pass
            elif self.calibration_status == 3:
                pass
        elif key_press in (Qt.Key_Right, Qt.Key_D): # RIGHT
            if   self.calibration_status == 1:
                cali_action('camcaliright')
            elif self.calibration_status == 2:
                cali_action('fwcaliright')
            elif self.calibration_status == 3:
                cali_action('bwcaliright')
        elif key_press in (Qt.Key_Down, Qt.Key_S):  # DOWN
            if   self.calibration_status == 1:
                cali_action('camcalidown')
            elif self.calibration_status == 2:
                pass
            elif self.calibration_status == 3:
                pass
        elif key_press in (Qt.Key_Left, Qt.Key_A):  # LEFT
            if   self.calibration_status == 1:
                cali_action('camcalileft')
            elif self.calibration_status == 2:
                cali_action('fwcalileft')
            elif self.calibration_status == 3:
                cali_action('bwcalileft')
                cali_action('forward')
        elif key_press == Qt.Key_Escape:            # ESC
            run_action('stop')
            self.close()
项目:server    作者:happypandax    | 项目源码 | 文件源码
def create_ui(self):
        w = QWidget(self)
        settings_group = QGroupBox(t("", default="Configuration"), w)
        settings_group_l = QVBoxLayout(settings_group)
        settings = SettingsTabs()
        settings_group_l.addWidget(settings)

        buttons = QGroupBox(w)
        self.server_btn = QPushButton(self.start_ico, t("", default="Start server"))
        self.server_btn.clicked.connect(self.toggle_server)
        self.server_btn.setShortcut(Qt.CTRL | Qt.Key_S)

        #self.webclient_btn = QPushButton(self.start_ico, t("", default="Start webclient"))
        # self.webclient_btn.clicked.connect(self.toggle_client)
        # self.webclient_btn.setShortcut(Qt.CTRL|Qt.Key_W)

        open_config_btn = QPushButton(qta.icon("fa.cogs"), t("", default="Open configuration"))
        open_config_btn.clicked.connect(self.open_cfg)
        open_config_btn.setShortcut(Qt.CTRL | Qt.Key_C)

        convert_btn = QPushButton(qta.icon("fa.refresh"), t("", default="HP to HPX"))
        convert_btn.clicked.connect(self.convert_hp)

        for b in (self.server_btn, open_config_btn, convert_btn):
            b.setFixedHeight(40)
        button_layout = QHBoxLayout(buttons)
        button_layout.addWidget(self.server_btn)
        # button_layout.addWidget(self.webclient_btn)
        button_layout.addWidget(open_config_btn)
        button_layout.addWidget(convert_btn)

        infos = QGroupBox(t("", default="Info"))
        info_layout = QHBoxLayout(infos)
        version_layout = QFormLayout()
        version_layout.addRow(t("", default="Server version") +
                              ':', QLabel(".".join(str(x) for x in constants.version)))
        version_layout.addRow(t("", default="Webclient version") +
                              ':', QLabel(".".join(str(x) for x in constants.version_web)))
        version_layout.addRow(t("", default="Database version") +
                              ':', QLabel(".".join(str(x) for x in constants.version_db)))

        connect_layout = QFormLayout()
        connect_layout.addRow(t("", default="Server") + '@', QLabel(config.host.value + ':' + str(config.port.value)))
        connect_layout.addRow(t("", default="Webclient") + '@',
                              QLabel(config.host_web.value + ':' + str(config.port_web.value)))
        info_layout.addLayout(connect_layout)
        info_layout.addLayout(version_layout)

        main_layout = QVBoxLayout(w)
        main_layout.addWidget(settings_group)
        main_layout.addWidget(infos)
        main_layout.addWidget(buttons)
        self.setCentralWidget(w)

        self.tray.setIcon(QIcon(os.path.join(constants.dir_static, "favicon.ico")))
        self.tray.activated.connect(self.tray_activated)
        tray_menu = QMenu()
        tray_menu.addAction(t("", default="Show"), lambda: self.show())
        tray_menu.addSeparator()
        tray_menu.addAction(t("", default="Quit"), lambda: self.real_close())
        self.tray.setContextMenu(tray_menu)