From 35ee75d43459b4ef23e391913c5ca7e1d6b9310a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Sat, 21 May 2011 13:41:10 +0200 Subject: [PATCH 01/50] Woblink store --- src/calibre/customize/builtins.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index ac26544207..fd80f14b60 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1236,6 +1236,12 @@ class StoreWizardsTowerBooksStore(StoreBase): description = 'Wizard\'s Tower Press.' actual_plugin = 'calibre.gui2.store.wizards_tower_books_plugin:WizardsTowerBooksStore' +class StoreWoblinkStore(StoreBase): + name = 'Woblink' + author = 'Tomasz Długosz' + description = _('Czytanie zdarza się wszędzie!') + actual_plugin = 'calibre.gui2.store.woblink_plugin:WoblinkStore' + plugins += [ StoreArchiveOrgStore, StoreAmazonKindleStore, @@ -1264,7 +1270,8 @@ plugins += [ StoreSmashwordsStore, StoreWaterstonesUKStore, StoreWeightlessBooksStore, - StoreWizardsTowerBooksStore + StoreWizardsTowerBooksStore, + StoreWoblinkStore ] # }}} From 215e3fa699d9e8b03e88221c1ce9c38feef44702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Sat, 21 May 2011 13:44:04 +0200 Subject: [PATCH 02/50] Woblink store, missed file --- src/calibre/gui2/store/woblink_plugin.py | 76 ++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/calibre/gui2/store/woblink_plugin.py diff --git a/src/calibre/gui2/store/woblink_plugin.py b/src/calibre/gui2/store/woblink_plugin.py new file mode 100644 index 0000000000..9659f72fd1 --- /dev/null +++ b/src/calibre/gui2/store/woblink_plugin.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) + +__license__ = 'GPL 3' +__copyright__ = '2011, Tomasz Długosz ' +__docformat__ = 'restructuredtext en' + +import re +import urllib +from contextlib import closing + +from lxml import html + +from PyQt4.Qt import QUrl + +from calibre import browser, url_slash_cleaner +from calibre.gui2 import open_url +from calibre.gui2.store import StorePlugin +from calibre.gui2.store.basic_config import BasicStoreConfig +from calibre.gui2.store.search_result import SearchResult +from calibre.gui2.store.web_store_dialog import WebStoreDialog + +class WoblinkStore(BasicStoreConfig, StorePlugin): + + def open(self, parent=None, detail_item=None, external=False): + + url = 'http://woblink.com/publication' + detail_url = None + + if detail_item: + detail_url = 'http://woblink.com' + detail_item + + if external or self.config.get('open_external', False): + open_url(QUrl(url_slash_cleaner(detail_url if detail_url else url))) + else: + d = WebStoreDialog(self.gui, url, parent, detail_url) + d.setWindowTitle(self.name) + d.set_tags(self.config.get('tags', '')) + d.exec_() + + def search(self, query, max_results=10, timeout=60): + url = 'http://woblink.com/publication?query' + urllib.quote_plus(query.encode('utf-8')) + + br = browser() + + counter = max_results + with closing(br.open(url, timeout=timeout)) as f: + doc = html.fromstring(f.read()) + for data in doc.xpath('//div[@class="book-item"]'): + if counter <= 0: + break + + id = ''.join(data.xpath('.//td[@class="w10 va-t"]/a[1]/@href')) + if not id: + continue + + cover_url = ''.join(data.xpath('.//td[@class="w10 va-t"]/a[1]/img/@src')) + title = ''.join(data.xpath('.//h3[@class="title"]/a[1]/text()')) + author = ''.join(data.xpath('.//p[@class="author"]/a[1]/text()')) + price = ''.join(data.xpath('.//div[@class="prices"]/p[1]/span/text()')) + price = re.sub('PLN', ' zł', price) + price = re.sub('\.', ',', price) + + counter -= 1 + + s = SearchResult() + s.cover_url = 'http://woblink.com' + cover_url + s.title = title.strip() + s.author = author.strip() + s.price = price + s.detail_item = id.strip() + s.drm = SearchResult.DRM_LOCKED + s.formats = 'EPUB' + + yield s From f14c1a65fdb6aa6f4e0a7f873b8d57bd11d3f96b Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 21 May 2011 09:35:45 -0400 Subject: [PATCH 03/50] Store: Amazon UK and DE, fix search url. --- src/calibre/gui2/store/amazon_de_plugin.py | 2 +- src/calibre/gui2/store/amazon_uk_plugin.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/store/amazon_de_plugin.py b/src/calibre/gui2/store/amazon_de_plugin.py index 782d6bf0ed..f7b17a2e83 100644 --- a/src/calibre/gui2/store/amazon_de_plugin.py +++ b/src/calibre/gui2/store/amazon_de_plugin.py @@ -16,7 +16,7 @@ class AmazonDEKindleStore(AmazonKindleStore): For comments on the implementation, please see amazon_plugin.py ''' - search_url = 'http://www.amazon.de/s/url=search-alias%3Ddigital-text&field-keywords=' + search_url = 'http://www.amazon.de/s/?url=search-alias%3Ddigital-text&field-keywords=' details_url = 'http://amazon.de/dp/' drm_search_text = u'Gleichzeitige Verwendung von Geräten' drm_free_text = u'Keine Einschränkung' diff --git a/src/calibre/gui2/store/amazon_uk_plugin.py b/src/calibre/gui2/store/amazon_uk_plugin.py index 770db6cfd9..9544add17c 100644 --- a/src/calibre/gui2/store/amazon_uk_plugin.py +++ b/src/calibre/gui2/store/amazon_uk_plugin.py @@ -17,7 +17,7 @@ class AmazonUKKindleStore(AmazonKindleStore): For comments on the implementation, please see amazon_plugin.py ''' - search_url = 'http://www.amazon.co.uk/s/url=search-alias%3Ddigital-text&field-keywords=' + search_url = 'http://www.amazon.co.uk/s/?url=search-alias%3Ddigital-text&field-keywords=' details_url = 'http://amazon.co.uk/dp/' def open(self, parent=None, detail_item=None, external=False): From c3a2c3f458304abaef826e08f61265a235df5d50 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sat, 21 May 2011 19:24:04 +0100 Subject: [PATCH 04/50] Add option to color custom enumeration values in the library view --- src/calibre/gui2/library/delegates.py | 25 ++++++++++++++++ .../gui2/preferences/create_custom_column.py | 21 ++++++++++++-- .../gui2/preferences/create_custom_column.ui | 29 ++++++++++++++++--- 3 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index e2234f6df5..ae01081736 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -274,6 +274,31 @@ class CcEnumDelegate(QStyledItemDelegate): # {{{ Delegate for text/int/float data. ''' + def __init__(self, parent): + QStyledItemDelegate.__init__(self, parent) + self.document = QTextDocument() + + def paint(self, painter, option, index): + style = self.parent().style() + txt = unicode(index.data(Qt.DisplayRole).toString()) + self.document.setPlainText(txt) + painter.save() + if hasattr(QStyle, 'CE_ItemViewItem'): + style.drawControl(QStyle.CE_ItemViewItem, option, + painter, self.parent()) + elif option.state & QStyle.State_Selected: + painter.fillRect(option.rect, option.palette.highlight()) + m = index.model() + col = m.column_map[index.column()] + colors = m.custom_columns[col]['display'].get('enum_colors', []) + values = m.custom_columns[col]['display']['enum_values'] + if len(colors) > 0 and txt in values: + painter.fillRect(option.rect, QColor(colors[values.index(txt)])) + painter.setClipRect(option.rect) + painter.translate(option.rect.topLeft()) + self.document.drawContents(painter) + painter.restore() + def createEditor(self, parent, option, index): m = index.model() col = m.column_map[index.column()] diff --git a/src/calibre/gui2/preferences/create_custom_column.py b/src/calibre/gui2/preferences/create_custom_column.py index 7b891b782c..180c3aed7a 100644 --- a/src/calibre/gui2/preferences/create_custom_column.py +++ b/src/calibre/gui2/preferences/create_custom_column.py @@ -6,7 +6,7 @@ __copyright__ = '2010, Kovid Goyal ' import re from functools import partial -from PyQt4.Qt import QDialog, Qt, QListWidgetItem, QVariant +from PyQt4.Qt import QDialog, Qt, QListWidgetItem, QVariant, QColor from calibre.gui2.preferences.create_custom_column_ui import Ui_QCreateCustomColumn from calibre.gui2 import error_dialog @@ -126,6 +126,7 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): c['display'].get('make_category', False)) elif ct == 'enumeration': self.enum_box.setText(','.join(c['display'].get('enum_values', []))) + self.enum_colors.setText(','.join(c['display'].get('enum_colors', []))) self.datatype_changed() if ct in ['text', 'composite', 'enumeration']: self.use_decorations.setChecked(c['display'].get('use_decorations', False)) @@ -170,7 +171,7 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): for x in ('box', 'default_label', 'label', 'sort_by', 'sort_by_label', 'make_category'): getattr(self, 'composite_'+x).setVisible(col_type in ['composite', '*composite']) - for x in ('box', 'default_label', 'label'): + for x in ('box', 'default_label', 'label', 'colors', 'colors_label'): getattr(self, 'enum_'+x).setVisible(col_type == 'enumeration') self.use_decorations.setVisible(col_type in ['text', 'composite', 'enumeration']) self.is_names.setVisible(col_type == '*text') @@ -247,7 +248,21 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): if l[i] in l[i+1:]: return self.simple_error('', _('The value "{0}" is in the ' 'list more than once').format(l[i])) - display_dict = {'enum_values': l} + c = unicode(self.enum_colors.text()) + if c: + c = [v.strip() for v in unicode(self.enum_colors.text()).split(',')] + else: + c = [] + print c, len(c) + if len(c) != 0 and len(c) != len(l): + return self.simple_error('', _('The colors box must be empty or ' + 'contain the same number of items as the value box')) + for tc in c: + if tc not in QColor.colorNames(): + return self.simple_error('', + _('The color {0} is unknown').format(tc)) + + display_dict = {'enum_values': l, 'enum_colors': c} elif col_type == 'text' and is_multiple: display_dict = {'is_names': self.is_names.isChecked()} diff --git a/src/calibre/gui2/preferences/create_custom_column.ui b/src/calibre/gui2/preferences/create_custom_column.ui index 619b0c6212..2bdadd4b9d 100644 --- a/src/calibre/gui2/preferences/create_custom_column.ui +++ b/src/calibre/gui2/preferences/create_custom_column.ui @@ -304,8 +304,8 @@ Everything else will show nothing. - - + + @@ -320,13 +320,34 @@ four values, the first of them being the empty value. - + The empty string is always the first value - Default: (nothing) + Values + + + + + + + + 0 + 0 + + + + A list of color names to use when displaying an item. The +list must be empty or contain a color for each value. + + + + + + + Colors From 994974fb59afea4e781c99b0019c4d425f4ee714 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sat, 21 May 2011 19:34:23 +0100 Subject: [PATCH 05/50] Add tooltip listing all colors available --- src/calibre/gui2/preferences/create_custom_column.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/preferences/create_custom_column.py b/src/calibre/gui2/preferences/create_custom_column.py index 180c3aed7a..3a245580dd 100644 --- a/src/calibre/gui2/preferences/create_custom_column.py +++ b/src/calibre/gui2/preferences/create_custom_column.py @@ -132,6 +132,9 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): self.use_decorations.setChecked(c['display'].get('use_decorations', False)) elif ct == '*text': self.is_names.setChecked(c['display'].get('is_names', False)) + + all_colors = [unicode(s) for s in list(QColor.colorNames())] + self.enum_colors_label.setToolTip('

' + ', '.join(all_colors) + '

') self.exec_() def shortcut_activated(self, url): @@ -253,7 +256,6 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn): c = [v.strip() for v in unicode(self.enum_colors.text()).split(',')] else: c = [] - print c, len(c) if len(c) != 0 and len(c) != len(l): return self.simple_error('', _('The colors box must be empty or ' 'contain the same number of items as the value box')) From 6eec4fa410eddb376b62d064549460ee754031bb Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sat, 21 May 2011 19:40:27 +0100 Subject: [PATCH 06/50] More robust coloring code in the CC Enum Delegate --- src/calibre/gui2/library/delegates.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index ae01081736..1af0482a31 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -289,11 +289,14 @@ class CcEnumDelegate(QStyledItemDelegate): # {{{ elif option.state & QStyle.State_Selected: painter.fillRect(option.rect, option.palette.highlight()) m = index.model() - col = m.column_map[index.column()] - colors = m.custom_columns[col]['display'].get('enum_colors', []) - values = m.custom_columns[col]['display']['enum_values'] + cc = m.custom_columns[m.column_map[index.column()]]['display'] + colors = cc.get('enum_colors', []) + values = cc.get('enum_values', []) if len(colors) > 0 and txt in values: - painter.fillRect(option.rect, QColor(colors[values.index(txt)])) + try: + painter.fillRect(option.rect, QColor(colors[values.index(txt)])) + except: + pass painter.setClipRect(option.rect) painter.translate(option.rect.topLeft()) self.document.drawContents(painter) From 4a8f83305f56679a3ded6f108d4475789ec1c2bd Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 21 May 2011 18:39:54 -0400 Subject: [PATCH 07/50] Store: Add config widget for search accessible via the store plugin preferences. --- src/calibre/customize/builtins.py | 11 +++++ .../gui2/store/search/download_thread.py | 13 +++--- src/calibre/gui2/store/search/models.py | 6 +-- src/calibre/gui2/store/search/search.py | 45 +++++++++++++++---- 4 files changed, 58 insertions(+), 17 deletions(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index ac26544207..8490630bb8 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -854,6 +854,17 @@ class ActionStore(InterfaceActionBase): name = 'Store' author = 'John Schember' actual_plugin = 'calibre.gui2.actions.store:StoreAction' + + def customization_help(self, gui=False): + return 'Customize the behavior of the store search.' + + def config_widget(self): + from calibre.gui2.store.config.store import config_widget as get_cw + return get_cw() + + def save_settings(self, config_widget): + from calibre.gui2.store.config.store import save_settings as save + save(config_widget) plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog, ActionConvert, ActionDelete, ActionEditMetadata, ActionView, diff --git a/src/calibre/gui2/store/search/download_thread.py b/src/calibre/gui2/store/search/download_thread.py index 97279d7773..1fc74a5748 100644 --- a/src/calibre/gui2/store/search/download_thread.py +++ b/src/calibre/gui2/store/search/download_thread.py @@ -22,7 +22,7 @@ class GenericDownloadThreadPool(object): at the end of the function. ''' - def __init__(self, thread_type, thread_count): + def __init__(self, thread_type, thread_count=1): self.thread_type = thread_type self.thread_count = thread_count @@ -30,6 +30,9 @@ class GenericDownloadThreadPool(object): self.results = Queue() self.threads = [] + def set_thread_count(self, thread_count): + self.thread_count = thread_count + def add_task(self): ''' This must be implemented in a sub class and this function @@ -92,8 +95,8 @@ class SearchThreadPool(GenericDownloadThreadPool): def __init__(self, thread_count): GenericDownloadThreadPool.__init__(self, SearchThread, thread_count) - def add_task(self, query, store_name, store_plugin, timeout): - self.tasks.put((query, store_name, store_plugin, timeout)) + def add_task(self, query, store_name, store_plugin, max_results, timeout): + self.tasks.put((query, store_name, store_plugin, max_results, timeout)) GenericDownloadThreadPool.add_task(self) @@ -112,8 +115,8 @@ class SearchThread(Thread): def run(self): while self._run and not self.tasks.empty(): try: - query, store_name, store_plugin, timeout = self.tasks.get() - for res in store_plugin.search(query, timeout=timeout): + query, store_name, store_plugin, max_results, timeout = self.tasks.get() + for res in store_plugin.search(query, max_results=max_results, timeout=timeout): if not self._run: return res.store_name = store_name diff --git a/src/calibre/gui2/store/search/models.py b/src/calibre/gui2/store/search/models.py index adc90e3b14..059c1d73ed 100644 --- a/src/calibre/gui2/store/search/models.py +++ b/src/calibre/gui2/store/search/models.py @@ -33,7 +33,7 @@ class Matches(QAbstractItemModel): HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store')] HTML_COLS = (1, 4) - def __init__(self): + def __init__(self, cover_thread_count=2, detail_thread_count=4): QAbstractItemModel.__init__(self) self.DRM_LOCKED_ICON = QPixmap(I('drm-locked.png')).scaledToHeight(64, @@ -51,8 +51,8 @@ class Matches(QAbstractItemModel): self.matches = [] self.query = '' self.search_filter = SearchFilter() - self.cover_pool = CoverThreadPool(2) - self.details_pool = DetailsThreadPool(4) + self.cover_pool = CoverThreadPool(cover_thread_count) + self.details_pool = DetailsThreadPool(detail_thread_count) self.sort_col = 2 self.sort_order = Qt.AscendingOrder diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py index f9ac45e707..906ba0b4ff 100644 --- a/src/calibre/gui2/store/search/search.py +++ b/src/calibre/gui2/store/search/search.py @@ -18,9 +18,6 @@ from calibre.gui2.store.search.download_thread import SearchThreadPool, \ CacheUpdateThreadPool from calibre.gui2.store.search.search_ui import Ui_Dialog -HANG_TIME = 75000 # milliseconds seconds -TIMEOUT = 75 # seconds - class SearchDialog(QDialog, Ui_Dialog): def __init__(self, istores, parent=None, query=''): @@ -28,13 +25,22 @@ class SearchDialog(QDialog, Ui_Dialog): self.setupUi(self) self.config = JSONConfig('store/search') - self.search_edit.initialize('store_search_search') + + # Loads variables that store various settings. + # This needs to be called soon in __init__ because + # the variables it sets up are used later. + self.load_settings() # We keep a cache of store plugins and reference them by name. self.store_plugins = istores - self.search_pool = SearchThreadPool(4) - self.cache_pool = CacheUpdateThreadPool(2) + + # Setup our worker threads. + self.search_pool = SearchThreadPool(self.search_thread_count) + self.cache_pool = CacheUpdateThreadPool(self.cache_thread_count) + self.results_view.model().cover_pool.set_thread_count(self.cover_thread_count) + self.results_view.model().details_pool.set_thread_count(self.details_thread_count) + # Check for results and hung threads. self.checker = QTimer() self.progress_checker = QTimer() @@ -42,7 +48,7 @@ class SearchDialog(QDialog, Ui_Dialog): # Update store caches silently. for p in self.store_plugins.values(): - self.cache_pool.add_task(p, 30) + self.cache_pool.add_task(p, self.timeout) # Add check boxes for each store so the user # can disable searching specific stores on a @@ -128,7 +134,7 @@ class SearchDialog(QDialog, Ui_Dialog): # Add plugins that the user has checked to the search pool's work queue. for n in store_names: if getattr(self, 'store_check_' + n).isChecked(): - self.search_pool.add_task(query, n, self.store_plugins[n], TIMEOUT) + self.search_pool.add_task(query, n, self.store_plugins[n], self.max_results, self.timeout) self.hang_check = 0 self.checker.start(100) self.pi.startAnimation() @@ -202,11 +208,32 @@ class SearchDialog(QDialog, Ui_Dialog): self.results_view.model().sort_order = self.config.get('sort_order', Qt.AscendingOrder) self.results_view.header().setSortIndicator(self.results_view.model().sort_col, self.results_view.model().sort_order) + def load_settings(self): + # Seconds + self.timeout = self.config.get('timeout', 75) + # Milliseconds + self.hang_time = self.config.get('hang_time', 75) * 1000 + self.max_results = self.config.get('max_results', 10) + + # Number of threads to run for each type of operation + self.search_thread_count = self.config.get('search_thread_count', 4) + self.cache_thread_count = self.config.get('cache_thread_count', 2) + self.cover_thread_count = self.config.get('cover_thread_count', 2) + self.details_thread_count = self.config.get('details_thread_count', 4) + + def config_finished(self): + self.load_settings() + + self.search_pool.set_thread_count(self.search_thread_count) + self.cache_pool.set_thread_count(self.cache_thread_count) + self.results_view.model().cover_pool.set_thread_count(self.cover_thread_count) + self.results_view.model().details_pool.set_thread_count(self.details_thread_count) + def get_results(self): # We only want the search plugins to run # a maximum set amount of time before giving up. self.hang_check += 1 - if self.hang_check >= HANG_TIME: + if self.hang_check >= self.hang_time: self.search_pool.abort() self.checker.stop() else: From 4610ea2e7209640f1d7667cf46cd4bd6b6a9c43f Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 21 May 2011 18:58:30 -0400 Subject: [PATCH 08/50] Store: Enchance search dialog. --- src/calibre/gui2/store/search/search.py | 10 +- src/calibre/gui2/store/search/search.ui | 169 +++++++++++++++--------- 2 files changed, 108 insertions(+), 71 deletions(-) diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py index 906ba0b4ff..e76f15c58e 100644 --- a/src/calibre/gui2/store/search/search.py +++ b/src/calibre/gui2/store/search/search.py @@ -54,15 +54,15 @@ class SearchDialog(QDialog, Ui_Dialog): # can disable searching specific stores on a # per search basis. stores_check_widget = QWidget() - stores_group_layout = QVBoxLayout() - stores_check_widget.setLayout(stores_group_layout) + store_list_layout = QVBoxLayout() + stores_check_widget.setLayout(store_list_layout) for x in sorted(self.store_plugins.keys(), key=lambda x: x.lower()): cbox = QCheckBox(x) cbox.setChecked(False) - stores_group_layout.addWidget(cbox) + store_list_layout.addWidget(cbox) setattr(self, 'store_check_' + x, cbox) - stores_group_layout.addStretch() - self.stores_group.setWidget(stores_check_widget) + store_list_layout.addStretch() + self.store_list.setWidget(stores_check_widget) # Set the search query self.search_edit.setText(query) diff --git a/src/calibre/gui2/store/search/search.ui b/src/calibre/gui2/store/search/search.ui index 8dd423baec..42f91de735 100644 --- a/src/calibre/gui2/store/search/search.ui +++ b/src/calibre/gui2/store/search/search.ui @@ -6,8 +6,8 @@ 0 0 - 937 - 669 + 584 + 533 @@ -20,7 +20,7 @@ true - + @@ -66,8 +66,14 @@ Stores + + 0 + + + 0 + - + true @@ -76,15 +82,18 @@ 0 0 - 215 - 93 + 207 + 130 - + + + 0 + @@ -108,76 +117,104 @@ + + + + - - - Open a selected book in the system's web browser + + + + 1 + 0 + - - Open in &external browser + + + 0 + 0 + + + + true + + + + 32 + 32 + + + + false + + + false + + + false + + + true + + + false + + + + + + Configure + + + + + + + Open a selected book in the system's web browser + + + Open in &external browser + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + - - - - 2 - 0 - - - - Qt::Horizontal - - - - Qt::Horizontal - - - - - 1 - 0 - - - - - 0 - 0 - - - - true - - - - 32 - 32 - - - - false - - - false - - - false - - - true - - - false - - - -
+ + + + Books: + + + + + + + 0 + + + From 44366b2c97f4153d4efd4d329a9765144785246d Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 21 May 2011 19:09:14 -0400 Subject: [PATCH 09/50] Store: Show number of results. --- src/calibre/gui2/store/search/models.py | 7 ++++++- src/calibre/gui2/store/search/search.py | 7 +++++++ src/calibre/gui2/store/search/search.ui | 6 +++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/store/search/models.py b/src/calibre/gui2/store/search/models.py index 059c1d73ed..d7941480cc 100644 --- a/src/calibre/gui2/store/search/models.py +++ b/src/calibre/gui2/store/search/models.py @@ -9,7 +9,8 @@ __docformat__ = 'restructuredtext en' import re from operator import attrgetter -from PyQt4.Qt import (Qt, QAbstractItemModel, QVariant, QPixmap, QModelIndex, QSize) +from PyQt4.Qt import (Qt, QAbstractItemModel, QVariant, QPixmap, QModelIndex, QSize, + pyqtSignal) from calibre.gui2 import NONE from calibre.gui2.store.search_result import SearchResult @@ -30,6 +31,8 @@ def comparable_price(text): class Matches(QAbstractItemModel): + total_changed = pyqtSignal(int) + HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store')] HTML_COLS = (1, 4) @@ -69,6 +72,7 @@ class Matches(QAbstractItemModel): self.query = '' self.cover_pool.abort() self.details_pool.abort() + self.total_changed.emit(self.rowCount()) self.reset() def add_result(self, result, store_plugin): @@ -101,6 +105,7 @@ class Matches(QAbstractItemModel): self.matches = list(self.search_filter.parse(self.query)) else: self.matches = list(self.search_filter.universal_set()) + self.total_changed.emit(self.rowCount()) self.sort(self.sort_col, self.sort_order, False) self.layoutChanged.emit() diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py index e76f15c58e..18ea50f125 100644 --- a/src/calibre/gui2/store/search/search.py +++ b/src/calibre/gui2/store/search/search.py @@ -78,9 +78,11 @@ class SearchDialog(QDialog, Ui_Dialog): self.checker.timeout.connect(self.get_results) self.progress_checker.timeout.connect(self.check_progress) self.results_view.activated.connect(self.open_store) + self.results_view.model().total_changed.connect(self.update_book_total) self.select_all_stores.clicked.connect(self.stores_select_all) self.select_invert_stores.clicked.connect(self.stores_select_invert) self.select_none_stores.clicked.connect(self.stores_select_none) + self.configure.clicked.connect(self.do_config) self.finished.connect(self.dialog_closed) self.progress_checker.start(100) @@ -221,6 +223,9 @@ class SearchDialog(QDialog, Ui_Dialog): self.cover_thread_count = self.config.get('cover_thread_count', 2) self.details_thread_count = self.config.get('details_thread_count', 4) + def do_config(self): + pass + def config_finished(self): self.load_settings() @@ -249,6 +254,8 @@ class SearchDialog(QDialog, Ui_Dialog): if not self.search_pool.threads_running() and not self.results_view.model().has_results(): info_dialog(self, _('No matches'), _('Couldn\'t find any books matching your query.'), show=True, show_copy_button=False) + def update_book_total(self, total): + self.total.setText('%s' % total) def open_store(self, index): result = self.results_view.model().get_result(index) diff --git a/src/calibre/gui2/store/search/search.ui b/src/calibre/gui2/store/search/search.ui index 42f91de735..905620f688 100644 --- a/src/calibre/gui2/store/search/search.ui +++ b/src/calibre/gui2/store/search/search.ui @@ -82,8 +82,8 @@ 0 0 - 207 - 130 + 102 + 129 @@ -209,7 +209,7 @@ - + 0 From 0c315cdb1ea78634031ae603ca88bedeede359b3 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 21 May 2011 19:22:05 -0400 Subject: [PATCH 10/50] Store: Allow search to be configured in the search dialog. --- src/calibre/gui2/store/search/search.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py index 18ea50f125..3e4edf37a2 100644 --- a/src/calibre/gui2/store/search/search.py +++ b/src/calibre/gui2/store/search/search.py @@ -9,10 +9,12 @@ __docformat__ = 'restructuredtext en' import re from random import shuffle -from PyQt4.Qt import (Qt, QDialog, QTimer, QCheckBox, QVBoxLayout, QIcon, QWidget) +from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox, + QVBoxLayout, QIcon, QWidget) from calibre.gui2 import JSONConfig, info_dialog from calibre.gui2.progress_indicator import ProgressIndicator +from calibre.gui2.store.config.search_widget import StoreConfigWidget from calibre.gui2.store.search.adv_search_builder import AdvSearchBuilderDialog from calibre.gui2.store.search.download_thread import SearchThreadPool, \ CacheUpdateThreadPool @@ -224,9 +226,23 @@ class SearchDialog(QDialog, Ui_Dialog): self.details_thread_count = self.config.get('details_thread_count', 4) def do_config(self): - pass + d = QDialog(self) + button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) + v = QVBoxLayout(d) + button_box.accepted.connect(d.accept) + button_box.rejected.connect(d.reject) + d.setWindowTitle(_('Customize get books search')) + config_widget = StoreConfigWidget(self.config) + v.addWidget(config_widget) + v.addWidget(button_box) + + d.exec_() + + if d.result() == QDialog.Accepted: + config_widget.save_settings() + self.config_changed() - def config_finished(self): + def config_changed(self): self.load_settings() self.search_pool.set_thread_count(self.search_thread_count) From 894affa1b40efd9be20d5fd84f0f4be4ef5b6d3f Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 21 May 2011 19:38:48 -0400 Subject: [PATCH 11/50] Store: search dialog, change button. Add open external as a config option. --- src/calibre/gui2/store/search/search.py | 10 +++++++++- src/calibre/gui2/store/search/search.ui | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py index 3e4edf37a2..c7c252034d 100644 --- a/src/calibre/gui2/store/search/search.py +++ b/src/calibre/gui2/store/search/search.py @@ -74,6 +74,7 @@ class SearchDialog(QDialog, Ui_Dialog): self.top_layout.addWidget(self.pi) self.adv_search_button.setIcon(QIcon(I('search.png'))) + self.configure.setIcon(QIcon(I('config.png'))) self.adv_search_button.clicked.connect(self.build_adv_search) self.search.clicked.connect(self.do_search) @@ -200,7 +201,7 @@ class SearchDialog(QDialog, Ui_Dialog): else: self.resize_columns() - self.open_external.setChecked(self.config.get('open_external', True)) + self.open_external.setChecked(self.should_open_external) store_check = self.config.get('store_checked', None) if store_check: @@ -217,7 +218,9 @@ class SearchDialog(QDialog, Ui_Dialog): self.timeout = self.config.get('timeout', 75) # Milliseconds self.hang_time = self.config.get('hang_time', 75) * 1000 + self.max_results = self.config.get('max_results', 10) + self.should_open_external = self.config.get('open_external', True) # Number of threads to run for each type of operation self.search_thread_count = self.config.get('search_thread_count', 4) @@ -226,6 +229,10 @@ class SearchDialog(QDialog, Ui_Dialog): self.details_thread_count = self.config.get('details_thread_count', 4) def do_config(self): + # Save values that need to be synced between the dialog and the + # search widget. + self.config['open_external'] = self.open_external.isChecked() + d = QDialog(self) button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) v = QVBoxLayout(d) @@ -245,6 +252,7 @@ class SearchDialog(QDialog, Ui_Dialog): def config_changed(self): self.load_settings() + self.open_external.setChecked(self.should_open_external) self.search_pool.set_thread_count(self.search_thread_count) self.cache_pool.set_thread_count(self.cache_thread_count) self.results_view.model().cover_pool.set_thread_count(self.cover_thread_count) diff --git a/src/calibre/gui2/store/search/search.ui b/src/calibre/gui2/store/search/search.ui index 905620f688..0360fa5f98 100644 --- a/src/calibre/gui2/store/search/search.ui +++ b/src/calibre/gui2/store/search/search.ui @@ -164,9 +164,9 @@ - + - Configure + ... From ab55a25674d64426fa06877ec6b9c6a1bb87b8a9 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 21 May 2011 21:17:27 -0400 Subject: [PATCH 12/50] Store: add missed files. Add more quick functions for listing stores and which ones are enabled. --- src/calibre/customize/ui.py | 23 ++- src/calibre/gui2/store/config/__init__.py | 0 .../gui2/store/config/search_widget.py | 45 +++++ .../gui2/store/config/search_widget.ui | 162 ++++++++++++++++++ src/calibre/gui2/store/config/store.py | 14 ++ src/calibre/gui2/ui.py | 4 +- 6 files changed, 243 insertions(+), 5 deletions(-) create mode 100644 src/calibre/gui2/store/config/__init__.py create mode 100644 src/calibre/gui2/store/config/search_widget.py create mode 100644 src/calibre/gui2/store/config/search_widget.ui create mode 100644 src/calibre/gui2/store/config/store.py diff --git a/src/calibre/customize/ui.py b/src/calibre/customize/ui.py index e955336d3f..0a21b0b42e 100644 --- a/src/calibre/customize/ui.py +++ b/src/calibre/customize/ui.py @@ -216,9 +216,26 @@ def store_plugins(): customization = config['plugin_customization'] for plugin in _initialized_plugins: if isinstance(plugin, Store): - if not is_disabled(plugin): - plugin.site_customization = customization.get(plugin.name, '') - yield plugin + plugin.site_customization = customization.get(plugin.name, '') + yield plugin + +def available_store_plugins(): + for plugin in store_plugins(): + if not is_disabled(plugin): + yield plugin + +def stores(): + stores = set([]) + for plugin in store_plugins(): + stores.add(plugin.name) + return stores + +def available_stores(): + stores = set([]) + for plugin in available_store_plugins(): + stores.add(plugin.name) + return stores + # }}} # Metadata read/write {{{ diff --git a/src/calibre/gui2/store/config/__init__.py b/src/calibre/gui2/store/config/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/calibre/gui2/store/config/search_widget.py b/src/calibre/gui2/store/config/search_widget.py new file mode 100644 index 0000000000..43e911a432 --- /dev/null +++ b/src/calibre/gui2/store/config/search_widget.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) + +__license__ = 'GPL 3' +__copyright__ = '2011, John Schember ' +__docformat__ = 'restructuredtext en' + +from PyQt4.Qt import QWidget + +from calibre.gui2 import JSONConfig +from calibre.gui2.store.config.search_widget_ui import Ui_Form + +class StoreConfigWidget(QWidget, Ui_Form): + + def __init__(self, config=None): + QWidget.__init__(self) + self.setupUi(self) + + self.config = JSONConfig('store/search') if not config else config + + # These default values should be the same as in + # calibre.gui2.store.search.search:SearchDialog.load_settings + # Seconds + self.opt_timeout.setValue(self.config.get('timeout', 75)) + self.opt_hang_time.setValue(self.config.get('hang_time', 75)) + + self.opt_max_results.setValue(self.config.get('max_results', 10)) + self.opt_open_external.setChecked(self.config.get('open_external', True)) + + # Number of threads to run for each type of operation + self.opt_search_thread_count.setValue(self.config.get('search_thread_count', 4)) + self.opt_cache_thread_count.setValue(self.config.get('cache_thread_count', 2)) + self.opt_cover_thread_count.setValue(self.config.get('cover_thread_count', 2)) + self.opt_details_thread_count.setValue(self.config.get('details_thread_count', 4)) + + def save_settings(self): + self.config['timeout'] = self.opt_timeout.value() + self.config['hang_time'] = self.opt_hang_time.value() + self.config['max_results'] = self.opt_max_results.value() + self.config['open_external'] = self.opt_open_external.isChecked() + self.config['search_thread_count'] = self.opt_search_thread_count.value() + self.config['cache_thread_count'] = self.opt_cache_thread_count.value() + self.config['cover_thread_count'] = self.opt_cover_thread_count.value() + self.config['details_thread_count'] = self.opt_details_thread_count.value() diff --git a/src/calibre/gui2/store/config/search_widget.ui b/src/calibre/gui2/store/config/search_widget.ui new file mode 100644 index 0000000000..a73aae3ea5 --- /dev/null +++ b/src/calibre/gui2/store/config/search_widget.ui @@ -0,0 +1,162 @@ + + + Form + + + + 0 + 0 + 465 + 396 + + + + Form + + + + + + Time + + + + + + Number of seconds to wait for a store to respond + + + + + + + 1 + + + + + + + Number of seconds to let a store process results + + + + + + + 1 + + + 99 + + + 1 + + + 1 + + + + + + + + + + Display + + + + + + Maximum number of results to show per store + + + + + + + 1 + + + + + + + Open search result in system browser + + + + + + + + + + Threads + + + + + + Number of search threads to use + + + + + + + 1 + + + + + + + Number of cache update threads to use + + + + + + + 1 + + + + + + + Number of conver download threads to use + + + + + + + 1 + + + + + + + Number of details threads to use + + + + + + + 1 + + + + + + + + + + + diff --git a/src/calibre/gui2/store/config/store.py b/src/calibre/gui2/store/config/store.py new file mode 100644 index 0000000000..0e05514867 --- /dev/null +++ b/src/calibre/gui2/store/config/store.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) + +__license__ = 'GPL 3' +__copyright__ = '2011, John Schember ' +__docformat__ = 'restructuredtext en' + +def config_widget(): + from calibre.gui2.store.config.search_widget import StoreConfigWidget + return StoreConfigWidget() + +def save_settings(config_widget): + config_widget.save_settings() diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 122bfc81b4..df0e20e1bc 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -23,7 +23,7 @@ from calibre.constants import __appname__, isosx from calibre.utils.config import prefs, dynamic from calibre.utils.ipc.server import Server from calibre.library.database2 import LibraryDatabase2 -from calibre.customize.ui import interface_actions, store_plugins +from calibre.customize.ui import interface_actions, enabled_store_plugins from calibre.gui2 import error_dialog, GetMetadata, open_url, \ gprefs, max_available_height, config, info_dialog, Dispatcher, \ question_dialog @@ -144,7 +144,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{ def load_store_plugins(self): self.istores = OrderedDict() - for store in store_plugins(): + for store in enabled_store_plugins(): if self.opts.ignore_plugins and store.plugin_path is not None: continue try: From 8ae27a865f2d14bbe13bc30ec7ee5c1036bfe26c Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 21 May 2011 21:21:53 -0400 Subject: [PATCH 13/50] ... --- src/calibre/gui2/store/config/store.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/calibre/gui2/store/config/store.py b/src/calibre/gui2/store/config/store.py index 0e05514867..ddc24870bd 100644 --- a/src/calibre/gui2/store/config/store.py +++ b/src/calibre/gui2/store/config/store.py @@ -6,6 +6,10 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' +''' +Config widget access functions for configuring the store action. +''' + def config_widget(): from calibre.gui2.store.config.search_widget import StoreConfigWidget return StoreConfigWidget() From bc8ea972e337544d476c657f16e9328de03e5395 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 21 May 2011 22:12:00 -0400 Subject: [PATCH 14/50] Store: Fix google books leaving out some books. Add meta info to store plugins. --- src/calibre/customize/builtins.py | 111 ++++++++++++++++++ src/calibre/gui2/store/google_books_plugin.py | 2 +- 2 files changed, 112 insertions(+), 1 deletion(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 8490630bb8..c085185a6e 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1108,144 +1108,255 @@ class StoreAmazonKindleStore(StoreBase): name = 'Amazon Kindle' description = _('Kindle books from Amazon.') actual_plugin = 'calibre.gui2.store.amazon_plugin:AmazonKindleStore' + + drm_free_only = False + location = 'US' + formats = ['KINDLE'] class StoreAmazonDEKindleStore(StoreBase): name = 'Amazon DE Kindle' description = _('Kindle books from Amazon.de.') actual_plugin = 'calibre.gui2.store.amazon_de_plugin:AmazonDEKindleStore' + + drm_free_only = False + location = 'DE' + formats = ['KINDLE'] class StoreAmazonUKKindleStore(StoreBase): name = 'Amazon UK Kindle' description = _('Kindle books from Amazon.uk.') actual_plugin = 'calibre.gui2.store.amazon_uk_plugin:AmazonUKKindleStore' + + drm_free_only = False + location = 'UK' + formats = ['KINDLE'] class StoreArchiveOrgStore(StoreBase): name = 'Archive.org' description = _('Free Books : Download & Streaming : Ebook and Texts Archive : Internet Archive.') actual_plugin = 'calibre.gui2.store.archive_org_plugin:ArchiveOrgStore' + drm_free_only = True + location = 'US' + formats = ['DAISY', 'DJVU', 'EPUB', 'MOBI', 'PDF', 'TXT'] class StoreBaenWebScriptionStore(StoreBase): name = 'Baen WebScription' description = _('Ebooks for readers.') actual_plugin = 'calibre.gui2.store.baen_webscription_plugin:BaenWebScriptionStore' + + drm_free_only = True + location = 'US' + formats = ['EPUB', 'LIT', 'LRF', 'MOBI', 'RB', 'RTF', 'ZIP'] class StoreBNStore(StoreBase): name = 'Barnes and Noble' description = _('Books, Textbooks, eBooks, Toys, Games and More.') actual_plugin = 'calibre.gui2.store.bn_plugin:BNStore' + + drm_free_only = False + location = 'US' + formats = ['NOOK'] class StoreBeamEBooksDEStore(StoreBase): name = 'Beam EBooks DE' description = _('Der eBook Shop.') actual_plugin = 'calibre.gui2.store.beam_ebooks_de_plugin:BeamEBooksDEStore' + + drm_free_only = False + location = 'DE' + formats = ['MOBI', 'PDF'] class StoreBeWriteStore(StoreBase): name = 'BeWrite Books' description = _('Publishers of fine books.') actual_plugin = 'calibre.gui2.store.bewrite_plugin:BeWriteStore' + + drm_free_only = True + location = 'US' + formats = ['EPUB', 'MOBI', 'PDF'] class StoreDieselEbooksStore(StoreBase): name = 'Diesel eBooks' description = _('World Famous eBook Store.') actual_plugin = 'calibre.gui2.store.diesel_ebooks_plugin:DieselEbooksStore' + + drm_free_only = False + location = 'US' + formats = ['EPUB', 'PDF'] class StoreEbookscomStore(StoreBase): name = 'eBooks.com' description = _('The digital bookstore.') actual_plugin = 'calibre.gui2.store.ebooks_com_plugin:EbookscomStore' + + drm_free_only = False + location = 'US' + formats = ['EPUB', 'LIT', 'MOBI', 'PDF'] class StoreEPubBuyDEStore(StoreBase): name = 'EPUBBuy DE' description = _('EPUBReaders eBook Shop.') actual_plugin = 'calibre.gui2.store.epubbuy_de_plugin:EPubBuyDEStore' + + drm_free_only = True + location = 'DE' + formats = ['EPUB'] class StoreEHarlequinStore(StoreBase): name = 'eHarlequin' description = _('Entertain, enrich, inspire.') actual_plugin = 'calibre.gui2.store.eharlequin_plugin:EHarlequinStore' + + drm_free_only = False + location = 'US' + formats = ['EPUB', 'PDF'] class StoreFeedbooksStore(StoreBase): name = 'Feedbooks' description = _('Read anywhere.') actual_plugin = 'calibre.gui2.store.feedbooks_plugin:FeedbooksStore' + + drm_free_only = False + location = 'FR' + formats = ['EPUB', 'MOBI', 'PDF'] class StoreFoylesUKStore(StoreBase): name = 'Foyles UK' description = _('Foyles of London, online.') actual_plugin = 'calibre.gui2.store.foyles_uk_plugin:FoylesUKStore' + drm_free_only = False + location = 'UK' + formats = ['EPUB', 'PDF'] + class StoreGandalfStore(StoreBase): name = 'Gandalf' author = 'Tomasz Długosz' description = _('Zaczarowany świat książek') actual_plugin = 'calibre.gui2.store.gandalf_plugin:GandalfStore' + drm_free_only = False + location = 'PL' + formats = ['EPUB', 'PDF'] + class StoreGoogleBooksStore(StoreBase): name = 'Google Books' description = _('Google Books') actual_plugin = 'calibre.gui2.store.google_books_plugin:GoogleBooksStore' + + drm_free_only = False + location = 'US' + formats = ['EPUB', 'PDF', 'TXT'] class StoreGutenbergStore(StoreBase): name = 'Project Gutenberg' description = _('The first producer of free ebooks.') actual_plugin = 'calibre.gui2.store.gutenberg_plugin:GutenbergStore' + + drm_free_only = True + location = 'US' + formats = ['EPUB', 'HTML', 'MOBI', 'PDB', 'TXT'] class StoreKoboStore(StoreBase): name = 'Kobo' description = _('eReading: anytime. anyplace.') actual_plugin = 'calibre.gui2.store.kobo_plugin:KoboStore' + + drm_free_only = False + location = 'US' + formats = ['EPUB'] class StoreManyBooksStore(StoreBase): name = 'ManyBooks' description = _('The best ebooks at the best price: free!') actual_plugin = 'calibre.gui2.store.manybooks_plugin:ManyBooksStore' + + drm_free_only = True + location = 'US' + formats = ['EPUB', 'FB2', 'JAR', 'LIT', 'LRF', 'MOBI', 'PDB', 'PDF', 'RB', 'RTF', 'TCR', 'TXT', 'ZIP'] class StoreMobileReadStore(StoreBase): name = 'MobileRead' description = _('Ebooks handcrafted with the utmost care.') actual_plugin = 'calibre.gui2.store.mobileread.mobileread_plugin:MobileReadStore' + drm_free_only = True + location = 'CH' + formats = ['EPUB', 'IMP', 'LRF', 'LIT', 'MOBI', 'PDF'] + class StoreNextoStore(StoreBase): name = 'Nexto' author = 'Tomasz Długosz' description = _('Audiobooki mp3, ebooki, prasa - księgarnia internetowa.') actual_plugin = 'calibre.gui2.store.nexto_plugin:NextoStore' + + drm_free_only = False + location = 'PL' + formats = ['EPUB', 'PDF'] class StoreOpenLibraryStore(StoreBase): name = 'Open Library' description = _('One web page for every book.') actual_plugin = 'calibre.gui2.store.open_library_plugin:OpenLibraryStore' + + drm_free_only = True + location = ['US'] + formats = ['DAISY', 'DJVU', 'EPUB', 'MOBI', 'PDF', 'TXT'] class StoreOReillyStore(StoreBase): name = 'OReilly' description = _('DRM-Free tech ebooks.') actual_plugin = 'calibre.gui2.store.oreilly_plugin:OReillyStore' + + drm_free_only = True + location = 'US' + formats = ['APK', 'DAISY', 'EPUB', 'MOBI', 'PDF'] class StorePragmaticBookshelfStore(StoreBase): name = 'Pragmatic Bookshelf' description = _('The Pragmatic Bookshelf') actual_plugin = 'calibre.gui2.store.pragmatic_bookshelf_plugin:PragmaticBookshelfStore' + drm_free_only = True + location = 'US' + formats = ['EPUB', 'MOBI', 'PDF'] + class StoreSmashwordsStore(StoreBase): name = 'Smashwords' description = _('Your ebook. Your way.') actual_plugin = 'calibre.gui2.store.smashwords_plugin:SmashwordsStore' + + drm_free_only = True + location = 'US' + formats = ['EPUB', 'HTML', 'LRF', 'MOBI', 'PDB', 'RTF', 'TXT'] class StoreWaterstonesUKStore(StoreBase): name = 'Waterstones UK' description = _('Feel every word.') actual_plugin = 'calibre.gui2.store.waterstones_uk_plugin:WaterstonesUKStore' + + drm_free_only = False + location = 'UK' + formats = ['EPUB', 'PDF'] class StoreWeightlessBooksStore(StoreBase): name = 'Weightless Books' description = '(e)Books That Don\'t Weigh You Down.' actual_plugin = 'calibre.gui2.store.weightless_books_plugin:WeightlessBooksStore' + drm_free_only = True + location = 'US' + formats = ['EPUB', 'HTML', 'LIT', 'MOBI', 'PDF'] + class StoreWizardsTowerBooksStore(StoreBase): name = 'Wizards Tower Books' description = 'Wizard\'s Tower Press.' actual_plugin = 'calibre.gui2.store.wizards_tower_books_plugin:WizardsTowerBooksStore' + + drm_free_only = True + location = 'UK' + formats = ['EPUB', 'MOBI'] plugins += [ StoreArchiveOrgStore, diff --git a/src/calibre/gui2/store/google_books_plugin.py b/src/calibre/gui2/store/google_books_plugin.py index 6db0cc10b8..938ca70664 100644 --- a/src/calibre/gui2/store/google_books_plugin.py +++ b/src/calibre/gui2/store/google_books_plugin.py @@ -51,7 +51,7 @@ class GoogleBooksStore(BasicStoreConfig, StorePlugin): title = ''.join(data.xpath('.//h3/a//text()')) authors = data.xpath('.//span[@class="gl"]//a//text()') - if authors[-1].strip().lower() == 'preview': + if authors[-1].strip().lower() in ('preview', 'read'): authors = authors[:-1] else: continue From 957155ea4b7530097b11f04bf982f4f86478be8f Mon Sep 17 00:00:00 2001 From: John Schember Date: Sat, 21 May 2011 22:27:32 -0400 Subject: [PATCH 15/50] Store: Fix change to function name change. --- src/calibre/gui2/ui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index df0e20e1bc..cf9f6ee610 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -23,7 +23,7 @@ from calibre.constants import __appname__, isosx from calibre.utils.config import prefs, dynamic from calibre.utils.ipc.server import Server from calibre.library.database2 import LibraryDatabase2 -from calibre.customize.ui import interface_actions, enabled_store_plugins +from calibre.customize.ui import interface_actions, available_store_plugins from calibre.gui2 import error_dialog, GetMetadata, open_url, \ gprefs, max_available_height, config, info_dialog, Dispatcher, \ question_dialog @@ -144,7 +144,7 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, EmailMixin, # {{{ def load_store_plugins(self): self.istores = OrderedDict() - for store in enabled_store_plugins(): + for store in available_store_plugins(): if self.opts.ignore_plugins and store.plugin_path is not None: continue try: From d9dc12c9d9a68522c8cf2bc2e38cb169d067bd77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Sun, 22 May 2011 13:32:29 +0200 Subject: [PATCH 16/50] Add new variables for Woblink --- src/calibre/customize/builtins.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 783a5e7f94..f27df26d3d 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1364,6 +1364,10 @@ class StoreWoblinkStore(StoreBase): description = _('Czytanie zdarza się wszędzie!') actual_plugin = 'calibre.gui2.store.woblink_plugin:WoblinkStore' + drm_free_only = False + location = 'PL' + formats = ['EPUB'] + plugins += [ StoreArchiveOrgStore, StoreAmazonKindleStore, From c3688278d0ac265fa4d53a084ca1b855300c9dcc Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 22 May 2011 13:00:30 +0100 Subject: [PATCH 17/50] First cut at template-based column coloring --- .../gui2/dialogs/template_line_editor.py | 31 +++++++ src/calibre/gui2/init.py | 1 + src/calibre/gui2/library/delegates.py | 79 +++++++----------- src/calibre/gui2/library/models.py | 36 +++++++- src/calibre/gui2/preferences/look_feel.py | 8 ++ src/calibre/gui2/preferences/look_feel.ui | 83 +++++++++++++++++++ src/calibre/library/database2.py | 4 + 7 files changed, 191 insertions(+), 51 deletions(-) create mode 100644 src/calibre/gui2/dialogs/template_line_editor.py diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py new file mode 100644 index 0000000000..d7ba8e4900 --- /dev/null +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai + +__license__ = 'GPL v3' +__copyright__ = '2010, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + +from PyQt4.Qt import (SIGNAL, QLineEdit) +from calibre.gui2.dialogs.template_dialog import TemplateDialog + +class LineEditWithTextBox(QLineEdit): + + ''' + Extend the context menu of a QLineEdit to include more actions. + ''' + + def contextMenuEvent(self, event): + menu = self.createStandardContextMenu() + menu.addSeparator() + + action_open_editor = menu.addAction(_('Open Editor')) + + self.connect(action_open_editor, SIGNAL('triggered()'), self.open_editor) + menu.exec_(event.globalPos()) + + def open_editor(self): + t = TemplateDialog(self, self.text()) + if t.exec_(): + self.setText(t.textbox.toPlainText()) + + diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index a75ff01b21..079e1814c3 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -65,6 +65,7 @@ class LibraryViewMixin(object): # {{{ self.build_context_menus() self.library_view.model().set_highlight_only(config['highlight_search_matches']) + self.library_view.model().set_color_templates() def build_context_menus(self): lm = QMenu(self) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 1af0482a31..042e568d8b 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -7,11 +7,12 @@ __docformat__ = 'restructuredtext en' from math import cos, sin, pi -from PyQt4.Qt import QColor, Qt, QModelIndex, QSize, \ - QPainterPath, QLinearGradient, QBrush, \ +from PyQt4.Qt import QColor, Qt, QModelIndex, QSize, QPalette, \ + QPainterPath, QLinearGradient, QBrush, QApplication, \ QPen, QStyle, QPainter, QStyleOptionViewItemV4, \ QIcon, QDoubleSpinBox, QVariant, QSpinBox, \ - QStyledItemDelegate, QComboBox, QTextDocument + QStyledItemDelegate, QComboBox, QTextDocument, \ + QAbstractTextDocumentLayout from calibre.gui2 import UNDEFINED_QDATE, error_dialog from calibre.gui2.widgets import EnLineEdit @@ -51,9 +52,7 @@ class RatingDelegate(QStyledItemDelegate): # {{{ return QSize(5*(self.SIZE), self.SIZE+4) def paint(self, painter, option, index): - style = self._parent.style() - option = QStyleOptionViewItemV4(option) - self.initStyleOption(option, self.dummy) + self.initStyleOption(option, index) num = index.model().data(index, Qt.DisplayRole).toInt()[0] def draw_star(): painter.save() @@ -65,18 +64,24 @@ class RatingDelegate(QStyledItemDelegate): # {{{ painter.restore() painter.save() - if hasattr(QStyle, 'CE_ItemViewItem'): - style.drawControl(QStyle.CE_ItemViewItem, option, - painter, self._parent) - elif option.state & QStyle.State_Selected: + if option.state & QStyle.State_Selected: painter.fillRect(option.rect, option.palette.highlight()) + else: + painter.fillRect(option.rect, option.backgroundBrush) + try: painter.setRenderHint(QPainter.Antialiasing) painter.setClipRect(option.rect) y = option.rect.center().y()-self.SIZE/2. x = option.rect.left() - painter.setPen(self.PEN) - painter.setBrush(self.brush) + brush = index.model().data(index, role=Qt.ForegroundRole) + if brush is None: + pen = self.PEN + painter.setBrush(self.COLOR) + else: + pen = QPen(brush, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin) + painter.setBrush(brush) + painter.setPen(pen) painter.translate(x, y) i = 0 while i < num: @@ -274,34 +279,6 @@ class CcEnumDelegate(QStyledItemDelegate): # {{{ Delegate for text/int/float data. ''' - def __init__(self, parent): - QStyledItemDelegate.__init__(self, parent) - self.document = QTextDocument() - - def paint(self, painter, option, index): - style = self.parent().style() - txt = unicode(index.data(Qt.DisplayRole).toString()) - self.document.setPlainText(txt) - painter.save() - if hasattr(QStyle, 'CE_ItemViewItem'): - style.drawControl(QStyle.CE_ItemViewItem, option, - painter, self.parent()) - elif option.state & QStyle.State_Selected: - painter.fillRect(option.rect, option.palette.highlight()) - m = index.model() - cc = m.custom_columns[m.column_map[index.column()]]['display'] - colors = cc.get('enum_colors', []) - values = cc.get('enum_values', []) - if len(colors) > 0 and txt in values: - try: - painter.fillRect(option.rect, QColor(colors[values.index(txt)])) - except: - pass - painter.setClipRect(option.rect) - painter.translate(option.rect.topLeft()) - self.document.drawContents(painter) - painter.restore() - def createEditor(self, parent, option, index): m = index.model() col = m.column_map[index.column()] @@ -339,17 +316,19 @@ class CcCommentsDelegate(QStyledItemDelegate): # {{{ self.document = QTextDocument() def paint(self, painter, option, index): - style = self.parent().style() - self.document.setHtml(index.data(Qt.DisplayRole).toString()) + self.initStyleOption(option, index) + style = QApplication.style() if option.widget is None \ + else option.widget.style() + self.document.setHtml(option.text) + option.text = "" + style.drawControl(QStyle.CE_ItemViewItem, option, painter); + ctx = QAbstractTextDocumentLayout.PaintContext() + ctx.palette = option.palette #.setColor(QPalette.Text, QColor("red")); + textRect = style.subElementRect(QStyle.SE_ItemViewItemText, option) painter.save() - if hasattr(QStyle, 'CE_ItemViewItem'): - style.drawControl(QStyle.CE_ItemViewItem, option, - painter, self.parent()) - elif option.state & QStyle.State_Selected: - painter.fillRect(option.rect, option.palette.highlight()) - painter.setClipRect(option.rect) - painter.translate(option.rect.topLeft()) - self.document.drawContents(painter) + painter.translate(textRect.topLeft()) + painter.setClipRect(textRect.translated(-textRect.topLeft())) + self.document.documentLayout().draw(painter, ctx) painter.restore() def createEditor(self, parent, option, index): diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index fc1117167d..7d6cfadacb 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -14,6 +14,7 @@ from PyQt4.Qt import (QAbstractTableModel, Qt, pyqtSignal, QIcon, QImage, from calibre.gui2 import NONE, UNDEFINED_QDATE from calibre.utils.pyparsing import ParseException from calibre.ebooks.metadata import fmt_sidx, authors_to_string, string_to_authors +from calibre.ebooks.metadata.book.base import composite_formatter from calibre.ptempfile import PersistentTemporaryFile from calibre.utils.config import tweaks, prefs from calibre.utils.date import dt_factory, qt_to_dt @@ -96,6 +97,7 @@ class BooksModel(QAbstractTableModel): # {{{ self.ids_to_highlight_set = set() self.current_highlighted_idx = None self.highlight_only = False + self.column_color_map = {} self.read_config() def change_alignment(self, colname, alignment): @@ -532,6 +534,16 @@ class BooksModel(QAbstractTableModel): # {{{ img = self.default_image return img + def set_color_templates(self): + print 'here' + self.column_color_map = {} + for i in range(1,self.db.column_color_count+1): + name = self.db.prefs.get('column_color_name_'+str(i)) + if name: + print name, self.db.prefs.get('column_color_template_'+str(i)) + self.column_color_map[name] = \ + self.db.prefs.get('column_color_template_'+str(i)) + self.refresh() def build_data_convertors(self): def authors(r, idx=-1): @@ -693,9 +705,31 @@ class BooksModel(QAbstractTableModel): # {{{ return NONE if role in (Qt.DisplayRole, Qt.EditRole): return self.column_to_dc_map[col](index.row()) - elif role == Qt.BackgroundColorRole: + elif role == Qt.BackgroundRole: if self.id(index) in self.ids_to_highlight_set: return QColor('lightgreen') + elif role == Qt.ForegroundRole: + key = self.column_map[col] + if key in self.column_color_map: + mi = self.db.get_metadata(self.id(index), index_is_id=True) + fmt = self.column_color_map[key] + try: + color = composite_formatter.safe_format(fmt, mi, '', mi) + return QColor(color) + except: + return None + elif self.is_custom_column(key) and \ + self.custom_columns[key]['datatype'] == 'enumeration': + cc = self.custom_columns[self.column_map[col]]['display'] + colors = cc.get('enum_colors', []) + values = cc.get('enum_values', []) + txt = unicode(index.data(Qt.DisplayRole).toString()) + if len(colors) > 0 and txt in values: + try: + return QColor(colors[values.index(txt)]) + except: + pass + return None elif role == Qt.DecorationRole: if self.column_to_dc_decorator_map[col] is not None: return self.column_to_dc_decorator_map[index.column()](index.row()) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index ee2d7a5428..fc6990fcc9 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -159,6 +159,13 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.df_up_button.clicked.connect(self.move_df_up) self.df_down_button.clicked.connect(self.move_df_down) + choices = db.field_metadata.displayable_field_keys() + choices.sort(key=sort_key) + choices.insert(0, '') + for i in range(1, db.column_color_count+1): + r('column_color_name_'+str(i), db.prefs, choices=choices) + r('column_color_template_'+str(i), db.prefs) + def initialize(self): ConfigWidgetBase.initialize(self) font = gprefs['font'] @@ -238,6 +245,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): return rr def refresh_gui(self, gui): + gui.library_view.model().set_color_templates() self.update_font_display() gui.tags_view.reread_collapse_parameters() gui.library_view.refresh_book_details() diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index 244b811cbd..d7fca70c08 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -407,6 +407,84 @@ then the tags will be displayed each on their own line. + + + + :/images/cover_flow.png:/images/cover_flow.png + + + Column Coloring + + + + + + Column name + + + + + + + Selection template + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 690 + 283 + + + + + +
@@ -417,6 +495,11 @@ then the tags will be displayed each on their own line. QLineEdit
calibre/gui2/complete.h
+ + LineEditWithTextBox + QLineEdit +
calibre/gui2/dialogs/template_line_editor.h
+
diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 9a740a08b7..819ac2cd24 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -211,6 +211,10 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): defs = self.prefs.defaults defs['gui_restriction'] = defs['cs_restriction'] = '' defs['categories_using_hierarchy'] = [] + self.column_color_count = 5 + for i in range(1,self.column_color_count+1): + defs['column_color_name_'+str(i)] = '' + defs['column_color_template_'+str(i)] = '' # Migrate the bool tristate tweak defs['bools_are_tristate'] = \ From 3c92c4a988eca819c813baf2f306cc0cfbff69c9 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 22 May 2011 14:14:23 +0100 Subject: [PATCH 18/50] More work on coloring columns. Refactor the template editor, add some documentation for the new template function first_non_empty, add help text to the configuration dialog. --- .../gui2/dialogs/template_line_editor.py | 2 +- src/calibre/gui2/library/models.py | 2 - src/calibre/gui2/preferences/look_feel.py | 26 +++++++- src/calibre/gui2/preferences/look_feel.ui | 66 +++++++++++-------- src/calibre/gui2/preferences/plugboard.py | 26 +------- src/calibre/manual/template_lang.rst | 1 + src/calibre/utils/formatter_functions.py | 19 +++++- 7 files changed, 85 insertions(+), 57 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index d7ba8e4900..69999f59a0 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en' from PyQt4.Qt import (SIGNAL, QLineEdit) from calibre.gui2.dialogs.template_dialog import TemplateDialog -class LineEditWithTextBox(QLineEdit): +class TemplateLineEditor(QLineEdit): ''' Extend the context menu of a QLineEdit to include more actions. diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 7d6cfadacb..83bf5868ba 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -535,12 +535,10 @@ class BooksModel(QAbstractTableModel): # {{{ return img def set_color_templates(self): - print 'here' self.column_color_map = {} for i in range(1,self.db.column_color_count+1): name = self.db.prefs.get('column_color_name_'+str(i)) if name: - print name, self.db.prefs.get('column_color_template_'+str(i)) self.column_color_map[name] = \ self.db.prefs.get('column_color_template_'+str(i)) self.refresh() diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index fc6990fcc9..97400c45bd 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -6,7 +6,7 @@ __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' from PyQt4.Qt import (QApplication, QFont, QFontInfo, QFontDialog, - QAbstractListModel, Qt) + QAbstractListModel, Qt, QColor) from calibre.gui2.preferences import ConfigWidgetBase, test_widget, CommaSeparatedList from calibre.gui2.preferences.look_feel_ui import Ui_Form @@ -159,12 +159,36 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.df_up_button.clicked.connect(self.move_df_up) self.df_down_button.clicked.connect(self.move_df_down) + self.color_help_text.setWordWrap(True) + self.color_help_text.setText('

