本文整理汇总了Python中PyQt5.Qt.QKeySequence类的典型用法代码示例。如果您正苦于以下问题:Python QKeySequence类的具体用法?Python QKeySequence怎么用?Python QKeySequence使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QKeySequence类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: key_press_event
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
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: get_match
def get_match(self, event_or_sequence, ignore=tuple()):
q = event_or_sequence
if isinstance(q, QKeyEvent):
q = QKeySequence(q.key() | (int(q.modifiers()) & ~Qt.KeypadModifier))
for key in self.order:
if key not in ignore:
for seq in self.get_sequences(key):
if seq.matches(q) == QKeySequence.ExactMatch:
return key
return None
示例4: custom_keys
def custom_keys(self):
if self.use_default.isChecked():
return None
ans = []
for which in (1, 2):
button = getattr(self, 'button%d'%which)
t = unicode(button.text())
if t == _('None'):
continue
ks = QKeySequence(t, QKeySequence.NativeText)
if not ks.isEmpty():
ans.append(ks)
return tuple(ans)
示例5: keysequence_from_event
def keysequence_from_event(ev): # {{{
k, mods = ev.key(), int(ev.modifiers())
if k 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
letter = QKeySequence(k).toString(QKeySequence.PortableText)
if mods & Qt.SHIFT and letter.lower() == letter.upper():
# Something like Shift+* or Shift+> we have to remove the shift,
# since it is included in keycode.
mods = mods & ~Qt.SHIFT
return QKeySequence(k | mods)
示例6: init_search_box_mixin
def init_search_box_mixin(self):
self.search.initialize('main_search_history', colorize=True,
help_text=_('Search (For Advanced Search click the button to the left)'))
self.search.cleared.connect(self.search_box_cleared)
# Queued so that search.current_text will be correct
self.search.changed.connect(self.search_box_changed,
type=Qt.QueuedConnection)
self.search.focus_to_library.connect(self.focus_to_library)
self.clear_button.clicked.connect(self.search.clear_clicked)
self.advanced_search_button.clicked[bool].connect(self.do_advanced_search)
self.search.clear()
self.search.setMaximumWidth(self.width()-150)
self.action_focus_search = QAction(self)
shortcuts = list(
map(lambda x:unicode(x.toString(QKeySequence.PortableText)),
QKeySequence.keyBindings(QKeySequence.Find)))
shortcuts += ['/', 'Alt+S']
self.keyboard.register_shortcut('start search', _('Start search'),
default_keys=shortcuts, action=self.action_focus_search)
self.action_focus_search.triggered.connect(self.focus_search_box)
self.addAction(self.action_focus_search)
self.search.setStatusTip(re.sub(r'<\w+>', ' ',
unicode(self.search.toolTip())))
self.advanced_search_button.setStatusTip(self.advanced_search_button.toolTip())
self.clear_button.setStatusTip(self.clear_button.toolTip())
self.set_highlight_only_button_icon()
self.highlight_only_button.clicked.connect(self.highlight_only_clicked)
tt = _('Enable or disable search highlighting.') + '<br><br>'
tt += config.help('highlight_search_matches')
self.highlight_only_button.setToolTip(tt)
示例7: setEditorData
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)
示例8: key_press_event
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)
示例9: finalize
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
示例10: quickmarks
def quickmarks():
global _quickmarks
if _quickmarks is None:
from .utils import parse_url
_quickmarks = {}
try:
with open(os.path.join(config_dir, 'quickmarks'), 'rb') as f:
for line in f.read().decode('utf-8').splitlines():
line = line.strip()
if line and not line.startswith('#'):
key, url = line.partition(' ')[::2]
key = QKeySequence.fromString(key)[0]
url = parse_url(url)
_quickmarks[key] = url
except FileNotFoundError:
pass
return _quickmarks
示例11: init_search_box_mixin
def init_search_box_mixin(self):
self.search.initialize(
"main_search_history",
colorize=True,
help_text=_("Search (For Advanced Search click the button to the left)"),
)
self.search.cleared.connect(self.search_box_cleared)
# Queued so that search.current_text will be correct
self.search.changed.connect(self.search_box_changed, type=Qt.QueuedConnection)
self.search.focus_to_library.connect(self.focus_to_library)
self.clear_button.clicked.connect(self.search.clear_clicked)
self.advanced_search_button.clicked[bool].connect(self.do_advanced_search)
self.search.clear()
self.search.setMaximumWidth(self.width() - 150)
self.action_focus_search = QAction(self)
shortcuts = list(
map(lambda x: unicode(x.toString(QKeySequence.PortableText)), QKeySequence.keyBindings(QKeySequence.Find))
)
shortcuts += ["/", "Alt+S"]
self.keyboard.register_shortcut(
"start search", _("Start search"), default_keys=shortcuts, action=self.action_focus_search
)
self.action_focus_search.triggered.connect(self.focus_search_box)
self.addAction(self.action_focus_search)
self.search.setStatusTip(re.sub(r"<\w+>", " ", unicode(self.search.toolTip())))
self.advanced_search_button.setStatusTip(self.advanced_search_button.toolTip())
self.clear_button.setStatusTip(self.clear_button.toolTip())
self.set_highlight_only_button_icon()
self.highlight_only_button.clicked.connect(self.highlight_only_clicked)
tt = _("Enable or disable search highlighting.") + "<br><br>"
tt += config.help("highlight_search_matches")
self.highlight_only_button.setToolTip(tt)
self.highlight_only_action = ac = QAction(self)
self.addAction(ac), ac.triggered.connect(self.highlight_only_clicked)
self.keyboard.register_shortcut(
"highlight search results", _("Highlight search results"), action=self.highlight_only_action
)
示例12: access_key
def access_key(k):
'Return shortcut text suitable for adding to a menu item'
if QKeySequence.keyBindings(k):
return '\t' + QKeySequence(k).toString(QKeySequence.NativeText)
return ''
示例13: get_keys
def get_keys(x):
if isinstance(x, str):
x = [x]
for k in x:
if isinstance(k, str):
yield QKeySequence.fromString(k)[0]