~suutari-olli/openlp/escape-fixes-1294111-1497637

« back to all changes in this revision

Viewing changes to openlp/core/ui/shortcutlistform.py

  • Committer: suutari-olli
  • Date: 2016-01-07 02:53:59 UTC
  • mfrom: (2557.2.31 openlp)
  • Revision ID: suutari.olli@gmail.com-20160107025359-q2feybbwxaoihqxr
Merge to trunk on 1/7/2015.

I noticed this branch also seems to be fixing this bug:
https://bugs.launchpad.net/openlp/+bug/1531691

However, escape item still remains buggy with problems related to resuming
video and presentations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
###############################################################################
5
5
# OpenLP - Open Source Lyrics Projection                                      #
6
6
# --------------------------------------------------------------------------- #
7
 
# Copyright (c) 2008-2015 OpenLP Developers                                   #
 
7
# Copyright (c) 2008-2016 OpenLP Developers                                   #
8
8
# --------------------------------------------------------------------------- #
9
9
# This program is free software; you can redistribute it and/or modify it     #
10
10
# under the terms of the GNU General Public License as published by the Free  #
24
24
import logging
25
25
import re
26
26
 
27
 
from PyQt4 import QtCore, QtGui
 
27
from PyQt5 import QtCore, QtGui, QtWidgets
28
28
 
29
29
from openlp.core.common import RegistryProperties, Settings, translate
30
30
from openlp.core.utils.actions import ActionList
35
35
log = logging.getLogger(__name__)
36
36
 
37
37
 
38
 
class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog, RegistryProperties):
 
38
class ShortcutListForm(QtWidgets.QDialog, Ui_ShortcutListDialog, RegistryProperties):
39
39
    """
40
40
    The shortcut list dialog
41
41
    """
96
96
        key_sequence = QtGui.QKeySequence(key_string)
97
97
        if self._validiate_shortcut(self._current_item_action(), key_sequence):
98
98
            if self.primary_push_button.isChecked():
99
 
                self._adjust_button(self.primary_push_button, False, text=key_sequence.toString())
 
99
                self._adjust_button(self.primary_push_button, False,
 
100
                                    text=self.get_shortcut_string(key_sequence, for_display=True))
100
101
            elif self.alternate_push_button.isChecked():
101
 
                self._adjust_button(self.alternate_push_button, False, text=key_sequence.toString())
 
102
                self._adjust_button(self.alternate_push_button, False,
 
103
                                    text=self.get_shortcut_string(key_sequence, for_display=True))
102
104
 
103
 
    def exec_(self):
 
105
    def exec(self):
104
106
        """
105
107
        Execute the dialog
106
108
        """
108
110
        self.reload_shortcut_list()
109
111
        self._adjust_button(self.primary_push_button, False, False, '')
110
112
        self._adjust_button(self.alternate_push_button, False, False, '')
111
 
        return QtGui.QDialog.exec_(self)
 
113
        return QtWidgets.QDialog.exec(self)
112
114
 
113
115
    def reload_shortcut_list(self):
114
116
        """
119
121
            # Check if the category is for internal use only.
120
122
            if category.name is None:
121
123
                continue
122
 
            item = QtGui.QTreeWidgetItem([category.name])
 
124
            item = QtWidgets.QTreeWidgetItem([category.name])
123
125
            for action in category.actions:
124
126
                action_text = REMOVE_AMPERSAND.sub('', action.text())
125
 
                action_item = QtGui.QTreeWidgetItem([action_text])
 
127
                action_item = QtWidgets.QTreeWidgetItem([action_text])
126
128
                action_item.setIcon(0, action.icon())
127
129
                action_item.setData(0, QtCore.Qt.UserRole, action)
128
130
                tool_tip_text = action.toolTip()
142
144
        This refreshes the item's shortcuts shown in the list. Note, this neither adds new actions nor removes old
143
145
        actions.
144
146
        """
145
 
        iterator = QtGui.QTreeWidgetItemIterator(self.tree_widget)
 
147
        iterator = QtWidgets.QTreeWidgetItemIterator(self.tree_widget)
146
148
        while iterator.value():
147
149
            item = iterator.value()
148
150
            iterator += 1
154
156
                item.setText(1, '')
155
157
                item.setText(2, '')
156
158
            elif len(shortcuts) == 1:
157
 
                item.setText(1, shortcuts[0].toString())
 
159
                item.setText(1, self.get_shortcut_string(shortcuts[0], for_display=True))
158
160
                item.setText(2, '')
159
161
            else:
160
 
                item.setText(1, shortcuts[0].toString())
161
 
                item.setText(2, shortcuts[1].toString())
 
162
                item.setText(1, self.get_shortcut_string(shortcuts[0], for_display=True))
 
163
                item.setText(2, self.get_shortcut_string(shortcuts[1], for_display=True))
162
164
        self.on_current_item_changed()
163
165
 
164
166
    def on_primary_push_button_clicked(self, toggled):
238
240
            self.alternate_push_button.setChecked(False)
239
241
        else:
240
242
            if action.default_shortcuts:
241
 
                primary_label_text = action.default_shortcuts[0].toString()
 
243
                primary_label_text = self.get_shortcut_string(action.default_shortcuts[0], for_display=True)
242
244
                if len(action.default_shortcuts) == 2:
243
 
                    alternate_label_text = action.default_shortcuts[1].toString()
 
