本文整理汇总了Python中PyQt4.QtGui.QKeySequence类的典型用法代码示例。如果您正苦于以下问题:Python QKeySequence类的具体用法?Python QKeySequence怎么用?Python QKeySequence使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QKeySequence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createButton
def createButton(self, button, propertyDict = dict()):
"""
Creates the buttons according to the user size definition
button: Button name
propertyDict: optional dict parameters that may contain other properties to button, such as color, tooltip and custom category
"""
pushButton = QtGui.QPushButton(button)
keys = propertyDict.keys()
styleSheet = ''
if 'buttonColor' in keys:
r, g, b, a = propertyDict['buttonColor'].split(',')
styleSheet += "background-color:rgba({0},{1},{2},{3});".format(r, g, b, a)
if 'buttonToolTip' in keys:
pushButton.setToolTip(propertyDict['buttonToolTip'])
if 'buttonShortcut' in keys:
keySequence = QKeySequence(propertyDict['buttonShortcut'])
pushButton.setText('{0} [{1}]'.format(button, keySequence.toString(format = QKeySequence.NativeText)))
pushButton.setShortcut(keySequence)
pushButton.clicked.connect(self.reclassify)
pushButton.toggled.connect(self.acquire)
if self.size == 0:
pushButton.setMinimumSize(100, 25)
styleSheet += 'font-size:12px;'
elif self.size == 1:
pushButton.setMinimumSize(100, 40)
styleSheet += 'font-size:20px;'
elif self.size == 2:
pushButton.setMinimumSize(100, 80)
styleSheet += 'font-size:30px;'
pushButton.setStyleSheet(styleSheet)
self.buttons.append(pushButton)
return pushButton
示例2: removeShortcut
def removeShortcut(action, key):
"""Removes matching QKeySequence from the list of the action."""
key = QKeySequence(key)
shortcuts = action.shortcuts()
for s in action.shortcuts():
if key.matches(s) or s.matches(key):
shortcuts.remove(s)
action.setShortcuts(shortcuts)
示例3: test_load_default_shortcuts
def test_load_default_shortcuts(self):
shorts_count = self.shortcuts_manager.result_widget.topLevelItemCount()
item = self.shortcuts_manager.result_widget.topLevelItem(0)
shortcut_keys = item.text(1)
# Expected data
expected_key = QKeySequence(Qt.CTRL + Qt.Key_N)
expected_key_str = expected_key.toString(QKeySequence.NativeText)
# Just one shortcut should be loaded
self.assertEqual(shorts_count, 1)
# The key should be the same as the expected
self.assertEqual(shortcut_keys, expected_key_str)
示例4: _add_global_shortcut_listener
def _add_global_shortcut_listener(self, keyseq):
# Create a shortcut for this new key sequence
# Note: We associate the shortcut with the ENTIRE WINDOW.
# We intercept the shortcut and decide which widget to direct it to.
# (We don't rely on Qt to do this for us.)
# Note: This class assumes that all widgets using shortcuts belong to the SAME main window.
assert keyseq not in self._global_shortcuts
keyseq = QKeySequence(keyseq)
keytext = str(keyseq.toString())
self._global_shortcuts[keytext] = QShortcut( QKeySequence(keyseq),
getMainWindow(),
member=partial(self._handle_shortcut_pressed, keytext),
context=Qt.ApplicationShortcut )
示例5: create_actions
def create_actions(self):
new_tab_action = QAction('&New Tab', self)
new_tab_action.setShortcuts(QKeySequence.AddTab)
self.connect(new_tab_action, SIGNAL('triggered()'), self.new_tab)
self.new_tab_action = new_tab_action
close_tab_action = QAction('&Close Tab', self)
close_tab_action.setShortcuts(QKeySequence.Close)
self.connect(close_tab_action, SIGNAL('triggered()'), self.close_tab)
self.close_tab_action = close_tab_action
open_action = QAction('&Open...', self)
open_action.setShortcuts(QKeySequence.Open)
self.connect(open_action, SIGNAL('triggered()'), self.open_file)
self.open_action = open_action
save_as_action = QAction('Save &As...', self)
save_as_action.setShortcuts(QKeySequence.SaveAs)
self.connect(save_as_action, SIGNAL('triggered()'), self.save_as_file)
self.save_as_action = save_as_action
exit_action = QAction('E&xit', self)
exit_action.setMenuRole(QAction.QuitRole)
self.connect(exit_action, SIGNAL('triggered()'),
self, SLOT('close()'))
self.exit_action = exit_action
next_tab_action = QAction('Next Tab', self)
bindings = QKeySequence.keyBindings(QKeySequence.NextChild)
if sys.platform == 'darwin':
bindings.append('Meta+PgDown')
bindings.append('Meta+Tab')
else:
bindings.append('Ctrl+PgDown')
next_tab_action.setShortcuts(bindings)
self.connect(next_tab_action, SIGNAL('triggered()'), self.focus_next_tab);
self.addAction(next_tab_action)
previous_tab_action = QAction('Previous Tab', self)
bindings = QKeySequence.keyBindings(QKeySequence.PreviousChild)
if sys.platform == 'darwin':
bindings.append('Meta+PgUp')
bindings.append('Meta+Shift+Tab')
else:
bindings.append('Ctrl+PgUp')
previous_tab_action.setShortcuts(bindings)
self.connect(previous_tab_action, SIGNAL('triggered()'), self.focus_previous_tab);
self.addAction(previous_tab_action)
示例6: filter
def filter(self, filterString: str, item: QTreeWidgetItem) -> bool:
visible = (filterString == "")
columnCount = item.columnCount()
for i in range(columnCount):
if not visible:
break
text = item.text(i)
if HostOsInfo.isMacHost():
# accept e.g. Cmd+E in the filter. the text shows special fancy characters for Cmd
if i == columnCount - 1:
key = QKeySequence.fromString(text, QKeySequence.NativeText)
if not key.isEmpty():
text = key.toString(QKeySequence.PortableText)
text.replace("Ctrl", "Cmd")
text.replace("Meta", "Ctrl")
text.replace("Alt", "Opt")
if filterString.upper() in text.upper(): # case insensitive
visible = True
childCount = item.childCount()
if childCount > 0:
# force visibility if this item matches
leafFilterString = "" if visible else filterString
for i in range(childCount):
citem = item.child(i) # QTreeWidgetItem
if not filter(leafFilterString, citem):
visible = True
item.setHidden(not visible)
return not visible
示例7: importShortcut
def importShortcut(filename, widget, schemeWidget):
"""Loads shortcuts from a file"""
try:
d = ET.parse(filename)
root = d.getroot()
if root.tag != 'frescobaldi-shortcut':
raise ValueError(_("No shortcuts found."))
except Exception as e:
QMessageBox.critical(widget, app.caption(_("Error")),
_("Can't read from source:\n\n{url}\n\n{error}").format(
url=filename, error=e))
return
schemeWidget.scheme.blockSignals(True)
scheme = schemeWidget.addScheme(root.get('name'))
schemeWidget.scheme.blockSignals(False)
for col in root.findall('collection'):
for name in col.findall('name'):
shortcuts = [QKeySequence.fromString(shortcut.text) for shortcut in name.findall('shortcut')]
item = widget.item(col.attrib['name'], name.attrib['name'])
if item:
item.setShortcuts(shortcuts, scheme)
schemeWidget.disableDefault(False)
schemeWidget.currentChanged.emit()
schemeWidget.changed.emit()
示例8: validateAction
def validateAction(self, row, column):
if column != 1:
return
table = self.actionTable
item = table.item(row, column)
shortcutText = QKeySequence(item.text()).toString()
thisRow = table.row(item)
if not shortcutText.isEmpty():
for row in range(table.rowCount()):
if row == thisRow:
continue
other = table.item(row, 1)
if other.text() == shortcutText:
other.setText(item.oldShortcutText)
break
item.setText(shortcutText)
item.oldShortcutText = shortcutText
table.resizeColumnToContents(1)
示例9: startRecording
def startRecording(self):
self.setFocus(True) # because of QTBUG 17810
self.setDown(True)
self.setStyleSheet("text-align: left;")
self._isrecording = True
self._recseq = QKeySequence()
self._modifiers = int(QApplication.keyboardModifiers() & (Qt.SHIFT | Qt.CTRL | Qt.ALT | Qt.META))
self.grabKeyboard()
self.updateDisplay()
示例10: change_keyseq
def change_keyseq(self, group, name, old_keyseq, keyseq):
"""
Customize a shortcut's activating key sequence.
"""
if old_keyseq:
old_keyseq = QKeySequence(old_keyseq)
old_keytext = str(old_keyseq.toString())
self._keyseq_target_actions[old_keytext].remove( (group, name) )
try:
keyseq = QKeySequence(keyseq)
keytext = str(keyseq.toString())
target_name_set = self._keyseq_target_actions[keytext]
except KeyError:
target_name_set = self._keyseq_target_actions[keytext] = set()
self._add_global_shortcut_listener( keyseq )
target_name_set.add( (group, name) )
self._update_tooltip( group, name, keyseq )
示例11: shortcut
def shortcut(item):
"""Returns a suitable text for the keyboard shortcut of the given item.
Item may be a QAction, a QShortcut, a QKeySequence or a
QKeySequence.StandardKey.
The text is meant to be used in the help docs.
"""
if isinstance(item, QAction):
seq = item.shortcut()
elif isinstance(item, QShortcut):
seq = item.key()
elif isinstance(item, QKeySequence.StandardKey):
seq = QKeySequence(item)
else:
seq = item
return seq.toString(QKeySequence.NativeText) or _("(no key defined)")
示例12: eventFilter
def eventFilter( self, object, event ):
"""
Filters out key press events for the shortcut section for this edit.
:param object | <QObject>
event | <QEvent>
"""
if ( object != self.uiShortcutTXT ):
return False
if ( event.type() == event.KeyPress ):
seq = QKeySequence(event.key() + int(event.modifiers()))
self.uiShortcutTXT.setText( seq.toString() )
return True
elif ( event.type() == event.KeyRelease):
return True
return False
示例13: __init__
def __init__(self, parent=None):
super(KeySequenceButton, self).__init__(parent)
self.setIcon(icons.get("configure"))
self._modifierlessAllowed = False
self._seq = QKeySequence()
self._timer = QTimer()
self._timer.setSingleShot(True)
self._isrecording = False
self.clicked.connect(self.startRecording)
self._timer.timeout.connect(self.doneRecording)
示例14: keyPressEvent
def keyPressEvent(self, ev):
if not self._isrecording:
return super(KeySequenceButton, self).keyPressEvent(ev)
if ev.isAutoRepeat():
return
modifiers = int(ev.modifiers() & (Qt.SHIFT | Qt.CTRL | Qt.ALT | Qt.META))
ev.accept()
key = ev.key()
# check if key is a modifier or a character key without modifier (and if that is allowed)
if (
# don't append the key if the key is -1 (garbage) or a modifier ...
key not in (-1, Qt.Key_AltGr, Qt.Key_Shift, Qt.Key_Control, Qt.Key_Alt, Qt.Key_Meta, Qt.Key_Menu)
# or if this is the first key and without modifier and modifierless keys are not allowed
and (
self._modifierlessAllowed
or self._recseq.count() > 0
or modifiers & ~Qt.SHIFT
or not ev.text()
or (
modifiers & Qt.SHIFT
and key
in (
Qt.Key_Return,
Qt.Key_Space,
Qt.Key_Tab,
Qt.Key_Backtab,
Qt.Key_Backspace,
Qt.Key_Delete,
Qt.Key_Escape,
)
)
)
):
# change Shift+Backtab into Shift+Tab
if key == Qt.Key_Backtab and modifiers & Qt.SHIFT:
key = Qt.Key_Tab | modifiers
# remove the Shift modifier if it doesn't make sense
# elif (Qt.Key_Exclam <= key <= Qt.Key_At
# or Qt.Key_Z < key <= 0x0ff):
# key = key | (modifiers & ~Qt.SHIFT)
else:
key = key | modifiers
# append max. 4 keystrokes
if self._recseq.count() < 4:
l = list(self._recseq)
l.append(key)
self._recseq = QKeySequence(*l)
self._modifiers = modifiers
self.controlTimer()
self.updateDisplay()
示例15: test_save_shortcuts
def test_save_shortcuts(self):
data = []
def called():
data.append(True)
actions = gui.FakeActions()
setattr(actions, 'update_shortcuts', called)
self.patch(shortcut_manager.actions, 'Actions', lambda: actions)
self.shortcuts_manager.result_widget.clear()
key = QKeySequence(Qt.CTRL + Qt.SHIFT + Qt.Key_N)
key_str = key.toString(QKeySequence.NativeText)
tree_data = ["New File", key_str, "New-File"]
item = QTreeWidgetItem(self.shortcuts_manager.result_widget, tree_data)
item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
# Before save there is nothing in QSettings
self.assertEqual(self.settings.value("New-File", None), None)
# Save
self.shortcuts_manager.save()
# After save there is a value for New-File QSettings
self.assertEqual(self.settings.values["New-File"], key_str)
# After save check if NINJA call the update_shortcuts in actios.Actions
self.assertEqual(data, [True])