' + + _('Here you can specify coloring rules for fields shown in the ' + 'library view. Choose the field you wish to color, then ' + 'supply a template that specifies the color to use.') + + '

' + + _('The template must evaluate to one of the color names shown ' + 'below. You can use any legal template expression. ' + 'For example, you can set the title to always display in ' + 'green using the template "green" (without the quotes). ' + 'To show the title in blue if the book has the tag "Science ' + 'Fiction", red if the book has the tag "Mystery", or black if ' + 'the book has neither tag, use ' + '"{tags:switch(Science Fiction,blue,Mystery,red,)}" ' + 'To show the title in green if it has one format, blue if it ' + 'two formats, and red if more, use ' + "\"program:cmp(count(field('formats'),','), 2, 'green', 'blue', 'red')\"") + + '

' + + _('Note: if you want to color a "custom column with a fixed set ' + 'of values", it is possible and often easier to specify the ' + 'colors in the column definition dialog. There you can ' + 'provide a color for each value without using a template.')+ '

') choices = db.field_metadata.displayable_field_keys() choices.sort(key=sort_key) choices.insert(0, '') for i in range(1, db.column_color_count+1): r('column_color_name_'+str(i), db.prefs, choices=choices) r('column_color_template_'+str(i), db.prefs) + all_colors = [unicode(s) for s in list(QColor.colorNames())] + self.colors_box.setText(', '.join(all_colors)) def initialize(self): ConfigWidgetBase.initialize(self) diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index d7fca70c08..aa5afe26dd 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -416,72 +416,80 @@ then the tags will be displayed each on their own line. Column Coloring - + Column name - + + + + + Selection template - + - - - - - - - - - + - + - + - + - + - + - + - - - - Qt::Vertical + + + + + + + + + + + + Color names - - - 690 - 283 - + + + + + + + 0 + 1 + - + @@ -496,7 +504,7 @@ then the tags will be displayed each on their own line.
calibre/gui2/complete.h
- LineEditWithTextBox + TemplateLineEditor QLineEdit
calibre/gui2/dialogs/template_line_editor.h
diff --git a/src/calibre/gui2/preferences/plugboard.py b/src/calibre/gui2/preferences/plugboard.py index b4b1d4e08e..cf632c04c0 100644 --- a/src/calibre/gui2/preferences/plugboard.py +++ b/src/calibre/gui2/preferences/plugboard.py @@ -7,12 +7,12 @@ __docformat__ = 'restructuredtext en' import copy -from PyQt4.Qt import Qt, QLineEdit, QComboBox, SIGNAL, QListWidgetItem +from PyQt4.Qt import Qt, QComboBox, QListWidgetItem from calibre.customize.ui import is_disabled from calibre.gui2 import error_dialog, question_dialog from calibre.gui2.device import device_name_for_plugboards -from calibre.gui2.dialogs.template_dialog import TemplateDialog +from calibre.gui2.dialogs.template_line_editor import TemplateLineEditor from calibre.gui2.preferences import ConfigWidgetBase, test_widget from calibre.gui2.preferences.plugboard_ui import Ui_Form from calibre.customize.ui import metadata_writers, device_plugins @@ -24,26 +24,6 @@ from calibre.library.server.content import plugboard_content_server_value, \ from calibre.utils.formatter import validation_formatter -class LineEditWithTextBox(QLineEdit): - - ''' - Extend the context menu of a QLineEdit to include more actions. - ''' - - def contextMenuEvent(self, event): - menu = self.createStandardContextMenu() - menu.addSeparator() - - action_open_editor = menu.addAction(_('Open Editor')) - - self.connect(action_open_editor, SIGNAL('triggered()'), self.open_editor) - menu.exec_(event.globalPos()) - - def open_editor(self): - t = TemplateDialog(self, self.text()) - if t.exec_(): - self.setText(t.textbox.toPlainText()) - class ConfigWidget(ConfigWidgetBase, Ui_Form): def genesis(self, gui): @@ -107,7 +87,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.source_widgets = [] self.dest_widgets = [] for i in range(0, len(self.dest_fields)-1): - w = LineEditWithTextBox(self) + w = TemplateLineEditor(self) self.source_widgets.append(w) self.fields_layout.addWidget(w, 5+i, 0, 1, 1) w = QComboBox(self) diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index 0fd396fb64..9b5fe63f25 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -234,6 +234,7 @@ The following functions are available in addition to those described in single-f * ``cmp(x, y, lt, eq, gt)`` -- compares x and y after converting both to numbers. Returns ``lt`` if x < y. Returns ``eq`` if x == y. Otherwise returns ``gt``. * ``divide(x, y)`` -- returns x / y. Throws an exception if either x or y are not numbers. * ``field(name)`` -- returns the metadata field named by ``name``. + * ``first_non_empty(value, value, ...) -- returns the first value that is not empty. If all values are empty, then the empty value is returned. You can have as many values as you want. * ``format_date(x, date_format)`` -- format_date(val, format_string) -- format the value, which must be a date field, using the format_string, returning a string. The formatting codes are:: d : the day as number without a leading zero (1 to 31) diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index aa8e4fb3a3..59a750bcc5 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -562,6 +562,22 @@ class BuiltinBooksize(BuiltinFormatterFunction): pass return '' +class BuiltinFirstNonEmpty(BuiltinFormatterFunction): + name = 'first_non_empty' + arg_count = -1 + doc = _('first_non_empty(value, value, ...) -- ' + 'returns the first value that is not empty. If all values are ' + 'empty, then the empty value is returned.' + 'You can have as many values as you want.') + + def evaluate(self, formatter, kwargs, mi, locals, *args): + i = 0 + while i < len(args): + if args[i]: + return args[i] + i += 1 + return '' + builtin_add = BuiltinAdd() builtin_assign = BuiltinAssign() builtin_booksize = BuiltinBooksize() @@ -571,8 +587,9 @@ builtin_contains = BuiltinContains() builtin_count = BuiltinCount() builtin_divide = BuiltinDivide() builtin_eval = BuiltinEval() -builtin_format_date = BuiltinFormat_date() +builtin_first_non_empty = BuiltinFirstNonEmpty() builtin_field = BuiltinField() +builtin_format_date = BuiltinFormat_date() builtin_ifempty = BuiltinIfempty() builtin_list_item = BuiltinListitem() builtin_lookup = BuiltinLookup() From 776536599e78f73b527c4a3c3a123d257075c9cb Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 22 May 2011 09:22:01 -0400 Subject: [PATCH 19/50] ... --- src/calibre/customize/__init__.py | 8 +++++ src/calibre/customize/builtins.py | 56 +++++++++++++++---------------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index 6118e5583b..ecb452faca 100644 --- a/src/calibre/customize/__init__.py +++ b/src/calibre/customize/__init__.py @@ -610,6 +610,14 @@ class StoreBase(Plugin): # {{{ minimum_calibre_version = (0, 8, 0) actual_plugin = None + + # Does the store only distribute ebooks without DRM. + drm_free_only = False + # This is the 2 letter country code for the corporate + # headquarters of the store. + headquarters = '' + # All formats the store distributes ebooks in. + formats = [] def load_actual_plugin(self, gui): ''' diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index c085185a6e..8c0ef84d50 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1110,7 +1110,7 @@ class StoreAmazonKindleStore(StoreBase): actual_plugin = 'calibre.gui2.store.amazon_plugin:AmazonKindleStore' drm_free_only = False - location = 'US' + headquarters = 'US' formats = ['KINDLE'] class StoreAmazonDEKindleStore(StoreBase): @@ -1119,7 +1119,7 @@ class StoreAmazonDEKindleStore(StoreBase): actual_plugin = 'calibre.gui2.store.amazon_de_plugin:AmazonDEKindleStore' drm_free_only = False - location = 'DE' + headquarters = 'DE' formats = ['KINDLE'] class StoreAmazonUKKindleStore(StoreBase): @@ -1128,7 +1128,7 @@ class StoreAmazonUKKindleStore(StoreBase): actual_plugin = 'calibre.gui2.store.amazon_uk_plugin:AmazonUKKindleStore' drm_free_only = False - location = 'UK' + headquarters = 'UK' formats = ['KINDLE'] class StoreArchiveOrgStore(StoreBase): @@ -1137,7 +1137,7 @@ class StoreArchiveOrgStore(StoreBase): actual_plugin = 'calibre.gui2.store.archive_org_plugin:ArchiveOrgStore' drm_free_only = True - location = 'US' + headquarters = 'US' formats = ['DAISY', 'DJVU', 'EPUB', 'MOBI', 'PDF', 'TXT'] class StoreBaenWebScriptionStore(StoreBase): @@ -1146,7 +1146,7 @@ class StoreBaenWebScriptionStore(StoreBase): actual_plugin = 'calibre.gui2.store.baen_webscription_plugin:BaenWebScriptionStore' drm_free_only = True - location = 'US' + headquarters = 'US' formats = ['EPUB', 'LIT', 'LRF', 'MOBI', 'RB', 'RTF', 'ZIP'] class StoreBNStore(StoreBase): @@ -1155,7 +1155,7 @@ class StoreBNStore(StoreBase): actual_plugin = 'calibre.gui2.store.bn_plugin:BNStore' drm_free_only = False - location = 'US' + headquarters = 'US' formats = ['NOOK'] class StoreBeamEBooksDEStore(StoreBase): @@ -1164,7 +1164,7 @@ class StoreBeamEBooksDEStore(StoreBase): actual_plugin = 'calibre.gui2.store.beam_ebooks_de_plugin:BeamEBooksDEStore' drm_free_only = False - location = 'DE' + headquarters = 'DE' formats = ['MOBI', 'PDF'] class StoreBeWriteStore(StoreBase): @@ -1173,7 +1173,7 @@ class StoreBeWriteStore(StoreBase): actual_plugin = 'calibre.gui2.store.bewrite_plugin:BeWriteStore' drm_free_only = True - location = 'US' + headquarters = 'US' formats = ['EPUB', 'MOBI', 'PDF'] class StoreDieselEbooksStore(StoreBase): @@ -1182,7 +1182,7 @@ class StoreDieselEbooksStore(StoreBase): actual_plugin = 'calibre.gui2.store.diesel_ebooks_plugin:DieselEbooksStore' drm_free_only = False - location = 'US' + headquarters = 'US' formats = ['EPUB', 'PDF'] class StoreEbookscomStore(StoreBase): @@ -1191,7 +1191,7 @@ class StoreEbookscomStore(StoreBase): actual_plugin = 'calibre.gui2.store.ebooks_com_plugin:EbookscomStore' drm_free_only = False - location = 'US' + headquarters = 'US' formats = ['EPUB', 'LIT', 'MOBI', 'PDF'] class StoreEPubBuyDEStore(StoreBase): @@ -1200,7 +1200,7 @@ class StoreEPubBuyDEStore(StoreBase): actual_plugin = 'calibre.gui2.store.epubbuy_de_plugin:EPubBuyDEStore' drm_free_only = True - location = 'DE' + headquarters = 'DE' formats = ['EPUB'] class StoreEHarlequinStore(StoreBase): @@ -1209,7 +1209,7 @@ class StoreEHarlequinStore(StoreBase): actual_plugin = 'calibre.gui2.store.eharlequin_plugin:EHarlequinStore' drm_free_only = False - location = 'US' + headquarters = 'US' formats = ['EPUB', 'PDF'] class StoreFeedbooksStore(StoreBase): @@ -1218,7 +1218,7 @@ class StoreFeedbooksStore(StoreBase): actual_plugin = 'calibre.gui2.store.feedbooks_plugin:FeedbooksStore' drm_free_only = False - location = 'FR' + headquarters = 'FR' formats = ['EPUB', 'MOBI', 'PDF'] class StoreFoylesUKStore(StoreBase): @@ -1227,7 +1227,7 @@ class StoreFoylesUKStore(StoreBase): actual_plugin = 'calibre.gui2.store.foyles_uk_plugin:FoylesUKStore' drm_free_only = False - location = 'UK' + headquarters = 'UK' formats = ['EPUB', 'PDF'] class StoreGandalfStore(StoreBase): @@ -1237,7 +1237,7 @@ class StoreGandalfStore(StoreBase): actual_plugin = 'calibre.gui2.store.gandalf_plugin:GandalfStore' drm_free_only = False - location = 'PL' + headquarters = 'PL' formats = ['EPUB', 'PDF'] class StoreGoogleBooksStore(StoreBase): @@ -1246,7 +1246,7 @@ class StoreGoogleBooksStore(StoreBase): actual_plugin = 'calibre.gui2.store.google_books_plugin:GoogleBooksStore' drm_free_only = False - location = 'US' + headquarters = 'US' formats = ['EPUB', 'PDF', 'TXT'] class StoreGutenbergStore(StoreBase): @@ -1255,7 +1255,7 @@ class StoreGutenbergStore(StoreBase): actual_plugin = 'calibre.gui2.store.gutenberg_plugin:GutenbergStore' drm_free_only = True - location = 'US' + headquarters = 'US' formats = ['EPUB', 'HTML', 'MOBI', 'PDB', 'TXT'] class StoreKoboStore(StoreBase): @@ -1264,7 +1264,7 @@ class StoreKoboStore(StoreBase): actual_plugin = 'calibre.gui2.store.kobo_plugin:KoboStore' drm_free_only = False - location = 'US' + headquarters = 'US' formats = ['EPUB'] class StoreManyBooksStore(StoreBase): @@ -1273,7 +1273,7 @@ class StoreManyBooksStore(StoreBase): actual_plugin = 'calibre.gui2.store.manybooks_plugin:ManyBooksStore' drm_free_only = True - location = 'US' + headquarters = 'US' formats = ['EPUB', 'FB2', 'JAR', 'LIT', 'LRF', 'MOBI', 'PDB', 'PDF', 'RB', 'RTF', 'TCR', 'TXT', 'ZIP'] class StoreMobileReadStore(StoreBase): @@ -1282,7 +1282,7 @@ class StoreMobileReadStore(StoreBase): actual_plugin = 'calibre.gui2.store.mobileread.mobileread_plugin:MobileReadStore' drm_free_only = True - location = 'CH' + headquarters = 'CH' formats = ['EPUB', 'IMP', 'LRF', 'LIT', 'MOBI', 'PDF'] class StoreNextoStore(StoreBase): @@ -1292,7 +1292,7 @@ class StoreNextoStore(StoreBase): actual_plugin = 'calibre.gui2.store.nexto_plugin:NextoStore' drm_free_only = False - location = 'PL' + headquarters = 'PL' formats = ['EPUB', 'PDF'] class StoreOpenLibraryStore(StoreBase): @@ -1301,7 +1301,7 @@ class StoreOpenLibraryStore(StoreBase): actual_plugin = 'calibre.gui2.store.open_library_plugin:OpenLibraryStore' drm_free_only = True - location = ['US'] + headquarters = ['US'] formats = ['DAISY', 'DJVU', 'EPUB', 'MOBI', 'PDF', 'TXT'] class StoreOReillyStore(StoreBase): @@ -1310,7 +1310,7 @@ class StoreOReillyStore(StoreBase): actual_plugin = 'calibre.gui2.store.oreilly_plugin:OReillyStore' drm_free_only = True - location = 'US' + headquarters = 'US' formats = ['APK', 'DAISY', 'EPUB', 'MOBI', 'PDF'] class StorePragmaticBookshelfStore(StoreBase): @@ -1319,7 +1319,7 @@ class StorePragmaticBookshelfStore(StoreBase): actual_plugin = 'calibre.gui2.store.pragmatic_bookshelf_plugin:PragmaticBookshelfStore' drm_free_only = True - location = 'US' + headquarters = 'US' formats = ['EPUB', 'MOBI', 'PDF'] class StoreSmashwordsStore(StoreBase): @@ -1328,7 +1328,7 @@ class StoreSmashwordsStore(StoreBase): actual_plugin = 'calibre.gui2.store.smashwords_plugin:SmashwordsStore' drm_free_only = True - location = 'US' + headquarters = 'US' formats = ['EPUB', 'HTML', 'LRF', 'MOBI', 'PDB', 'RTF', 'TXT'] class StoreWaterstonesUKStore(StoreBase): @@ -1337,7 +1337,7 @@ class StoreWaterstonesUKStore(StoreBase): actual_plugin = 'calibre.gui2.store.waterstones_uk_plugin:WaterstonesUKStore' drm_free_only = False - location = 'UK' + headquarters = 'UK' formats = ['EPUB', 'PDF'] class StoreWeightlessBooksStore(StoreBase): @@ -1346,7 +1346,7 @@ class StoreWeightlessBooksStore(StoreBase): actual_plugin = 'calibre.gui2.store.weightless_books_plugin:WeightlessBooksStore' drm_free_only = True - location = 'US' + headquarters = 'US' formats = ['EPUB', 'HTML', 'LIT', 'MOBI', 'PDF'] class StoreWizardsTowerBooksStore(StoreBase): @@ -1355,7 +1355,7 @@ class StoreWizardsTowerBooksStore(StoreBase): actual_plugin = 'calibre.gui2.store.wizards_tower_books_plugin:WizardsTowerBooksStore' drm_free_only = True - location = 'UK' + headquarters = 'UK' formats = ['EPUB', 'MOBI'] plugins += [ From 4ddb1e852ba181d6cfd03dcb8bd31aae758475d1 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 22 May 2011 15:22:33 +0100 Subject: [PATCH 20/50] Improvements on coloring: add an in_list formatter function. Add more documentation in the preference screen. Add a scroll bar to the doc in the preferences screen. --- src/calibre/gui2/preferences/look_feel.py | 24 ++++++++++++++++------- src/calibre/gui2/preferences/look_feel.ui | 10 +++++++++- src/calibre/utils/formatter_functions.py | 17 ++++++++++++++++ 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 97400c45bd..c96d980505 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -159,7 +159,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.df_up_button.clicked.connect(self.move_df_up) self.df_down_button.clicked.connect(self.move_df_down) - self.color_help_text.setWordWrap(True) self.color_help_text.setText('

