From f328f4d8eb8acd93cb634f3372bc2abda5b93385 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 12 Jun 2017 22:37:09 +0530 Subject: [PATCH 1/9] pep8 --- src/calibre/db/cli/cmd_add.py | 1 + src/calibre/db/fields.py | 2 +- src/calibre/devices/kobo/driver.py | 6 +++--- src/calibre/utils/formatter.py | 4 ++-- src/calibre/utils/formatter_functions.py | 3 +++ 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/calibre/db/cli/cmd_add.py b/src/calibre/db/cli/cmd_add.py index 2e00cfb8a0..e5edcaf403 100644 --- a/src/calibre/db/cli/cmd_add.py +++ b/src/calibre/db/cli/cmd_add.py @@ -20,6 +20,7 @@ from calibre.utils.localization import canonicalize_lang readonly = False version = 0 # change this if you change signature of implementation() + def to_stream(data): ans = BytesIO(data[1]) ans.name = data[0] diff --git a/src/calibre/db/fields.py b/src/calibre/db/fields.py index e00307187b..036a04f771 100644 --- a/src/calibre/db/fields.py +++ b/src/calibre/db/fields.py @@ -25,6 +25,7 @@ from calibre.utils.localization import calibre_langcode_to_name def bool_sort_key(bools_are_tristate): return (lambda x:{True: 1, False: 2, None: 3}.get(x, 3)) if bools_are_tristate else lambda x:{True: 1, False: 2, None: 2}.get(x, 2) + IDENTITY = lambda x: x @@ -756,4 +757,3 @@ def create_field(name, table, bools_are_tristate, get_template_functions): elif table.metadata['datatype'] == 'series': cls = SeriesField return cls(name, table, bools_are_tristate, get_template_functions) - diff --git a/src/calibre/devices/kobo/driver.py b/src/calibre/devices/kobo/driver.py index 9bd21b1665..867079701a 100644 --- a/src/calibre/devices/kobo/driver.py +++ b/src/calibre/devices/kobo/driver.py @@ -1451,15 +1451,15 @@ class KOBOTOUCH(KOBO): def open_linux(self): super(KOBOTOUCH, self).open_linux() - + self.swap_drives_if_needed() def open_osx(self): # Just dump some info to the logs. super(KOBOTOUCH, self).open_osx() - # Wrap some debugging output in a try/except so that it unlikely to break things completely. - try: + # Wrap some debugging output in a try/except so that it unlikely to break things completely. + try: if DEBUG: from calibre.constants import plugins usbobserver, usbobserver_err = plugins['usbobserver'] diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index 9e9e3130a5..2a47fc5823 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -12,8 +12,7 @@ import re, string, traceback from calibre import prints from calibre.constants import DEBUG -from calibre.utils.formatter_functions import formatter_functions, compile_user_function -from calibre.utils.config import tweaks +from calibre.utils.formatter_functions import formatter_functions class _Parser(object): @@ -174,6 +173,7 @@ class _Parser(object): else: self.error(_('expression is not function or constant')) + class TemplateFormatter(string.Formatter): ''' Provides a format function that substitutes '' for any missing value diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index bd3d20ae6e..c5feaf0688 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -1635,6 +1635,7 @@ class UserFunction(FormatterUserFunction): cls = locals_['UserFunction'](name, doc, arg_count, eval_func) return cls + def compile_user_template_functions(funcs): compiled_funcs = {} for func in funcs: @@ -1653,6 +1654,7 @@ def compile_user_template_functions(funcs): traceback.print_exc() return compiled_funcs + def load_user_template_functions(library_uuid, funcs, precompiled_user_functions=None): unload_user_template_functions(library_uuid) if precompiled_user_functions: @@ -1661,5 +1663,6 @@ def load_user_template_functions(library_uuid, funcs, precompiled_user_functions compiled_funcs = compile_user_template_functions(funcs) formatter_functions().register_functions(library_uuid, compiled_funcs.values()) + def unload_user_template_functions(library_uuid): formatter_functions().unregister_functions(library_uuid) From 713da0ad7ba5ae16fb6897245cd93df1d108f1dd Mon Sep 17 00:00:00 2001 From: bobbysteel Date: Mon, 12 Jun 2017 22:36:32 +0100 Subject: [PATCH 2/9] remove one more "follow" nag --- recipes/nytimes.recipe | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recipes/nytimes.recipe b/recipes/nytimes.recipe index ebe4b09379..3763804257 100644 --- a/recipes/nytimes.recipe +++ b/recipes/nytimes.recipe @@ -231,7 +231,8 @@ class NYTimes(BasicNewsRecipe): re.compile('commentCount'), 'lede-container', 'credit', - 'caption-video' + 'caption-video', + 'upshot-social' ]}), dict( attrs={'class': lambda x: x and 'related-coverage-marginalia' in x.split()}), From be88316b10bdbabc12453195a169ba50f3f79bf1 Mon Sep 17 00:00:00 2001 From: bobbysteel Date: Mon, 12 Jun 2017 22:37:52 +0100 Subject: [PATCH 3/9] remove one more "follow" nag --- recipes/nytimes_sub.recipe | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/recipes/nytimes_sub.recipe b/recipes/nytimes_sub.recipe index 94007285e7..317a55fdf9 100644 --- a/recipes/nytimes_sub.recipe +++ b/recipes/nytimes_sub.recipe @@ -231,7 +231,8 @@ class NYTimes(BasicNewsRecipe): re.compile('commentCount'), 'lede-container', 'credit', - 'caption-video' + 'caption-video', + 'upshot-social' ]}), dict( attrs={'class': lambda x: x and 'related-coverage-marginalia' in x.split()}), From f2e479cfbb4ac8dfaea50dd0a7a8d267a1e84b5b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 13 Jun 2017 08:18:38 +0530 Subject: [PATCH 4/9] Also flatten the search highlights toggle button --- src/calibre/gui2/layout.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/calibre/gui2/layout.py b/src/calibre/gui2/layout.py index e6d83ce5e1..f70becdf0a 100644 --- a/src/calibre/gui2/layout.py +++ b/src/calibre/gui2/layout.py @@ -230,6 +230,9 @@ class SearchBar(QFrame): # {{{ _('Do Quick Search (you can also press the Enter key)')) x = parent.highlight_only_button = QToolButton(self) + x.setAutoRaise(True) + x.setText(_('Highlight')) + x.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) x.setIcon(QIcon(I('arrow-down.png'))) l.addWidget(x) From b363c3809b2393df5d4c7cd74eba0bbfdb319474 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 13 Jun 2017 08:25:04 +0530 Subject: [PATCH 5/9] ... --- src/calibre/gui2/tag_browser/ui.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/tag_browser/ui.py b/src/calibre/gui2/tag_browser/ui.py index f6551569f7..b25c45e7a1 100644 --- a/src/calibre/gui2/tag_browser/ui.py +++ b/src/calibre/gui2/tag_browser/ui.py @@ -380,7 +380,7 @@ class TagBrowserBar(QWidget): # {{{ ac = QAction(parent) parent.addAction(ac) parent.keyboard.register_shortcut('tag browser find box', - _('Find item'), default_keys=(), + _('Find next match'), default_keys=(), action=ac, group=_('Tag browser')) ac.triggered.connect(self.set_focus_to_find_box) @@ -393,7 +393,7 @@ class TagBrowserBar(QWidget): # {{{ ac = QAction(parent) parent.addAction(ac) parent.keyboard.register_shortcut('tag browser find button', - _('Find button'), default_keys=(), + _('Find in Tag browser'), default_keys=(), action=ac, group=_('Tag browser')) ac.triggered.connect(self.search_button.click) @@ -489,7 +489,7 @@ class TagBrowserWidget(QWidget): # {{{ ac = QAction(parent) parent.addAction(ac) parent.keyboard.register_shortcut('tag browser alter', - _('Alter Tag browser'), default_keys=(), + _('Change Tag browser'), default_keys=(), action=ac, group=_('Tag browser')) ac.triggered.connect(l.showMenu) From 9c68e1d14624d6fc3c5eb7f331cbfad79d4a18ca Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 13 Jun 2017 08:33:13 +0530 Subject: [PATCH 6/9] Fix up/down arrow keys not working in Find in Tag browser box --- src/calibre/gui2/tag_browser/ui.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/tag_browser/ui.py b/src/calibre/gui2/tag_browser/ui.py index b25c45e7a1..5443f41a10 100644 --- a/src/calibre/gui2/tag_browser/ui.py +++ b/src/calibre/gui2/tag_browser/ui.py @@ -341,6 +341,22 @@ class TagBrowserMixin(object): # {{{ # }}} +class FindBox(HistoryLineEdit): # {{{ + + def keyPressEvent(self, event): + k = event.key() + if k not in (Qt.Key_Up, Qt.Key_Down): + return HistoryLineEdit.keyPressEvent(self, event) + self.blockSignals(True) + if k == Qt.Key_Down and self.currentIndex() == 0 and not self.lineEdit().text(): + self.setCurrentIndex(1), self.setCurrentIndex(0) + event.accept() + else: + HistoryLineEdit.keyPressEvent(self, event) + self.blockSignals(False) +# }}} + + class TagBrowserBar(QWidget): # {{{ def __init__(self, parent): @@ -365,7 +381,7 @@ class TagBrowserBar(QWidget): # {{{ self.label = la = QLabel(self) la.setText(_('Tag browser')) - self.item_search = HistoryLineEdit(parent) + self.item_search = FindBox(parent) self.item_search.setMinimumContentsLength(5) self.item_search.setSizeAdjustPolicy(self.item_search.AdjustToMinimumContentsLengthWithIcon) self.item_search.initialize('tag_browser_search') From cd53c0d904a5720d20f271c3b58addf321e1b2b6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 13 Jun 2017 08:36:40 +0530 Subject: [PATCH 7/9] Dont show the Find text on the search button when displaying the find box --- src/calibre/gui2/tag_browser/ui.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/tag_browser/ui.py b/src/calibre/gui2/tag_browser/ui.py index 5443f41a10..0cd82af9de 100644 --- a/src/calibre/gui2/tag_browser/ui.py +++ b/src/calibre/gui2/tag_browser/ui.py @@ -402,9 +402,7 @@ class TagBrowserBar(QWidget): # {{{ self.search_button = QToolButton() self.search_button.setCursor(Qt.PointingHandCursor) - self.search_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.search_button.setIcon(QIcon(I('search.png'))) - self.search_button.setText(_('Find')) self.search_button.setToolTip(_('Find the first/next matching item')) ac = QAction(parent) parent.addAction(ac) @@ -415,7 +413,7 @@ class TagBrowserBar(QWidget): # {{{ self.toggle_search_button = b = QToolButton(self) le = self.item_search.lineEdit() - le.addAction(QIcon(I('window-close.png')), le.LeadingPosition).triggered.connect(self.toggle_search_button.click) + le.addAction(QIcon(I('window-close.png')), le.LeadingPosition).triggered.connect(self.close_find_box) b.setCursor(Qt.PointingHandCursor) b.setIcon(QIcon(I('search.png'))) b.setCheckable(True) @@ -425,6 +423,11 @@ class TagBrowserBar(QWidget): # {{{ b.toggled.connect(self.update_searchbar_state) self.update_searchbar_state() + def close_find_box(self): + self.item_search.setCurrentIndex(0) + self.item_search.setCurrentText('') + self.toggle_search_button.click() + def set_focus_to_find_box(self): self.toggle_search_button.setChecked(True) self.item_search.setFocus() From 5c94fe50b29c08dbddfc7a05bacf0e8866036319 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 13 Jun 2017 08:45:31 +0530 Subject: [PATCH 8/9] Move cover grid sort button to after the VL button so it is a little more prominent --- src/calibre/gui2/layout.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/calibre/gui2/layout.py b/src/calibre/gui2/layout.py index f70becdf0a..4d38904e05 100644 --- a/src/calibre/gui2/layout.py +++ b/src/calibre/gui2/layout.py @@ -201,6 +201,23 @@ class SearchBar(QFrame): # {{{ self.vl_sep.setFrameStyle(QFrame.VLine | QFrame.Sunken) l.addWidget(self.vl_sep) + parent.sort_sep = QFrame(self) + parent.sort_sep.setFrameStyle(QFrame.VLine | QFrame.Sunken) + parent.sort_sep.setVisible(False) + parent.sort_button = self.sort_button = sb = QToolButton(self) + sb.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) + sb.setToolTip(_('Change how the displayed books are sorted')) + sb.setCursor(Qt.PointingHandCursor) + sb.setPopupMode(QToolButton.InstantPopup) + sb.setAutoRaise(True) + sb.setText(_('Sort')) + sb.setIcon(QIcon(I('sort.png'))) + sb.setMenu(QMenu()) + sb.menu().aboutToShow.connect(self.populate_sort_menu) + sb.setVisible(False) + l.addWidget(sb) + l.addWidget(parent.sort_sep) + x = parent.search = SearchBox2(self) x.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum) x.setObjectName("search") @@ -273,23 +290,6 @@ class SearchBar(QFrame): # {{{ l.addWidget(x) x.setVisible(not tweaks['show_saved_search_box']) - parent.sort_sep = QFrame(self) - parent.sort_sep.setFrameStyle(QFrame.VLine | QFrame.Sunken) - parent.sort_sep.setVisible(False) - l.addWidget(parent.sort_sep) - parent.sort_button = self.sort_button = sb = QToolButton(self) - sb.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) - sb.setToolTip(_('Change how the displayed books are sorted')) - sb.setCursor(Qt.PointingHandCursor) - sb.setPopupMode(QToolButton.InstantPopup) - sb.setAutoRaise(True) - sb.setText(_('Sort')) - sb.setIcon(QIcon(I('sort.png'))) - sb.setMenu(QMenu()) - sb.menu().aboutToShow.connect(self.populate_sort_menu) - sb.setVisible(False) - l.addWidget(sb) - def populate_sort_menu(self): from calibre.gui2.ui import get_gui get_gui().iactions['Sort By'].update_menu(self.sort_button.menu()) From 0dd9de8aae612b0ec7c6691cc613125c1c049922 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 13 Jun 2017 09:21:20 +0530 Subject: [PATCH 9/9] Also change text of highlight button when changing icon --- src/calibre/gui2/layout.py | 1 + src/calibre/gui2/search_box.py | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/layout.py b/src/calibre/gui2/layout.py index 4d38904e05..21d8d48168 100644 --- a/src/calibre/gui2/layout.py +++ b/src/calibre/gui2/layout.py @@ -249,6 +249,7 @@ class SearchBar(QFrame): # {{{ x = parent.highlight_only_button = QToolButton(self) x.setAutoRaise(True) x.setText(_('Highlight')) + x.setCursor(Qt.PointingHandCursor) x.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) x.setIcon(QIcon(I('arrow-down.png'))) l.addWidget(x) diff --git a/src/calibre/gui2/search_box.py b/src/calibre/gui2/search_box.py index 3cf8bf6544..f244677eb2 100644 --- a/src/calibre/gui2/search_box.py +++ b/src/calibre/gui2/search_box.py @@ -492,10 +492,13 @@ class SearchBoxMixin(object): # {{{ self.focus_to_library() def set_highlight_only_button_icon(self): + b = self.highlight_only_button if config['highlight_search_matches']: - self.highlight_only_button.setIcon(QIcon(I('highlight_only_on.png'))) + b.setIcon(QIcon(I('highlight_only_on.png'))) + b.setText(_('Filter')) else: - self.highlight_only_button.setIcon(QIcon(I('highlight_only_off.png'))) + b.setIcon(QIcon(I('highlight_only_off.png'))) + b.setText(_('Highlight')) self.highlight_only_button.setVisible(gprefs['show_highlight_toggle_button']) self.library_view.model().set_highlight_only(config['highlight_search_matches'])