Exemplo n.º 1
0
 def key_press_event(self, ev, which=0):
     code = ev.key()
     if self.capture == 0 or code in (0, Qt.Key.Key_unknown,
                                      Qt.Key.Key_Shift, Qt.Key.Key_Control,
                                      Qt.Key.Key_Alt, Qt.Key.Key_Meta,
                                      Qt.Key.Key_AltGr, Qt.Key.Key_CapsLock,
                                      Qt.Key.Key_NumLock,
                                      Qt.Key.Key_ScrollLock):
         return QWidget.keyPressEvent(self, ev)
     sequence = QKeySequence(code
                             | (int(ev.modifiers())
                                & (~Qt.KeyboardModifier.KeypadModifier)))
     setattr(self, 'shortcut%d' % which, sequence)
     self.clear_button(which)
     self.capture = 0
     dup_desc = self.dup_check(sequence, self.key)
     if dup_desc is not None:
         error_dialog(self,
                      _('Already assigned'),
                      unicode_type(
                          sequence.toString(
                              QKeySequence.SequenceFormat.NativeText)) +
                      ' ' + _('already assigned to') + ' ' + dup_desc,
                      show=True)
         self.clear_clicked(which=which)
Exemplo n.º 2
0
 def keyPressEvent(self, ev):
     k = ev.key()
     if k == Qt.Key_Escape:
         c = self.callback
         if c is not None:
             c(None)
         self.close() if self.parent() is None else self.hide()
         ev.accept()
         return
     if k == Qt.Key_Tab:
         self.next_completion()
         ev.accept()
         return
     if k == Qt.Key_Backtab:
         self.next_completion(forward=False)
         ev.accept()
         return
     if k in (Qt.Key_Enter, Qt.Key_Return):
         c = self.callback
         self.close() if self.parent() is None else self.hide()
         if c is not None:
             c(self.edit.text())
         else:
             self.run_command.emit(self.edit.text())
     return QWidget.keyPressEvent(self, ev)
Exemplo n.º 3
0
 def key_press_event(self, ev, which=0):
     code = ev.key()
     if self.capture == 0 or code in (
         0,
         Qt.Key_unknown,
         Qt.Key_Shift,
         Qt.Key_Control,
         Qt.Key_Alt,
         Qt.Key_Meta,
         Qt.Key_AltGr,
         Qt.Key_CapsLock,
         Qt.Key_NumLock,
         Qt.Key_ScrollLock,
     ):
         return QWidget.keyPressEvent(self, ev)
     button = getattr(self, "button%d" % which)
     font = QFont()
     button.setFont(font)
     sequence = QKeySequence(code | (int(ev.modifiers()) & ~Qt.KeypadModifier))
     button.setText(sequence.toString(QKeySequence.NativeText))
     self.capture = 0
     setattr(self, "shortcut%d" % which, sequence)
     dup_desc = self.dup_check(sequence, self.key)
     if dup_desc is not None:
         error_dialog(
             self,
             _("Already assigned"),
             unicode(sequence.toString(QKeySequence.NativeText)) + " " + _("already assigned to") + " " + dup_desc,
             show=True,
         )
         self.clear_clicked(which=which)
Exemplo n.º 4
0
Arquivo: ask.py Projeto: alok/vise
 def keyPressEvent(self, ev):
     k = ev.key()
     if k == Qt.Key_Escape:
         c = self.callback
         if c is not None:
             c(None)
         self.close() if self.parent() is None else self.hide()
         ev.accept()
         return
     if k == Qt.Key_Tab:
         self.next_completion()
         ev.accept()
         return
     if k == Qt.Key_Backtab:
         self.next_completion(forward=False)
         ev.accept()
         return
     if k in (Qt.Key_Enter, Qt.Key_Return):
         c = self.callback
         self.close() if self.parent() is None else self.hide()
         if c is not None:
             c(self.edit.text())
         else:
             self.run_command.emit(self.edit.text())
     return QWidget.keyPressEvent(self, ev)
Exemplo n.º 5
0
 def key_press_event(self, ev, which=0):
     code = ev.key()
     if self.capture == 0 or code in (0, Qt.Key_unknown, Qt.Key_Shift,
                                      Qt.Key_Control, Qt.Key_Alt,
                                      Qt.Key_Meta, Qt.Key_AltGr,
                                      Qt.Key_CapsLock, Qt.Key_NumLock,
                                      Qt.Key_ScrollLock):
         return QWidget.keyPressEvent(self, ev)
     button = getattr(self, 'button%d' % which)
     button.setStyleSheet('QPushButton { font-weight: normal}')
     mods = int(ev.modifiers()) & ~Qt.KeypadModifier
     txt = unicode(ev.text())
     if txt and txt.lower() == txt.upper():
         # We have a symbol like ! or > etc. In this case the value of code
         # already includes Shift, so remove it
         mods &= ~Qt.ShiftModifier
     sequence = QKeySequence(code | mods)
     button.setText(sequence.toString(QKeySequence.NativeText))
     self.capture = 0
     dup_desc = self.dup_check(sequence)
     if dup_desc is not None:
         error_dialog(self,
                      _('Already assigned'),
                      unicode(sequence.toString(QKeySequence.NativeText)) +
                      ' ' + _('already assigned to') + ' ' + dup_desc,
                      show=True)
         self.clear_clicked(which=which)
