mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Keyboard preferences: Add highligh_group() method to ease embedding of keyboard prefs in plugin config dialogs
This commit is contained in:
parent
e07df7d583
commit
6d43691e46
@ -149,11 +149,11 @@ class InterfaceAction(QObject):
|
|||||||
if shortcut_name is None and spec[0]:
|
if shortcut_name is None and spec[0]:
|
||||||
shortcut_name = unicode(spec[0])
|
shortcut_name = unicode(spec[0])
|
||||||
|
|
||||||
if shortcut_name and not (attr=='qaction' and self.popup_type ==
|
if shortcut_name and self.action_spec[0] and not (
|
||||||
QToolButton.InstantPopup):
|
attr == 'qaction' and self.popup_type == QToolButton.InstantPopup):
|
||||||
try:
|
try:
|
||||||
self.gui.keyboard.register_shortcut(self.unique_name + ' - ' + attr,
|
self.gui.keyboard.register_shortcut(self.unique_name + ' - ' + attr,
|
||||||
unicode(spec[0]), default_keys=keys,
|
shortcut_name, default_keys=keys,
|
||||||
action=shortcut_action, description=desc,
|
action=shortcut_action, description=desc,
|
||||||
group=self.action_spec[0])
|
group=self.action_spec[0])
|
||||||
except NameConflict as e:
|
except NameConflict as e:
|
||||||
|
@ -307,6 +307,18 @@ class ConfigModel(QAbstractItemModel, SearchQueryParser):
|
|||||||
return (self.index(ans[0], 0) if ans[1] < 0 else
|
return (self.index(ans[0], 0) if ans[1] < 0 else
|
||||||
self.index(ans[1], 0, self.index(ans[0], 0)))
|
self.index(ans[1], 0, self.index(ans[0], 0)))
|
||||||
|
|
||||||
|
def index_for_group(self, name):
|
||||||
|
for i in range(self.rowCount()):
|
||||||
|
node = self.data[i]
|
||||||
|
if node.data == name:
|
||||||
|
return self.index(i, 0)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def group_names(self):
|
||||||
|
for i in range(self.rowCount()):
|
||||||
|
node = self.data[i]
|
||||||
|
yield node.data
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
class Editor(QFrame): # {{{
|
class Editor(QFrame): # {{{
|
||||||
@ -632,6 +644,15 @@ class ShortcutConfig(QWidget): # {{{
|
|||||||
unicode(self.search.currentText()), backwards=True)
|
unicode(self.search.currentText()), backwards=True)
|
||||||
self.highlight_index(idx)
|
self.highlight_index(idx)
|
||||||
|
|
||||||
|
def highlight_group(self, group_name):
|
||||||
|
idx = self.view.model().index_for_group(group_name)
|
||||||
|
if idx is not None:
|
||||||
|
self.view.expand(idx)
|
||||||
|
self.view.scrollTo(idx, self.view.PositionAtTop)
|
||||||
|
self.view.selectionModel().select(idx,
|
||||||
|
self.view.selectionModel().ClearAndSelect)
|
||||||
|
self.view.setCurrentIndex(idx)
|
||||||
|
self.view.setFocus(Qt.OtherFocusReason)
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
@ -37,6 +37,9 @@ class ConfigWidget(ConfigWidgetBase):
|
|||||||
def refresh_gui(self, gui):
|
def refresh_gui(self, gui):
|
||||||
gui.keyboard.finalize()
|
gui.keyboard.finalize()
|
||||||
|
|
||||||
|
def highligh_group(self, group_name):
|
||||||
|
self.conf_widget.highlight_group(group_name)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
from PyQt4.Qt import QApplication
|
from PyQt4.Qt import QApplication
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user