本文整理汇总了Python中PyQt5.Qt.QKeySequence.toString方法的典型用法代码示例。如果您正苦于以下问题:Python QKeySequence.toString方法的具体用法?Python QKeySequence.toString怎么用?Python QKeySequence.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QKeySequence
的用法示例。
在下文中一共展示了QKeySequence.toString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: key_press_event
# 需要导入模块: from PyQt5.Qt import QKeySequence [as 别名]
# 或者: from PyQt5.Qt.QKeySequence import toString [as 别名]
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)
示例2: key_press_event
# 需要导入模块: from PyQt5.Qt import QKeySequence [as 别名]
# 或者: from PyQt5.Qt.QKeySequence import toString [as 别名]
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)
示例3: setEditorData
# 需要导入模块: from PyQt5.Qt import QKeySequence [as 别名]
# 或者: from PyQt5.Qt.QKeySequence import toString [as 别名]
def setEditorData(self, editor, index):
defs = index.data(DEFAULTS)
defs = _(" or ").join([unicode(x.toString(x.NativeText)) for x in defs])
editor.key = unicode(index.data(KEY))
editor.default_shortcuts.setText(_("&Default") + ": %s" % defs)
editor.default_shortcuts.setChecked(True)
editor.header.setText("<b>%s: %s</b>" % (_("Customize shortcuts for"), unicode(index.data(DESCRIPTION))))
custom = index.data(CUSTOM)
if custom:
editor.custom.setChecked(True)
for x in (0, 1):
button = getattr(editor, "button%d" % (x + 1))
if len(custom) > x:
seq = QKeySequence(custom[x])
button.setText(seq.toString(seq.NativeText))
setattr(editor, "shortcut%d" % (x + 1), seq)
示例4: key_press_event
# 需要导入模块: from PyQt5.Qt import QKeySequence [as 别名]
# 或者: from PyQt5.Qt.QKeySequence import toString [as 别名]
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)
示例5: finalize
# 需要导入模块: from PyQt5.Qt import QKeySequence [as 别名]
# 或者: from PyQt5.Qt.QKeySequence import toString [as 别名]
def finalize(shortcuts, custom_keys_map={}): # {{{
'''
Resolve conflicts and assign keys to every action in shortcuts, which must
be a OrderedDict. User specified mappings of unique names to keys (as a
list of strings) should be passed in in custom_keys_map. Return a mapping
of unique names to resolved keys. Also sets the set_to_default member
correctly for each shortcut.
'''
seen, keys_map = {}, {}
for unique_name, shortcut in shortcuts.iteritems():
ac = shortcut['action']
if ac is None or sip.isdeleted(ac):
if ac is not None and DEBUG:
prints('Shortcut %r has a deleted action' % unique_name)
continue
custom_keys = custom_keys_map.get(unique_name, None)
if custom_keys is None:
candidates = shortcut['default_keys']
shortcut['set_to_default'] = True
else:
candidates = custom_keys
shortcut['set_to_default'] = False
keys = []
for x in candidates:
ks = QKeySequence(x, QKeySequence.PortableText)
x = unicode(ks.toString(QKeySequence.PortableText))
if x in seen:
if DEBUG:
prints('Key %r for shortcut %s is already used by'
' %s, ignoring'%(x, shortcut['name'], seen[x]['name']))
keys_map[unique_name] = ()
continue
seen[x] = shortcut
keys.append(ks)
keys = tuple(keys)
keys_map[unique_name] = keys
ac.setShortcuts(list(keys))
return keys_map