Hide the Tag browser search box by default

Can be shown by clicking the search icon in the bottom of the Tag
Browser
This commit is contained in:
Kovid Goyal 2017-06-09 01:11:13 +05:30
parent 2c80dc2aed
commit 34acecce6a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 48 additions and 18 deletions

View File

@ -613,6 +613,22 @@ else:
replace_chars = re.compile("([\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF])") replace_chars = re.compile("([\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF])")
def html5_parse(raw, decoder=None, log=None, discard_namespaces=False, line_numbers=True, linenumber_attribute=None, replace_entities=True, fix_newlines=True):
if isinstance(raw, bytes):
raw = xml_to_unicode(raw)[0] if decoder is None else decoder(raw)
if replace_entities:
raw = xml_replace_entities(raw)
if fix_newlines:
raw = raw.replace('\r\n', '\n').replace('\r', '\n')
raw = replace_chars.sub('', raw)
from html5_parser import parse
root = parse(raw, maybe_xhtml=not discard_namespaces, line_number_attr=linenumber_attribute, keep_doctype=False)
if (discard_namespaces and root.tag != 'html') or (
not discard_namespaces and (root.tag != '{%s}%s' % (namespaces['html'], 'html') or root.prefix)):
raise ValueError('Failed to parse correctly, root has tag: %s and prefix: %s' % (root.tag, root.prefix))
return root
def parse_html5(raw, decoder=None, log=None, discard_namespaces=False, line_numbers=True, linenumber_attribute=None, replace_entities=True, fix_newlines=True): def parse_html5(raw, decoder=None, log=None, discard_namespaces=False, line_numbers=True, linenumber_attribute=None, replace_entities=True, fix_newlines=True):
if isinstance(raw, bytes): if isinstance(raw, bytes):
raw = xml_to_unicode(raw)[0] if decoder is None else decoder(raw) raw = xml_to_unicode(raw)[0] if decoder is None else decoder(raw)

View File

@ -12,7 +12,7 @@ from lxml import etree
from html5lib.constants import cdataElements, rcdataElements from html5lib.constants import cdataElements, rcdataElements
from calibre.ebooks.oeb.polish.tests.base import BaseTest from calibre.ebooks.oeb.polish.tests.base import BaseTest
from calibre.ebooks.oeb.polish.parsing import parse_html5 as parse from calibre.ebooks.oeb.polish.parsing import html5_parse as parse
from calibre.ebooks.oeb.base import XPath, XHTML_NS, SVG_NS, XLINK_NS from calibre.ebooks.oeb.base import XPath, XHTML_NS, SVG_NS, XLINK_NS
from calibre.ebooks.oeb.parse_utils import html5_parse from calibre.ebooks.oeb.parse_utils import html5_parse

View File

