mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
More PyQt busywork
Qt::Modifier doesnt work in PyQt6 so move to Qt::KeyboardModifier instead
This commit is contained in:
parent
91d0542274
commit
4e727166f5
@ -785,8 +785,7 @@ class Quickview(QDialog, Ui_Quickview):
|
||||
self.book_not_in_view_error()
|
||||
return
|
||||
key = self.column_order[column]
|
||||
modifiers = int(QApplication.keyboardModifiers())
|
||||
if modifiers in (Qt.Modifier.CTRL, Qt.Modifier.SHIFT):
|
||||
if QApplication.keyboardModifiers() in (Qt.KeyboardModifier.ControlModifier, Qt.KeyboardModifier.ShiftModifier):
|
||||
self.edit_metadata(book_id)
|
||||
else:
|
||||
self.view.select_cell(self.db.data.id_to_index(book_id),
|
||||
|
@ -32,17 +32,17 @@ class NameConflict(ValueError):
|
||||
|
||||
|
||||
def keysequence_from_event(ev): # {{{
|
||||
k, mods = ev.key(), int(ev.modifiers())
|
||||
k, mods = ev.key(), ev.modifiers()
|
||||
if k in (
|
||||
0, Qt.Key.Key_unknown, Qt.Key.Key_Shift, Qt.Key.Key_Control, Qt.Key.Key_Alt,
|
||||
Qt.Key.Key_Meta, Qt.Key.Key_AltGr, Qt.Key.Key_CapsLock, Qt.Key.Key_NumLock,
|
||||
Qt.Key.Key_ScrollLock):
|
||||
return
|
||||
letter = QKeySequence(k).toString(QKeySequence.SequenceFormat.PortableText)
|
||||
if mods & Qt.Modifier.SHIFT and letter.lower() == letter.upper():
|
||||
if mods & Qt.KeyboardModifier.ShiftModifier 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.Modifier.SHIFT
|
||||
mods = mods & ~Qt.KeyboardModifier.ShiftModifier
|
||||
return QKeySequence(k | mods)
|
||||
# }}}
|
||||
|
||||
|
@ -51,7 +51,10 @@ class EncodeError(ValueError):
|
||||
def handle_enter_press(self, ev, special_action=None, has_edit_cell=True):
|
||||
if ev.key() in (Qt.Key.Key_Enter, Qt.Key.Key_Return):
|
||||
mods = ev.modifiers()
|
||||
if mods & Qt.Modifier.CTRL or mods & Qt.Modifier.ALT or mods & Qt.Modifier.SHIFT or mods & Qt.Modifier.META:
|
||||
if (
|
||||
mods & Qt.KeyboardModifier.ControlModifier or mods & Qt.KeyboardModifier.AltModifier or
|
||||
mods & Qt.KeyboardModifier.ShiftModifier or mods & Qt.KeyboardModifier.MetaModifier
|
||||
):
|
||||
return
|
||||
if self.state() != QAbstractItemView.State.EditingState and self.hasFocus() and self.currentIndex().isValid():
|
||||
from calibre.gui2.ui import get_gui
|
||||
@ -1151,7 +1154,8 @@ class GridView(QListView):
|
||||
return index
|
||||
|
||||
def selectionCommand(self, index, event):
|
||||
if event and event.type() == QEvent.Type.KeyPress and event.key() in (Qt.Key.Key_Home, Qt.Key.Key_End) and event.modifiers() & Qt.Modifier.CTRL:
|
||||
if event and event.type() == QEvent.Type.KeyPress and event.key() in (Qt.Key.Key_Home, Qt.Key.Key_End
|
||||
) and event.modifiers() & Qt.KeyboardModifier.ControlModifier:
|
||||
return QItemSelectionModel.SelectionFlag.ClearAndSelect | QItemSelectionModel.SelectionFlag.Rows
|
||||
return super().selectionCommand(index, event)
|
||||
|
||||
|
@ -1205,7 +1205,8 @@ class BooksView(QTableView): # {{{
|
||||
return index
|
||||
|
||||
def selectionCommand(self, index, event):
|
||||
if event and event.type() == QEvent.Type.KeyPress and event.key() in (Qt.Key.Key_Home, Qt.Key.Key_End) and event.modifiers() & Qt.Modifier.CTRL:
|
||||
if event and event.type() == QEvent.Type.KeyPress and event.key() in (
|
||||
Qt.Key.Key_Home, Qt.Key.Key_End) and event.modifiers() & Qt.KeyboardModifier.ControlModifier:
|
||||
return QItemSelectionModel.SelectionFlag.ClearAndSelect | QItemSelectionModel.SelectionFlag.Rows
|
||||
return super().selectionCommand(index, event)
|
||||
|
||||
|
@ -646,7 +646,7 @@ class CompareMany(QDialog):
|
||||
b.clicked.connect(self.reject_all_remaining)
|
||||
self.sb = b = bb.addButton(_('R&eject'), QDialogButtonBox.ButtonRole.ActionRole)
|
||||
ac = QAction(self)
|
||||
ac.setShortcut(QKeySequence(Qt.Modifier.ALT | Qt.Modifier.SHIFT | Qt.Key.Key_Right))
|
||||
ac.setShortcut(QKeySequence(Qt.KeyboardModifier.AltModifier | Qt.KeyboardModifier.ShiftModifier | Qt.Key.Key_Right))
|
||||
ac.triggered.connect(b.click)
|
||||
self.addAction(ac)
|
||||
b.setToolTip(_('Reject changes and move to next [{}]').format(ac.shortcut().toString(QKeySequence.SequenceFormat.NativeText)))
|
||||
@ -655,7 +655,7 @@ class CompareMany(QDialog):
|
||||
if reject_button_tooltip:
|
||||
b.setToolTip(reject_button_tooltip)
|
||||
self.next_action = ac = QAction(self)
|
||||
ac.setShortcut(QKeySequence(Qt.Modifier.ALT | Qt.Key.Key_Right))
|
||||
ac.setShortcut(QKeySequence(Qt.KeyboardModifier.AltModifier | Qt.Key.Key_Right))
|
||||
self.addAction(ac)
|
||||
if action_button is not None:
|
||||
self.acb = b = bb.addButton(action_button[0], QDialogButtonBox.ButtonRole.ActionRole)
|
||||
|
@ -487,8 +487,7 @@ class TagsView(QTreeView): # {{{
|
||||
set_to: if None, advance the state. Otherwise must be one of the values
|
||||
in TAG_SEARCH_STATES
|
||||
'''
|
||||
modifiers = int(QApplication.keyboardModifiers())
|
||||
exclusive = modifiers not in (Qt.Modifier.CTRL, Qt.Modifier.SHIFT)
|
||||
exclusive = QApplication.keyboardModifiers() not in (Qt.KeyboardModifier.ControlModifier, Qt.KeyboardModifier.ShiftModifier)
|
||||
if self._model.toggle(index, exclusive, set_to=set_to):
|
||||
# Reset the focus back to TB if it has it before the toggle
|
||||
# Must ask this question before starting the search because
|
||||
|
@ -641,16 +641,16 @@ class TreeWidget(QTreeWidget): # {{{
|
||||
item.setData(0, Qt.ItemDataRole.DisplayRole, fmt % (num + i))
|
||||
|
||||
def keyPressEvent(self, ev):
|
||||
if ev.key() == Qt.Key.Key_Left and ev.modifiers() & Qt.Modifier.CTRL:
|
||||
if ev.key() == Qt.Key.Key_Left and ev.modifiers() & Qt.KeyboardModifier.ControlModifier:
|
||||
self.move_left()
|
||||
ev.accept()
|
||||
elif ev.key() == Qt.Key.Key_Right and ev.modifiers() & Qt.Modifier.CTRL:
|
||||
elif ev.key() == Qt.Key.Key_Right and ev.modifiers() & Qt.KeyboardModifier.ControlModifier:
|
||||
self.move_right()
|
||||
ev.accept()
|
||||
elif ev.key() == Qt.Key.Key_Up and (ev.modifiers() & Qt.Modifier.CTRL or ev.modifiers() & Qt.Modifier.ALT):
|
||||
elif ev.key() == Qt.Key.Key_Up and (ev.modifiers() & Qt.KeyboardModifier.ControlModifier or ev.modifiers() & Qt.KeyboardModifier.AltModifier):
|
||||
self.move_up()
|
||||
ev.accept()
|
||||
elif ev.key() == Qt.Key.Key_Down and (ev.modifiers() & Qt.Modifier.CTRL or ev.modifiers() & Qt.Modifier.ALT):
|
||||
elif ev.key() == Qt.Key.Key_Down and (ev.modifiers() & Qt.KeyboardModifier.ControlModifier or ev.modifiers() & Qt.KeyboardModifier.AltModifier):
|
||||
self.move_down()
|
||||
ev.accept()
|
||||
elif ev.key() in (Qt.Key.Key_Delete, Qt.Key.Key_Backspace):
|
||||
@ -663,7 +663,7 @@ class TreeWidget(QTreeWidget): # {{{
|
||||
item = self.currentItem()
|
||||
|
||||
def key(k):
|
||||
sc = str(QKeySequence(k | Qt.Modifier.CTRL).toString(QKeySequence.SequenceFormat.NativeText))
|
||||
sc = str(QKeySequence(k | Qt.KeyboardModifier.ControlModifier).toString(QKeySequence.SequenceFormat.NativeText))
|
||||
return ' [%s]'%sc
|
||||
|
||||
if item is not None:
|
||||
|
@ -806,7 +806,7 @@ class CharSelect(Dialog):
|
||||
self.raise_()
|
||||
|
||||
def char_selected(self, c):
|
||||
if QApplication.keyboardModifiers() & Qt.Modifier.CTRL:
|
||||
if QApplication.keyboardModifiers() & Qt.KeyboardModifier.ControlModifier:
|
||||
self.hide()
|
||||
if self.parent() is None or self.parent().focusWidget() is None:
|
||||
QApplication.clipboard().setText(c)
|
||||
|
@ -180,11 +180,11 @@ class ChoosePopupWidget(QWidget):
|
||||
if key == Qt.Key.Key_Escape:
|
||||
self.abort(), ev.accept()
|
||||
return True
|
||||
if key == Qt.Key.Key_Tab and not ev.modifiers() & Qt.Modifier.CTRL:
|
||||
if key == Qt.Key.Key_Tab and not ev.modifiers() & Qt.KeyboardModifier.ControlModifier:
|
||||
self.choose_next_result(previous=ev.modifiers() & Qt.KeyboardModifier.ShiftModifier)
|
||||
ev.accept()
|
||||
return True
|
||||
if key == Qt.Key.Key_Backtab and not ev.modifiers() & Qt.Modifier.CTRL:
|
||||
if key == Qt.Key.Key_Backtab and not ev.modifiers() & Qt.KeyboardModifier.ControlModifier:
|
||||
self.choose_next_result(previous=ev.modifiers() & Qt.KeyboardModifier.ShiftModifier)
|
||||
return True
|
||||
if key in (Qt.Key.Key_Up, Qt.Key.Key_Down):
|
||||
|
@ -29,7 +29,7 @@ from polyglot.builtins import codepoint_to_chr, iteritems, itervalues
|
||||
|
||||
string_length = lambda x: strlen(str(x)) # Needed on narrow python builds, as subclasses of unicode dont work
|
||||
KEY = Qt.Key.Key_J
|
||||
MODIFIER = Qt.Modifier.META if ismacos else Qt.Modifier.CTRL
|
||||
MODIFIER = Qt.KeyboardModifier.MetaModifier if ismacos else Qt.KeyboardModifier.ControlModifier
|
||||
|
||||
SnipKey = namedtuple('SnipKey', 'trigger syntaxes')
|
||||
|
||||
|
@ -811,7 +811,7 @@ class TextEdit(PlainTextEdit):
|
||||
# For some reason using eventFilter for this does not work, so we
|
||||
# implement it here
|
||||
self.completion_popup.abort()
|
||||
if ev.modifiers() & Qt.Modifier.CTRL:
|
||||
if ev.modifiers() & Qt.KeyboardModifier.ControlModifier:
|
||||
url = self.link_for_position(ev.pos())
|
||||
if url is not None:
|
||||
ev.accept()
|
||||
|
Loading…
x
Reference in New Issue
Block a user