Exemplo n.º 6
0
 def key_press_event(self, ev, which=0):
     code = ev.key()
     if self.capture == 0 or code in (0, Qt.Key_unknown,
             Qt.Key_Shift, Qt.Key_Control, Qt.Key_Alt, Qt.Key_Meta,
             Qt.Key_AltGr, Qt.Key_CapsLock, Qt.Key_NumLock, Qt.Key_ScrollLock):
         return QWidget.keyPressEvent(self, ev)
     button = getattr(self, 'button%d'%which)
     button.setStyleSheet('QPushButton { font-weight: normal}')
     mods = int(ev.modifiers()) & ~Qt.KeypadModifier
     # for some reason qt sometimes produces ascii control codes in text,
     # for example ctrl+shift+u will give text == '\x15' on linux
     txt = clean_ascii_chars(ev.text())
     if txt and txt.lower() == txt.upper():
         # We have a symbol like ! or > etc. In this case the value of code
         # already includes Shift, so remove it
         mods &= ~Qt.ShiftModifier
     sequence = QKeySequence(code|mods)
     button.setText(sequence.toString(QKeySequence.NativeText))
     self.capture = 0
     dup_desc = self.dup_check(sequence)
     if dup_desc is not None:
         error_dialog(self, _('Already assigned'),
                 unicode(sequence.toString(QKeySequence.NativeText)) + ' ' +
                 _('already assigned to') + ' ' + dup_desc, show=True)
         self.clear_clicked(which=which)
Exemplo n.º 7
0
 def keyPressEvent(self, ev):
     sc = get_shortcut_for(self, ev)
     if ev.key() == Qt.Key_Escape or sc == 'toggle_bookmarks':
         self.toggle_requested.emit()
         return
     if sc == 'new_bookmark':
         self.create_requested.emit()
         return
     return QWidget.keyPressEvent(self, ev)
Exemplo n.º 8
0
    def key_press_event(self, ev, which=0):
        if self.capture == 0:
            return QWidget.keyPressEvent(self, ev)
        sequence = keysequence_from_event(ev)
        if sequence is None:
            return QWidget.keyPressEvent(self, ev)
        ev.accept()

        button = getattr(self, 'button%d'%which)
        button.setStyleSheet('QPushButton { font-weight: normal}')
        button.setText(sequence.toString(QKeySequence.NativeText))
        self.capture = 0
        dup_desc = self.dup_check(sequence)
        if dup_desc is not None:
            error_dialog(self, _('Already assigned'),
                    unicode(sequence.toString(QKeySequence.NativeText)) + ' ' +
                    _('already assigned to') + ' ' + dup_desc, show=True)
            self.clear_clicked(which=which)
Exemplo n.º 9
0
    def key_press_event(self, ev, which=0):
        if self.capture == 0:
            return QWidget.keyPressEvent(self, ev)
        sequence = keysequence_from_event(ev)
        if sequence is None:
            return QWidget.keyPressEvent(self, ev)
        ev.accept()

        button = getattr(self, 'button%d'%which)
        button.setStyleSheet('QPushButton { font-weight: normal}')
        button.setText(sequence.toString(QKeySequence.NativeText))
        self.capture = 0
        dup_desc = self.dup_check(sequence)
        if dup_desc is not None:
            error_dialog(self, _('Already assigned'),
                    unicode(sequence.toString(QKeySequence.NativeText)) + ' ' +
                    _('already assigned to') + ' ' + dup_desc, show=True)
            self.clear_clicked(which=which)
Exemplo n.º 10
0
 def keyPressEvent(self, ev):
     k = ev.key()
     if k in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down) and self.selection_state.rect is not None and self.has_selection:
         ev.accept()
         delta = 10 if ev.modifiers() & Qt.ShiftModifier else 1
         x = y = 0
         if k in (Qt.Key_Left, Qt.Key_Right):
             x = delta * (-1 if k == Qt.Key_Left else 1)
         else:
             y = delta * (-1 if k == Qt.Key_Up else 1)
         self.move_selection_rect(x, y)
         self.update()
     else:
         return QWidget.keyPressEvent(self, ev)
