Keyboard preferences: Add highligh_group() method to ease embedding of keyboard prefs in plugin config dialogs

This commit is contained in:
Kovid Goyal 2011-08-27 12:14:26 -06:00
parent e07df7d583
commit 6d43691e46
3 changed files with 27 additions and 3 deletions

View File

@ -149,11 +149,11 @@ class InterfaceAction(QObject):
if shortcut_name is None and spec[0]:
shortcut_name = unicode(spec[0])
if shortcut_name and not (attr=='qaction' and self.popup_type ==
QToolButton.InstantPopup):
if shortcut_name and self.action_spec[0] and not (
attr == 'qaction' and self.popup_type == QToolButton.InstantPopup):
try:
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,
group=self.action_spec[0])
except NameConflict as e:

View File

@ -307,6 +307,18 @@ class ConfigModel(QAbstractItemModel, SearchQueryParser):
return (self.index(ans[0], 0) if ans[1] < 0 else
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): # {{{
@ -632,6 +644,15 @@ class ShortcutConfig(QWidget): # {{{
unicode(self.search.currentText()), backwards=True)
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)
# }}}

View File

@ -37,6 +37,9 @@ class ConfigWidget(ConfigWidgetBase):
def refresh_gui(self, gui):
gui.keyboard.finalize()
def highligh_group(self, group_name):
self.conf_widget.highlight_group(group_name)
if __name__ == '__main__':
from PyQt4.Qt import QApplication
app = QApplication([])