245
                    alternate_label_text = self.get_shortcut_string(action.default_shortcuts[1], for_display=True)
244
246
            shortcuts = self._action_shortcuts(action)
245
247
            # We do not want to loose pending changes, that is why we have to keep the text when, this function has not
246
248
            # been triggered by a signal.
248
250
                primary_text = self.primary_push_button.text()
249
251
                alternate_text = self.alternate_push_button.text()
250
252
            elif len(shortcuts) == 1:
251
 
                primary_text = shortcuts[0].toString()
 
253
                primary_text = self.get_shortcut_string(shortcuts[0], for_display=True)
252
254
            elif len(shortcuts) == 2:
253
 
                primary_text = shortcuts[0].toString()
254
 
                alternate_text = shortcuts[1].toString()
 
255
                primary_text = self.get_shortcut_string(shortcuts[0], for_display=True)
 
256
                alternate_text = self.get_shortcut_string(shortcuts[1], for_display=True)
255
257
        # When we are capturing a new shortcut, we do not want, the buttons to display the current shortcut.
256
258
        if self.primary_push_button.isChecked():
257
259
            primary_text = ''
273
275
        """
274
276
        Restores all default shortcuts.
275
277
        """
276
 
        if self.button_box.buttonRole(button) != QtGui.QDialogButtonBox.ResetRole:
 
278
        if self.button_box.buttonRole(button) != QtWidgets.QDialogButtonBox.ResetRole:
277
279
            return
278
 
        if QtGui.QMessageBox.question(self, translate('OpenLP.ShortcutListDialog', 'Restore Default Shortcuts'),
279
 
                                      translate('OpenLP.ShortcutListDialog', 'Do you want to restore all '
280
 
                                                'shortcuts to their defaults?'),
281
 
                                      QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes |
282
 
                                                                        QtGui.QMessageBox.No)) == QtGui.QMessageBox.No:
 
280
        if QtWidgets.QMessageBox.question(self, translate('OpenLP.ShortcutListDialog', 'Restore Default Shortcuts'),
 
281
                                          translate('OpenLP.ShortcutListDialog', 'Do you want to restore all '
 
282
                                                    'shortcuts to their defaults?'),
 
283
                                          QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Yes |
 
284
                                                                                QtWidgets.QMessageBox.No)
 
285
                                          ) == QtWidgets.QMessageBox.No:
283
286
            return
284
287
        self._adjust_button(self.primary_push_button, False, text='')
285
288
        self._adjust_button(self.alternate_push_button, False, text='')
304
307
        primary_button_text = ''
305
308
        alternate_button_text = ''
306
309
        if temp_shortcuts:
307
 
            primary_button_text = temp_shortcuts[0].toString()
 
310
            primary_button_text = self.get_shortcut_string(temp_shortcuts[0], for_display=True)
308
311
        if len(temp_shortcuts) == 2:
309
 
            alternate_button_text = temp_shortcuts[1].toString()
 
312
            alternate_button_text = self.get_shortcut_string(temp_shortcuts[1], for_display=True)
310
313
        self.primary_push_button.setText(primary_button_text)
311
314
        self.alternate_push_button.setText(alternate_button_text)
312
315
 
334
337
                continue
335
338
            for action in category.actions:
336
339
                if action in self.changed_actions:
337
 
                    old_shortcuts = list(map(QtGui.QKeySequence.toString, action.shortcuts()))
 
340
                    old_shortcuts = list(map(self.get_shortcut_string, action.shortcuts()))
338
341
                    action.setShortcuts(self.changed_actions[action])
339
342
                    self.action_list.update_shortcut_map(action, old_shortcuts)
340
343
                settings.setValue(action.objectName(), action.shortcuts())
417
420
            self.main_window.warning_message(translate('OpenLP.ShortcutListDialog', 'Duplicate Shortcut'),
418
421
                                             translate('OpenLP.ShortcutListDialog',
419
422
                                                       'The shortcut "%s" is already assigned to another action, please'
420
 
                                                       ' use a different shortcut.') % key_sequence.toString())
 
423
                                                       ' use a different shortcut.') %
 
424
                                             self.get_shortcut_string(key_sequence, for_display=True))
421
425
            self.dialog_was_shown = True
422
426
        return is_valid
423
427
 
424
428
    def _action_shortcuts(self, action):
425
429
        """
426
430
        This returns the shortcuts for the given ``action``, which also includes those shortcuts which are not saved
427
 
        yet but already assigned (as changes yre applied when closing the dialog).
 
431
        yet but already assigned (as changes are applied when closing the dialog).
428
432
        """
429
433
        if action in self.changed_actions:
430
434
            return self.changed_actions[action]
452
456
            button.setChecked(checked)
453
457
        if enabled is not None:
454
458
            button.setEnabled(enabled)
 
459
 
 
460
    @staticmethod
 
461
    def get_shortcut_string(shortcut, for_display=False):
 
462
        if for_display:
 
463
            if any(modifier in shortcut.toString() for modifier in ['Ctrl', 'Alt', 'Meta', 'Shift']):
 
464
                sequence_format = QtGui.QKeySequence.NativeText
 
465
            else:
 
466
                sequence_format = QtGui.QKeySequence.PortableText
 
467
        else:
 
468
            sequence_format = QtGui.QKeySequence.PortableText
 
469
        return shortcut.toString(sequence_format)