More stupid PyQt enums

This commit is contained in:
Kovid Goyal 2020-12-20 12:12:49 +05:30
parent 7709deb8d5
commit 252431b903
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 13 additions and 13 deletions

View File

@ -379,7 +379,7 @@ if ismacos:
if self.clone_shortcuts: if self.clone_shortcuts:
sc = self.clone.shortcut() sc = self.clone.shortcut()
if sc and not sc.isEmpty(): if sc and not sc.isEmpty():
self.setText(self.text() + '\t' + sc.toString(sc.NativeText)) self.setText(self.text() + '\t' + sc.toString(QKeySequence.SequenceFormat.NativeText))
if self.clone.menu() is None: if self.clone.menu() is None:
if not self.is_top_level: if not self.is_top_level:
self.setMenu(None) self.setMenu(None)

View File

@ -303,7 +303,7 @@ class ConfigModel(SearchQueryParser, QAbstractItemModel):
if sc['persist_shortcut']: if sc['persist_shortcut']:
options_map[un] = options_map.get(un, {}) options_map[un] = options_map.get(un, {})
options_map[un]['persist_shortcut'] = sc['persist_shortcut'] options_map[un]['persist_shortcut'] = sc['persist_shortcut']
keys = [unicode_type(k.toString(k.PortableText)) for k in sc['keys']] keys = [unicode_type(k.toString(QKeySequence.SequenceFormat.PortableText)) for k in sc['keys']]
kmap[un] = keys kmap[un] = keys
with self.keyboard.config: with self.keyboard.config:
self.keyboard.config['map'] = kmap self.keyboard.config['map'] = kmap
@ -451,11 +451,11 @@ class Editor(QFrame): # {{{
self.default_keys = [QKeySequence(k, QKeySequence.SequenceFormat.PortableText) for k self.default_keys = [QKeySequence(k, QKeySequence.SequenceFormat.PortableText) for k
in shortcut['default_keys']] in shortcut['default_keys']]
self.current_keys = list(shortcut['keys']) self.current_keys = list(shortcut['keys'])
default = ', '.join([unicode_type(k.toString(k.NativeText)) for k in default = ', '.join([unicode_type(k.toString(QKeySequence.SequenceFormat.NativeText)) for k in
self.default_keys]) self.default_keys])
if not default: if not default:
default = _('None') default = _('None')
current = ', '.join([unicode_type(k.toString(k.NativeText)) for k in current = ', '.join([unicode_type(k.toString(QKeySequence.SequenceFormat.NativeText)) for k in
self.current_keys]) self.current_keys])
if not current: if not current:
current = _('None') current = _('None')
@ -469,7 +469,7 @@ class Editor(QFrame): # {{{
self.use_custom.setChecked(True) self.use_custom.setChecked(True)
for key, which in zip(self.current_keys, [1,2]): for key, which in zip(self.current_keys, [1,2]):
button = getattr(self, 'button%d'%which) button = getattr(self, 'button%d'%which)
button.setText(key.toString(key.NativeText)) button.setText(key.toString(QKeySequence.SequenceFormat.NativeText))
def custom_toggled(self, checked): def custom_toggled(self, checked):
for w in ('1', '2'): for w in ('1', '2'):
@ -559,7 +559,7 @@ class Delegate(QStyledItemDelegate): # {{{
elif data.is_shortcut: elif data.is_shortcut:
shortcut = data.data shortcut = data.data
# Shortcut # Shortcut
keys = [unicode_type(k.toString(k.NativeText)) for k in shortcut['keys']] keys = [unicode_type(k.toString(QKeySequence.SequenceFormat.NativeText)) for k in shortcut['keys']]
if not keys: if not keys:
keys = _('None') keys = _('None')
else: else:

View File

@ -7,7 +7,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
import sys, gc, weakref import sys, gc, weakref
from PyQt5.Qt import (QMainWindow, QTimer, QAction, QMenu, QMenuBar, QIcon, from PyQt5.Qt import (QMainWindow, QTimer, QAction, QMenu, QMenuBar, QIcon,
QObject) QObject, QKeySequence)
from calibre.utils.config import OptionParser from calibre.utils.config import OptionParser
from calibre.gui2 import error_dialog from calibre.gui2 import error_dialog
from calibre import prints, as_unicode, prepare_string_for_xml from calibre import prints, as_unicode, prepare_string_for_xml
@ -165,7 +165,7 @@ def clone_menu(menu):
ans.setSeparator(True) ans.setSeparator(True)
return ans return ans
sc = ac.shortcut() sc = ac.shortcut()
sc = '' if sc.isEmpty() else sc.toString(sc.NativeText) sc = '' if sc.isEmpty() else sc.toString(QKeySequence.SequenceFormat.NativeText)
text = ac.text() text = ac.text()
if '\t' not in text: if '\t' not in text:
text += '\t' + sc text += '\t' + sc