Exemplo n.º 11
0
    def keyPressEvent(self, event):
        if not self.isStarted or self.curPiece.shape() == Tetrominoes.NoShape:
            QWidget.keyPressEvent(self, event)
            return

        key = event.key()
        if key == Qt.Key_P:
            self.pause()
            return
        if self.isPaused:
            return
        elif key == Qt.Key_Left:
            self.tryMove(self.curPiece, self.curX - 1, self.curY)
        elif key == Qt.Key_Right:
            self.tryMove(self.curPiece, self.curX + 1, self.curY)
        elif key == Qt.Key_Down or key == Qt.Key_Space:
            self.dropDown()
        elif key == Qt.Key_Up:
            self.tryMove(self.curPiece.rotatedLeft(), self.curX, self.curY)
        elif key == Qt.Key_D:
            self.oneLineDown()
        else:
            QWidget.keyPressEvent(self, event)
Exemplo n.º 12
0
 def keyPressEvent(self, ev):
     k = ev.key()
     if k in (Qt.Key_Left, Qt.Key_Right, Qt.Key_Up, Qt.Key_Down) and self.selection_state.rect is not None and self.has_selection:
         ev.accept()
         delta = 10 if ev.modifiers() & Qt.ShiftModifier else 1
         x = y = 0
         if k in (Qt.Key_Left, Qt.Key_Right):
             x = delta * (-1 if k == Qt.Key_Left else 1)
         else:
             y = delta * (-1 if k == Qt.Key_Up else 1)
         self.move_selection_rect(x, y)
         self.update()
     else:
         return QWidget.keyPressEvent(self, ev)
Exemplo n.º 13
0
    def keyPressEvent(self, event):
        if not self.isStarted or self.curPiece.shape() == Tetrominoes.NoShape:
            QWidget.keyPressEvent(self, event)
            return

        key = event.key()
        if key == Qt.Key_P:
            self.pause()
            return
        if self.isPaused:
            return
        elif key == Qt.Key_Left:
            self.tryMove(self.curPiece, self.curX - 1, self.curY)
        elif key == Qt.Key_Right:
            self.tryMove(self.curPiece, self.curX + 1, self.curY)
        elif key == Qt.Key_Down or key == Qt.Key_Space:
            self.dropDown()
        elif key == Qt.Key_Up:
            self.tryMove(self.curPiece.rotatedLeft(), self.curX, self.curY)
        elif key == Qt.Key_D:
            self.oneLineDown()
        else:
            QWidget.keyPressEvent(self, event)
Exemplo n.º 14
0
 def key_press_event(self, ev, which=0):
     code = ev.key()
     if self.capture == 0 or code in (0, Qt.Key_unknown,
             Qt.Key_Shift, Qt.Key_Control, Qt.Key_Alt, Qt.Key_Meta,
             Qt.Key_AltGr, Qt.Key_CapsLock, Qt.Key_NumLock, Qt.Key_ScrollLock):
         return QWidget.keyPressEvent(self, ev)
     sequence = QKeySequence(code|(int(ev.modifiers())&~Qt.KeypadModifier))
     setattr(self, 'shortcut%d'%which, sequence)
     self.clear_button(which)
     self.capture = 0
     dup_desc = self.dup_check(sequence, self.key)
     if dup_desc is not None:
         error_dialog(self, _('Already assigned'),
                 unicode_type(sequence.toString(QKeySequence.NativeText)) + ' ' +
                 _('already assigned to') + ' ' + dup_desc, show=True)
         self.clear_clicked(which=which)
Exemplo n.º 15
0
 def keyPressEvent(self, *args, **kwargs):
     """
     Overriding of parent's (Qt) method, that's why camelCase used.
     Ctrl+Enter executes query.
     """
     # check if Ctrl+Enter|Return pressed
     if (args[0].key() == QtCore.Qt.Key_Enter
             or args[0].key() == QtCore.Qt.Key_Return
         ) and args[0].modifiers() == QtCore.Qt.ControlModifier:
         # execute query
         self.execute_query()
     elif args[0].key() == QtCore.Qt.Key_Escape:
         self.pbClose.clicked.emit()
     else:
         # regular reaction
         return QWidget.keyPressEvent(self, *args, **kwargs)
Exemplo n.º 16
0
 def keyPressEvent(self, ev):
     if ev.key() == Qt.Key_Escape:
         self.hide_panel()
         ev.accept()
     else:
         return QWidget.keyPressEvent(self, ev)
Exemplo n.º 17
0
 def keyPressEvent(self, ev):
     if ev.key() == Qt.Key_Escape or get_shortcut_for(self, ev) == 'toggle_bookmarks':
         self.toggle_requested.emit()
         return
     return QWidget.keyPressEvent(self, ev)
Exemplo n.º 18
0
 def keyPressEvent(self, ev):
     if ev.key() == Qt.Key_Escape:
         self.hide_panel()
         ev.accept()
     else:
         return QWidget.keyPressEvent(self, ev)
Exemplo n.º 19
0
 def keyPressEvent(self, ev):
     if ev.key() == Qt.Key_Escape:
         self.hide_search_panel.emit()
         ev.accept()
         return
     return QWidget.keyPressEvent(self, ev)