コード例 #1
0
    def qtKey(self, event):
        '''
        Return the components of a Qt key event.

        Modifiers are handled separately.

        Return (keynum, text, toString, ch).

        keynum: event.key()
        ch:     g.u(chr(keynum)) or '' if there is an exception.
        toString:
            For special keys: made-up spelling that become part of the setting.
            For all others:   QtGui.QKeySequence(keynum).toString()
        text:   event.text()
        '''
        keynum = event.key()
        text = event.text()  # This is the unicode character!
        qt = QtCore.Qt
        d = {
            qt.Key_Alt:
            'Key_Alt',
            qt.Key_AltGr:
            'Key_AltGr',
            # On Windows, when the KeyDown event for this key is sent,
            # the Ctrl+Alt modifiers are also set.
            qt.Key_Control:
            'Key_Control',  # MacOS: Command key
            qt.Key_Meta:
            'Key_Meta',
            # MacOS: Control key, Alt-Key on Microsoft keyboard on MacOs.
            qt.Key_Shift:
            'Key_Shift',
            qt.Key_NumLock:
            'Num_Lock',
            # 868.
        }
        if d.get(keynum):
            if 0:  # Allow bare modifier key.
                toString = d.get(keynum)
            else:
                toString = ''
        else:
            toString = QtGui.QKeySequence(keynum).toString()
        # Fix bug 1244461: Numpad 'Enter' key does not work in minibuffer
        if toString == 'Enter':
            toString = 'Return'
        if toString == 'Esc':
            toString = 'Escape'
        try:
            ch1 = chr(keynum)
        except ValueError:
            ch1 = ''
        try:
            ch = g.u(ch1)
        except UnicodeError:
            ch = ch1
        text = g.u(text)
        toString = g.u(toString)
        return keynum, text, toString, ch
コード例 #2
0
    def qtKey(self, event):
        '''
        Return the components of a Qt key event.

        Modifiers are handled separately.

        Return keynum,text,toString,ch

        keynum: event.key()
        ch:     g.u(chr(keynum)) or '' if there is an exception.
        toString:
            For special keys: made-up spelling that become part of the setting.
            For all others:   QtGui.QKeySequence(keynum).toString()
        text:   event.text()
        '''
        trace = False and not g.unitTesting
        keynum = event.key()
        text = event.text() # This is the unicode text.
        qt = QtCore.Qt
        d = {
            qt.Key_Shift: 'Key_Shift',
            qt.Key_Control: 'Key_Control', # MacOS: Command key
            qt.Key_Meta: 'Key_Meta', # MacOS: Control key, Alt-Key on Microsoft keyboard on MacOs.
            qt.Key_Alt: 'Key_Alt',
            qt.Key_AltGr: 'Key_AltGr',
                # On Windows, when the KeyDown event for this key is sent,
                # the Ctrl+Alt modifiers are also set.
        }
        if d.get(keynum):
            toString = d.get(keynum)
        else:
            toString = QtGui.QKeySequence(keynum).toString()
        # Fix bug 1244461: Numpad 'Enter' key does not work in minibuffer
        if toString == 'Enter':
            toString = 'Return'
        try:
            ch1 = chr(keynum)
        except ValueError:
            ch1 = ''
        try:
            ch = g.u(ch1)
        except UnicodeError:
            ch = ch1
        text = g.u(text)
        toString = g.u(toString)
        if trace and self.keyIsActive:
            mods = '+'.join(self.qtMods(event))
            g.trace(
                'keynum %7x ch %3s toString %s %s' % (
                keynum, repr(ch), mods, repr(toString)))
        return keynum, text, toString, ch
コード例 #3
0
ファイル: qt_events.py プロジェクト: ATikhonov2/leo-editor
    def qtKey(self, event):
        """
        Return the components of a Qt key event.

        Modifiers are handled separately.

        Return (keynum, text, toString, ch).

        keynum: event.key()
        ch:     chr(keynum) or '' if there is an exception.
        toString:
            For special keys: made-up spelling that become part of the setting.
            For all others:   QtGui.QKeySequence(keynum).toString()
        text:   event.text()
        """
        text, toString, ch = '', '', ''  # Defaults.
        #
        # Leo 6.4: Test keynum's directly.
        #          The values are the same in Qt4, Qt5, Qt6.
        keynum = event.key()
        if keynum in (
                0x01000020,  # Key_Shift	
                0x01000021,  # Key_Control
                0x01000022,  # Key_Meta
                0x01000023,  # Key_Alt
                0x01001103,  # Key_AltGr	
                0x01000024,  # Key_CapsLock
        ):
            # Disallow bare modifiers.
            return keynum, text, toString, ch
        #
        # Compute toString and ch.
        text = event.text()  # This is the unicode character!
        toString = QtGui.QKeySequence(keynum).toString()
        #
        # #1244461: Numpad 'Enter' key does not work in minibuffer
        if toString == 'Enter':
            toString = 'Return'
        if toString == 'Esc':
            toString = 'Escape'
        try:
            ch = chr(keynum)
        except ValueError:
            pass
        return keynum, text, toString, ch