mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 02:34:06 -04:00
In Preferences: add Ctrl-Up and Ctrl-Down as keyboard shortcuts for lists with movement buttons.
This commit is contained in:
parent
6a66b99ed0
commit
f58052b3bc
@ -9,7 +9,7 @@ import textwrap
|
||||
|
||||
from qt.core import (QWidget, pyqtSignal, QCheckBox, QAbstractSpinBox, QApplication,
|
||||
QLineEdit, QComboBox, Qt, QIcon, QDialog, QVBoxLayout,
|
||||
QDialogButtonBox)
|
||||
QDialogButtonBox, QListView, QEvent, QListWidget, QTableWidget)
|
||||
|
||||
from calibre.customize.ui import preferences_plugins
|
||||
from calibre.utils.config import ConfigProxy
|
||||
@ -401,6 +401,58 @@ def show_config_widget(category, name, gui=None, show_restart_msg=False,
|
||||
gui.shutdown()
|
||||
return rr
|
||||
|
||||
|
||||
class ListViewWithMoveByKeyPress(QListView):
|
||||
|
||||
def set_movement_functions(self, up_function, down_function):
|
||||
self.up_function = up_function
|
||||
self.down_function = down_function
|
||||
|
||||
def event(self, event):
|
||||
if (event.type() == QEvent.KeyPress and
|
||||
QApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier):
|
||||
if event.key() == Qt.Key.Key_Up:
|
||||
self.up_function()
|
||||
elif event.key() == Qt.Key.Key_Down:
|
||||
self.down_function()
|
||||
return True
|
||||
return QListView.event(self, event)
|
||||
|
||||
|
||||
class ListWidgetWithMoveByKeyPress(QListWidget):
|
||||
|
||||
def set_movement_functions(self, up_function, down_function):
|
||||
self.up_function = up_function
|
||||
self.down_function = down_function
|
||||
|
||||
def event(self, event):
|
||||
if (event.type() == QEvent.KeyPress and
|
||||
QApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier):
|
||||
if event.key() == Qt.Key.Key_Up:
|
||||
self.up_function()
|
||||
elif event.key() == Qt.Key.Key_Down:
|
||||
self.down_function()
|
||||
return True
|
||||
return QListWidget.event(self, event)
|
||||
|
||||
|
||||
class TableWidgetWithMoveByKeyPress(QTableWidget):
|
||||
|
||||
def set_movement_functions(self, up_function, down_function):
|
||||
self.up_function = up_function
|
||||
self.down_function = down_function
|
||||
|
||||
def event(self, event):
|
||||
if (event.type() == QEvent.KeyPress and
|
||||
QApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier):
|
||||
if event.key() == Qt.Key.Key_Up:
|
||||
self.up_function()
|
||||
elif event.key() == Qt.Key.Key_Down:
|
||||
self.down_function()
|
||||
return True
|
||||
return QTableWidget.event(self, event)
|
||||
|
||||
|
||||
# Testing {{{
|
||||
|
||||
|
||||
|
@ -69,6 +69,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
|
||||
self.input_up_button.clicked.connect(self.up_input)
|
||||
self.input_down_button.clicked.connect(self.down_input)
|
||||
self.opt_input_order.set_movement_functions(self.up_input, self.down_input)
|
||||
self.opt_input_order.dropEvent = partial(input_order_drop_event, self)
|
||||
for signal in ('Activated', 'Changed', 'DoubleClicked', 'Clicked'):
|
||||
signal = getattr(self.opt_internally_viewed_formats, 'item'+signal)
|
||||
|
@ -90,7 +90,7 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_10">
|
||||
<item>
|
||||
<widget class="QListWidget" name="opt_input_order">
|
||||
<widget class="ListWidgetWithMoveByKeyPress" name="opt_input_order">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
@ -311,6 +311,13 @@ per library.</p></string>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ListWidgetWithMoveByKeyPress</class>
|
||||
<extends>QListWidget</extends>
|
||||
<header>calibre/gui2/preferences.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../../../resources/images.qrc"/>
|
||||
</resources>
|
||||
|
@ -26,6 +26,7 @@ from calibre.gui2 import (
|
||||
)
|
||||
from calibre.gui2.dialogs.template_dialog import TemplateDialog
|
||||
from calibre.gui2.metadata.single_download import RichTextDelegate
|
||||
from calibre.gui2.preferences import ListViewWithMoveByKeyPress
|
||||
from calibre.gui2.widgets2 import ColorButton, FlowLayout, Separator
|
||||
from calibre.library.coloring import (
|
||||
Rule, color_row_key, conditionable_columns, displayable_columns,
|
||||
@ -956,10 +957,10 @@ class RulesModel(QAbstractListModel): # {{{
|
||||
# }}}
|
||||
|
||||
|
||||
class RulesView(QListView): # {{{
|
||||
class RulesView(ListViewWithMoveByKeyPress): # {{{
|
||||
|
||||
def __init__(self, parent, enable_convert_buttons_function):
|
||||
QListView.__init__(self, parent)
|
||||
ListViewWithMoveByKeyPress.__init__(self, parent)
|
||||
self.enable_convert_buttons_function = enable_convert_buttons_function
|
||||
|
||||
def currentChanged(self, new, prev):
|
||||
@ -1016,6 +1017,8 @@ class EditRules(QWidget): # {{{
|
||||
b.setIcon(QIcon.ic('arrow-down.png'))
|
||||
b.setToolTip(_('Move the selected rule down'))
|
||||
b.clicked.connect(partial(self.move_rows, moving_up=False))
|
||||
self.rules_view.set_movement_functions(partial(self.move_rows, moving_up=True),
|
||||
partial(self.move_rows, moving_up=False))
|
||||
g.addWidget(b, 1, 1, 1, 1, Qt.AlignmentFlag.AlignBottom)
|
||||
|
||||
l.addLayout(g, l.rowCount(), 0, 1, 2)
|
||||
|
@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
|
||||
import copy, sys
|
||||
from contextlib import suppress
|
||||
|
||||
from qt.core import Qt, QTableWidgetItem, QIcon
|
||||
from qt.core import Qt, QTableWidgetItem, QIcon, QAbstractItemView
|
||||
|
||||
from calibre.gui2 import gprefs, Application
|
||||
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
|
||||
@ -34,6 +34,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
|
||||
self.column_up.clicked.connect(self.up_column)
|
||||
self.column_down.clicked.connect(self.down_column)
|
||||
self.opt_columns.setSelectionMode(QAbstractItemView.SingleSelection)
|
||||
self.opt_columns.set_movement_functions(self.up_column, self.down_column)
|
||||
self.del_custcol_button.clicked.connect(self.del_custcol)
|
||||
self.add_custcol_button.clicked.connect(self.add_custcol)
|
||||
self.add_col_button.clicked.connect(self.add_custcol)
|
||||
|
@ -25,7 +25,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QTableWidget" name="opt_columns">
|
||||
<widget class="TableWidgetWithMoveByKeyPress" name="opt_columns">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -203,6 +203,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>TableWidgetWithMoveByKeyPress</class>
|
||||
<extends>QTableWidget</extends>
|
||||
<header>calibre/gui2/preferences.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources>
|
||||
<include location="../../../../resources/images.qrc"/>
|
||||
</resources>
|
||||
|
@ -642,52 +642,46 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
self.current_font = self.initial_font = None
|
||||
self.change_font_button.clicked.connect(self.change_font)
|
||||
|
||||
self.display_model = DisplayedFields(self.gui.current_db,
|
||||
self.field_display_order)
|
||||
self.display_model = DisplayedFields(self.gui.current_db, self.field_display_order)
|
||||
self.display_model.dataChanged.connect(self.changed_signal)
|
||||
self.field_display_order.setModel(self.display_model)
|
||||
connect_lambda(self.df_up_button.clicked, self,
|
||||
lambda self: move_field_up(self.field_display_order, self.display_model))
|
||||
connect_lambda(self.df_down_button.clicked, self,
|
||||
lambda self: move_field_down(self.field_display_order, self.display_model))
|
||||
mu = partial(move_field_up, self.field_display_order, self.display_model)
|
||||
md = partial(move_field_down, self.field_display_order, self.display_model)
|
||||
self.df_up_button.clicked.connect(mu)
|
||||
self.df_down_button.clicked.connect(md)
|
||||
self.field_display_order.set_movement_functions(mu, md)
|
||||
|
||||
self.em_display_model = EMDisplayedFields(self.gui.current_db,
|
||||
self.em_display_order)
|
||||
self.em_display_model = EMDisplayedFields(self.gui.current_db, self.em_display_order)
|
||||
self.em_display_model.dataChanged.connect(self.changed_signal)
|
||||
self.em_display_order.setModel(self.em_display_model)
|
||||
connect_lambda(self.em_up_button.clicked, self,
|
||||
lambda self: move_field_up(self.em_display_order, self.em_display_model))
|
||||
connect_lambda(self.em_down_button.clicked, self,
|
||||
lambda self: move_field_down(self.em_display_order, self.em_display_model))
|
||||
self.em_export_layout_button.clicked.connect(partial(self.export_layout,
|
||||
model=self.em_display_model))
|
||||
self.em_import_layout_button.clicked.connect(partial(self.import_layout,
|
||||
model=self.em_display_model))
|
||||
self.em_reset_layout_button.clicked.connect(partial(self.reset_layout,
|
||||
model=self.em_display_model))
|
||||
mu = partial(move_field_up, self.em_display_order, self.em_display_model)
|
||||
md = partial(move_field_down, self.em_display_order, self.em_display_model)
|
||||
self.em_display_order.set_movement_functions(mu, md)
|
||||
self.em_up_button.clicked.connect(mu)
|
||||
self.em_down_button.clicked.connect(md)
|
||||
self.em_export_layout_button.clicked.connect(partial(self.export_layout, model=self.em_display_model))
|
||||
self.em_import_layout_button.clicked.connect(partial(self.import_layout, model=self.em_display_model))
|
||||
self.em_reset_layout_button.clicked.connect(partial(self.reset_layout, model=self.em_display_model))
|
||||
|
||||
self.qv_display_model = QVDisplayedFields(self.gui.current_db,
|
||||
self.qv_display_order)
|
||||
self.qv_display_model = QVDisplayedFields(self.gui.current_db, self.qv_display_order)
|
||||
self.qv_display_model.dataChanged.connect(self.changed_signal)
|
||||
self.qv_display_order.setModel(self.qv_display_model)
|
||||
connect_lambda(self.qv_up_button.clicked, self,
|
||||
lambda self: move_field_up(self.qv_display_order, self.qv_display_model))
|
||||
connect_lambda(self.qv_down_button.clicked, self,
|
||||
lambda self: move_field_down(self.qv_display_order, self.qv_display_model))
|
||||
mu = partial(move_field_up, self.qv_display_order, self.qv_display_model)
|
||||
md = partial(move_field_down, self.qv_display_order, self.qv_display_model)
|
||||
self.qv_display_order.set_movement_functions(mu, md)
|
||||
self.qv_up_button.clicked.connect(mu)
|
||||
self.qv_down_button.clicked.connect(md)
|
||||
|
||||
self.tb_display_model = TBDisplayedFields(self.gui.current_db,
|
||||
self.tb_display_order,
|
||||
self.tb_display_model = TBDisplayedFields(self.gui.current_db, self.tb_display_order,
|
||||
category_icons=self.gui.tags_view.model().category_custom_icons)
|
||||
self.tb_display_model.dataChanged.connect(self.changed_signal)
|
||||
self.tb_display_order.setModel(self.tb_display_model)
|
||||
self.tb_reset_layout_button.clicked.connect(partial(self.reset_layout,
|
||||
model=self.tb_display_model))
|
||||
self.tb_export_layout_button.clicked.connect(partial(self.export_layout,
|
||||
model=self.tb_display_model))
|
||||
self.tb_import_layout_button.clicked.connect(partial(self.import_layout,
|
||||
model=self.tb_display_model))
|
||||
self.tb_reset_layout_button.clicked.connect(partial(self.reset_layout, model=self.tb_display_model))
|
||||
self.tb_export_layout_button.clicked.connect(partial(self.export_layout, model=self.tb_display_model))
|
||||
self.tb_import_layout_button.clicked.connect(partial(self.import_layout, model=self.tb_display_model))
|
||||
self.tb_up_button.clicked.connect(self.tb_up_button_clicked)
|
||||
self.tb_down_button.clicked.connect(self.tb_down_button_clicked)
|
||||
self.tb_display_order.set_movement_functions(self.tb_up_button_clicked, self.tb_down_button_clicked)
|
||||
|
||||
self.tb_categories_to_part_model = TBPartitionedFields(self.gui.current_db,
|
||||
self.tb_cats_to_partition,
|
||||
@ -701,8 +695,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
self.tb_partition_import_layout_button.clicked.connect(partial(self.import_layout,
|
||||
model=self.tb_categories_to_part_model))
|
||||
|
||||
self.tb_hierarchical_cats_model = TBHierarchicalFields(self.gui.current_db,
|
||||
self.tb_hierarchical_cats,
|
||||
self.tb_hierarchical_cats_model = TBHierarchicalFields(self.gui.current_db, self.tb_hierarchical_cats,
|
||||
category_icons=self.gui.tags_view.model().category_custom_icons)
|
||||
self.tb_hierarchical_cats_model.dataChanged.connect(self.changed_signal)
|
||||
self.tb_hierarchical_cats.setModel(self.tb_hierarchical_cats_model)
|
||||
@ -716,17 +709,16 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
||||
self.fill_tb_search_order_box()
|
||||
self.tb_search_order_up_button.clicked.connect(self.move_tb_search_up)
|
||||
self.tb_search_order_down_button.clicked.connect(self.move_tb_search_down)
|
||||
self.tb_search_order.set_movement_functions(self.move_tb_search_up, self.move_tb_search_down)
|
||||
self.tb_search_order_reset_button.clicked.connect(self.reset_tb_search_order)
|
||||
|
||||
self.edit_rules = EditRules(self.tabWidget)
|
||||
self.edit_rules.changed.connect(self.changed_signal)
|
||||
self.tabWidget.addTab(self.edit_rules,
|
||||
QIcon.ic('format-fill-color.png'), _('Column &coloring'))
|
||||
self.tabWidget.addTab(self.edit_rules, QIcon.ic('format-fill-color.png'), _('Column &coloring'))
|
||||
|
||||
self.icon_rules = EditRules(self.tabWidget)
|
||||
self.icon_rules.changed.connect(self.changed_signal)
|
||||
self.tabWidget.addTab(self.icon_rules,
|
||||
QIcon.ic('icon_choose.png'), _('Column &icons'))
|
||||
self.tabWidget.addTab(self.icon_rules, QIcon.ic('icon_choose.png'), _('Column &icons'))
|
||||
|
||||
self.grid_rules = EditRules(self.emblems_tab)
|
||||
self.grid_rules.changed.connect(self.changed_signal)
|
||||
|
@ -753,7 +753,7 @@ A value of zero means calculate automatically.</string>
|
||||
<item row="3" column="1">
|
||||
<widget class="QToolButton" name="df_down_button">
|
||||
<property name="toolTip">
|
||||
<string>Move down</string>
|
||||
<string>Move down. Keyboard shortcut: Ctrl-Down arrow</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
@ -764,7 +764,7 @@ A value of zero means calculate automatically.</string>
|
||||
<item row="1" column="1">
|
||||
<widget class="QToolButton" name="df_up_button">
|
||||
<property name="toolTip">
|
||||
<string>Move up</string>
|
||||
<string>Move up. Keyboard shortcut: Ctrl-Up arrow</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
@ -786,7 +786,7 @@ A value of zero means calculate automatically.</string>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" rowspan="3">
|
||||
<widget class="QListView" name="field_display_order">
|
||||
<widget class="ListViewWithMoveByKeyPress" name="field_display_order">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -914,7 +914,7 @@ A value of zero means calculate automatically.</string>
|
||||
<item row="3" column="1">
|
||||
<widget class="QToolButton" name="em_down_button">
|
||||
<property name="toolTip">
|
||||
<string>Move down</string>
|
||||
<string>Move down. Keyboard shortcut: Ctrl-Down arrow</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
@ -925,7 +925,7 @@ A value of zero means calculate automatically.</string>
|
||||
<item row="1" column="1">
|
||||
<widget class="QToolButton" name="em_up_button">
|
||||
<property name="toolTip">
|
||||
<string>Move up</string>
|
||||
<string>Move up. Keyboard shortcut: Ctrl-Up arrow</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
@ -947,7 +947,7 @@ A value of zero means calculate automatically.</string>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="0" rowspan="3">
|
||||
<widget class="QListView" name="em_display_order">
|
||||
<widget class="ListViewWithMoveByKeyPress" name="em_display_order">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -1162,7 +1162,7 @@ using the Tab key. The F2 (Edit) key will still open the template editor.</p&
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" rowspan="3">
|
||||
<widget class="QListView" name="tb_display_order">
|
||||
<widget class="ListViewWithMoveByKeyPress" name="tb_display_order">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
@ -1177,7 +1177,7 @@ using the Tab key. The F2 (Edit) key will still open the template editor.</p&
|
||||
<item row="1" column="1">
|
||||
<widget class="QToolButton" name="tb_up_button">
|
||||
<property name="toolTip">
|
||||
<string>Move up. User categories and Saved searches cannot be moved</string>
|
||||
<string>Move up. User categories and Saved searches cannot be moved. Keyboard shortcut: Ctrl-Up arrow</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
@ -1201,7 +1201,7 @@ using the Tab key. The F2 (Edit) key will still open the template editor.</p&
|
||||
<item row="3" column="1">
|
||||
<widget class="QToolButton" name="tb_down_button">
|
||||
<property name="toolTip">
|
||||
<string>Move down. User categories and Saved searches cannot be moved</string>
|
||||
<string>Move down. User categories and Saved searches cannot be moved. Keyboard shortcut: Ctrl-Down arrow</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
@ -1691,7 +1691,7 @@ that don't have children.</p></string>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="12" column="0" rowspan="3">
|
||||
<widget class="QListWidget" name="tb_search_order">
|
||||
<widget class="ListWidgetWithMoveByKeyPress" name="tb_search_order">
|
||||
<property name="sizeAdjustPolicy">
|
||||
<enum>QAbstractScrollArea::AdjustToContents</enum>
|
||||
</property>
|
||||
@ -1700,7 +1700,7 @@ that don't have children.</p></string>
|
||||
<item row="12" column="1">
|
||||
<widget class="QToolButton" name="tb_search_order_up_button">
|
||||
<property name="toolTip">
|
||||
<string>Move up.</string>
|
||||
<string>Move up. Keyboard shortcut: Ctrl-Up arrow</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
@ -1724,7 +1724,7 @@ that don't have children.</p></string>
|
||||
<item row="14" column="1">
|
||||
<widget class="QToolButton" name="tb_search_order_down_button">
|
||||
<property name="toolTip">
|
||||
<string>Move down.</string>
|
||||
<string>Move down. Keyboard shortcut: Ctrl-Down arrow</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
@ -1985,7 +1985,7 @@ column being examined (the left-hand pane)</p></string>
|
||||
<item row="0" column="1">
|
||||
<widget class="QToolButton" name="qv_up_button">
|
||||
<property name="toolTip">
|
||||
<string>Move up</string>
|
||||
<string>Move up. Keyboard shortcut: Ctrl-Up arrow</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
@ -1996,7 +1996,7 @@ column being examined (the left-hand pane)</p></string>
|
||||
<item row="2" column="1">
|
||||
<widget class="QToolButton" name="qv_down_button">
|
||||
<property name="toolTip">
|
||||
<string>Move down</string>
|
||||
<string>Move down. Keyboard shortcut: Ctrl-Down arrow</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../../../../resources/images.qrc">
|
||||
@ -2005,7 +2005,7 @@ column being examined (the left-hand pane)</p></string>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" rowspan="3">
|
||||
<widget class="QListView" name="qv_display_order">
|
||||
<widget class="ListViewWithMoveByKeyPress" name="qv_display_order">
|
||||
<property name="alternatingRowColors">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -2043,7 +2043,17 @@ column being examined (the left-hand pane)</p></string>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidgets>ListWidgetWithMoveByKeyPress
|
||||
<customwidget>
|
||||
<class>ListViewWithMoveByKeyPress</class>
|
||||
<extends>QListView</extends>
|
||||
<header>calibre/gui2/preferences.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ListWidgetWithMoveByKeyPress</class>
|
||||
<extends>QListWidget</extends>
|
||||
<header>calibre/gui2/preferences.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>EditWithComplete</class>
|
||||
<extends>QComboBox</extends>
|
||||
|
Loading…
x
Reference in New Issue
Block a user