' + _('Here you can specify coloring rules for fields shown in the ' 'library view. Choose the field you wish to color, then ' @@ -169,14 +168,25 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): 'below. You can use any legal template expression. ' 'For example, you can set the title to always display in ' 'green using the template "green" (without the quotes). ' - 'To show the title in blue if the book has the tag "Science ' - 'Fiction", red if the book has the tag "Mystery", or black if ' - 'the book has neither tag, use ' - '"{tags:switch(Science Fiction,blue,Mystery,red,)}" ' + 'To show the title in the color named in the custom column ' + '#column, use "{#column}". To show the title in blue if the ' + 'custom column #column contains the value "foo", in red if the ' + 'column contains the value "bar", otherwise in black, use ' + '

{#column:switch(foo,blue,bar,red,black)}
' + 'To show the title in blue if the book has the exact tag ' + '"Science Fiction", red if the book has the exact tag ' + '"Mystery", or black if the book has neither tag, use' + "
program: \n"
+                  "    t = field('tags'); \n"
+                  "    first_non_empty(\n"
+                  "        in_list(t, ',', '^Science Fiction$', 'blue', ''), \n"
+                  "        in_list(t, ',', '^Mystery$', 'red', 'black'))
" 'To show the title in green if it has one format, blue if it ' - 'two formats, and red if more, use ' - "\"program:cmp(count(field('formats'),','), 2, 'green', 'blue', 'red')\"") + + 'two formats, and red if more, use' + "
program:cmp(count(field('formats'),','), 2, 'green', 'blue', 'red')
") + '