@ -11,9 +11,9 @@ from functools import partial
from PyQt5.Qt import ( from PyQt5.Qt import (
Qt, QIcon, QWidget, QHBoxLayout, QVBoxLayout, QToolButton, QLabel, QFrame, Qt, QIcon, QWidget, QHBoxLayout, QVBoxLayout, QToolButton, QLabel, QFrame,
QTimer, QMenu, QPushButton, QActionGroup, QAction) QTimer, QMenu, QActionGroup, QAction)
from calibre.gui2 import error_dialog, question_dialog from calibre.gui2 import error_dialog, question_dialog, gprefs
from calibre.gui2.widgets import HistoryLineEdit from calibre.gui2.widgets import HistoryLineEdit
from calibre.library.field_metadata import category_icon_map from calibre.library.field_metadata import category_icon_map
from calibre.utils.icu import sort_key from calibre.utils.icu import sort_key
@ -345,21 +345,17 @@ class TagBrowserWidget(QWidget): # {{{
def __init__(self, parent): def __init__(self, parent):
QWidget.__init__(self, parent) QWidget.__init__(self, parent)
self.parent = parent self.parent = parent
self._layout = QVBoxLayout() self._layout = QVBoxLayout(self)
self.setLayout(self._layout)
self._layout.setContentsMargins(0,0,0,0) self._layout.setContentsMargins(0,0,0,0)
# Set up the find box & button # Set up the find box & button
search_layout = QHBoxLayout() search_layout = QHBoxLayout()
self._layout.addLayout(search_layout) search_layout.setAlignment(Qt.AlignLeft | Qt.AlignBottom)
search_layout.setContentsMargins(0, 0, 0, 0)
self.item_search = HistoryLineEdit(parent) self.item_search = HistoryLineEdit(parent)
self.item_search.setMinimumContentsLength(5) self.item_search.setMinimumContentsLength(5)
self.item_search.setSizeAdjustPolicy(self.item_search.AdjustToMinimumContentsLengthWithIcon) self.item_search.setSizeAdjustPolicy(self.item_search.AdjustToMinimumContentsLengthWithIcon)
try: self.item_search.lineEdit().setPlaceholderText(_('Find in Tag browser'))
self.item_search.lineEdit().setPlaceholderText(
_('Find item in Tag browser'))
except:
pass # Using Qt < 4.7
self.item_search.setToolTip(_( self.item_search.setToolTip(_(
'Search for items. This is a "contains" search; items containing the\n' 'Search for items. This is a "contains" search; items containing the\n'
'text anywhere in the name will be found. You can limit the search\n' 'text anywhere in the name will be found. You can limit the search\n'
@ -387,9 +383,9 @@ class TagBrowserWidget(QWidget): # {{{
ac.triggered.connect(self.search_button.click) ac.triggered.connect(self.search_button.click)
self.expand_button = QToolButton() self.expand_button = QToolButton()
self.expand_button.setText('-') self.expand_button.setText('')
self.expand_button.setToolTip(_('Collapse all categories')) self.expand_button.setToolTip(_('Collapse all categories'))
search_layout.addWidget(self.expand_button) search_layout.insertWidget(0, self.expand_button)
search_layout.setStretch(0, 10) search_layout.setStretch(0, 10)
search_layout.setStretch(1, 1) search_layout.setStretch(1, 1)
search_layout.setStretch(2, 1) search_layout.setStretch(2, 1)
@ -428,13 +424,22 @@ class TagBrowserWidget(QWidget): # {{{
self.not_found_label_timer.setSingleShot(True) self.not_found_label_timer.setSingleShot(True)
self.not_found_label_timer.timeout.connect(self.not_found_label_timer_event, self.not_found_label_timer.timeout.connect(self.not_found_label_timer_event,
type=Qt.QueuedConnection) type=Qt.QueuedConnection)
self.toggle_search_button = b = QToolButton(self)
parent.alter_tb = l = QPushButton(parent) b.setIcon(QIcon(I('search.png')))
l.setText(_('Alter Tag browser')) b.setCheckable(True)
l.setIcon(QIcon(I('tags.png'))) search_layout.insertWidget(1, b)
b.setChecked(gprefs.get('tag browser search box visible', False))
b.setToolTip(_('Search for items in the Tag browser'))
b.toggled.connect(self.update_search_state)
parent.alter_tb = l = QToolButton(parent)
l.setPopupMode(l.InstantPopup)
l.setToolTip(_('Alter Tag browser'))
l.setIcon(QIcon(I('config.png')))
l.m = QMenu() l.m = QMenu()
l.setMenu(l.m) l.setMenu(l.m)
self._layout.addWidget(l) self._layout.addLayout(search_layout)
search_layout.insertWidget(0, l)
self.update_search_state()
ac = QAction(parent) ac = QAction(parent)
parent.addAction(ac) parent.addAction(ac)
parent.keyboard.register_shortcut('tag browser alter', parent.keyboard.register_shortcut('tag browser alter',
@ -493,6 +498,14 @@ class TagBrowserWidget(QWidget): # {{{
# self.leak_test_timer.timeout.connect(self.test_for_leak) # self.leak_test_timer.timeout.connect(self.test_for_leak)
# self.leak_test_timer.start(5000) # self.leak_test_timer.start(5000)
def save_state(self):
gprefs.set('tag browser search box visible', self.toggle_search_button.isChecked())
def update_search_state(self):
shown = self.toggle_search_button.isChecked()
self.search_button.setVisible(shown)
self.item_search.setVisible(shown)
def toggle_item(self): def toggle_item(self):
self.tags_view.toggle_current_index() self.tags_view.toggle_current_index()

View File

@ -890,6 +890,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{
config.set('main_window_geometry', self.saveGeometry()) config.set('main_window_geometry', self.saveGeometry())
dynamic.set('sort_history', self.library_view.model().sort_history) dynamic.set('sort_history', self.library_view.model().sort_history)
self.save_layout_state() self.save_layout_state()
self.stack.tb_widget.save_state()
def quit(self, checked=True, restart=False, debug_on_restart=False, def quit(self, checked=True, restart=False, debug_on_restart=False,
confirm_quit=True): confirm_quit=True):