View File

@ -170,7 +170,7 @@ class Delegate(QStyledItemDelegate):
def setEditorData(self, editor, index): def setEditorData(self, editor, index):
defs = index.data(DEFAULTS) defs = index.data(DEFAULTS)
defs = _(' or ').join([unicode_type(x.toString(x.NativeText)) for x in defs]) defs = _(' or ').join([unicode_type(x.toString(QKeySequence.SequenceFormat.NativeText)) for x in defs])
editor.key = unicode_type(index.data(KEY)) editor.key = unicode_type(index.data(KEY))
editor.default_shortcuts.setText(_('&Default') + ': %s' % defs) editor.default_shortcuts.setText(_('&Default') + ': %s' % defs)
editor.default_shortcuts.setChecked(True) editor.default_shortcuts.setChecked(True)
@ -183,7 +183,7 @@ class Delegate(QStyledItemDelegate):
button = getattr(editor, 'button%d'%(x+1)) button = getattr(editor, 'button%d'%(x+1))
if len(custom) > x: if len(custom) > x:
seq = QKeySequence(custom[x]) seq = QKeySequence(custom[x])
button.setText(seq.toString(seq.NativeText)) button.setText(seq.toString(QKeySequence.SequenceFormat.NativeText))
setattr(editor, 'shortcut%d'%(x+1), seq) setattr(editor, 'shortcut%d'%(x+1), seq)
def setModelData(self, editor, model, index): def setModelData(self, editor, model, index):
@ -251,7 +251,7 @@ class Shortcuts(QAbstractListModel):
return self.descriptions[key] return self.descriptions[key]
def get_shortcuts(self, key): def get_shortcuts(self, key):
return [unicode_type(x.toString(x.NativeText)) for x in return [unicode_type(x.toString(QKeySequence.SequenceFormat.NativeText)) for x in
self.get_sequences(key)] self.get_sequences(key)]
def data(self, index, role): def data(self, index, role):

View File

@ -11,7 +11,7 @@ from PyQt5.Qt import (QIcon, QFont, QLabel, QListWidget, QAction, QEvent,
QListWidgetItem, QTextCharFormat, QApplication, QSyntaxHighlighter, QListWidgetItem, QTextCharFormat, QApplication, QSyntaxHighlighter,
QCursor, QColor, QWidget, QPixmap, QSplitterHandle, QToolButton, QCursor, QColor, QWidget, QPixmap, QSplitterHandle, QToolButton,
Qt, pyqtSignal, QRegExp, QSize, QSplitter, QPainter, QPageSize, QPrinter, Qt, pyqtSignal, QRegExp, QSize, QSplitter, QPainter, QPageSize, QPrinter,
QLineEdit, QComboBox, QPen, QGraphicsScene, QMenu, QStringListModel, QLineEdit, QComboBox, QPen, QGraphicsScene, QMenu, QStringListModel, QKeySequence,
QCompleter, QTimer, QRect, QGraphicsView, QPagedPaintDevice, QPalette) QCompleter, QTimer, QRect, QGraphicsView, QPagedPaintDevice, QPalette)
from calibre.constants import iswindows, ismacos from calibre.constants import iswindows, ismacos
@ -1009,7 +1009,7 @@ class LayoutButton(QToolButton):
def update_shortcut(self, action_toggle=None): def update_shortcut(self, action_toggle=None):
action_toggle = action_toggle or getattr(self, 'action_toggle', None) action_toggle = action_toggle or getattr(self, 'action_toggle', None)
if action_toggle: if action_toggle:
sc = ', '.join(sc.toString(sc.NativeText) sc = ', '.join(sc.toString(QKeySequence.SequenceFormat.NativeText)
for sc in action_toggle.shortcuts()) for sc in action_toggle.shortcuts())
self.shortcut = sc or '' self.shortcut = sc or ''
self.update_text() self.update_text()