' + + _('You can access a multi-line template editor from the ' + 'context menu (right-click).') + '

' + _('Note: if you want to color a "custom column with a fixed set ' 'of values", it is possible and often easier to specify the ' 'colors in the column definition dialog. There you can ' diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index aa5afe26dd..1194109c6c 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -424,7 +424,12 @@ then the tags will be displayed each on their own line. - + + + true + + + @@ -483,6 +488,9 @@ then the tags will be displayed each on their own line. + + true + 0 diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 59a750bcc5..c53277f3ce 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -327,6 +327,22 @@ class BuiltinSwitch(BuiltinFormatterFunction): return args[i+1] i += 2 +class BuiltinInList(BuiltinFormatterFunction): + name = 'in_list' + arg_count = 5 + doc = _('in_list(val, separator, pattern, found_val, not_found_val) -- ' + 'treat val as a list of items separated by separator, ' + 'comparing the pattern against each value in the list. If the ' + 'pattern matches a value, return found_val, otherwise return ' + 'not_found_val.') + + def evaluate(self, formatter, kwargs, mi, locals, val, sep, pat, fv, nfv): + l = [v.strip() for v in val.split(sep) if v.strip()] + for v in l: + if re.search(pat, v): + return fv + return nfv + class BuiltinRe(BuiltinFormatterFunction): name = 're' arg_count = 3 @@ -591,6 +607,7 @@ builtin_first_non_empty = BuiltinFirstNonEmpty() builtin_field = BuiltinField() builtin_format_date = BuiltinFormat_date() builtin_ifempty = BuiltinIfempty() +builtin_in_list = BuiltinInList() builtin_list_item = BuiltinListitem() builtin_lookup = BuiltinLookup() builtin_lowercase = BuiltinLowercase() From 42cce14fa9329b9172732720ea13e93879b4aaea Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 22 May 2011 10:25:08 -0400 Subject: [PATCH 21/50] Store: Add real description. Correct authors. --- src/calibre/customize/__init__.py | 1 + src/calibre/customize/builtins.py | 62 +++++++++++++++++-------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index ecb452faca..bf8151fe15 100644 --- a/src/calibre/customize/__init__.py +++ b/src/calibre/customize/__init__.py @@ -608,6 +608,7 @@ class StoreBase(Plugin): # {{{ author = 'John Schember' type = _('Store') minimum_calibre_version = (0, 8, 0) + version = (1, 0, 1) actual_plugin = None diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 8c0ef84d50..778aba6780 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1115,7 +1115,8 @@ class StoreAmazonKindleStore(StoreBase): class StoreAmazonDEKindleStore(StoreBase): name = 'Amazon DE Kindle' - description = _('Kindle books from Amazon.de.') + author = 'Charles Haley' + description = _('Kindle books from Amazon\'s German website.') actual_plugin = 'calibre.gui2.store.amazon_de_plugin:AmazonDEKindleStore' drm_free_only = False @@ -1124,7 +1125,8 @@ class StoreAmazonDEKindleStore(StoreBase): class StoreAmazonUKKindleStore(StoreBase): name = 'Amazon UK Kindle' - description = _('Kindle books from Amazon.uk.') + author = 'Charles Haley' + description = _('Kindle books from Amazon\'s UK web site. Also, includes French language ebooks.') actual_plugin = 'calibre.gui2.store.amazon_uk_plugin:AmazonUKKindleStore' drm_free_only = False @@ -1133,7 +1135,7 @@ class StoreAmazonUKKindleStore(StoreBase): class StoreArchiveOrgStore(StoreBase): name = 'Archive.org' - description = _('Free Books : Download & Streaming : Ebook and Texts Archive : Internet Archive.') + description = _('An Internet library offering permanent access for researchers, historians, scholars, people with disabilities, and the general public to historical collections that exist in digital format.') actual_plugin = 'calibre.gui2.store.archive_org_plugin:ArchiveOrgStore' drm_free_only = True @@ -1142,7 +1144,7 @@ class StoreArchiveOrgStore(StoreBase): class StoreBaenWebScriptionStore(StoreBase): name = 'Baen WebScription' - description = _('Ebooks for readers.') + description = _('Sci-Fi & Fantasy brought to you by Jim Baen.') actual_plugin = 'calibre.gui2.store.baen_webscription_plugin:BaenWebScriptionStore' drm_free_only = True @@ -1151,7 +1153,7 @@ class StoreBaenWebScriptionStore(StoreBase): class StoreBNStore(StoreBase): name = 'Barnes and Noble' - description = _('Books, Textbooks, eBooks, Toys, Games and More.') + description = _('The world\'s largest book seller. As the ultimate destination for book lovers, Barnes & Noble.com offers an incredible array of content.') actual_plugin = 'calibre.gui2.store.bn_plugin:BNStore' drm_free_only = False @@ -1160,16 +1162,17 @@ class StoreBNStore(StoreBase): class StoreBeamEBooksDEStore(StoreBase): name = 'Beam EBooks DE' - description = _('Der eBook Shop.') + author = 'Charles Haley' + description = _('Thousands of German-language eBooks.') actual_plugin = 'calibre.gui2.store.beam_ebooks_de_plugin:BeamEBooksDEStore' - drm_free_only = False + drm_free_only = True headquarters = 'DE' - formats = ['MOBI', 'PDF'] + formats = ['EPUB', 'MOBI', 'PDF'] class StoreBeWriteStore(StoreBase): name = 'BeWrite Books' - description = _('Publishers of fine books.') + description = _('Publishers of fine books. Highly selective and editorially driven. Does not offer: books for children or exclusively YA, erotica, swords-and-sorcery fantasy and space-opera-style science fiction. All other genres are represented.') actual_plugin = 'calibre.gui2.store.bewrite_plugin:BeWriteStore' drm_free_only = True @@ -1178,7 +1181,7 @@ class StoreBeWriteStore(StoreBase): class StoreDieselEbooksStore(StoreBase): name = 'Diesel eBooks' - description = _('World Famous eBook Store.') + description = _('Instant access to over 2.4 million titles from hundreds of publishers including Harlequin, HarperCollins, John Wiley & Sons, McGraw-Hill, Simon & Schuster and Random House.') actual_plugin = 'calibre.gui2.store.diesel_ebooks_plugin:DieselEbooksStore' drm_free_only = False @@ -1187,7 +1190,7 @@ class StoreDieselEbooksStore(StoreBase): class StoreEbookscomStore(StoreBase): name = 'eBooks.com' - description = _('The digital bookstore.') + description = _('Sells books in multiple electronic formats in all categories. Technical infrastructure is cutting edge, robust and scalable, with servers in the US and Europe.') actual_plugin = 'calibre.gui2.store.ebooks_com_plugin:EbookscomStore' drm_free_only = False @@ -1196,7 +1199,8 @@ class StoreEbookscomStore(StoreBase): class StoreEPubBuyDEStore(StoreBase): name = 'EPUBBuy DE' - description = _('EPUBReaders eBook Shop.') + author = 'Charles Haley' + description = _('Fiction and Non-Fiction. Only sells EPUB ebooks. German-language.') actual_plugin = 'calibre.gui2.store.epubbuy_de_plugin:EPubBuyDEStore' drm_free_only = True @@ -1205,16 +1209,16 @@ class StoreEPubBuyDEStore(StoreBase): class StoreEHarlequinStore(StoreBase): name = 'eHarlequin' - description = _('Entertain, enrich, inspire.') + description = _('A global leader in series romance and one of the world\'s leading publishers of books for women. Offers women a broad range of reading from romance to bestseller fiction, from young adult novels to erotic literature, from nonfiction to fantasy, from African-American novels to inspirational romance, and more.') actual_plugin = 'calibre.gui2.store.eharlequin_plugin:EHarlequinStore' drm_free_only = False - headquarters = 'US' + headquarters = 'CA' formats = ['EPUB', 'PDF'] class StoreFeedbooksStore(StoreBase): name = 'Feedbooks' - description = _('Read anywhere.') + description = _('Feedbooks is a cloud publishing and distribution service, connected to a large ecosystem of reading systems and social networks. Provides a variety of genres from independent and classic books.') actual_plugin = 'calibre.gui2.store.feedbooks_plugin:FeedbooksStore' drm_free_only = False @@ -1223,7 +1227,8 @@ class StoreFeedbooksStore(StoreBase): class StoreFoylesUKStore(StoreBase): name = 'Foyles UK' - description = _('Foyles of London, online.') + author = 'Charles Haley' + description = _('Foyles of London\'s ebook store. Provides extensive range covering all subjects.') actual_plugin = 'calibre.gui2.store.foyles_uk_plugin:FoylesUKStore' drm_free_only = False @@ -1233,7 +1238,7 @@ class StoreFoylesUKStore(StoreBase): class StoreGandalfStore(StoreBase): name = 'Gandalf' author = 'Tomasz Długosz' - description = _('Zaczarowany świat książek') + description = _('Polish language-store.') actual_plugin = 'calibre.gui2.store.gandalf_plugin:GandalfStore' drm_free_only = False @@ -1251,7 +1256,7 @@ class StoreGoogleBooksStore(StoreBase): class StoreGutenbergStore(StoreBase): name = 'Project Gutenberg' - description = _('The first producer of free ebooks.') + description = _('The first producer of free ebooks. Free in the United States because their copyright has expired. They may not be free of copyright in other countries. Readers outside of the United States must check the copyright laws of their countries before downloading or redistributing our ebooks.') actual_plugin = 'calibre.gui2.store.gutenberg_plugin:GutenbergStore' drm_free_only = True @@ -1260,7 +1265,7 @@ class StoreGutenbergStore(StoreBase): class StoreKoboStore(StoreBase): name = 'Kobo' - description = _('eReading: anytime. anyplace.') + description = _('With over 2.3 million eBooks to browse we have engaged readers in over 200 countries in Kobo eReading. Our eBook listings include New York Times Bestsellers, award winners, classics and more!') actual_plugin = 'calibre.gui2.store.kobo_plugin:KoboStore' drm_free_only = False @@ -1269,7 +1274,7 @@ class StoreKoboStore(StoreBase): class StoreManyBooksStore(StoreBase): name = 'ManyBooks' - description = _('The best ebooks at the best price: free!') + description = _('Public domain and creative commons works from many sources.') actual_plugin = 'calibre.gui2.store.manybooks_plugin:ManyBooksStore' drm_free_only = True @@ -1288,7 +1293,7 @@ class StoreMobileReadStore(StoreBase): class StoreNextoStore(StoreBase): name = 'Nexto' author = 'Tomasz Długosz' - description = _('Audiobooki mp3, ebooki, prasa - księgarnia internetowa.') + description = _('Polish language-store.') actual_plugin = 'calibre.gui2.store.nexto_plugin:NextoStore' drm_free_only = False @@ -1297,7 +1302,7 @@ class StoreNextoStore(StoreBase): class StoreOpenLibraryStore(StoreBase): name = 'Open Library' - description = _('One web page for every book.') + description = _('One web page for every book ever published. The goal is to be a true online library. Over 20 million records from a variety of large catalogs as well as single contributions, with more on the way.') actual_plugin = 'calibre.gui2.store.open_library_plugin:OpenLibraryStore' drm_free_only = True @@ -1306,7 +1311,7 @@ class StoreOpenLibraryStore(StoreBase): class StoreOReillyStore(StoreBase): name = 'OReilly' - description = _('DRM-Free tech ebooks.') + description = _('Programming and tech ebooks from OReilly.') actual_plugin = 'calibre.gui2.store.oreilly_plugin:OReillyStore' drm_free_only = True @@ -1315,7 +1320,7 @@ class StoreOReillyStore(StoreBase): class StorePragmaticBookshelfStore(StoreBase): name = 'Pragmatic Bookshelf' - description = _('The Pragmatic Bookshelf') + description = _('The Pragmatic Bookshelf\'s collection of programming and tech books avaliable as ebooks.') actual_plugin = 'calibre.gui2.store.pragmatic_bookshelf_plugin:PragmaticBookshelfStore' drm_free_only = True @@ -1324,7 +1329,7 @@ class StorePragmaticBookshelfStore(StoreBase): class StoreSmashwordsStore(StoreBase): name = 'Smashwords' - description = _('Your ebook. Your way.') + description = _('An ebook publishing and distribution platform for ebook authors, publishers and readers. Covers many genres and formats.') actual_plugin = 'calibre.gui2.store.smashwords_plugin:SmashwordsStore' drm_free_only = True @@ -1333,7 +1338,8 @@ class StoreSmashwordsStore(StoreBase): class StoreWaterstonesUKStore(StoreBase): name = 'Waterstones UK' - description = _('Feel every word.') + author = 'Charles Haley' + description = _('Waterstone\'s mission is to be the leading Bookseller on the High Street and online providing customers the widest choice, great value and expert advice from a team passionate about Bookselling.') actual_plugin = 'calibre.gui2.store.waterstones_uk_plugin:WaterstonesUKStore' drm_free_only = False @@ -1342,7 +1348,7 @@ class StoreWaterstonesUKStore(StoreBase): class StoreWeightlessBooksStore(StoreBase): name = 'Weightless Books' - description = '(e)Books That Don\'t Weigh You Down.' + description = _('An independent DRM-free ebooksite devoted to ebooks of all sorts.') actual_plugin = 'calibre.gui2.store.weightless_books_plugin:WeightlessBooksStore' drm_free_only = True @@ -1351,7 +1357,7 @@ class StoreWeightlessBooksStore(StoreBase): class StoreWizardsTowerBooksStore(StoreBase): name = 'Wizards Tower Books' - description = 'Wizard\'s Tower Press.' + description = _('A science fiction and fantasy publisher. Concentrates mainly on making out-of-print works available once more as e-books, and helping other small presses exploit the e-book market. Also publishes a small number of limited-print-run anthologies with a view to encouraging diversity in the science fiction and fantasy field.') actual_plugin = 'calibre.gui2.store.wizards_tower_books_plugin:WizardsTowerBooksStore' drm_free_only = True From ca5dc817c22e70ada00dd0c9feb7ad8ea0ea0238 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 22 May 2011 15:26:32 +0100 Subject: [PATCH 22/50] Add the new in_list function to the documentation --- src/calibre/manual/template_lang.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index 9b5fe63f25..69c77e5bfd 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -123,7 +123,8 @@ The functions available are: * ``contains(pattern, text if match, text if not match`` -- checks if field contains matches for the regular expression `pattern`. Returns `text if match` if matches are found, otherwise it returns `text if no match`. * ``count(separator)`` -- interprets the value as a list of items separated by `separator`, returning the number of items in the list. Most lists use a comma as the separator, but authors uses an ampersand. Examples: `{tags:count(,)}`, `{authors:count(&)}` * ``ifempty(text)`` -- if the field is not empty, return the value of the field. Otherwise return `text`. - * ``list_item(index, separator)`` -- interpret the value as a list of items separated by `separator`, returning the `index`th item. The first item is number zero. The last item can be returned using `list_item(-1,separator)`. If the item is not in the list, then the empty value is returned. The separator has the same meaning as in the `count` function. + * ``in_list(separator, pattern, found_val, not_found_val)`` -- interpret the field as a list of items separated by `separator`, comparing the `pattern` against each value in the list. If the pattern matches a value, return `found_val`, otherwise return `not_found_val`. + * ``list_item(index, separator)`` -- interpret the field as a list of items separated by `separator`, returning the `index`th item. The first item is number zero. The last item can be returned using `list_item(-1,separator)`. If the item is not in the list, then the empty value is returned. The separator has the same meaning as in the `count` function. * ``re(pattern, replacement)`` -- return the field after applying the regular expression. All instances of `pattern` are replaced with `replacement`. As in all of |app|, these are python-compatible regular expressions. * ``shorten(left chars, middle text, right chars)`` -- Return a shortened version of the field, consisting of `left chars` characters from the beginning of the field, followed by `middle text`, followed by `right chars` characters from the end of the string. `Left chars` and `right chars` must be integers. For example, assume the title of the book is `Ancient English Laws in the Times of Ivanhoe`, and you want it to fit in a space of at most 15 characters. If you use ``{title:shorten(9,-,5)}``, the result will be `Ancient E-nhoe`. If the field's length is less than ``left chars`` + ``right chars`` + the length of ``middle text``, then the field will be used intact. For example, the title `The Dome` would not be changed. * ``switch(pattern, value, pattern, value, ..., else_value)`` -- for each ``pattern, value`` pair, checks if the field matches the regular expression ``pattern`` and if so, returns that ``value``. If no ``pattern`` matches, then ``else_value`` is returned. You can have as many ``pattern, value`` pairs as you want. From 80bf19cfc17d67393fd1ce4d4ad0b3a837d5bb87 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 22 May 2011 10:51:17 -0400 Subject: [PATCH 23/50] Store: Make description non-translatable. Make descriptions unicode. --- src/calibre/customize/__init__.py | 4 +++ src/calibre/customize/builtins.py | 60 +++++++++++++++---------------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/calibre/customize/__init__.py b/src/calibre/customize/__init__.py index bf8151fe15..3d265aed1c 100644 --- a/src/calibre/customize/__init__.py +++ b/src/calibre/customize/__init__.py @@ -607,6 +607,10 @@ class StoreBase(Plugin): # {{{ supported_platforms = ['windows', 'osx', 'linux'] author = 'John Schember' type = _('Store') + # Information about the store. Should be in the primary language + # of the store. This should not be translatable when set by + # a subclass. + description = _('An ebook store.') minimum_calibre_version = (0, 8, 0) version = (1, 0, 1) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 778aba6780..ea9e555c11 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1106,7 +1106,7 @@ plugins += [LookAndFeel, Behavior, Columns, Toolbar, Search, InputOptions, # Store plugins {{{ class StoreAmazonKindleStore(StoreBase): name = 'Amazon Kindle' - description = _('Kindle books from Amazon.') + description = u'Kindle books from Amazon.' actual_plugin = 'calibre.gui2.store.amazon_plugin:AmazonKindleStore' drm_free_only = False @@ -1116,7 +1116,7 @@ class StoreAmazonKindleStore(StoreBase): class StoreAmazonDEKindleStore(StoreBase): name = 'Amazon DE Kindle' author = 'Charles Haley' - description = _('Kindle books from Amazon\'s German website.') + description = u'Kindle Bücher von Amazon.' actual_plugin = 'calibre.gui2.store.amazon_de_plugin:AmazonDEKindleStore' drm_free_only = False @@ -1126,7 +1126,7 @@ class StoreAmazonDEKindleStore(StoreBase): class StoreAmazonUKKindleStore(StoreBase): name = 'Amazon UK Kindle' author = 'Charles Haley' - description = _('Kindle books from Amazon\'s UK web site. Also, includes French language ebooks.') + description = u'Kindle books from Amazon\'s UK web site. Also, includes French language ebooks.' actual_plugin = 'calibre.gui2.store.amazon_uk_plugin:AmazonUKKindleStore' drm_free_only = False @@ -1135,7 +1135,7 @@ class StoreAmazonUKKindleStore(StoreBase): class StoreArchiveOrgStore(StoreBase): name = 'Archive.org' - description = _('An Internet library offering permanent access for researchers, historians, scholars, people with disabilities, and the general public to historical collections that exist in digital format.') + description = u'An Internet library offering permanent access for researchers, historians, scholars, people with disabilities, and the general public to historical collections that exist in digital format.' actual_plugin = 'calibre.gui2.store.archive_org_plugin:ArchiveOrgStore' drm_free_only = True @@ -1144,7 +1144,7 @@ class StoreArchiveOrgStore(StoreBase): class StoreBaenWebScriptionStore(StoreBase): name = 'Baen WebScription' - description = _('Sci-Fi & Fantasy brought to you by Jim Baen.') + description = u'Sci-Fi & Fantasy brought to you by Jim Baen.' actual_plugin = 'calibre.gui2.store.baen_webscription_plugin:BaenWebScriptionStore' drm_free_only = True @@ -1153,7 +1153,7 @@ class StoreBaenWebScriptionStore(StoreBase): class StoreBNStore(StoreBase): name = 'Barnes and Noble' - description = _('The world\'s largest book seller. As the ultimate destination for book lovers, Barnes & Noble.com offers an incredible array of content.') + description = u'The world\'s largest book seller. As the ultimate destination for book lovers, Barnes & Noble.com offers an incredible array of content.' actual_plugin = 'calibre.gui2.store.bn_plugin:BNStore' drm_free_only = False @@ -1163,7 +1163,7 @@ class StoreBNStore(StoreBase): class StoreBeamEBooksDEStore(StoreBase): name = 'Beam EBooks DE' author = 'Charles Haley' - description = _('Thousands of German-language eBooks.') + description = u'Der eBook Shop.' actual_plugin = 'calibre.gui2.store.beam_ebooks_de_plugin:BeamEBooksDEStore' drm_free_only = True @@ -1172,7 +1172,7 @@ class StoreBeamEBooksDEStore(StoreBase): class StoreBeWriteStore(StoreBase): name = 'BeWrite Books' - description = _('Publishers of fine books. Highly selective and editorially driven. Does not offer: books for children or exclusively YA, erotica, swords-and-sorcery fantasy and space-opera-style science fiction. All other genres are represented.') + description = u'Publishers of fine books. Highly selective and editorially driven. Does not offer: books for children or exclusively YA, erotica, swords-and-sorcery fantasy and space-opera-style science fiction. All other genres are represented.' actual_plugin = 'calibre.gui2.store.bewrite_plugin:BeWriteStore' drm_free_only = True @@ -1181,7 +1181,7 @@ class StoreBeWriteStore(StoreBase): class StoreDieselEbooksStore(StoreBase): name = 'Diesel eBooks' - description = _('Instant access to over 2.4 million titles from hundreds of publishers including Harlequin, HarperCollins, John Wiley & Sons, McGraw-Hill, Simon & Schuster and Random House.') + description = u'Instant access to over 2.4 million titles from hundreds of publishers including Harlequin, HarperCollins, John Wiley & Sons, McGraw-Hill, Simon & Schuster and Random House.' actual_plugin = 'calibre.gui2.store.diesel_ebooks_plugin:DieselEbooksStore' drm_free_only = False @@ -1190,7 +1190,7 @@ class StoreDieselEbooksStore(StoreBase): class StoreEbookscomStore(StoreBase): name = 'eBooks.com' - description = _('Sells books in multiple electronic formats in all categories. Technical infrastructure is cutting edge, robust and scalable, with servers in the US and Europe.') + description = u'Sells books in multiple electronic formats in all categories. Technical infrastructure is cutting edge, robust and scalable, with servers in the US and Europe.' actual_plugin = 'calibre.gui2.store.ebooks_com_plugin:EbookscomStore' drm_free_only = False @@ -1200,7 +1200,7 @@ class StoreEbookscomStore(StoreBase): class StoreEPubBuyDEStore(StoreBase): name = 'EPUBBuy DE' author = 'Charles Haley' - description = _('Fiction and Non-Fiction. Only sells EPUB ebooks. German-language.') + description = u'Deutsch epub-Spezialisten.' actual_plugin = 'calibre.gui2.store.epubbuy_de_plugin:EPubBuyDEStore' drm_free_only = True @@ -1209,7 +1209,7 @@ class StoreEPubBuyDEStore(StoreBase): class StoreEHarlequinStore(StoreBase): name = 'eHarlequin' - description = _('A global leader in series romance and one of the world\'s leading publishers of books for women. Offers women a broad range of reading from romance to bestseller fiction, from young adult novels to erotic literature, from nonfiction to fantasy, from African-American novels to inspirational romance, and more.') + description = u'A global leader in series romance and one of the world\'s leading publishers of books for women. Offers women a broad range of reading from romance to bestseller fiction, from young adult novels to erotic literature, from nonfiction to fantasy, from African-American novels to inspirational romance, and more.' actual_plugin = 'calibre.gui2.store.eharlequin_plugin:EHarlequinStore' drm_free_only = False @@ -1218,7 +1218,7 @@ class StoreEHarlequinStore(StoreBase): class StoreFeedbooksStore(StoreBase): name = 'Feedbooks' - description = _('Feedbooks is a cloud publishing and distribution service, connected to a large ecosystem of reading systems and social networks. Provides a variety of genres from independent and classic books.') + description = u'Feedbooks is a cloud publishing and distribution service, connected to a large ecosystem of reading systems and social networks. Provides a variety of genres from independent and classic books.' actual_plugin = 'calibre.gui2.store.feedbooks_plugin:FeedbooksStore' drm_free_only = False @@ -1228,7 +1228,7 @@ class StoreFeedbooksStore(StoreBase): class StoreFoylesUKStore(StoreBase): name = 'Foyles UK' author = 'Charles Haley' - description = _('Foyles of London\'s ebook store. Provides extensive range covering all subjects.') + description = u'Foyles of London\'s ebook store. Provides extensive range covering all subjects.' actual_plugin = 'calibre.gui2.store.foyles_uk_plugin:FoylesUKStore' drm_free_only = False @@ -1237,8 +1237,8 @@ class StoreFoylesUKStore(StoreBase): class StoreGandalfStore(StoreBase): name = 'Gandalf' - author = 'Tomasz Długosz' - description = _('Polish language-store.') + author = u'Tomasz Długosz' + description = u'Zaczarowany świat książek.' actual_plugin = 'calibre.gui2.store.gandalf_plugin:GandalfStore' drm_free_only = False @@ -1247,7 +1247,7 @@ class StoreGandalfStore(StoreBase): class StoreGoogleBooksStore(StoreBase): name = 'Google Books' - description = _('Google Books') + description = u'Google Books' actual_plugin = 'calibre.gui2.store.google_books_plugin:GoogleBooksStore' drm_free_only = False @@ -1256,7 +1256,7 @@ class StoreGoogleBooksStore(StoreBase): class StoreGutenbergStore(StoreBase): name = 'Project Gutenberg' - description = _('The first producer of free ebooks. Free in the United States because their copyright has expired. They may not be free of copyright in other countries. Readers outside of the United States must check the copyright laws of their countries before downloading or redistributing our ebooks.') + description = u'The first producer of free ebooks. Free in the United States because their copyright has expired. They may not be free of copyright in other countries. Readers outside of the United States must check the copyright laws of their countries before downloading or redistributing our ebooks.' actual_plugin = 'calibre.gui2.store.gutenberg_plugin:GutenbergStore' drm_free_only = True @@ -1265,7 +1265,7 @@ class StoreGutenbergStore(StoreBase): class StoreKoboStore(StoreBase): name = 'Kobo' - description = _('With over 2.3 million eBooks to browse we have engaged readers in over 200 countries in Kobo eReading. Our eBook listings include New York Times Bestsellers, award winners, classics and more!') + description = u'With over 2.3 million eBooks to browse we have engaged readers in over 200 countries in Kobo eReading. Our eBook listings include New York Times Bestsellers, award winners, classics and more!' actual_plugin = 'calibre.gui2.store.kobo_plugin:KoboStore' drm_free_only = False @@ -1274,7 +1274,7 @@ class StoreKoboStore(StoreBase): class StoreManyBooksStore(StoreBase): name = 'ManyBooks' - description = _('Public domain and creative commons works from many sources.') + description = u'Public domain and creative commons works from many sources.' actual_plugin = 'calibre.gui2.store.manybooks_plugin:ManyBooksStore' drm_free_only = True @@ -1283,7 +1283,7 @@ class StoreManyBooksStore(StoreBase): class StoreMobileReadStore(StoreBase): name = 'MobileRead' - description = _('Ebooks handcrafted with the utmost care.') + description = u'Ebooks handcrafted with the utmost care.' actual_plugin = 'calibre.gui2.store.mobileread.mobileread_plugin:MobileReadStore' drm_free_only = True @@ -1292,8 +1292,8 @@ class StoreMobileReadStore(StoreBase): class StoreNextoStore(StoreBase): name = 'Nexto' - author = 'Tomasz Długosz' - description = _('Polish language-store.') + author = u'Tomasz Długosz' + description = u'Ebooki, prasa - księgarnia internetowa.' actual_plugin = 'calibre.gui2.store.nexto_plugin:NextoStore' drm_free_only = False @@ -1302,7 +1302,7 @@ class StoreNextoStore(StoreBase): class StoreOpenLibraryStore(StoreBase): name = 'Open Library' - description = _('One web page for every book ever published. The goal is to be a true online library. Over 20 million records from a variety of large catalogs as well as single contributions, with more on the way.') + description = u'One web page for every book ever published. The goal is to be a true online library. Over 20 million records from a variety of large catalogs as well as single contributions, with more on the way.' actual_plugin = 'calibre.gui2.store.open_library_plugin:OpenLibraryStore' drm_free_only = True @@ -1311,7 +1311,7 @@ class StoreOpenLibraryStore(StoreBase): class StoreOReillyStore(StoreBase): name = 'OReilly' - description = _('Programming and tech ebooks from OReilly.') + description = u'Programming and tech ebooks from OReilly.' actual_plugin = 'calibre.gui2.store.oreilly_plugin:OReillyStore' drm_free_only = True @@ -1320,7 +1320,7 @@ class StoreOReillyStore(StoreBase): class StorePragmaticBookshelfStore(StoreBase): name = 'Pragmatic Bookshelf' - description = _('The Pragmatic Bookshelf\'s collection of programming and tech books avaliable as ebooks.') + description = u'The Pragmatic Bookshelf\'s collection of programming and tech books avaliable as ebooks.' actual_plugin = 'calibre.gui2.store.pragmatic_bookshelf_plugin:PragmaticBookshelfStore' drm_free_only = True @@ -1329,7 +1329,7 @@ class StorePragmaticBookshelfStore(StoreBase): class StoreSmashwordsStore(StoreBase): name = 'Smashwords' - description = _('An ebook publishing and distribution platform for ebook authors, publishers and readers. Covers many genres and formats.') + description = u'An ebook publishing and distribution platform for ebook authors, publishers and readers. Covers many genres and formats.' actual_plugin = 'calibre.gui2.store.smashwords_plugin:SmashwordsStore' drm_free_only = True @@ -1339,7 +1339,7 @@ class StoreSmashwordsStore(StoreBase): class StoreWaterstonesUKStore(StoreBase): name = 'Waterstones UK' author = 'Charles Haley' - description = _('Waterstone\'s mission is to be the leading Bookseller on the High Street and online providing customers the widest choice, great value and expert advice from a team passionate about Bookselling.') + description = u'Waterstone\'s mission is to be the leading Bookseller on the High Street and online providing customers the widest choice, great value and expert advice from a team passionate about Bookselling.' actual_plugin = 'calibre.gui2.store.waterstones_uk_plugin:WaterstonesUKStore' drm_free_only = False @@ -1348,7 +1348,7 @@ class StoreWaterstonesUKStore(StoreBase): class StoreWeightlessBooksStore(StoreBase): name = 'Weightless Books' - description = _('An independent DRM-free ebooksite devoted to ebooks of all sorts.') + description = u'An independent DRM-free ebooksite devoted to ebooks of all sorts.' actual_plugin = 'calibre.gui2.store.weightless_books_plugin:WeightlessBooksStore' drm_free_only = True @@ -1357,7 +1357,7 @@ class StoreWeightlessBooksStore(StoreBase): class StoreWizardsTowerBooksStore(StoreBase): name = 'Wizards Tower Books' - description = _('A science fiction and fantasy publisher. Concentrates mainly on making out-of-print works available once more as e-books, and helping other small presses exploit the e-book market. Also publishes a small number of limited-print-run anthologies with a view to encouraging diversity in the science fiction and fantasy field.') + description = u'A science fiction and fantasy publisher. Concentrates mainly on making out-of-print works available once more as e-books, and helping other small presses exploit the e-book market. Also publishes a small number of limited-print-run anthologies with a view to encouraging diversity in the science fiction and fantasy field.' actual_plugin = 'calibre.gui2.store.wizards_tower_books_plugin:WizardsTowerBooksStore' drm_free_only = True From f97bcfb1a8799d685722c56f76b6b659836c8810 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 22 May 2011 10:46:50 -0600 Subject: [PATCH 24/50] Try harder to recover on systems where people run temp file cleaners that delete the temp files of running programs --- src/calibre/ptempfile.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/calibre/ptempfile.py b/src/calibre/ptempfile.py index bff13dd248..01e8f18339 100644 --- a/src/calibre/ptempfile.py +++ b/src/calibre/ptempfile.py @@ -29,6 +29,10 @@ def remove_dir(x): def base_dir(): global _base_dir + if _base_dir is not None and not os.path.exists(_base_dir): + # Some people seem to think that running temp file cleaners that + # delete the temp dirs of running programs is a good idea! + _base_dir = None if _base_dir is None: td = os.environ.get('CALIBRE_WORKER_TEMP_DIR', None) if td is not None: From 8336bd6e4986effa3a184a410d885f95989c4d29 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 22 May 2011 10:48:45 -0600 Subject: [PATCH 25/50] Update Washington Post. Fixes #786609 (Updated recipe for The Washington Post) --- recipes/icons/wash_post.png | Bin 0 -> 1158 bytes recipes/wash_post.recipe | 119 ++++++++++++++++++++---------------- 2 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 recipes/icons/wash_post.png diff --git a/recipes/icons/wash_post.png b/recipes/icons/wash_post.png new file mode 100644 index 0000000000000000000000000000000000000000..e392e4c3ff7b37e4106fb51359242e524fd80413 GIT binary patch literal 1158 zcmV;11bO?3P)000C{Nklx)Fm$tUHn1T`pB@Ttt(^HNa$8s*_kt_87BKouTIfwzs!0FE4{^j5W{W#bFs^Z;zT_ZyXZCJZLmrU0w0j zSh7mSkA^Uoi({0u6+Aj+Y7Z9EpgicPifQm2DiQfXt5x!c7O{l@*avq)a4=tkhW8JH zpoW-3O@SRt2}`BjOf?D~9v*N(j0Nv1d`)P^(jOko)QVFg)7wEy@C0MqXvhn|3xmDC zzsH7D`0`;ooxZ%h#59=XGOd)VWU{Xj(=v&;*CH-qsZQJk_qqD~MdGzf=> zhw?N2MbPH!>x;j*k^zsz+~x%wA0L~~Xb6_52r%9mQi2zl0S+j$vor?mWB*U^|+4{1moQ9d{{v}EeboxQU>u->~!YsiL0n};OsC12){Sjcl{yI?m zL>-Yt-e5?3xlBXA0e;f#ZJ3t_rwUX?cmGF*Q@^`rL!6kBL{*GJMh))Tjd-uhK%3ZU z%Q_$|)oXD>Nbwq*WA>t6>e-RVh=n!mxf^7!=}a&y0aIhbGO!0=Ih{`ZgzxlxV!^$U z>>#y#{ZQE0Qxo3Ava?C(ibL0ziUC&=Z9{Vgu+->G)I~&rlYjV1<>p+BosxKL2 zZ-!BAY|Ijz)U3yhIMf6s&Q^IgZ74fzY~+6{;Wx>GU|EroHdC|K7Fm*sdCFf6gQDJO zNdb(2teH-Ty5%$k5{ Date: Sun, 22 May 2011 18:32:03 +0100 Subject: [PATCH 26/50] Make coloring work across change_libraries --- src/calibre/gui2/init.py | 1 - src/calibre/gui2/library/models.py | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index 079e1814c3..a75ff01b21 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -65,7 +65,6 @@ class LibraryViewMixin(object): # {{{ self.build_context_menus() self.library_view.model().set_highlight_only(config['highlight_search_matches']) - self.library_view.model().set_color_templates() def build_context_menus(self): lm = QMenu(self) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 83bf5868ba..a3e7438908 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -157,6 +157,7 @@ class BooksModel(QAbstractTableModel): # {{{ self.database_changed.emit(db) self.stop_metadata_backup() self.start_metadata_backup() + self.set_color_templates() def start_metadata_backup(self): self.metadata_backup = MetadataBackup(self.db) @@ -535,6 +536,7 @@ class BooksModel(QAbstractTableModel): # {{{ return img def set_color_templates(self): + print 'here' self.column_color_map = {} for i in range(1,self.db.column_color_count+1): name = self.db.prefs.get('column_color_name_'+str(i)) From 6087a6a6603868fa752b15a30b074ebd7e7e7243 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 22 May 2011 18:34:34 +0100 Subject: [PATCH 27/50] Remove print statement --- src/calibre/gui2/library/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index a3e7438908..b378256a42 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -536,7 +536,6 @@ class BooksModel(QAbstractTableModel): # {{{ return img def set_color_templates(self): - print 'here' self.column_color_map = {} for i in range(1,self.db.column_color_count+1): name = self.db.prefs.get('column_color_name_'+str(i)) From b0db4939688f0b7d737feee16a50087ee2f775e7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 22 May 2011 12:29:31 -0600 Subject: [PATCH 28/50] ... --- src/calibre/gui2/actions/copy_to_library.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/actions/copy_to_library.py b/src/calibre/gui2/actions/copy_to_library.py index 2e4d0380be..7190d1486f 100644 --- a/src/calibre/gui2/actions/copy_to_library.py +++ b/src/calibre/gui2/actions/copy_to_library.py @@ -16,7 +16,7 @@ from calibre.gui2 import error_dialog, Dispatcher, warning_dialog from calibre.gui2.dialogs.progress import ProgressDialog from calibre.utils.config import prefs, tweaks -class Worker(Thread): +class Worker(Thread): # {{{ def __init__(self, ids, db, loc, progress, done, delete_after): Thread.__init__(self) @@ -75,7 +75,7 @@ class Worker(Thread): if co is not None: newdb.set_conversion_options(x, 'PIPE', co) self.processed.add(x) - +# }}} class CopyToLibraryAction(InterfaceAction): From 3487ed762ea084d6d44d9e3a9446f6e87e87e1a8 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 22 May 2011 19:34:03 +0100 Subject: [PATCH 29/50] Switch refresh to reset when loading column color templates --- src/calibre/gui2/library/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index b378256a42..2576518d92 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -153,11 +153,11 @@ class BooksModel(QAbstractTableModel): # {{{ self.headers[col] = self.custom_columns[col]['name'] self.build_data_convertors() + self.set_color_templates(reset=False) self.reset() self.database_changed.emit(db) self.stop_metadata_backup() self.start_metadata_backup() - self.set_color_templates() def start_metadata_backup(self): self.metadata_backup = MetadataBackup(self.db) @@ -535,14 +535,15 @@ class BooksModel(QAbstractTableModel): # {{{ img = self.default_image return img - def set_color_templates(self): + def set_color_templates(self, reset=True): self.column_color_map = {} for i in range(1,self.db.column_color_count+1): name = self.db.prefs.get('column_color_name_'+str(i)) if name: self.column_color_map[name] = \ self.db.prefs.get('column_color_template_'+str(i)) - self.refresh() + if reset: + self.reset() def build_data_convertors(self): def authors(r, idx=-1): From 8a4ceb206d57b8e133cefec77736930c1d94e418 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 22 May 2011 12:43:25 -0600 Subject: [PATCH 30/50] Fix ratings deleegate to use model supplied color --- src/calibre/gui2/library/delegates.py | 20 +++++++++++++------- src/calibre/gui2/library/models.py | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index e2234f6df5..b3012a7211 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -40,10 +40,7 @@ class RatingDelegate(QStyledItemDelegate): # {{{ 50 + 40 * sin(0.8 * i * pi)) self.star_path.closeSubpath() self.star_path.setFillRule(Qt.WindingFill) - gradient = QLinearGradient(0, 0, 0, 100) - gradient.setColorAt(0.0, self.COLOR) - gradient.setColorAt(1.0, self.COLOR) - self.brush = QBrush(gradient) + self.gradient = QLinearGradient(0, 0, 0, 100) self.factor = self.SIZE/100. def sizeHint(self, option, index): @@ -53,7 +50,8 @@ class RatingDelegate(QStyledItemDelegate): # {{{ def paint(self, painter, option, index): style = self._parent.style() option = QStyleOptionViewItemV4(option) - self.initStyleOption(option, self.dummy) + self.initStyleOption(option, index) + option.text = u'' num = index.model().data(index, Qt.DisplayRole).toInt()[0] def draw_star(): painter.save() @@ -65,6 +63,7 @@ class RatingDelegate(QStyledItemDelegate): # {{{ painter.restore() painter.save() + if hasattr(QStyle, 'CE_ItemViewItem'): style.drawControl(QStyle.CE_ItemViewItem, option, painter, self._parent) @@ -75,8 +74,15 @@ class RatingDelegate(QStyledItemDelegate): # {{{ painter.setClipRect(option.rect) y = option.rect.center().y()-self.SIZE/2. x = option.rect.left() - painter.setPen(self.PEN) - painter.setBrush(self.brush) + color = index.data(Qt.ForegroundRole) + if color.isNull() or not color.isValid(): + color = self.COLOR + else: + color = QColor(color) + painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin)) + self.gradient.setColorAt(0.0, color) + self.gradient.setColorAt(1.0, color) + painter.setBrush(QBrush(self.gradient)) painter.translate(x, y) i = 0 while i < num: diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index fc1117167d..0baf98ecdd 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -693,9 +693,9 @@ class BooksModel(QAbstractTableModel): # {{{ return NONE if role in (Qt.DisplayRole, Qt.EditRole): return self.column_to_dc_map[col](index.row()) - elif role == Qt.BackgroundColorRole: + elif role == Qt.BackgroundRole: if self.id(index) in self.ids_to_highlight_set: - return QColor('lightgreen') + return QVariant(QColor('lightgreen')) elif role == Qt.DecorationRole: if self.column_to_dc_decorator_map[col] is not None: return self.column_to_dc_decorator_map[index.column()](index.row()) From c90382e059de39be3da1778862f42cec995e60ca Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 22 May 2011 12:46:06 -0600 Subject: [PATCH 31/50] ... --- src/calibre/gui2/library/delegates.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index b3012a7211..7265be89c8 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -7,11 +7,11 @@ __docformat__ = 'restructuredtext en' from math import cos, sin, pi -from PyQt4.Qt import QColor, Qt, QModelIndex, QSize, \ - QPainterPath, QLinearGradient, QBrush, \ - QPen, QStyle, QPainter, QStyleOptionViewItemV4, \ - QIcon, QDoubleSpinBox, QVariant, QSpinBox, \ - QStyledItemDelegate, QComboBox, QTextDocument +from PyQt4.Qt import (QColor, Qt, QModelIndex, QSize, + QPainterPath, QLinearGradient, QBrush, + QPen, QStyle, QPainter, QStyleOptionViewItemV4, + QIcon, QDoubleSpinBox, QVariant, QSpinBox, + QStyledItemDelegate, QComboBox, QTextDocument) from calibre.gui2 import UNDEFINED_QDATE, error_dialog from calibre.gui2.widgets import EnLineEdit @@ -27,7 +27,6 @@ from calibre.gui2.dialogs.template_dialog import TemplateDialog class RatingDelegate(QStyledItemDelegate): # {{{ COLOR = QColor("blue") SIZE = 16 - PEN = QPen(COLOR, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin) def __init__(self, parent): QStyledItemDelegate.__init__(self, parent) From 0bd580f572cd5b5a10c9167adc6f8f5c717d0dc3 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 22 May 2011 19:53:26 +0100 Subject: [PATCH 32/50] Remove unused PEN declaration --- src/calibre/gui2/library/delegates.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 6d962c9129..4f002c2c48 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -28,7 +28,6 @@ from calibre.gui2.dialogs.template_dialog import TemplateDialog class RatingDelegate(QStyledItemDelegate): # {{{ COLOR = QColor("blue") SIZE = 16 - PEN = QPen(COLOR, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin) def __init__(self, parent): QStyledItemDelegate.__init__(self, parent) From 29b453ba23177adc9cd740cada0f6b7ba08e23f4 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 22 May 2011 19:55:46 +0100 Subject: [PATCH 33/50] Check for color valid when using column coloring --- src/calibre/gui2/library/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 2576518d92..6e8e79d3b3 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -726,7 +726,9 @@ class BooksModel(QAbstractTableModel): # {{{ txt = unicode(index.data(Qt.DisplayRole).toString()) if len(colors) > 0 and txt in values: try: - return QColor(colors[values.index(txt)]) + color = colors[values.index(txt)] + if QColor.isValid(color): + return QColor(color) except: pass return None From de969af505aeaf32507c19229081371a850549b9 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 22 May 2011 20:12:47 +0100 Subject: [PATCH 34/50] Improve robustness in column coloring. --- src/calibre/gui2/library/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 6e8e79d3b3..9d90c44f18 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -715,7 +715,8 @@ class BooksModel(QAbstractTableModel): # {{{ fmt = self.column_color_map[key] try: color = composite_formatter.safe_format(fmt, mi, '', mi) - return QColor(color) + if QColor.isValid(color): + return QColor(color) except: return None elif self.is_custom_column(key) and \ From 1c448eae14a53fa95f2ee24271139245f41ddb26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Sun, 22 May 2011 21:41:42 +0200 Subject: [PATCH 35/50] new descriptions --- src/calibre/customize/builtins.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 0e239a2706..89d9512317 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1238,7 +1238,7 @@ class StoreFoylesUKStore(StoreBase): class StoreGandalfStore(StoreBase): name = 'Gandalf' author = u'Tomasz Długosz' - description = u'Zaczarowany świat książek.' + description = u'Księgarnia internetowa Gandalf.' actual_plugin = 'calibre.gui2.store.gandalf_plugin:GandalfStore' drm_free_only = False @@ -1293,7 +1293,7 @@ class StoreMobileReadStore(StoreBase): class StoreNextoStore(StoreBase): name = 'Nexto' author = u'Tomasz Długosz' - description = u'Ebooki, prasa - księgarnia internetowa.' + description = u'Największy w Polsce sklep internetowy z audiobookami mp3, ebookami pdf oraz prasą do pobrania on-line.' actual_plugin = 'calibre.gui2.store.nexto_plugin:NextoStore' drm_free_only = False From 478369c7cba88cf04d8778d8d4b2ea14c40872ed Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 22 May 2011 20:47:47 +0100 Subject: [PATCH 36/50] Add colors icon to preferences dialog. Correctly clean template values when the column is set to empty. --- src/calibre/gui2/preferences/look_feel.py | 8 +++++++- src/calibre/gui2/preferences/look_feel.ui | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index c96d980505..ffbc82eefd 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -194,7 +194,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): choices = db.field_metadata.displayable_field_keys() choices.sort(key=sort_key) choices.insert(0, '') - for i in range(1, db.column_color_count+1): + self.column_color_count = db.column_color_count+1 + for i in range(1, self.column_color_count): r('column_color_name_'+str(i), db.prefs, choices=choices) r('column_color_template_'+str(i), db.prefs) all_colors = [unicode(s) for s in list(QColor.colorNames())] @@ -267,6 +268,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.changed_signal.emit() def commit(self, *args): + for i in range(1, self.column_color_count): + col = getattr(self, 'opt_column_color_name_'+str(i)) + if not col.currentText(): + temp = getattr(self, 'opt_column_color_template_'+str(i)) + temp.setText('') rr = ConfigWidgetBase.commit(self, *args) if self.current_font != self.initial_font: gprefs['font'] = (self.current_font[:4] if self.current_font else diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index 1194109c6c..9dedcf4f8c 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -410,7 +410,7 @@ then the tags will be displayed each on their own line. - :/images/cover_flow.png:/images/cover_flow.png + :/images/format-fill-color.png:/images/format-fill-color.png Column Coloring From fa50fa00b3f508560bda6a49e594600586162d36 Mon Sep 17 00:00:00 2001 From: John Schember Date: Sun, 22 May 2011 17:18:48 -0400 Subject: [PATCH 37/50] Store: Fix Woblink. --- src/calibre/customize/builtins.py | 2 +- src/calibre/gui2/store/woblink_plugin.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 89d9512317..383a154eff 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1367,7 +1367,7 @@ class StoreWizardsTowerBooksStore(StoreBase): class StoreWoblinkStore(StoreBase): name = 'Woblink' author = 'Tomasz Długosz' - description = _('Czytanie zdarza się wszędzie!') + description = u'Czytanie zdarza się wszędzie!' actual_plugin = 'calibre.gui2.store.woblink_plugin:WoblinkStore' drm_free_only = False diff --git a/src/calibre/gui2/store/woblink_plugin.py b/src/calibre/gui2/store/woblink_plugin.py index 9659f72fd1..69be8f2e94 100644 --- a/src/calibre/gui2/store/woblink_plugin.py +++ b/src/calibre/gui2/store/woblink_plugin.py @@ -40,7 +40,7 @@ class WoblinkStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://woblink.com/publication?query' + urllib.quote_plus(query.encode('utf-8')) + url = 'http://woblink.com/publication?query=' + urllib.quote_plus(query.encode('utf-8')) br = browser() From ed7a6180aeca7aef8a93bc5738855f8d048cff4b Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 22 May 2011 22:30:35 +0100 Subject: [PATCH 38/50] Change pathname generation to use the correct value for {id} --- src/calibre/devices/usbms/device.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index c46e9539c9..45b72abe74 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -926,8 +926,8 @@ class Device(DeviceConfig, DevicePlugin): if not isinstance(template, unicode): template = template.decode('utf-8') app_id = str(getattr(mdata, 'application_id', '')) - # The db id will be in the created filename - extra_components = get_components(template, mdata, fname, + id_ = mdata.get('id', fname) + extra_components = get_components(template, mdata, id_, timefmt=opts.send_timefmt, length=maxlen-len(app_id)-1) if not extra_components: extra_components.append(sanitize(self.filename_callback(fname, From a74ee044bb1dec7b164060fffacb496641aec634 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 22 May 2011 20:11:06 -0600 Subject: [PATCH 39/50] ... --- src/calibre/gui2/preferences/look_feel.ui | 51 ++++++++++++++--------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index 970052ad2e..ad990a1586 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -467,25 +467,6 @@ then the tags will be displayed each on their own line. - - - - - 0 - 1 - - - - - 16777215 - 100 - - - - true - - - @@ -524,6 +505,38 @@ then the tags will be displayed each on their own line. + + + + + 16777215 + 120 + + + + true + + + + + 0 + 0 + 687 + 61 + + + + + + + true + + + + + + + From 257195be1f79361950e4b94167e06b07421870d0 Mon Sep 17 00:00:00 2001 From: John Schember Date: Mon, 23 May 2011 07:44:03 -0400 Subject: [PATCH 40/50] .. --- src/calibre/customize/builtins.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 383a154eff..680e36d0f3 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1269,7 +1269,7 @@ class StoreKoboStore(StoreBase): actual_plugin = 'calibre.gui2.store.kobo_plugin:KoboStore' drm_free_only = False - headquarters = 'US' + headquarters = 'CA' formats = ['EPUB'] class StoreManyBooksStore(StoreBase): From 6ff2d3c346b57681ce3e2620f6f86999c77bbf1a Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 23 May 2011 13:58:56 +0100 Subject: [PATCH 41/50] Add syntax highlighting and parenthesis matching to the template editor --- src/calibre/gui2/dialogs/template_dialog.py | 203 +++++++++++++++++++- 1 file changed, 202 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py index 174056ef80..da2b730444 100644 --- a/src/calibre/gui2/dialogs/template_dialog.py +++ b/src/calibre/gui2/dialogs/template_dialog.py @@ -5,10 +5,190 @@ __license__ = 'GPL v3' import json -from PyQt4.Qt import Qt, QDialog, QDialogButtonBox +from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QSyntaxHighlighter, + QRegExp, QSettings, QVariant, QApplication, + QTextCharFormat, QFont, QColor, QCursor) + from calibre.gui2.dialogs.template_dialog_ui import Ui_TemplateDialog from calibre.utils.formatter_functions import formatter_functions +class ParenPosition: + + def __init__(self, block, pos, paren): + self.block = block + self.pos = pos + self.paren = paren + self.highlight = False + + def set_highlight(self, to_what): + self.highlight = to_what + +class TemplateHighlighter(QSyntaxHighlighter): + + Config = {} + Rules = [] + Formats = {} + + KEYWORDS = ["program"] + + def __init__(self, parent=None): + super(TemplateHighlighter, self).__init__(parent) + + self.initializeFormats() + + TemplateHighlighter.Rules.append((QRegExp( + "|".join([r"\b%s\b" % keyword for keyword in self.KEYWORDS])), + "keyword")) + TemplateHighlighter.Rules.append((QRegExp( + "|".join([r"\b%s\b" % builtin for builtin in + formatter_functions.get_builtins()])), + "builtin")) + + TemplateHighlighter.Rules.append((QRegExp( + r"\b[+-]?[0-9]+[lL]?\b" + r"|\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b" + r"|\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b"), + "number")) + + stringRe = QRegExp(r"""(?:[^:]'[^']*'|"[^"]*")""") + stringRe.setMinimal(True) + TemplateHighlighter.Rules.append((stringRe, "string")) + + lparenRe = QRegExp(r'\(') + lparenRe.setMinimal(True) + TemplateHighlighter.Rules.append((lparenRe, "lparen")) + rparenRe = QRegExp(r'\)') + rparenRe.setMinimal(True) + TemplateHighlighter.Rules.append((rparenRe, "rparen")) + + self.regenerate_paren_positions() + self.highlighted_paren = False + + def initializeFormats(self): + Config = self.Config + Config["fontfamily"] = "Bitstream Vera Sans Mono" + Config["fontsize"] = 10 + for name, color, bold, italic in ( + ("normal", "#000000", False, False), + ("keyword", "#000080", True, False), + ("builtin", "#0000A0", False, False), + ("comment", "#007F00", False, True), + ("string", "#808000", False, False), + ("number", "#924900", False, False), + ("lparen", "#000000", True, True), + ("rparen", "#000000", True, True)): + Config["%sfontcolor" % name] = color + Config["%sfontbold" % name] = bold + Config["%sfontitalic" % name] = italic + + baseFormat = QTextCharFormat() + baseFormat.setFontFamily(Config["fontfamily"]) + baseFormat.setFontPointSize(Config["fontsize"]) + + for name in ("normal", "keyword", "builtin", "comment", + "string", "number", "lparen", "rparen"): + format = QTextCharFormat(baseFormat) + format.setForeground(QColor(Config["%sfontcolor" % name])) + if Config["%sfontbold" % name]: + format.setFontWeight(QFont.Bold) + format.setFontItalic(Config["%sfontitalic" % name]) + self.Formats[name] = format + + def find_paren(self, bn, pos): + for pp in self.paren_positions: + if pp.block == bn and pp.pos == pos: + return pp + return None + + def highlightBlock(self, text): + bn = self.currentBlock().blockNumber() + textLength = text.length() + + self.setFormat(0, textLength, self.Formats["normal"]) + + if text.isEmpty(): + pass + elif text[0] == "#": + self.setFormat(0, text.length(), self.Formats["comment"]) + return + + for regex, format in TemplateHighlighter.Rules: + i = regex.indexIn(text) + while i >= 0: + length = regex.matchedLength() + if format in ['lparen', 'rparen']: + pp = self.find_paren(bn, i) + if pp and pp.highlight: + self.setFormat(i, length, self.Formats[format]) + else: + self.setFormat(i, length, self.Formats[format]) + i = regex.indexIn(text, i + length) + + if self.generate_paren_positions: + t = unicode(text) + i = 0 + first = True + while i < len(t): + c = t[i] + if c == ':': + if first and i+1 < len(t) and t[i+1] == "'": + i += 2 + elif c in ["'", '"']: + first = False + i += 1 + j = t[i:].find(c) + if j < 0: + i = len(t) + else: + i = i + j + elif c == '(': + self.paren_positions.append(ParenPosition(bn, i, '(')) + elif c == ')': + self.paren_positions.append(ParenPosition(bn, i, ')')) + i += 1 + + def rehighlight(self): + QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) + QSyntaxHighlighter.rehighlight(self) + QApplication.restoreOverrideCursor() + + def check_cursor_pos(self, chr, block, pos_in_block): + found_pp = -1 + for i, pp in enumerate(self.paren_positions): + pp.set_highlight(False) + if pp.block == block and pp.pos == pos_in_block: + found_pp = i + + if chr not in ['(', ')']: + if self.highlighted_paren: + self.rehighlight() + self.highlighted_paren = False + return + + if found_pp >= 0: + stack = 0 + if chr == '(': + list = self.paren_positions[found_pp+1:] + else: + list = reversed(self.paren_positions[0:found_pp]) + for pp in list: + if pp.paren == chr: + stack += 1; + elif stack: + stack -= 1 + else: + pp.set_highlight(True) + self.paren_positions[found_pp].set_highlight(True) + break + self.highlighted_paren = True + self.rehighlight() + + def regenerate_paren_positions(self): + self.generate_paren_positions = True + self.paren_positions = [] + self.rehighlight() + self.generate_paren_positions = False + class TemplateDialog(QDialog, Ui_TemplateDialog): def __init__(self, parent, text): @@ -20,6 +200,11 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): self.setWindowFlags(self.windowFlags()&(~Qt.WindowContextHelpButtonHint)) self.setWindowIcon(icon) + self.last_text = '' + self.highlighter = TemplateHighlighter(self.textbox.document()) + self.textbox.cursorPositionChanged.connect(self.text_cursor_changed) + self.textbox.textChanged.connect(self.textbox_changed) + self.textbox.setTabStopWidth(10) self.source_code.setTabStopWidth(10) self.documentation.setReadOnly(True) @@ -46,6 +231,22 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): self.function.setCurrentIndex(0) self.function.currentIndexChanged[str].connect(self.function_changed) + def textbox_changed(self): + cur_text = unicode(self.textbox.toPlainText()) + if self.last_text != cur_text: + self.last_text = cur_text + self.highlighter.regenerate_paren_positions() + + def text_cursor_changed(self): + cursor = self.textbox.textCursor() + block_number = cursor.blockNumber() + pos_in_block = cursor.positionInBlock() + position = cursor.position() + t = unicode(self.textbox.toPlainText()) + if position < len(t): + self.highlighter.check_cursor_pos(t[position], block_number, + pos_in_block) + def function_changed(self, toWhat): name = unicode(toWhat) self.source_code.clear() From e624da286e8bd3f47990750815bab6b9f1fb6842 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 23 May 2011 16:12:02 +0100 Subject: [PATCH 42/50] Improvements to paren matching algorithm. --- src/calibre/gui2/dialogs/template_dialog.py | 25 ++++++++++++--------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py index da2b730444..b82e8b00bd 100644 --- a/src/calibre/gui2/dialogs/template_dialog.py +++ b/src/calibre/gui2/dialogs/template_dialog.py @@ -28,6 +28,7 @@ class TemplateHighlighter(QSyntaxHighlighter): Config = {} Rules = [] Formats = {} + BN_FACTOR = 1000 KEYWORDS = ["program"] @@ -95,10 +96,8 @@ class TemplateHighlighter(QSyntaxHighlighter): self.Formats[name] = format def find_paren(self, bn, pos): - for pp in self.paren_positions: - if pp.block == bn and pp.pos == pos: - return pp - return None + dex = bn * self.BN_FACTOR + pos + return self.paren_pos_map.get(dex, None) def highlightBlock(self, text): bn = self.currentBlock().blockNumber() @@ -127,24 +126,27 @@ class TemplateHighlighter(QSyntaxHighlighter): if self.generate_paren_positions: t = unicode(text) i = 0 - first = True + foundQuote = False while i < len(t): c = t[i] if c == ':': - if first and i+1 < len(t) and t[i+1] == "'": + # Deal with the funky syntax of template program mode. + # This won't work if there are more than one template + # expression in the document. + if not foundQuote and i+1 < len(t) and t[i+1] == "'": i += 2 elif c in ["'", '"']: - first = False + foundQuote = True i += 1 j = t[i:].find(c) if j < 0: i = len(t) else: i = i + j - elif c == '(': - self.paren_positions.append(ParenPosition(bn, i, '(')) - elif c == ')': - self.paren_positions.append(ParenPosition(bn, i, ')')) + elif c in ['(', ')']: + pp = ParenPosition(bn, i, c) + self.paren_positions.append(pp) + self.paren_pos_map[bn*self.BN_FACTOR+i] = pp i += 1 def rehighlight(self): @@ -186,6 +188,7 @@ class TemplateHighlighter(QSyntaxHighlighter): def regenerate_paren_positions(self): self.generate_paren_positions = True self.paren_positions = [] + self.paren_pos_map = {} self.rehighlight() self.generate_paren_positions = False From e2cc48381d4fa53c5c7e92a10f7aec88fc6fcbba Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 23 May 2011 11:08:14 -0600 Subject: [PATCH 43/50] Nicer error message when user attempts to set title/author via Edit metadata dialog and one of the files is open in another program. --- src/calibre/gui2/metadata/basic_widgets.py | 34 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/metadata/basic_widgets.py b/src/calibre/gui2/metadata/basic_widgets.py index d662256def..d58ac4a379 100644 --- a/src/calibre/gui2/metadata/basic_widgets.py +++ b/src/calibre/gui2/metadata/basic_widgets.py @@ -88,11 +88,22 @@ class TitleEdit(EnLineEdit): def commit(self, db, id_): title = self.current_val - if self.COMMIT: - getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False) - else: - getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False, - commit=False) + try: + if self.COMMIT: + getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False) + else: + getattr(db, 'set_'+ self.TITLE_ATTR)(id_, title, notify=False, + commit=False) + except (IOError, OSError) as err: + if getattr(err, 'errno', -1) == 13: # Permission denied + import traceback + fname = err.filename if err.filename else 'file' + error_dialog(self, _('Permission denied'), + _('Could not open %s. Is it being used by another' + ' program?')%fname, det_msg=traceback.format_exc(), + show=True) + return False + raise return True @dynamic_property @@ -225,8 +236,19 @@ class AuthorsEdit(MultiCompleteComboBox): def commit(self, db, id_): authors = self.current_val - self.books_to_refresh |= db.set_authors(id_, authors, notify=False, + try: + self.books_to_refresh |= db.set_authors(id_, authors, notify=False, allow_case_change=True) + except (IOError, OSError) as err: + if getattr(err, 'errno', -1) == 13: # Permission denied + import traceback + fname = err.filename if err.filename else 'file' + error_dialog(self, _('Permission denied'), + _('Could not open %s. Is it being used by another' + ' program?')%fname, det_msg=traceback.format_exc(), + show=True) + return False + raise return True @dynamic_property From a654486d81923e2800e8ac5a5ccdb45e306136a1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 23 May 2011 12:06:03 -0600 Subject: [PATCH 44/50] Fix #786723 (Device to add - Pocketbook 360 Plus) --- src/calibre/devices/eb600/driver.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/calibre/devices/eb600/driver.py b/src/calibre/devices/eb600/driver.py index 01277980db..dbccd72ee9 100644 --- a/src/calibre/devices/eb600/driver.py +++ b/src/calibre/devices/eb600/driver.py @@ -95,9 +95,8 @@ class POCKETBOOK360(EB600): FORMATS = ['epub', 'fb2', 'prc', 'mobi', 'pdf', 'djvu', 'rtf', 'chm', 'txt'] - VENDOR_NAME = 'PHILIPS' - WINDOWS_MAIN_MEM = 'MASS_STORGE' - WINDOWS_CARD_A_MEM = 'MASS_STORGE' + VENDOR_NAME = ['PHILIPS', '__POCKET'] + WINDOWS_MAIN_MEM = WINDOWS_CARD_A_MEM = ['MASS_STORGE', 'BOOK_USB_STORAGE'] OSX_MAIN_MEM = 'Philips Mass Storge Media' OSX_CARD_A_MEM = 'Philips Mass Storge Media' From 669d3770533b35452812c9dd75f21af91cca7981 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 23 May 2011 12:07:33 -0600 Subject: [PATCH 45/50] Warn about Hotmail's asinine SMTP policy --- src/calibre/gui2/wizard/send_email.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/wizard/send_email.py b/src/calibre/gui2/wizard/send_email.py index 44cd8dd2e4..5c7d916e1a 100644 --- a/src/calibre/gui2/wizard/send_email.py +++ b/src/calibre/gui2/wizard/send_email.py @@ -138,8 +138,11 @@ class SendEmail(QWidget, Ui_Form): 'username': '', 'url': 'www.hotmail.com', 'extra': _('If you are setting up a new' - ' hotmail account, you must log in to it ' - ' once before you will be able to send mails.'), + ' hotmail account, Microsoft requires that you ' + ' verify your account periodically, before it' + ' will let calibre send email. In this case, I' + ' strongly suggest you setup a free gmail account' + ' instead.'), } }[service] d = QDialog(self) From 67d019712851b50eda01d96c5304e4cd4fa52ec9 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 23 May 2011 19:11:56 +0100 Subject: [PATCH 46/50] Add tags wizard. Robustness changes to the formatter, model, and look_feel. --- .../gui2/dialogs/template_line_editor.py | 100 +++++++++++++++++- src/calibre/gui2/library/models.py | 9 +- src/calibre/gui2/preferences/look_feel.py | 10 +- src/calibre/utils/formatter.py | 2 +- 4 files changed, 112 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index c3598a8abb..a6269a9bbc 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -5,8 +5,12 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from PyQt4.Qt import QLineEdit +from PyQt4.Qt import (QLineEdit, QDialog, QGridLayout, QLabel, + QDialogButtonBox, QColor, QTimer, QComboBox) + from calibre.gui2.dialogs.template_dialog import TemplateDialog +from calibre.gui2.complete import MultiCompleteComboBox +from calibre.gui2 import error_dialog class TemplateLineEditor(QLineEdit): @@ -14,13 +18,22 @@ class TemplateLineEditor(QLineEdit): Extend the context menu of a QLineEdit to include more actions. ''' + def __init__(self, parent): + QLineEdit.__init__(self, parent) + self.tags = None + + def set_tags(self, tags): + self.tags = tags + def contextMenuEvent(self, event): menu = self.createStandardContextMenu() menu.addSeparator() action_open_editor = menu.addAction(_('Open Template Editor')) - action_open_editor.triggered.connect(self.open_editor) + if self.tags: + action_tag_wizard = menu.addAction(_('Open Tag Wizard')) + action_tag_wizard.triggered.connect(self.tag_wizard) menu.exec_(event.globalPos()) def open_editor(self): @@ -29,4 +42,87 @@ class TemplateLineEditor(QLineEdit): if t.exec_(): self.setText(t.textbox.toPlainText()) + def tag_wizard(self): + txt = unicode(self.text()) + if txt and not txt.startswith('program:\n#tag wizard'): + error_dialog(self, _('Invalid text'), + _('The text in the box was not generated by this wizard'), + show=True, show_copy_button=False) + return + d = TagWizard(self, self.tags, unicode(self.text())) + if d.exec_(): + self.setText(d.template) +class TagWizard(QDialog): + + def __init__(self, parent, tags, txt): + QDialog.__init__(self, parent) + + self.tags = tags + l = QGridLayout() + self.setLayout(l) + l.addWidget(QLabel(_('Tag Value')), 0, 0, 1, 1) + l.addWidget(QLabel(_('Color')), 0, 1, 1, 1) + self.tagboxes = [] + self.colorboxes = [] + self.colors = [unicode(s) for s in list(QColor.colorNames())] + self.colors.insert(0, '') + for i in range(0, 10): + tb = MultiCompleteComboBox(self) + tb.set_separator(', ') + tb.update_items_cache(self.tags) + self.tagboxes.append(tb) + l.addWidget(tb, i+1, 0, 1, 1) + cb = QComboBox(self) + cb.addItems(self.colors) + self.colorboxes.append(cb) + l.addWidget(cb, i+1, 1, 1, 1) + + if txt: + lines = txt.split('\n')[3:] + i = 0 + for line in lines: + if line.startswith('#'): + t,c = line[1:].split(':|:') + try: + self.colorboxes[i].setCurrentIndex(self.colorboxes[i].findText(c)) + self.tagboxes[i].setText(t) + except: + pass + i += 1 + + bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel, parent=self) + l.addWidget(bb, 100, 1, 1, 1) + bb.accepted.connect(self.accepted) + bb.rejected.connect(self.reject) + self.template = '' + + def accepted(self): + res = ("program:\n#tag wizard -- do not directly edit\n" + " t = field('tags');\n first_non_empty(\n") + lines = [] + for tb, cb in zip(self.tagboxes, self.colorboxes): + tags = [t.strip() for t in unicode(tb.currentText()).split(',') if t.strip()] + c = unicode(cb.currentText()).strip() + if not tags or not c: + continue + if c not in self.colors: + error_dialog(self, _('Invalid color'), + _('The color {0} is not valid').format(c), + show=True, show_copy_button=False) + return False + for t in tags: + lines.append(" in_list(t, ',', '^{0}$', '{1}', '')".format(t, c)) + res += ',\n'.join(lines) + res += ')\n' + self.template = res + res = '' + for tb, cb in zip(self.tagboxes, self.colorboxes): + t = unicode(tb.currentText()).strip() + if t.endswith(','): + t = t[:-1] + c = unicode(cb.currentText()).strip() + if t and c: + res += '#' + t + ':|:' + c + '\n' + self.template += res + self.accept() \ No newline at end of file diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index d698655746..86c5871193 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -98,6 +98,7 @@ class BooksModel(QAbstractTableModel): # {{{ self.current_highlighted_idx = None self.highlight_only = False self.column_color_map = {} + self.colors = [unicode(c) for c in QColor.colorNames()] self.read_config() def change_alignment(self, colname, alignment): @@ -714,9 +715,11 @@ class BooksModel(QAbstractTableModel): # {{{ mi = self.db.get_metadata(self.id(index), index_is_id=True) fmt = self.column_color_map[key] try: - color = QColor(composite_formatter.safe_format(fmt, mi, '', mi)) - if color.isValid(): - return QVariant(color) + color = composite_formatter.safe_format(fmt, mi, '', mi) + if color in self.colors: + color = QColor(color) + if color.isValid(): + return QVariant(color) except: return NONE elif self.is_custom_column(key) and \ diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 1c9d4abfce..61ec47ef62 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -198,9 +198,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): choices.sort(key=sort_key) choices.insert(0, '') self.column_color_count = db.column_color_count+1 + tags = db.all_tags() for i in range(1, self.column_color_count): r('column_color_name_'+str(i), db.prefs, choices=choices) r('column_color_template_'+str(i), db.prefs) + temp = getattr(self, 'opt_column_color_template_'+str(i)) + temp.set_tags(tags) all_colors = [unicode(s) for s in list(QColor.colorNames())] self.colors_box.setText(', '.join(all_colors)) @@ -273,9 +276,10 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): def commit(self, *args): for i in range(1, self.column_color_count): col = getattr(self, 'opt_column_color_name_'+str(i)) - if not col.currentText(): - temp = getattr(self, 'opt_column_color_template_'+str(i)) - temp.setText('') + tpl = getattr(self, 'opt_column_color_template_'+str(i)) + if not col.currentIndex() or not unicode(tpl.text()).strip(): + col.setCurrentIndex(0) + tpl.setText('') rr = ConfigWidgetBase.commit(self, *args) if self.current_font != self.initial_font: gprefs['font'] = (self.current_font[:4] if self.current_font else diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index 2e40275beb..fccd0015c1 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -215,7 +215,7 @@ class TemplateFormatter(string.Formatter): (r'\w+', lambda x,t: (2, t)), (r'".*?((? Date: Mon, 23 May 2011 19:19:18 +0100 Subject: [PATCH 47/50] Improved documentation --- src/calibre/gui2/preferences/look_feel.py | 6 ++++++ src/calibre/gui2/preferences/look_feel.ui | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 61ec47ef62..7692a8aba7 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -167,6 +167,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): '' 'tutorial on using templates.') + '

