mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Tag browser focus changes discussed in other PR.
This commit is contained in:
parent
c61b669501
commit
195b396602
@ -414,7 +414,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
|
|||||||
r('tag_browser_hide_empty_categories', gprefs)
|
r('tag_browser_hide_empty_categories', gprefs)
|
||||||
r('tag_browser_always_autocollapse', gprefs)
|
r('tag_browser_always_autocollapse', gprefs)
|
||||||
r('tag_browser_show_tooltips', gprefs)
|
r('tag_browser_show_tooltips', gprefs)
|
||||||
r('tag_browser_allow_keyboard_focus', gprefs, restart_required=True)
|
r('tag_browser_allow_keyboard_focus', gprefs)
|
||||||
r('bd_show_cover', gprefs)
|
r('bd_show_cover', gprefs)
|
||||||
r('bd_overlay_cover_size', gprefs)
|
r('bd_overlay_cover_size', gprefs)
|
||||||
r('cover_grid_width', gprefs)
|
r('cover_grid_width', gprefs)
|
||||||
|
@ -1111,7 +1111,7 @@ see the counts by hovering your mouse over any item.</string>
|
|||||||
<item row="14" column="0" colspan="2">
|
<item row="14" column="0" colspan="2">
|
||||||
<widget class="QCheckBox" name="opt_tag_browser_allow_keyboard_focus">
|
<widget class="QCheckBox" name="opt_tag_browser_allow_keyboard_focus">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Allow the Tag browser to have keyboard focus (needs restart)</string>
|
<string>Allow the Tag browser to have keyboard focus</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string><p>When checked, the Tag browser can get keyboard focus, allowing
|
<string><p>When checked, the Tag browser can get keyboard focus, allowing
|
||||||
|
@ -6,7 +6,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
import os, re
|
import os, re, traceback
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
@ -206,9 +206,7 @@ class TagsView(QTreeView): # {{{
|
|||||||
self._model.user_categories_edited.connect(self.user_categories_edited,
|
self._model.user_categories_edited.connect(self.user_categories_edited,
|
||||||
type=Qt.QueuedConnection)
|
type=Qt.QueuedConnection)
|
||||||
self._model.drag_drop_finished.connect(self.drag_drop_finished)
|
self._model.drag_drop_finished.connect(self.drag_drop_finished)
|
||||||
self.set_look_and_feel()
|
self.set_look_and_feel(first=True)
|
||||||
if not gprefs['tag_browser_allow_keyboard_focus']:
|
|
||||||
self.setFocusPolicy(Qt.NoFocus)
|
|
||||||
QApplication.instance().palette_changed.connect(self.set_style_sheet, type=Qt.QueuedConnection)
|
QApplication.instance().palette_changed.connect(self.set_style_sheet, type=Qt.QueuedConnection)
|
||||||
|
|
||||||
def set_style_sheet(self):
|
def set_style_sheet(self):
|
||||||
@ -234,11 +232,27 @@ class TagsView(QTreeView): # {{{
|
|||||||
'''.replace('PAD', unicode_type(gprefs['tag_browser_item_padding'])) + (
|
'''.replace('PAD', unicode_type(gprefs['tag_browser_item_padding'])) + (
|
||||||
'' if gprefs['tag_browser_old_look'] else stylish_tb))
|
'' if gprefs['tag_browser_old_look'] else stylish_tb))
|
||||||
|
|
||||||
def set_look_and_feel(self):
|
def set_look_and_feel(self, first=False):
|
||||||
self.set_style_sheet()
|
self.set_style_sheet()
|
||||||
self.setAlternatingRowColors(gprefs['tag_browser_old_look'])
|
self.setAlternatingRowColors(gprefs['tag_browser_old_look'])
|
||||||
self.itemDelegate().old_look = gprefs['tag_browser_old_look']
|
self.itemDelegate().old_look = gprefs['tag_browser_old_look']
|
||||||
|
|
||||||
|
if gprefs['tag_browser_allow_keyboard_focus']:
|
||||||
|
self.setFocusPolicy(Qt.StrongFocus)
|
||||||
|
else:
|
||||||
|
self.setFocusPolicy(Qt.NoFocus)
|
||||||
|
# Ensure the TB doesn't keep the focus it might already have. When this
|
||||||
|
# method is first called during GUI initialization not everything is
|
||||||
|
# set up, in which case don't try to change the focus.
|
||||||
|
# Note: this process has the side effect of moving the focus to the
|
||||||
|
# library view whenever a look & feel preference is changed.
|
||||||
|
if not first:
|
||||||
|
try:
|
||||||
|
from calibre.gui2.ui import get_gui
|
||||||
|
get_gui().shift_esc()
|
||||||
|
except:
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def hidden_categories(self):
|
def hidden_categories(self):
|
||||||
return self._model.hidden_categories
|
return self._model.hidden_categories
|
||||||
@ -309,9 +323,6 @@ class TagsView(QTreeView): # {{{
|
|||||||
# I don't see how current_index can ever be not valid, but ...
|
# I don't see how current_index can ever be not valid, but ...
|
||||||
self.currentIndex().isValid()):
|
self.currentIndex().isValid()):
|
||||||
self.toggle_current_index()
|
self.toggle_current_index()
|
||||||
# Reset the focus to the TB. Use the singleshot in case
|
|
||||||
# some of of searching is done using queued signals.
|
|
||||||
QTimer.singleShot(0, lambda: self.setFocus())
|
|
||||||
return
|
return
|
||||||
QTreeView.keyPressEvent(self, event)
|
QTreeView.keyPressEvent(self, event)
|
||||||
|
|
||||||
@ -414,7 +425,15 @@ class TagsView(QTreeView): # {{{
|
|||||||
modifiers = int(QApplication.keyboardModifiers())
|
modifiers = int(QApplication.keyboardModifiers())
|
||||||
exclusive = modifiers not in (Qt.CTRL, Qt.SHIFT)
|
exclusive = modifiers not in (Qt.CTRL, Qt.SHIFT)
|
||||||
if self._model.toggle(index, exclusive, set_to=set_to):
|
if self._model.toggle(index, exclusive, set_to=set_to):
|
||||||
|
# Reset the focus back to TB if it has it before the toggle
|
||||||
|
# Must ask this question before starting the search because
|
||||||
|
# it changes the focus
|
||||||
|
has_focus = self.hasFocus()
|
||||||
self.tags_marked.emit(self.search_string)
|
self.tags_marked.emit(self.search_string)
|
||||||
|
if has_focus and gprefs['tag_browser_allow_keyboard_focus']:
|
||||||
|
# Reset the focus to the TB. Use the singleshot in case
|
||||||
|
# some of searching is done using queued signals.
|
||||||
|
QTimer.singleShot(0, lambda: self.setFocus())
|
||||||
|
|
||||||
def conditional_clear(self, search_string):
|
def conditional_clear(self, search_string):
|
||||||
if search_string != self.search_string:
|
if search_string != self.search_string:
|
||||||
@ -444,7 +463,6 @@ class TagsView(QTreeView): # {{{
|
|||||||
self._model.set_custom_category_icon(key, unicode_type(path))
|
self._model.set_custom_category_icon(key, unicode_type(path))
|
||||||
self.recount()
|
self.recount()
|
||||||
except:
|
except:
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return
|
return
|
||||||
if action == 'clear_icon':
|
if action == 'clear_icon':
|
||||||
@ -573,7 +591,6 @@ class TagsView(QTreeView): # {{{
|
|||||||
self._model.set_categories_filter(None)
|
self._model.set_categories_filter(None)
|
||||||
self._model.rebuild_node_tree()
|
self._model.rebuild_node_tree()
|
||||||
except Exception:
|
except Exception:
|
||||||
import traceback
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user