openlp/openlp/core/ui/shortcutlistdialog.py

153 lines
8.0 KiB
Python
Raw Normal View History

2010-10-07 21:27:26 +00:00
# -*- coding: utf-8 -*-
2019-04-13 13:00:22 +00:00
##########################################################################
# OpenLP - Open Source Lyrics Projection #
# ---------------------------------------------------------------------- #
2022-02-01 10:10:57 +00:00
# Copyright (c) 2008-2022 OpenLP Developers #
2019-04-13 13:00:22 +00:00
# ---------------------------------------------------------------------- #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program. If not, see <https://www.gnu.org/licenses/>. #
##########################################################################
2013-02-01 21:34:23 +00:00
"""
The list of shortcuts within a dialog.
"""
2015-11-07 00:49:40 +00:00
from PyQt5 import QtCore, QtWidgets
2010-10-07 21:27:26 +00:00
2017-10-07 07:05:07 +00:00
from openlp.core.common.i18n import translate
from openlp.core.lib.ui import create_button_box
2018-04-21 05:59:03 +00:00
from openlp.core.ui.icons import UiIcons
2010-10-07 21:27:26 +00:00
2013-02-01 21:34:23 +00:00
2015-11-07 00:49:40 +00:00
class CaptureShortcutButton(QtWidgets.QPushButton):
"""
A class to encapsulate a ``QPushButton``.
"""
def __init__(self, *args):
2013-02-01 21:34:23 +00:00
"""
Constructor
"""
2013-07-18 14:34:33 +00:00
super(CaptureShortcutButton, self).__init__(*args)
self.setCheckable(True)
def keyPressEvent(self, event):
"""
Block the ``Key_Space`` key, so that the button will not change the
checked state.
"""
if event.key() == QtCore.Qt.Key_Space and self.isChecked():
2011-05-01 15:54:05 +00:00
# Ignore the event, so that the parent can take care of this.
event.ignore()
2015-12-23 18:01:37 +00:00
class ShortcutTreeWidget(QtWidgets.QTreeWidget):
def __init__(self, *args):
super(ShortcutTreeWidget, self).__init__(*args)
def keyboardSearch(self, search):
2015-12-26 16:05:41 +00:00
"""
2015-12-26 16:08:50 +00:00
Ignore searches to prevent single letter searches from highlighting items.
2015-12-26 16:05:41 +00:00
:param search: Search string
"""
pass
2010-10-07 21:27:26 +00:00
class Ui_ShortcutListDialog(object):
2013-02-01 21:34:23 +00:00
"""
The UI widgets for the shortcut dialog.
"""
def setup_ui(self, shortcutListDialog):
2013-02-01 21:34:23 +00:00
"""
Set up the UI
"""
2013-08-31 18:17:38 +00:00
shortcutListDialog.setObjectName('shortcutListDialog')
2018-04-21 19:57:51 +00:00
shortcutListDialog.setWindowIcon(UiIcons().main_icon)
shortcutListDialog.resize(500, 438)
2015-11-07 00:49:40 +00:00
self.shortcut_list_layout = QtWidgets.QVBoxLayout(shortcutListDialog)
2013-12-24 15:55:01 +00:00
self.shortcut_list_layout.setObjectName('shortcut_list_layout')
2015-11-07 00:49:40 +00:00
self.description_label = QtWidgets.QLabel(shortcutListDialog)
2013-08-31 18:17:38 +00:00
self.description_label.setObjectName('description_label')
2013-03-07 08:05:43 +00:00
self.description_label.setWordWrap(True)
2013-12-24 15:55:01 +00:00
self.shortcut_list_layout.addWidget(self.description_label)
self.tree_widget = ShortcutTreeWidget(shortcutListDialog)
2013-12-24 15:55:01 +00:00
self.tree_widget.setObjectName('tree_widget')
self.tree_widget.setAlternatingRowColors(True)
self.tree_widget.setColumnCount(3)
self.tree_widget.setColumnWidth(0, 250)
self.shortcut_list_layout.addWidget(self.tree_widget)
2015-11-07 00:49:40 +00:00
self.details_layout = QtWidgets.QGridLayout()
2013-12-24 15:55:01 +00:00
self.details_layout.setObjectName('details_layout')
self.details_layout.setContentsMargins(-1, 0, -1, -1)
2015-11-07 00:49:40 +00:00
self.default_radio_button = QtWidgets.QRadioButton(shortcutListDialog)
2013-12-24 15:55:01 +00:00
self.default_radio_button.setObjectName('default_radio_button')
self.default_radio_button.setChecked(True)
self.details_layout.addWidget(self.default_radio_button, 0, 0, 1, 1)
2015-11-07 00:49:40 +00:00
self.custom_radio_button = QtWidgets.QRadioButton(shortcutListDialog)
2013-12-24 15:55:01 +00:00
self.custom_radio_button.setObjectName('custom_radio_button')
self.details_layout.addWidget(self.custom_radio_button, 1, 0, 1, 1)
2015-11-07 00:49:40 +00:00
self.primary_layout = QtWidgets.QHBoxLayout()
2013-12-24 15:55:01 +00:00
self.primary_layout.setObjectName('primary_layout')
self.primary_push_button = CaptureShortcutButton(shortcutListDialog)
self.primary_push_button.setObjectName('primary_push_button')
self.primary_push_button.setMinimumSize(QtCore.QSize(84, 0))
2019-07-03 13:23:23 +00:00
self.primary_push_button.setIcon(UiIcons().shortcuts)
2013-12-24 15:55:01 +00:00
self.primary_layout.addWidget(self.primary_push_button)
2015-11-07 00:49:40 +00:00
self.clear_primary_button = QtWidgets.QToolButton(shortcutListDialog)
2013-12-24 15:55:01 +00:00
self.clear_primary_button.setObjectName('clear_primary_button')
self.clear_primary_button.setMinimumSize(QtCore.QSize(0, 16))
2018-04-21 05:59:03 +00:00
self.clear_primary_button.setIcon(UiIcons().settings)
2013-12-24 15:55:01 +00:00
self.primary_layout.addWidget(self.clear_primary_button)
2013-12-24 20:45:29 +00:00
self.details_layout.addLayout(self.primary_layout, 1, 1, 1, 1)
2015-11-07 00:49:40 +00:00
self.alternate_layout = QtWidgets.QHBoxLayout()
2013-12-24 15:55:01 +00:00
self.alternate_layout.setObjectName('alternate_layout')
self.alternate_push_button = CaptureShortcutButton(shortcutListDialog)
self.alternate_push_button.setObjectName('alternate_push_button')
2018-04-21 05:59:03 +00:00
self.alternate_push_button.setIcon(UiIcons().settings)
2013-12-24 15:55:01 +00:00
self.alternate_layout.addWidget(self.alternate_push_button)
2015-11-07 00:49:40 +00:00
self.clear_alternate_button = QtWidgets.QToolButton(shortcutListDialog)
2013-12-24 15:55:01 +00:00
self.clear_alternate_button.setObjectName('clear_alternate_button')
2018-04-21 05:59:03 +00:00
self.clear_alternate_button.setIcon(UiIcons().settings)
2013-12-24 15:55:01 +00:00
self.alternate_layout.addWidget(self.clear_alternate_button)
2013-12-24 20:45:29 +00:00
self.details_layout.addLayout(self.alternate_layout, 1, 2, 1, 1)
2015-11-07 00:49:40 +00:00
self.primary_label = QtWidgets.QLabel(shortcutListDialog)
2013-12-24 15:55:01 +00:00
self.primary_label.setObjectName('primary_label')
self.details_layout.addWidget(self.primary_label, 0, 1, 1, 1)
2015-11-07 00:49:40 +00:00
self.alternate_label = QtWidgets.QLabel(shortcutListDialog)
2013-12-24 15:55:01 +00:00
self.alternate_label.setObjectName('alternate_label')
self.details_layout.addWidget(self.alternate_label, 0, 2, 1, 1)
2013-12-24 20:45:29 +00:00
self.shortcut_list_layout.addLayout(self.details_layout)
2013-08-31 18:17:38 +00:00
self.button_box = create_button_box(shortcutListDialog, 'button_box', ['cancel', 'ok', 'defaults'])
2013-01-27 20:36:18 +00:00
self.button_box.setOrientation(QtCore.Qt.Horizontal)
2013-12-24 15:55:01 +00:00
self.shortcut_list_layout.addWidget(self.button_box)
self.retranslate_ui(shortcutListDialog)
2010-10-07 21:27:26 +00:00
def retranslate_ui(self, shortcutListDialog):
2013-02-01 21:34:23 +00:00
"""
Translate the UI on the fly
"""
2012-12-29 13:35:16 +00:00
shortcutListDialog.setWindowTitle(translate('OpenLP.ShortcutListDialog', 'Configure Shortcuts'))
2013-03-07 08:05:43 +00:00
self.description_label.setText(
2012-12-29 13:35:16 +00:00
translate('OpenLP.ShortcutListDialog', 'Select an action and click one of the buttons below to start '
2013-12-24 15:55:01 +00:00
'capturing a new primary or alternate shortcut, respectively.'))
self.tree_widget.setHeaderLabels([translate('OpenLP.ShortcutListDialog', 'Action'),
translate('OpenLP.ShortcutListDialog', 'Shortcut'),
translate('OpenLP.ShortcutListDialog', 'Alternate')])
self.default_radio_button.setText(translate('OpenLP.ShortcutListDialog', 'Default'))
self.custom_radio_button.setText(translate('OpenLP.ShortcutListDialog', 'Custom'))
self.primary_push_button.setToolTip(translate('OpenLP.ShortcutListDialog', 'Capture shortcut.'))
self.alternate_push_button.setToolTip(translate('OpenLP.ShortcutListDialog', 'Capture shortcut.'))
self.clear_primary_button.setToolTip(translate('OpenLP.ShortcutListDialog',
'Restore the default shortcut of this action.'))
self.clear_alternate_button.setToolTip(translate('OpenLP.ShortcutListDialog',
'Restore the default shortcut of this action.'))