' + + _('If you want to color a field based on tags, then right-click ' + 'in an empty template line and choose tags wizard. ' + 'It will build a template for you. You can later edit that ' + 'template with the same wizard. If you edit it by hand, the ' + 'wizard might not work or might restore old values.') + + '

' + _('The template must evaluate to one of the color names shown ' 'below. You can use any legal template expression. ' 'For example, you can set the title to always display in ' diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index ad990a1586..31fa0df234 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -419,14 +419,14 @@ then the tags will be displayed each on their own line. - Column name + Column to color - Selection template + Color selection template From 0c22359203d77f6adf5018cda5e5650ab4b22c36 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 23 May 2011 13:41:14 -0600 Subject: [PATCH 48/50] ... --- src/calibre/gui2/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/widgets.py b/src/calibre/gui2/widgets.py index a7ecdf7b88..dd8d876005 100644 --- a/src/calibre/gui2/widgets.py +++ b/src/calibre/gui2/widgets.py @@ -833,7 +833,7 @@ class PythonHighlighter(QSyntaxHighlighter): Config["tabwidth"] = settings.value("tabwidth", QVariant(4)).toInt()[0] Config["fontfamily"] = settings.value("fontfamily", - QVariant("Bitstream Vera Sans Mono")).toString() + QVariant("monospace")).toString() Config["fontsize"] = settings.value("fontsize", QVariant(10)).toInt()[0] for name, color, bold, italic in ( From bd4b5ec6ea4f0a7fbdd22e9b3d1a96a9d8d17f20 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 23 May 2011 21:25:53 +0100 Subject: [PATCH 49/50] Add color tag wizard tool button --- src/calibre/gui2/preferences/look_feel.py | 6 ++-- src/calibre/gui2/preferences/look_feel.ui | 44 +++++++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 7692a8aba7..483934825d 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -208,8 +208,10 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): for i in range(1, self.column_color_count): r('column_color_name_'+str(i), db.prefs, choices=choices) r('column_color_template_'+str(i), db.prefs) - temp = getattr(self, 'opt_column_color_template_'+str(i)) - temp.set_tags(tags) + tpl = getattr(self, 'opt_column_color_template_'+str(i)) + tpl.set_tags(tags) + toolbutton = getattr(self, 'opt_column_color_wizard_'+str(i)) + toolbutton.clicked.connect(tpl.tag_wizard) all_colors = [unicode(s) for s in list(QColor.colorNames())] self.colors_box.setText(', '.join(all_colors)) diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index 31fa0df234..a67a3585cb 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -436,30 +436,70 @@ then the tags will be displayed each on their own line. + + + + + :/images/wizard.png:/images/wizard.png + + + + + + + + :/images/wizard.png:/images/wizard.png + + + + + + + + :/images/wizard.png:/images/wizard.png + + + + + + + + :/images/wizard.png:/images/wizard.png + + + + + + + + :/images/wizard.png:/images/wizard.png + + + @@ -467,7 +507,7 @@ then the tags will be displayed each on their own line. - + @@ -505,7 +545,7 @@ then the tags will be displayed each on their own line. - + From 610210f0b290f78c2957237b4c7b60e1e795bc27 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 23 May 2011 18:24:26 -0600 Subject: [PATCH 50/50] ... --- src/calibre/manual/conversion.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/src/calibre/manual/conversion.rst b/src/calibre/manual/conversion.rst index 73358e0f72..540da0fc9a 100644 --- a/src/calibre/manual/conversion.rst +++ b/src/calibre/manual/conversion.rst @@ -655,6 +655,7 @@ Some limitations of PDF input are: * Some PDFs use special glyphs to represent ll or ff or fi, etc. Conversion of these may or may not work depending on just how they are represented internally in the PDF. * Some PDFs store their images upside down with a rotation instruction, |app| currently doesn't support that instruction, so the images will be rotated in the output as well. * Links and Tables of Contents are not supported + * PDFs that use embedded non-unicode fonts to represent non-English characters will result in garbled output for those characters To re-iterate **PDF is a really, really bad** format to use as input. If you absolutely must use PDF, then be prepared for an output ranging anywhere from decent to unusable, depending on the input PDF.