From d1e336c3dd25a7b93a8e91e274a24c56ccb18fb1 Mon Sep 17 00:00:00 2001 From: GRiker Date: Thu, 19 May 2011 16:11:05 -0600 Subject: [PATCH 01/84] Removed log statement left over from debugging title_sort xform --- src/calibre/devices/apple/driver.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/calibre/devices/apple/driver.py b/src/calibre/devices/apple/driver.py index 42949215b2..66c2819e28 100644 --- a/src/calibre/devices/apple/driver.py +++ b/src/calibre/devices/apple/driver.py @@ -2743,7 +2743,6 @@ class ITUNES(DriverBase): # Update metadata from plugboard # If self.plugboard is None (no transforms), original metadata is returned intact metadata_x = self._xform_metadata_via_plugboard(metadata, this_book.format) - self.log("metadata.title_sort: %s metadata_x.title_sort: %s" % (metadata.title_sort, metadata_x.title_sort)) if isosx: if lb_added: lb_added.name.set(metadata_x.title) From be10ae02fda678a1ec0e2da16ae001d2b667996e Mon Sep 17 00:00:00 2001 From: Li Fanxi Date: Sat, 28 May 2011 02:09:41 +0800 Subject: [PATCH 02/84] [Bug] Missing API_KEY when getting book details. --- src/calibre/ebooks/metadata/sources/douban.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/ebooks/metadata/sources/douban.py b/src/calibre/ebooks/metadata/sources/douban.py index 70bf01a00e..8f8f5b80c4 100644 --- a/src/calibre/ebooks/metadata/sources/douban.py +++ b/src/calibre/ebooks/metadata/sources/douban.py @@ -46,6 +46,8 @@ cover_url = XPath("descendant::atom:link[@rel='image']/attribute::href") def get_details(browser, url, timeout): # {{{ try: + if Douban.DOUBAN_API_KEY and Douban.DOUBAN_API_KEY != '': + url = url + "?apikey=" + Douban.DOUBAN_API_KEY raw = browser.open_novisit(url, timeout=timeout).read() except Exception as e: gc = getattr(e, 'getcode', lambda : -1) From 549c65a55752dea1bfd0bda34844cda472a8979d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 28 May 2011 23:24:58 -0600 Subject: [PATCH 03/84] Change update message so that I stop getting annoyed by people that can't seem to understand that there is no compulsion to update. --- src/calibre/gui2/update.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/update.py b/src/calibre/gui2/update.py index 9929d50a7e..847b5785e9 100644 --- a/src/calibre/gui2/update.py +++ b/src/calibre/gui2/update.py @@ -52,7 +52,8 @@ class UpdateNotification(QDialog): self.label = QLabel('

'+ _('%s has been updated to version %s. ' 'See the new features.')%(__appname__, version)) + '">new features. Only update if one of the ' + 'new features or bug fixes is important to you.')%(__appname__, version)) self.label.setOpenExternalLinks(True) self.label.setWordWrap(True) self.setWindowTitle(_('Update available!')) From 456b6b423eab32be26a8aba637d5ee57fa16ae33 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 29 May 2011 00:31:14 -0600 Subject: [PATCH 04/84] ... --- src/calibre/manual/develop.rst | 2 +- src/calibre/manual/faq.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/manual/develop.rst b/src/calibre/manual/develop.rst index f95d51bfca..c49176ceb2 100644 --- a/src/calibre/manual/develop.rst +++ b/src/calibre/manual/develop.rst @@ -65,7 +65,7 @@ this, make your changes, then run:: bzr send -o my-changes This will create a :file:`my-changes` file in the current directory, -simply attach that to a ticket on the |app| `bug tracker `_. +simply attach that to a ticket on the |app| `bug tracker `_. If you plan to do a lot of development on |app|, then the best method is to create a `Launchpad `_ account. Once you have the account, you can use it to register diff --git a/src/calibre/manual/faq.rst b/src/calibre/manual/faq.rst index 1c0b49f30b..99c53e5a37 100644 --- a/src/calibre/manual/faq.rst +++ b/src/calibre/manual/faq.rst @@ -560,7 +560,7 @@ I want some feature added to |app|. What can I do? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You have two choices: 1. Create a patch by hacking on |app| and send it to me for review and inclusion. See `Development `_. - 2. `Open a ticket `_ (you have to register and login first). Remember that |app| development is done by volunteers, so if you get no response to your feature request, it means no one feels like implementing it. + 2. `Open a ticket `_ (you have to register and login first). Remember that |app| development is done by volunteers, so if you get no response to your feature request, it means no one feels like implementing it. How is |app| licensed? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ From 6c26b9debc72060cfc10f1239d96311c1691ed08 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 10:04:34 +0100 Subject: [PATCH 05/84] Add the ondevice() function to the template language --- src/calibre/library/database2.py | 1 + src/calibre/manual/template_lang.rst | 3 ++- src/calibre/utils/formatter_functions.py | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 819ac2cd24..df465c919e 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -860,6 +860,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): mi.uuid = row[fm['uuid']] mi.title_sort = row[fm['sort']] mi.book_size = row[fm['size']] + mi.ondevice_col= row[fm['ondevice']] mi.last_modified = row[fm['last_modified']] formats = row[fm['formats']] if not formats: diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index 059376565d..28c9855ce4 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -255,6 +255,7 @@ The following functions are available in addition to those described in single-f * ``not(value)`` -- returns the string "1" if the value is empty, otherwise returns the empty string. This function works well with test or first_non_empty. You can have as many values as you want. * ``merge_lists(list1, list2, separator)`` -- return a list made by merging the items in list1 and list2, removing duplicate items using a case-insensitive compare. If items differ in case, the one in list1 is used. The items in list1 and list2 are separated by separator, as are the items in the returned list. * ``multiply(x, y)`` -- returns x * y. Throws an exception if either x or y are not numbers. + * ``ondevice()`` -- return the string "Yes" if ondevice is set, otherwise return the empty string * ``or(value, value, ...)`` -- returns the string "1" if any value is not empty, otherwise returns the empty string. This function works well with test or first_non_empty. You can have as many values as you want. * ``print(a, b, ...)`` -- prints the arguments to standard output. Unless you start calibre from the command line (``calibre-debug -g``), the output will go to a black hole. * ``raw_field(name)`` -- returns the metadata field named by name without applying any formatting. @@ -277,7 +278,7 @@ Function classification summary: * Relational: ``cmp`` , ``strcmp`` for strings * String case changes: ``lowercase``, ``uppercase``, ``titlecase``, ``capitalize`` * String manipulation: ``re``, ``shorten``, ``substr`` - * Other: ``assign``, ``booksize``, ``print``, ``format_date``, + * Other: ``assign``, ``booksize``, ``format_date``, ``ondevice`` ``print`` .. _general_mode: diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 2f15d5d592..761da2c8e2 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -568,7 +568,7 @@ class BuiltinCapitalize(BuiltinFormatterFunction): class BuiltinBooksize(BuiltinFormatterFunction): name = 'booksize' arg_count = 0 - doc = _('booksize() -- return value of the field capitalized') + doc = _('booksize() -- return value of the size field') def evaluate(self, formatter, kwargs, mi, locals): if mi.book_size is not None: @@ -578,6 +578,21 @@ class BuiltinBooksize(BuiltinFormatterFunction): pass return '' +class BuiltinOndevice(BuiltinFormatterFunction): + name = 'ondevice' + arg_count = 0 + doc = _('ondevice() -- return Yes if ondevice is set, otherwise return ' + 'the empty string') + + def evaluate(self, formatter, kwargs, mi, locals): + print mi.ondevice_col + if mi.ondevice_col: + try: + return _('Yes') + except: + pass + return '' + class BuiltinFirstNonEmpty(BuiltinFormatterFunction): name = 'first_non_empty' arg_count = -1 @@ -687,6 +702,7 @@ builtin_lowercase = BuiltinLowercase() builtin_merge_lists = BuiltinMergeLists() builtin_multiply = BuiltinMultiply() builtin_not = BuiltinNot() +builtin_ondevice = BuiltinOndevice() builtin_or = BuiltinOr() builtin_print = BuiltinPrint() builtin_raw_field = BuiltinRaw_field() From faffa55cf1299cc1beaf257f0aea765db2d37fb5 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 10:05:47 +0100 Subject: [PATCH 06/84] take out print statement --- src/calibre/utils/formatter_functions.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 761da2c8e2..bf597d5b9c 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -585,7 +585,6 @@ class BuiltinOndevice(BuiltinFormatterFunction): 'the empty string') def evaluate(self, formatter, kwargs, mi, locals): - print mi.ondevice_col if mi.ondevice_col: try: return _('Yes') From 393cfe78cdca8f96b4e85d40e612087af86076f0 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 11:30:04 +0100 Subject: [PATCH 07/84] Improvements to editing templates and formatter exception reporting. Largest improvement is adding a value preview box to the template editor. --- src/calibre/ebooks/metadata/book/base.py | 39 +++++++-------- src/calibre/gui2/dialogs/template_dialog.py | 10 +++- src/calibre/gui2/dialogs/template_dialog.ui | 50 +++++++++++++------ .../gui2/dialogs/template_line_editor.py | 6 ++- src/calibre/gui2/library/delegates.py | 3 +- src/calibre/gui2/preferences/look_feel.py | 10 ++++ src/calibre/utils/formatter.py | 9 ++-- src/calibre/utils/formatter_functions.py | 21 +++----- 8 files changed, 92 insertions(+), 56 deletions(-) diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index 5dc3f25dfb..179a96e578 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -41,27 +41,24 @@ field_metadata = FieldMetadata() class SafeFormat(TemplateFormatter): - def get_value(self, key, args, kwargs): - try: - key = key.lower() - if key != 'title_sort' and key not in TOP_LEVEL_IDENTIFIERS: - key = field_metadata.search_term_to_field_key(key) - b = self.book.get_user_metadata(key, False) - if b and b['datatype'] == 'int' and self.book.get(key, 0) == 0: - v = '' - elif b and b['datatype'] == 'float' and self.book.get(key, 0.0) == 0.0: - v = '' - else: - v = self.book.format_field(key, series_with_index=False)[1] - if v is None: - return '' - if v == '': - return '' - return v - except: - if DEBUG: - traceback.print_exc() - return key + def get_value(self, orig_key, args, kwargs): + key = orig_key.lower() + if key != 'title_sort' and key not in TOP_LEVEL_IDENTIFIERS: + key = field_metadata.search_term_to_field_key(key) + if key is None or key not in self.book.all_field_keys(): + raise ValueError(_('Value: unknown field ') + orig_key) + b = self.book.get_user_metadata(key, False) + if b and b['datatype'] == 'int' and self.book.get(key, 0) == 0: + v = '' + elif b and b['datatype'] == 'float' and self.book.get(key, 0.0) == 0.0: + v = '' + else: + v = self.book.format_field(key, series_with_index=False)[1] + if v is None: + return '' + if v == '': + return '' + return v composite_formatter = SafeFormat() diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py index ca55bb0e66..083dacbf00 100644 --- a/src/calibre/gui2/dialogs/template_dialog.py +++ b/src/calibre/gui2/dialogs/template_dialog.py @@ -11,6 +11,7 @@ from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QSyntaxHighlighter, from calibre.gui2.dialogs.template_dialog_ui import Ui_TemplateDialog from calibre.utils.formatter_functions import formatter_functions +from calibre.ebooks.metadata.book.base import composite_formatter class ParenPosition: @@ -194,10 +195,13 @@ class TemplateHighlighter(QSyntaxHighlighter): class TemplateDialog(QDialog, Ui_TemplateDialog): - def __init__(self, parent, text): + def __init__(self, parent, text, mi): QDialog.__init__(self, parent) Ui_TemplateDialog.__init__(self) self.setupUi(self) + + self.mi = mi + # Remove help icon on title bar icon = self.windowIcon() self.setWindowFlags(self.windowFlags()&(~Qt.WindowContextHelpButtonHint)) @@ -233,12 +237,16 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): self.function.addItems(func_names) self.function.setCurrentIndex(0) self.function.currentIndexChanged[str].connect(self.function_changed) + self.textbox_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() + self.template_value.setText( + composite_formatter.safe_format(cur_text, self.mi, + _('EXCEPTION: '), self.mi)) def text_cursor_changed(self): cursor = self.textbox.textCursor() diff --git a/src/calibre/gui2/dialogs/template_dialog.ui b/src/calibre/gui2/dialogs/template_dialog.ui index dd8fb7bd88..d36cbbd3d4 100644 --- a/src/calibre/gui2/dialogs/template_dialog.ui +++ b/src/calibre/gui2/dialogs/template_dialog.ui @@ -23,19 +23,39 @@ - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - + + + Template value: + + + template_value + + + The value the of the template using the current book in the library view + + + + + + + true + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + Function &name: @@ -45,10 +65,10 @@ - + - + &Documentation: @@ -61,7 +81,7 @@ - + Python &code: @@ -74,7 +94,7 @@ - + @@ -84,7 +104,7 @@ - + diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index 98b74b391d..a724b5b072 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -21,6 +21,10 @@ class TemplateLineEditor(QLineEdit): def __init__(self, parent): QLineEdit.__init__(self, parent) self.tags = None + self.mi = None + + def set_mi(self, mi): + self.mi = mi def set_tags(self, tags): self.tags = tags @@ -37,7 +41,7 @@ class TemplateLineEditor(QLineEdit): menu.exec_(event.globalPos()) def open_editor(self): - t = TemplateDialog(self, self.text()) + t = TemplateDialog(self, self.text(), self.mi) t.setWindowTitle(_('Edit template')) if t.exec_(): self.setText(t.textbox.toPlainText()) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 6990a76b21..94c3deb403 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -418,8 +418,9 @@ class CcTemplateDelegate(QStyledItemDelegate): # {{{ def createEditor(self, parent, option, index): m = index.model() + mi = m.db.get_metadata(index.row(), index_is_id=False) text = m.custom_columns[m.column_map[index.column()]]['display']['composite_template'] - editor = TemplateDialog(parent, text) + editor = TemplateDialog(parent, text, mi) editor.setWindowTitle(_("Edit template")) editor.textbox.setTabChangesFocus(False) editor.textbox.setTabStopWidth(20) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index b6e6de1902..fcdd56fd5f 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -205,11 +205,21 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): choices.insert(0, '') self.column_color_count = db.column_color_count+1 tags = db.all_tags() + + mi=None + try: + idx = gui.library_view.currentIndex().row() + if idx: + mi = db.get_metadata(idx, index_is_id=False) + except: + pass + 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) tpl = getattr(self, 'opt_column_color_template_'+str(i)) tpl.set_tags(tags) + tpl.set_mi(mi) 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())] diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index fccd0015c1..695355330e 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -98,7 +98,10 @@ class _Parser(object): cls = funcs['assign'] return cls.eval_(self.parent, self.parent.kwargs, self.parent.book, self.parent.locals, id, self.expr()) - return self.parent.locals.get(id, _('unknown id ') + id) + val = self.parent.locals.get(id, None) + if val is None: + self.error(_('Unknown identifier ') + id) + return val # We have a function. # Check if it is a known one. We do this here so error reporting is # better, as it can identify the tokens near the problem. @@ -317,8 +320,8 @@ class TemplateFormatter(string.Formatter): try: ans = self.vformat(fmt, [], kwargs).strip() except Exception as e: - if DEBUG: - traceback.print_exc() +# if DEBUG: +# traceback.print_exc() ans = error_value + ' ' + e.message return ans diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index bf597d5b9c..d7b6e63f5e 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -63,20 +63,13 @@ class FormatterFunction(object): raise NotImplementedError() def eval_(self, formatter, kwargs, mi, locals, *args): - try: - ret = self.evaluate(formatter, kwargs, mi, locals, *args) - if isinstance(ret, (str, unicode)): - return ret - if isinstance(ret, (int, float, bool)): - return unicode(ret) - if isinstance(ret, list): - return ','.join(list) - except: - traceback.print_exc() - exc_type, exc_value, exc_traceback = sys.exc_info() - info = ': '.join(traceback.format_exception(exc_type, exc_value, - exc_traceback)[-2:]).replace('\n', '') - return _('Exception ') + info + ret = self.evaluate(formatter, kwargs, mi, locals, *args) + if isinstance(ret, (str, unicode)): + return ret + if isinstance(ret, (int, float, bool)): + return unicode(ret) + if isinstance(ret, list): + return ','.join(list) all_builtin_functions = [] class BuiltinFormatterFunction(FormatterFunction): From 52da86dbb6fa48d61ea852436082b6c7b8607e82 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 13:17:07 +0100 Subject: [PATCH 08/84] Added an else box to the tag color wizard. Also added more extensive tooltips. --- .../gui2/dialogs/template_line_editor.py | 61 ++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index a724b5b072..d466cecc55 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -69,10 +69,38 @@ class TagWizard(QDialog): self.setLayout(l) l.setColumnStretch(0, 1) l.setColumnMinimumWidth(0, 300) - l.addWidget(QLabel(_('Tags (more than one per box permitted)')), 0, 0, 1, 1) - l.addWidget(QLabel(_('Color')), 0, 1, 1, 1) + h = QLabel(_('Tags (see the popup help for more information)')) + h.setToolTip('

' + + _('You can enter more than one tag per box, separated by commas. ' + 'The comparison ignores letter case.
' + 'A tag value can be a regular expression. ' + 'When using regular expressions, note that the wizard ' + 'puts anchors (^ and $) around the expression, so you ' + 'must ensure your expression matches from the beginning ' + 'to the end of the tag.
' + 'Regular expression examples:') + '

    ' + + _('
  • .* matches any tag. No empty tags are ' + 'checked, so you don\'t need to worry about empty strings
  • ' + '
  • A.* matches any tag beginning with A
  • ' + '
  • .*mystery.* matches any tag containing ' + 'the word "mystery"
  • ') + '

') + l.addWidget(h , 0, 0, 1, 1) + c = QLabel(_('Color if tag found')) + c.setToolTip('

' + + _('At least one of the two color boxes must have a value. Leave ' + 'one color box empty if you want the template to use the next ' + 'line in this wizard. If both boxes are filled in, the rest of ' + 'the lines in this wizard will be ignored.') + '

') + l.addWidget(c, 0, 1, 1, 1) + c = QLabel(_('Color if tag not found')) + c.setToolTip('

' + + _('This box is usually filled in only on the last test. If it is ' + 'filled in before the last test, then the color for tag found box ' + 'must be empty or all the rest of the tests will be ignored.') + '

') + l.addWidget(c, 0, 2, 1, 1) self.tagboxes = [] self.colorboxes = [] + self.nfcolorboxes = [] self.colors = [unicode(s) for s in list(QColor.colorNames())] self.colors.insert(0, '') for i in range(0, 10): @@ -85,15 +113,25 @@ class TagWizard(QDialog): cb.addItems(self.colors) self.colorboxes.append(cb) l.addWidget(cb, i+1, 1, 1, 1) + cb = QComboBox(self) + cb.addItems(self.colors) + self.nfcolorboxes.append(cb) + l.addWidget(cb, i+1, 2, 1, 1) if txt: lines = txt.split('\n')[3:] i = 0 for line in lines: if line.startswith('#'): - t,c = line[1:].split(':|:') + vals = line[1:].split(':|:') + if len(vals) == 2: + t, c = vals + nc = '' + else: + t,c,nc = vals try: self.colorboxes[i].setCurrentIndex(self.colorboxes[i].findText(c)) + self.nfcolorboxes[i].setCurrentIndex(self.nfcolorboxes[i].findText(nc)) self.tagboxes[i].setText(t) except: pass @@ -109,28 +147,35 @@ class TagWizard(QDialog): 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): + for tb, cb, nfcb in zip(self.tagboxes, self.colorboxes, self.nfcolorboxes): tags = [t.strip() for t in unicode(tb.text()).split(',') if t.strip()] tags = '$|^'.join(tags) c = unicode(cb.currentText()).strip() - if not tags or not c: + nfc = unicode(nfcb.currentText()).strip() + if not tags or not (c or nfc): 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 - lines.append(" in_list(t, ',', '^{0}$', '{1}', '')".format(tags, c)) + if nfc not in self.colors: + error_dialog(self, _('Invalid color'), + _('The color {0} is not valid').format(nfc), + show=True, show_copy_button=False) + return False + lines.append(" in_list(t, ',', '^{0}$', '{1}', '{2}')".format(tags, c, nfc)) res += ',\n'.join(lines) res += ')\n' self.template = res res = '' - for tb, cb in zip(self.tagboxes, self.colorboxes): + for tb, cb, nfcb in zip(self.tagboxes, self.colorboxes, self.nfcolorboxes): t = unicode(tb.text()).strip() if t.endswith(','): t = t[:-1] c = unicode(cb.currentText()).strip() + nfc = unicode(nfcb.currentText()).strip() if t and c: - res += '#' + t + ':|:' + c + '\n' + res += '#' + t + ':|:' + c + ':|:' + nfc + '\n' self.template += res self.accept() From 67d570de1c99867e69796cac4710a409bfaf34c2 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 13:39:35 +0100 Subject: [PATCH 09/84] Permit empty keys in templates. Simplifies using functions that don't require a value --- src/calibre/ebooks/metadata/book/base.py | 2 ++ src/calibre/library/save_to_disk.py | 2 ++ src/calibre/utils/formatter.py | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index 179a96e578..f98bebe1dc 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -42,6 +42,8 @@ field_metadata = FieldMetadata() class SafeFormat(TemplateFormatter): def get_value(self, orig_key, args, kwargs): + if not orig_key: + return '' key = orig_key.lower() if key != 'title_sort' and key not in TOP_LEVEL_IDENTIFIERS: key = field_metadata.search_term_to_field_key(key) diff --git a/src/calibre/library/save_to_disk.py b/src/calibre/library/save_to_disk.py index dc83b44c01..5f49833564 100644 --- a/src/calibre/library/save_to_disk.py +++ b/src/calibre/library/save_to_disk.py @@ -134,6 +134,8 @@ class SafeFormat(TemplateFormatter): ''' def get_value(self, key, args, kwargs): + if key == '': + return '' try: key = key.lower() try: diff --git a/src/calibre/utils/formatter.py b/src/calibre/utils/formatter.py index 695355330e..ebf47db854 100644 --- a/src/calibre/utils/formatter.py +++ b/src/calibre/utils/formatter.py @@ -342,6 +342,8 @@ class EvalFormatter(TemplateFormatter): A template formatter that uses a simple dict instead of an mi instance ''' def get_value(self, key, args, kwargs): + if key == '': + return '' key = key.lower() return kwargs.get(key, _('No such variable ') + key) From 0d57a3fb18f03574a242789cce9189e33aa2e54e Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 14:09:01 +0100 Subject: [PATCH 10/84] Correct some problems with setting the ondevice column values when the device is disconnected. --- src/calibre/gui2/device.py | 3 ++- src/calibre/gui2/library/models.py | 2 +- src/calibre/utils/formatter_functions.py | 5 +---- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 3977a6bca1..dd9d7aaa50 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -1294,7 +1294,8 @@ class DeviceMixin(object): # {{{ self.book_db_uuid_path_map = None return - if not hasattr(self, 'db_book_uuid_cache'): + if not self.device_manager.is_device_connected or \ + not hasattr(self, 'db_book_uuid_cache'): return loc if self.book_db_id_cache is None: diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 554b104c34..793f2d353b 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -125,7 +125,7 @@ class BooksModel(QAbstractTableModel): # {{{ def refresh_ondevice(self): self.db.refresh_ondevice() - self.resort() + self.refresh(reset=False) self.research() def set_book_on_device_func(self, func): diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index d7b6e63f5e..76faf04941 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -579,10 +579,7 @@ class BuiltinOndevice(BuiltinFormatterFunction): def evaluate(self, formatter, kwargs, mi, locals): if mi.ondevice_col: - try: - return _('Yes') - except: - pass + return _('Yes') return '' class BuiltinFirstNonEmpty(BuiltinFormatterFunction): From 322e6d9ac44e9304cccfedda1d69a654f9805673 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 15:09:56 +0100 Subject: [PATCH 11/84] Add an RE box to the color tags wizard. Add the necessary function to the template language. Fix problem with passing mi to the template editor. --- src/calibre/ebooks/metadata/book/base.py | 2 +- .../gui2/dialogs/template_line_editor.py | 67 +++++++++++++------ src/calibre/gui2/preferences/look_feel.py | 3 +- src/calibre/utils/formatter_functions.py | 22 +++++- 4 files changed, 70 insertions(+), 24 deletions(-) diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index f98bebe1dc..3e2201f6a4 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -47,7 +47,7 @@ class SafeFormat(TemplateFormatter): key = orig_key.lower() if key != 'title_sort' and key not in TOP_LEVEL_IDENTIFIERS: key = field_metadata.search_term_to_field_key(key) - if key is None or key not in self.book.all_field_keys(): + if key is None or (self.book and key not in self.book.all_field_keys()): raise ValueError(_('Value: unknown field ') + orig_key) b = self.book.get_user_metadata(key, False) if b and b['datatype'] == 'int' and self.book.get(key, 0) == 0: diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index d466cecc55..3d199b156c 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -5,7 +5,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from PyQt4.Qt import (QLineEdit, QDialog, QGridLayout, QLabel, +from PyQt4.Qt import (QLineEdit, QDialog, QGridLayout, QLabel, QCheckBox, QDialogButtonBox, QColor, QComboBox, QIcon) from calibre.gui2.dialogs.template_dialog import TemplateDialog @@ -73,8 +73,8 @@ class TagWizard(QDialog): h.setToolTip('

' + _('You can enter more than one tag per box, separated by commas. ' 'The comparison ignores letter case.
' - 'A tag value can be a regular expression. ' - 'When using regular expressions, note that the wizard ' + 'A tag value can be a regular expression. Check the box to turn ' + 'them on. When using regular expressions, note that the wizard ' 'puts anchors (^ and $) around the expression, so you ' 'must ensure your expression matches from the beginning ' 'to the end of the tag.
' @@ -85,22 +85,29 @@ class TagWizard(QDialog): '

  • .*mystery.* matches any tag containing ' 'the word "mystery"
  • ') + '

    ') l.addWidget(h , 0, 0, 1, 1) + + c = QLabel(_('is RE')) + c.setToolTip('

    ' + + _('Check this box if the tag box contains regular expressions') + '

    ') + l.addWidget(c, 0, 1, 1, 1) + c = QLabel(_('Color if tag found')) c.setToolTip('

    ' + _('At least one of the two color boxes must have a value. Leave ' 'one color box empty if you want the template to use the next ' 'line in this wizard. If both boxes are filled in, the rest of ' 'the lines in this wizard will be ignored.') + '

    ') - l.addWidget(c, 0, 1, 1, 1) + l.addWidget(c, 0, 2, 1, 1) c = QLabel(_('Color if tag not found')) c.setToolTip('

    ' + _('This box is usually filled in only on the last test. If it is ' 'filled in before the last test, then the color for tag found box ' 'must be empty or all the rest of the tests will be ignored.') + '

    ') - l.addWidget(c, 0, 2, 1, 1) + l.addWidget(c, 0, 3, 1, 1) self.tagboxes = [] self.colorboxes = [] self.nfcolorboxes = [] + self.reboxes = [] self.colors = [unicode(s) for s in list(QColor.colorNames())] self.colors.insert(0, '') for i in range(0, 10): @@ -109,14 +116,20 @@ class TagWizard(QDialog): 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) - cb = QComboBox(self) - cb.addItems(self.colors) - self.nfcolorboxes.append(cb) - l.addWidget(cb, i+1, 2, 1, 1) + + w = QCheckBox(self) + self.reboxes.append(w) + l.addWidget(w, i+1, 1, 1, 1) + + w = QComboBox(self) + w.addItems(self.colors) + self.colorboxes.append(w) + l.addWidget(w, i+1, 2, 1, 1) + + w = QComboBox(self) + w.addItems(self.colors) + self.nfcolorboxes.append(w) + l.addWidget(w, i+1, 3, 1, 1) if txt: lines = txt.split('\n')[3:] @@ -127,18 +140,20 @@ class TagWizard(QDialog): if len(vals) == 2: t, c = vals nc = '' + re = False else: - t,c,nc = vals + t,c,nc,re = vals try: self.colorboxes[i].setCurrentIndex(self.colorboxes[i].findText(c)) self.nfcolorboxes[i].setCurrentIndex(self.nfcolorboxes[i].findText(nc)) self.tagboxes[i].setText(t) + self.reboxes[i].setChecked(re == '2') except: pass i += 1 bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel, parent=self) - l.addWidget(bb, 100, 1, 1, 1) + l.addWidget(bb, 100, 2, 1, 2) bb.accepted.connect(self.accepted) bb.rejected.connect(self.reject) self.template = '' @@ -147,11 +162,16 @@ class TagWizard(QDialog): res = ("program:\n#tag wizard -- do not directly edit\n" " t = field('tags');\n first_non_empty(\n") lines = [] - for tb, cb, nfcb in zip(self.tagboxes, self.colorboxes, self.nfcolorboxes): + for tb, cb, nfcb, reb in zip(self.tagboxes, self.colorboxes, + self.nfcolorboxes, self.reboxes): tags = [t.strip() for t in unicode(tb.text()).split(',') if t.strip()] - tags = '$|^'.join(tags) c = unicode(cb.currentText()).strip() nfc = unicode(nfcb.currentText()).strip() + re = reb.checkState() + if re == 2: + tags = '$|^'.join(tags) + else: + tags = ','.join(tags) if not tags or not (c or nfc): continue if c not in self.colors: @@ -164,18 +184,25 @@ class TagWizard(QDialog): _('The color {0} is not valid').format(nfc), show=True, show_copy_button=False) return False - lines.append(" in_list(t, ',', '^{0}$', '{1}', '{2}')".format(tags, c, nfc)) + if re == 2: + lines.append(" in_list(t, ',', '^{0}$', '{1}', '{2}')".\ + format(tags, c, nfc)) + else: + lines.append(" str_in_list(t, ',', '{0}', '{1}', '{2}')".\ + format(tags, c, nfc)) res += ',\n'.join(lines) res += ')\n' self.template = res res = '' - for tb, cb, nfcb in zip(self.tagboxes, self.colorboxes, self.nfcolorboxes): + for tb, cb, nfcb, reb in zip(self.tagboxes, self.colorboxes, + self.nfcolorboxes, self.reboxes): t = unicode(tb.text()).strip() if t.endswith(','): t = t[:-1] c = unicode(cb.currentText()).strip() nfc = unicode(nfcb.currentText()).strip() + re = unicode(reb.checkState()) if t and c: - res += '#' + t + ':|:' + c + ':|:' + nfc + '\n' + res += '#' + t + ':|:' + c + ':|:' + nfc + ':|:' + re + '\n' self.template += res self.accept() diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index fcdd56fd5f..37e4588b9b 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -209,8 +209,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): mi=None try: idx = gui.library_view.currentIndex().row() - if idx: - mi = db.get_metadata(idx, index_is_id=False) + mi = db.get_metadata(idx, index_is_id=False) except: pass diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 76faf04941..7d5dbe3e0e 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -8,7 +8,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import inspect, re, traceback, sys +import inspect, re, traceback from calibre.utils.titlecase import titlecase from calibre.utils.icu import capitalize, strcmp, sort_key @@ -336,6 +336,25 @@ class BuiltinInList(BuiltinFormatterFunction): return fv return nfv +class BuiltinStrInList(BuiltinFormatterFunction): + name = 'str_in_list' + arg_count = 5 + doc = _('str_in_list(val, separator, string, found_val, not_found_val) -- ' + 'treat val as a list of items separated by separator, ' + 'comparing the string against each value in the list. If the ' + 'string matches a value, return found_val, otherwise return ' + 'not_found_val. If the string contains separators, then it is ' + 'also treated as a list and each value is checked.') + + def evaluate(self, formatter, kwargs, mi, locals, val, sep, str, fv, nfv): + l = [v.strip() for v in val.split(sep) if v.strip()] + c = [v.strip() for v in str.split(sep) if v.strip()] + for v in l: + for t in c: + if strcmp(t, v) == 0: + return fv + return nfv + class BuiltinRe(BuiltinFormatterFunction): name = 're' arg_count = 3 @@ -700,6 +719,7 @@ builtin_select = BuiltinSelect() builtin_shorten = BuiltinShorten() builtin_strcat = BuiltinStrcat() builtin_strcmp = BuiltinStrcmp() +builtin_str_in_list = BuiltinStrInList() builtin_subitems = BuiltinSubitems() builtin_sublist = BuiltinSublist() builtin_substr = BuiltinSubstr() From b9b6286209dcf3e3355f6696cdfb0218e612c017 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 15:18:19 +0100 Subject: [PATCH 12/84] ... --- src/calibre/manual/template_lang.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index 28c9855ce4..ec398b5d28 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -130,6 +130,7 @@ The functions available are: * ``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. * ``lookup(pattern, field, pattern, field, ..., else_field)`` -- like switch, except the arguments are field (metadata) names, not text. The value of the appropriate field will be fetched and used. Note that because composite columns are fields, you can use this function in one composite field to use the value of some other composite field. This is extremely useful when constructing variable save paths (more later). * ``select(key)`` -- interpret the field as a comma-separated list of items, with the items being of the form "id:value". Find the pair with the id equal to key, and return the corresponding value. This function is particularly useful for extracting a value such as an isbn from the set of identifiers for a book. + * ``str_in_list(val, separator, string, found_val, not_found_val)`` -- treat val as a list of items separated by separator, comparing the string against each value in the list. If the string matches a value, return found_val, otherwise return not_found_val. If the string contains separators, then it is also treated as a list and each value is checked. * ``subitems(val, start_index, end_index)`` -- This function is used to break apart lists of tag-like hierarchical items such as genres. It interprets the value as a comma-separated list of tag-like items, where each item is a period-separated list. Returns a new list made by first finding all the period-separated tag-like items, then for each such item extracting the components from `start_index` to `end_index`, then combining the results back together. The first component in a period-separated list has an index of zero. If an index is negative, then it counts from the end of the list. As a special case, an end_index of zero is assumed to be the length of the list. Examples:: Assuming a #genre column containing "A.B.C": @@ -272,10 +273,10 @@ Function classification summary: * Boolean: ``and``, ``or``, ``not``. The function ``if_empty`` is similar to ``and`` called with one argument. * If-then-else: ``contains``, ``test`` * Iterating over values: ``first_non_empty``, ``lookup``, ``switch`` - * List lookup: ``in_list``, ``list_item``, ``select``, + * List lookup: ``in_list``, ``list_item``, ``select``, ``str_in_list`` * List manipulation: ``count``, ``merge_lists``, ``sublist``, ``subitems`` * Recursion: ``eval``, ``template`` - * Relational: ``cmp`` , ``strcmp`` for strings + * Relational: ``cmp`` (for numbers), ``strcmp`` (for strings) * String case changes: ``lowercase``, ``uppercase``, ``titlecase``, ``capitalize`` * String manipulation: ``re``, ``shorten``, ``substr`` * Other: ``assign``, ``booksize``, ``format_date``, ``ondevice`` ``print`` From 87bd2bd5716640f114acae839e7c1c598c477298 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 15:46:17 +0100 Subject: [PATCH 13/84] Make formatter functions that use regexps ignore case --- src/calibre/utils/formatter_functions.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 7d5dbe3e0e..32822e1d72 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -269,7 +269,7 @@ class BuiltinLookup(BuiltinFormatterFunction): while i < len(args): if i + 1 >= len(args): return formatter.vformat('{' + args[i].strip() + '}', [], kwargs) - if re.search(args[i], val): + if re.search(args[i], val, flags=re.I): return formatter.vformat('{'+args[i+1].strip() + '}', [], kwargs) i += 2 @@ -295,7 +295,7 @@ class BuiltinContains(BuiltinFormatterFunction): def evaluate(self, formatter, kwargs, mi, locals, val, test, value_if_present, value_if_not): - if re.search(test, val): + if re.search(test, val, flags=re.I): return value_if_present else: return value_if_not @@ -316,7 +316,7 @@ class BuiltinSwitch(BuiltinFormatterFunction): while i < len(args): if i + 1 >= len(args): return args[i] - if re.search(args[i], val): + if re.search(args[i], val, flags=re.I): return args[i+1] i += 2 @@ -332,7 +332,7 @@ class BuiltinInList(BuiltinFormatterFunction): 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): + if re.search(pat, v, flags=re.I): return fv return nfv @@ -364,7 +364,7 @@ class BuiltinRe(BuiltinFormatterFunction): 'python-compatible regular expressions') def evaluate(self, formatter, kwargs, mi, locals, val, pattern, replacement): - return re.sub(pattern, replacement, val) + return re.sub(pattern, replacement, val, flags=re.I) class BuiltinIfempty(BuiltinFormatterFunction): name = 'ifempty' From 267687f424a3527aac683a1ea00c0d87244b0fe9 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 15:48:20 +0100 Subject: [PATCH 14/84] ... --- src/calibre/manual/template_lang.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index ec398b5d28..f1d2844d37 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -114,6 +114,8 @@ The syntax for using functions is ``{field:function(arguments)}``, or ``{field:f If you have programming experience, please note that the syntax in this mode (single function) is not what you might expect. Strings are not quoted. Spaces are significant. All arguments must be constants; there is no sub-evaluation. Use :ref:`template program mode ` and :ref:`general program mode ` to avoid these differences. +Many functions use regular expressions. In all cases, regular expression matching is case-insensitive. + The functions available are: * ``lowercase()`` -- return value of the field in lower case. From 35bf5ed46e359a13211abd3f71a78da16de309db Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 17:36:06 +0100 Subject: [PATCH 15/84] Refresh the db when on_device is refreshed only if composite columns are defined. --- src/calibre/gui2/library/models.py | 2 +- src/calibre/library/caches.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 793f2d353b..554b104c34 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -125,7 +125,7 @@ class BooksModel(QAbstractTableModel): # {{{ def refresh_ondevice(self): self.db.refresh_ondevice() - self.refresh(reset=False) + self.resort() self.research() def set_book_on_device_func(self, func): diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index 98fd3a9fbc..2ad425fc00 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -914,6 +914,8 @@ class ResultCache(SearchQueryParser): # {{{ return len(self._map) def refresh_ondevice(self, db): + if self.composites: + self.refresh(db) ondevice_col = self.FIELD_MAP['ondevice'] for item in self._data: if item is not None: From 88709bb88ffbdc2cd5972987b89b4047fde831b2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 29 May 2011 11:06:56 -0600 Subject: [PATCH 16/84] Windows installer: Remember and use previous settings for installing desktop icons, adding to path, etc. --- setup/installer/windows/wix-template.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/setup/installer/windows/wix-template.xml b/setup/installer/windows/wix-template.xml index d4bfbc3c7c..0a85b6fb81 100644 --- a/setup/installer/windows/wix-template.xml +++ b/setup/installer/windows/wix-template.xml @@ -17,6 +17,7 @@ IncludeMaximum="yes" OnlyDetect="no" Language="1033" + MigrateFeatures="yes" Property="OLDPRODUCTFOUND"/> Date: Sun, 29 May 2011 11:26:35 -0600 Subject: [PATCH 17/84] Observatorul cultural by song2 and update Dilema Veche --- recipes/dilemaveche.recipe | 116 +++++++++++++++------------ recipes/observatorul_cultural.recipe | 64 +++++++++++++++ 2 files changed, 130 insertions(+), 50 deletions(-) create mode 100644 recipes/observatorul_cultural.recipe diff --git a/recipes/dilemaveche.recipe b/recipes/dilemaveche.recipe index 0d5013b287..8ba75c4123 100644 --- a/recipes/dilemaveche.recipe +++ b/recipes/dilemaveche.recipe @@ -1,55 +1,71 @@ -# -*- coding: utf-8 -*- -#!/usr/bin/env python - -__license__ = 'GPL v3' -__copyright__ = u'2011, Silviu Cotoar\u0103' -''' -dilemaveche.ro -''' - from calibre.web.feeds.news import BasicNewsRecipe class DilemaVeche(BasicNewsRecipe): - title = u'Dilema Veche' - __author__ = u'Silviu Cotoar\u0103' - description = u'Sunt vechi, domnule!' - publisher = u'Dilema Veche' - oldest_article = 50 - language = 'ro' - max_articles_per_feed = 100 - no_stylesheets = True - use_embedded_content = False - category = 'Ziare' - encoding = 'utf-8' - cover_url = 'http://www.dilemaveche.ro/sites/all/themes/dilema/theme/dilema_two/layouter/dilema_two_homepage/logo.png' - - conversion_options = { - 'comments' : description - ,'tags' : category - ,'language' : language - ,'publisher' : publisher - } - - keep_only_tags = [ - dict(name='h1', attrs={'class':'art_title'}) - , dict(name='h1', attrs={'class':'art_title online'}) - , dict(name='div', attrs={'class':'item'}) - , dict(name='div', attrs={'class':'art_content'}) - ] - + title = u'Dilema Veche' # apare vinerea, mai pe dupa-masa,depinde de Luiza cred (care se semneaza ca fiind creatorul fiecarui articol in feed-ul RSS) + __author__ = 'song2' # inspirat din scriptul pentru Le Monde. Inspired from the Le Monde script + description = '"Sint vechi, domnule!" (I.L. Caragiale)' + publisher = 'Adevarul Holding' + oldest_article = 7 + max_articles_per_feed = 200 + encoding = 'utf8' + language = 'ro' + masthead_url = 'http://www.dilemaveche.ro/sites/all/themes/dilema/theme/dilema_two/layouter/dilema_two_homepage/logo.png' + publication_type = 'magazine' + feeds = [ + ('Editoriale si opinii - Situatiunea', 'http://www.dilemaveche.ro/taxonomy/term/37/0/feed'), + ('Editoriale si opinii - Pe ce lume traim', 'http://www.dilemaveche.ro/taxonomy/term/38/0/feed'), + ('Editoriale si opinii - Bordeie si obiceie', 'http://www.dilemaveche.ro/taxonomy/term/44/0/feed'), + ('Editoriale si opinii - Talc Show', 'http://www.dilemaveche.ro/taxonomy/term/44/0/feed'), + ('Tema saptamanii', 'http://www.dilemaveche.ro/taxonomy/term/19/0/feed'), + ('La zi in cultura - Dilema va recomanda', 'http://www.dilemaveche.ro/taxonomy/term/58/0/feed'), + ('La zi in cultura - Carte', 'http://www.dilemaveche.ro/taxonomy/term/14/0/feed'), + ('La zi in cultura - Film', 'http://www.dilemaveche.ro/taxonomy/term/13/0/feed'), + ('La zi in cultura - Muzica', 'http://www.dilemaveche.ro/taxonomy/term/1341/0/feed'), + ('La zi in cultura - Arte performative', 'http://www.dilemaveche.ro/taxonomy/term/1342/0/feed'), + ('La zi in cultura - Arte vizuale', 'http://www.dilemaveche.ro/taxonomy/term/1512/0/feed'), + ('Societate - Ieri cu vedere spre azi', 'http://www.dilemaveche.ro/taxonomy/term/15/0/feed'), + ('Societate - Din polul opus', 'http://www.dilemaveche.ro/taxonomy/term/41/0/feed'), + ('Societate - Mass comedia', 'http://www.dilemaveche.ro/taxonomy/term/43/0/feed'), + ('Societate - La singular si la plural', 'http://www.dilemaveche.ro/taxonomy/term/42/0/feed'), + ('Oameni si idei - Educatie', 'http://www.dilemaveche.ro/taxonomy/term/46/0/feed'), + ('Oameni si idei - Polemici si dezbateri', 'http://www.dilemaveche.ro/taxonomy/term/48/0/feed'), + ('Oameni si idei - Stiinta si tehnologie', 'http://www.dilemaveche.ro/taxonomy/term/46/0/feed'), + ('Dileme on-line', 'http://www.dilemaveche.ro/taxonomy/term/005/0/feed') + ] + remove_tags_before = dict(name='div',attrs={'class':'spacer_10'}) remove_tags = [ - dict(name='div', attrs={'class':['article_details']}) - , dict(name='div', attrs={'class':['controale']}) - , dict(name='div', attrs={'class':['art_related_left']}) - ] + dict(name='div', attrs={'class':'art_related_left'}), + dict(name='div', attrs={'class':'controale'}), + dict(name='div', attrs={'class':'simple_overlay'}), + ] + remove_tags_after = [dict(id='facebookLike')] + remove_javascript = True + no_stylesheets = True + remove_empty_feeds = True + extra_css = """ + body{font-family: Georgia,Times,serif } + img{margin-bottom: 0.4em; display:block} + """ + def get_cover_url(self): + cover_url = None + soup = self.index_to_soup('http://dilemaveche.ro') + link_item = soup.find('div',attrs={'class':'box_dr_pdf_picture'}) + if link_item and link_item.a: + cover_url = link_item.a['href'] + br = BasicNewsRecipe.get_browser() + try: + br.open(cover_url) + except: #daca nu gaseste pdf-ul + self.log("\nPDF indisponibil") + link_item = soup.find('div',attrs={'class':'box_dr_pdf_picture'}) + if link_item and link_item.img: + cover_url = link_item.img['src'] + br = BasicNewsRecipe.get_browser() + try: + br.open(cover_url) + except: #daca nu gaseste nici imaginea mica mica + print('Mama lor de nenorociti! nu este nici pdf nici imagine') + cover_url ='http://www.dilemaveche.ro/sites/all/themes/dilema/theme/dilema_two/layouter/dilema_two_homepage/logo.png' + return cover_url + cover_margins = (10, 15, '#ffffff') - remove_tags_after = [ - dict(name='div', attrs={'class':['article_details']}) - ] - - feeds = [ - (u'Feeds', u'http://www.dilemaveche.ro/rss.xml') - ] - - def preprocess_html(self, soup): - return self.adeify_images(soup) diff --git a/recipes/observatorul_cultural.recipe b/recipes/observatorul_cultural.recipe new file mode 100644 index 0000000000..0d64334fd5 --- /dev/null +++ b/recipes/observatorul_cultural.recipe @@ -0,0 +1,64 @@ +import re +from calibre.web.feeds.news import BasicNewsRecipe +coverpage = None + +class ObservatorulCultural(BasicNewsRecipe): + title = u'Observatorul cultural' + __author__ = 'song2' #prelucrat dupa un script de http://www.thenowhereman.com + encoding = 'utf-8' + language = 'ro' + publication_type = 'magazine' + description = 'Spiritul critic in acÅĢiune\n' + no_stylesheets = True + remove_javascript = True + masthead_url='http://www.observatorcultural.ro/userfiles/article/sigla%20Observator%20cultural_02231058.JPG' + keep_only_tags = [ + dict(name='div', attrs={'class':'detaliuArticol'})] + remove_tags = [dict(name='div', attrs={'class':'comentariiArticol'}), + dict(name='div', attrs={'class':'postComment'}), + dict(name='div', attrs={'class':'utileArticol'}), + dict(name='p', attrs={'class':'butonComenteaza'}), + dict(name='h5'), + dict(name='div', attrs={'style':'margin-top: 0px; padding-top: 0px;'}) + ] + def parse_index(self): + soup = self.index_to_soup('http://www.observatorcultural.ro/Arhiva*-archive.html') + issueTag = soup.find('a', href=re.compile("observatorcultural.ro\/Numarul")) + issueURL = issueTag['href'] + print issueURL; + issueSoup = self.index_to_soup(issueURL) + feeds = [] + stories = [] + for categorie in issueSoup.findAll('dl',attrs={'class':'continutArhive'}): + categ=self.tag_to_string(categorie.find('dt')) + for story in categorie.findAll('dd'): + title=[] + for bucatele in story.findAll('a'): + title.append(bucatele) + if len(title)==1: #daca articolul nu are autor + stories.append({ + 'title' : self.tag_to_string(title[0]), + 'url' : title[0]['href'], + 'date' : '', + 'author' : ''}) + else: # daca articolul are autor len(title)=2 + stories.append({ + 'title' : self.tag_to_string(title[1]), + 'url' :title[1]['href'], + 'date' : '', + 'author' : self.tag_to_string(title[0])}) + print(self.tag_to_string(title[0])) + if 'Editorial' in categ: + global coverpage + coverpage=title[1]['href'] # am luat link-ul spre editorial + feeds.append((categ,stories)) + stories = [] + print feeds + return feeds +#procedura de luat coperta + def get_cover_url(self): + soup = self.index_to_soup(coverpage) + link_item = soup.find('a',attrs={'rel':'lightbox'}) # caut imaginea textului + a='' + cover_url = a.join(link_item.img['src'].split('_details_')) + return cover_url From f25c4232618063c096653faee6e2337b39fa43bf Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 18:28:21 +0100 Subject: [PATCH 18/84] Got the ondevice composite column optimization to work. --- src/calibre/library/caches.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/calibre/library/caches.py b/src/calibre/library/caches.py index 2ad425fc00..470bbcdfa8 100644 --- a/src/calibre/library/caches.py +++ b/src/calibre/library/caches.py @@ -200,6 +200,11 @@ class CacheRow(list): # {{{ def __getslice__(self, i, j): return self.__getitem__(slice(i, j)) + def refresh_composites(self): + for c in self._composites: + self[c] = None + self._must_do = True + # }}} class ResultCache(SearchQueryParser): # {{{ @@ -914,12 +919,11 @@ class ResultCache(SearchQueryParser): # {{{ return len(self._map) def refresh_ondevice(self, db): - if self.composites: - self.refresh(db) ondevice_col = self.FIELD_MAP['ondevice'] for item in self._data: if item is not None: item[ondevice_col] = db.book_on_device_string(item[0]) + item.refresh_composites() def refresh(self, db, field=None, ascending=True): temp = db.conn.get('SELECT * FROM meta2') From 7a6f8b13a2d83e38117268f3abd2d0845d36cd8d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 29 May 2011 12:58:54 -0600 Subject: [PATCH 19/84] ... --- src/calibre/gui2/update.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/update.py b/src/calibre/gui2/update.py index 847b5785e9..9aae245d98 100644 --- a/src/calibre/gui2/update.py +++ b/src/calibre/gui2/update.py @@ -49,11 +49,12 @@ class UpdateNotification(QDialog): self.logo.setMaximumWidth(110) self.logo.setPixmap(QPixmap(I('lt.png')).scaled(100, 100, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)) - self.label = QLabel('

    '+ + self.label = QLabel(('

    '+ _('%s has been updated to version %s. ' 'See the new features. Only update if one of the ' - 'new features or bug fixes is important to you.')%(__appname__, version)) + '">new features.') + '

    '+_('Update only if one of the ' + 'new features or bug fixes is important to you. ' + 'If the current version works well for you, do not update.'))%(__appname__, version)) self.label.setOpenExternalLinks(True) self.label.setWordWrap(True) self.setWindowTitle(_('Update available!')) From 19261f15eede6fdf17ec5769a31f8e28c69486bf Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 20:12:31 +0100 Subject: [PATCH 20/84] Add field box to color wizard --- .../gui2/dialogs/template_line_editor.py | 169 ++++++++++++------ src/calibre/gui2/preferences/look_feel.py | 3 +- src/calibre/utils/formatter_functions.py | 16 +- 3 files changed, 127 insertions(+), 61 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index 3d199b156c..bea2c4e316 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -5,12 +5,16 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' +from functools import partial +from collections import defaultdict + from PyQt4.Qt import (QLineEdit, QDialog, QGridLayout, QLabel, QCheckBox, QDialogButtonBox, QColor, QComboBox, QIcon) from calibre.gui2.dialogs.template_dialog import TemplateDialog from calibre.gui2.complete import MultiCompleteLineEdit from calibre.gui2 import error_dialog +from calibre.utils.icu import sort_key class TemplateLineEditor(QLineEdit): @@ -26,8 +30,8 @@ class TemplateLineEditor(QLineEdit): def set_mi(self, mi): self.mi = mi - def set_tags(self, tags): - self.tags = tags + def set_db(self, db): + self.db = db def contextMenuEvent(self, event): menu = self.createStandardContextMenu() @@ -35,9 +39,6 @@ class TemplateLineEditor(QLineEdit): 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): @@ -53,84 +54,117 @@ class TemplateLineEditor(QLineEdit): _('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())) + d = TagWizard(self, self.db, unicode(self.text())) if d.exec_(): self.setText(d.template) class TagWizard(QDialog): - def __init__(self, parent, tags, txt): + def __init__(self, parent, db, txt): QDialog.__init__(self, parent) - self.setWindowTitle(_('Tag Wizard')) + self.setWindowTitle(_('Coloring Wizard')) self.setWindowIcon(QIcon(I('wizard.png'))) - self.tags = tags + self.columns = [] + self.completion_values = defaultdict(dict) + for k in db.all_field_keys(): + m = db.metadata_for_field(k) + if m['datatype'] in ('text', 'enumeration', 'series'): + self.columns.append(k) + if m['is_custom']: +# self.completion_values[k] = {} + self.completion_values[k]['v'] = db.all_custom(m['label']) + elif k == 'tags': +# self.completion_values[k] = {} + self.completion_values[k]['v'] = db.all_tags() + else: + f = getattr(db, 'all' + k, None) + if f: + self.completion_values[k] = {} + self.completion_values[k]['v'] = [v[1] for v in f()] + if k in self.completion_values: + self.completion_values[k]['m'] = m['is_multiple'] + + self.columns.sort(key=sort_key) + self.columns.insert(0, '') + l = QGridLayout() self.setLayout(l) - l.setColumnStretch(0, 1) - l.setColumnMinimumWidth(0, 300) - h = QLabel(_('Tags (see the popup help for more information)')) + l.setColumnStretch(1, 10) + l.setColumnMinimumWidth(1, 300) + + h = QLabel(_('Column')) + l.addWidget(h, 0, 0, 1, 1) + + h = QLabel(_('Values (see the popup help for more information)')) h.setToolTip('

    ' + - _('You can enter more than one tag per box, separated by commas. ' + _('You can enter more than one value per box, separated by commas. ' 'The comparison ignores letter case.
    ' - 'A tag value can be a regular expression. Check the box to turn ' + 'A value can be a regular expression. Check the box to turn ' 'them on. When using regular expressions, note that the wizard ' 'puts anchors (^ and $) around the expression, so you ' 'must ensure your expression matches from the beginning ' - 'to the end of the tag.
    ' + 'to the end of the column you are checking.
    ' 'Regular expression examples:') + '

      ' + - _('
    • .* matches any tag. No empty tags are ' - 'checked, so you don\'t need to worry about empty strings
    • ' - '
    • A.* matches any tag beginning with A
    • ' - '
    • .*mystery.* matches any tag containing ' + _('
    • .* matches anything in the column. No ' + 'empty values are checked, so you don\'t need to worry about ' + 'empty strings
    • ' + '
    • A.* matches anything beginning with A
    • ' + '
    • .*mystery.* matches anything containing ' 'the word "mystery"
    • ') + '

    ') - l.addWidget(h , 0, 0, 1, 1) + l.addWidget(h , 0, 1, 1, 1) c = QLabel(_('is RE')) c.setToolTip('

    ' + - _('Check this box if the tag box contains regular expressions') + '

    ') - l.addWidget(c, 0, 1, 1, 1) + _('Check this box if the values box contains regular expressions') + '

    ') + l.addWidget(c, 0, 2, 1, 1) - c = QLabel(_('Color if tag found')) + c = QLabel(_('Color if value found')) c.setToolTip('

    ' + _('At least one of the two color boxes must have a value. Leave ' 'one color box empty if you want the template to use the next ' 'line in this wizard. If both boxes are filled in, the rest of ' 'the lines in this wizard will be ignored.') + '

    ') - l.addWidget(c, 0, 2, 1, 1) - c = QLabel(_('Color if tag not found')) + l.addWidget(c, 0, 3, 1, 1) + c = QLabel(_('Color if value not found')) c.setToolTip('

    ' + _('This box is usually filled in only on the last test. If it is ' - 'filled in before the last test, then the color for tag found box ' + 'filled in before the last test, then the color for value found box ' 'must be empty or all the rest of the tests will be ignored.') + '

    ') - l.addWidget(c, 0, 3, 1, 1) + l.addWidget(c, 0, 4, 1, 1) self.tagboxes = [] self.colorboxes = [] self.nfcolorboxes = [] self.reboxes = [] + self.colboxes = [] self.colors = [unicode(s) for s in list(QColor.colorNames())] self.colors.insert(0, '') for i in range(0, 10): + w = QComboBox() + w.addItems(self.columns) + l.addWidget(w, i+1, 0, 1, 1) + self.colboxes.append(w) + tb = MultiCompleteLineEdit(self) tb.set_separator(', ') - tb.update_items_cache(self.tags) self.tagboxes.append(tb) - l.addWidget(tb, i+1, 0, 1, 1) + l.addWidget(tb, i+1, 1, 1, 1) + w.currentIndexChanged[str].connect(partial(self.column_changed, valbox=tb)) w = QCheckBox(self) self.reboxes.append(w) - l.addWidget(w, i+1, 1, 1, 1) - - w = QComboBox(self) - w.addItems(self.colors) - self.colorboxes.append(w) l.addWidget(w, i+1, 2, 1, 1) w = QComboBox(self) w.addItems(self.colors) - self.nfcolorboxes.append(w) + self.colorboxes.append(w) l.addWidget(w, i+1, 3, 1, 1) + w = QComboBox(self) + w.addItems(self.colors) + self.nfcolorboxes.append(w) + l.addWidget(w, i+1, 4, 1, 1) + if txt: lines = txt.split('\n')[3:] i = 0 @@ -141,37 +175,59 @@ class TagWizard(QDialog): t, c = vals nc = '' re = False + f = 'tags' else: - t,c,nc,re = vals + t,c,f,nc,re = vals try: self.colorboxes[i].setCurrentIndex(self.colorboxes[i].findText(c)) self.nfcolorboxes[i].setCurrentIndex(self.nfcolorboxes[i].findText(nc)) self.tagboxes[i].setText(t) self.reboxes[i].setChecked(re == '2') + self.colboxes[i].setCurrentIndex(self.colboxes[i].findText(f)) except: pass i += 1 bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel, parent=self) - l.addWidget(bb, 100, 2, 1, 2) + l.addWidget(bb, 100, 3, 1, 2) bb.accepted.connect(self.accepted) bb.rejected.connect(self.reject) self.template = '' + def column_changed(self, s, valbox=None): + k = unicode(s) + if k in self.completion_values: + valbox.update_items_cache(self.completion_values[k]['v']) + if self.completion_values[k]['m']: + valbox.set_separator(', ') + else: + valbox.set_separator(None) + else: + valbox.update_items_cache([]) + valbox.set_separator(None) + def accepted(self): res = ("program:\n#tag wizard -- do not directly edit\n" - " t = field('tags');\n first_non_empty(\n") + " first_non_empty(\n") lines = [] - for tb, cb, nfcb, reb in zip(self.tagboxes, self.colorboxes, - self.nfcolorboxes, self.reboxes): - tags = [t.strip() for t in unicode(tb.text()).split(',') if t.strip()] + for tb, cb, fb, nfcb, reb in zip(self.tagboxes, self.colorboxes, + self.colboxes, self.nfcolorboxes, self.reboxes): + f = unicode(fb.currentText()) + if not f: + continue + m = self.completion_values[f]['m'] c = unicode(cb.currentText()).strip() nfc = unicode(nfcb.currentText()).strip() re = reb.checkState() - if re == 2: - tags = '$|^'.join(tags) + if m: + tags = [t.strip() for t in unicode(tb.text()).split(',') if t.strip()] + if re == 2: + tags = '$|^'.join(tags) + else: + tags = ','.join(tags) else: - tags = ','.join(tags) + tags = unicode(tb.text()).strip() + if not tags or not (c or nfc): continue if c not in self.colors: @@ -185,24 +241,33 @@ class TagWizard(QDialog): show=True, show_copy_button=False) return False if re == 2: - lines.append(" in_list(t, ',', '^{0}$', '{1}', '{2}')".\ - format(tags, c, nfc)) + if m: + lines.append(" in_list(field('{3}'), ',', '^{0}$', '{1}', '{2}')".\ + format(tags, c, nfc, f)) + else: + lines.append(" contains(field('{3}'), '{0}', '{1}', '{2}')".\ + format(tags, c, nfc, f)) else: - lines.append(" str_in_list(t, ',', '{0}', '{1}', '{2}')".\ - format(tags, c, nfc)) + if m: + lines.append(" str_in_list(field('{3}'), ',', '{0}', '{1}', '{2}')".\ + format(tags, c, nfc, f)) + else: + lines.append(" strcmp(field('{3}'), '{0}', '{2}', '{1}', '{2}')".\ + format(tags, c, nfc, f)) res += ',\n'.join(lines) res += ')\n' self.template = res res = '' - for tb, cb, nfcb, reb in zip(self.tagboxes, self.colorboxes, - self.nfcolorboxes, self.reboxes): + for tb, cb, fb, nfcb, reb in zip(self.tagboxes, self.colorboxes, + self.colboxes, self.nfcolorboxes, self.reboxes): t = unicode(tb.text()).strip() if t.endswith(','): t = t[:-1] c = unicode(cb.currentText()).strip() + f = unicode(fb.currentText()) nfc = unicode(nfcb.currentText()).strip() re = unicode(reb.checkState()) - if t and c: - res += '#' + t + ':|:' + c + ':|:' + nfc + ':|:' + re + '\n' + if f and t and c: + res += '#' + t + ':|:' + c + ':|:' + f +':|:' + nfc + ':|:' + re + '\n' self.template += res self.accept() diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 37e4588b9b..79db1aecf8 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -204,7 +204,6 @@ 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() mi=None try: @@ -217,7 +216,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): r('column_color_name_'+str(i), db.prefs, choices=choices) r('column_color_template_'+str(i), db.prefs) tpl = getattr(self, 'opt_column_color_template_'+str(i)) - tpl.set_tags(tags) + tpl.set_db(db) tpl.set_mi(mi) toolbutton = getattr(self, 'opt_column_color_wizard_'+str(i)) toolbutton.clicked.connect(tpl.tag_wizard) diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 32822e1d72..b66aec2cb9 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -331,9 +331,10 @@ class BuiltinInList(BuiltinFormatterFunction): 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, flags=re.I): - return fv + if l: + for v in l: + if re.search(pat, v, flags=re.I): + return fv return nfv class BuiltinStrInList(BuiltinFormatterFunction): @@ -349,10 +350,11 @@ class BuiltinStrInList(BuiltinFormatterFunction): def evaluate(self, formatter, kwargs, mi, locals, val, sep, str, fv, nfv): l = [v.strip() for v in val.split(sep) if v.strip()] c = [v.strip() for v in str.split(sep) if v.strip()] - for v in l: - for t in c: - if strcmp(t, v) == 0: - return fv + if l: + for v in l: + for t in c: + if strcmp(t, v) == 0: + return fv return nfv class BuiltinRe(BuiltinFormatterFunction): From cc288ff4cac08b4a3047ef3782aba344aa3b81a5 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 21:21:02 +0100 Subject: [PATCH 21/84] Add a preview field to the wizard. Vary the button according to whether the wizard created the template Don't show the template if wizard created --- .../gui2/dialogs/template_line_editor.py | 88 ++++++++++++++++--- src/calibre/gui2/preferences/look_feel.py | 9 +- 2 files changed, 81 insertions(+), 16 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index bea2c4e316..2e4a6595fd 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -8,9 +8,10 @@ __docformat__ = 'restructuredtext en' from functools import partial from collections import defaultdict -from PyQt4.Qt import (QLineEdit, QDialog, QGridLayout, QLabel, QCheckBox, - QDialogButtonBox, QColor, QComboBox, QIcon) +from PyQt4.Qt import (QLineEdit, QDialog, QGridLayout, QLabel, QCheckBox, QIcon, + QDialogButtonBox, QColor, QComboBox, QPushButton) +from calibre.ebooks.metadata.book.base import composite_formatter from calibre.gui2.dialogs.template_dialog import TemplateDialog from calibre.gui2.complete import MultiCompleteLineEdit from calibre.gui2 import error_dialog @@ -26,6 +27,7 @@ class TemplateLineEditor(QLineEdit): QLineEdit.__init__(self, parent) self.tags = None self.mi = None + self.txt = None def set_mi(self, mi): self.mi = mi @@ -42,46 +44,82 @@ class TemplateLineEditor(QLineEdit): menu.exec_(event.globalPos()) def open_editor(self): - t = TemplateDialog(self, self.text(), self.mi) + if self.txt: + t = TemplateDialog(self, self.txt, self.mi) + else: + t = TemplateDialog(self, self.text(), self.mi) t.setWindowTitle(_('Edit template')) if t.exec_(): self.setText(t.textbox.toPlainText()) + self.txt = None + + def show_wizard_button(self, txt): + if not txt or txt.startswith('program:\n#tag wizard'): + return True + return False + + def setText(self, txt): + txt = unicode(txt) + if txt and txt.startswith('program:\n#tag wizard'): + self.txt = txt + self.setReadOnly(True) + QLineEdit.setText(self, '') + QLineEdit.setText(self, _('Template generated by the wizard')) + self.setStyleSheet('TemplateLineEditor { color: gray }') + else: + QLineEdit.setText(self, txt) def tag_wizard(self): txt = unicode(self.text()) - if txt and not txt.startswith('program:\n#tag wizard'): + if txt and not self.txt: 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.db, unicode(self.text())) + d = TagWizard(self, self.db, unicode(self.txt), self.mi) if d.exec_(): self.setText(d.template) + def text(self): + if self.txt: + return self.txt + return QLineEdit.text(self) + class TagWizard(QDialog): - def __init__(self, parent, db, txt): + def __init__(self, parent, db, txt, mi): QDialog.__init__(self, parent) self.setWindowTitle(_('Coloring Wizard')) self.setWindowIcon(QIcon(I('wizard.png'))) + self.mi = mi + self.columns = [] self.completion_values = defaultdict(dict) for k in db.all_field_keys(): m = db.metadata_for_field(k) - if m['datatype'] in ('text', 'enumeration', 'series'): + if m['datatype'] in ('text', 'enumeration', 'series') and \ + m['is_category'] and k not in ('identifiers'): self.columns.append(k) if m['is_custom']: -# self.completion_values[k] = {} self.completion_values[k]['v'] = db.all_custom(m['label']) elif k == 'tags': -# self.completion_values[k] = {} self.completion_values[k]['v'] = db.all_tags() + elif k == 'formats': + self.completion_values[k]['v'] = db.all_formats() else: - f = getattr(db, 'all' + k, None) + if k in ('publisher'): + ck = k + 's' + else: + ck = k + f = getattr(db, 'all_' + ck, None) if f: - self.completion_values[k] = {} - self.completion_values[k]['v'] = [v[1] for v in f()] + if k == 'authors': + self.completion_values[k]['v'] = [v[1].\ + replace('|', ',') for v in f()] + else: + self.completion_values[k]['v'] = [v[1] for v in f()] + if k in self.completion_values: self.completion_values[k]['m'] = m['is_multiple'] @@ -188,12 +226,28 @@ class TagWizard(QDialog): pass i += 1 + w = QLabel(_('Preview')) + l.addWidget(w, 99, 0, 1, 1) + w = self.test_box = QLineEdit(self) + w.setReadOnly(True) + l.addWidget(w, 99, 1, 1, 1) + w = QPushButton(_('Test')) + l.addWidget(w, 99, 3, 1, 1) + w.clicked.connect(self.preview) + bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel, parent=self) l.addWidget(bb, 100, 3, 1, 2) bb.accepted.connect(self.accepted) bb.rejected.connect(self.reject) self.template = '' + def preview(self): + if not self.generate_program(): + return + t = composite_formatter.safe_format(self.template, self.mi, + _('EXCEPTION'), self.mi) + self.test_box.setText(t) + def column_changed(self, s, valbox=None): k = unicode(s) if k in self.completion_values: @@ -206,7 +260,7 @@ class TagWizard(QDialog): valbox.update_items_cache([]) valbox.set_separator(None) - def accepted(self): + def generate_program(self): res = ("program:\n#tag wizard -- do not directly edit\n" " first_non_empty(\n") lines = [] @@ -270,4 +324,10 @@ class TagWizard(QDialog): if f and t and c: res += '#' + t + ':|:' + c + ':|:' + f +':|:' + nfc + ':|:' + re + '\n' self.template += res - self.accept() + return True + + def accepted(self): + if self.generate_program(): + self.accept() + else: + self.template = '' diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 79db1aecf8..d292cada4b 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, QColor) + QAbstractListModel, Qt, QColor, QIcon) from calibre.gui2.preferences import ConfigWidgetBase, test_widget, CommaSeparatedList from calibre.gui2.preferences.look_feel_ui import Ui_Form @@ -215,11 +215,16 @@ 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) + txt = db.prefs.get('column_color_template_'+str(i), None) tpl = getattr(self, 'opt_column_color_template_'+str(i)) tpl.set_db(db) tpl.set_mi(mi) toolbutton = getattr(self, 'opt_column_color_wizard_'+str(i)) - toolbutton.clicked.connect(tpl.tag_wizard) + if tpl.show_wizard_button(txt): + toolbutton.clicked.connect(tpl.tag_wizard) + else: + toolbutton.clicked.connect(tpl.open_editor) + toolbutton.setIcon(QIcon(I('edit_input.png'))) all_colors = [unicode(s) for s in list(QColor.colorNames())] self.colors_box.setText(', '.join(all_colors)) From b8e12adf641fcd60966c22c59398f88738a1b70d Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 21:28:27 +0100 Subject: [PATCH 22/84] Fix help text --- src/calibre/gui2/preferences/look_feel.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index d292cada4b..3530931c9c 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -167,11 +167,10 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): '' 'tutorial on using templates.') + '

    ' + - _('If you want to color a field based on tags, then click the ' - 'button next to an empty line to open the tags wizard. ' + _('If you want to color a field based on contents of columns, ' + 'then click the button next to an empty line to open the 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.') + + 'template with the same wizard.') + '

    ' + _('The template must evaluate to one of the color names shown ' 'below. You can use any legal template expression. ' From 1ae716a115664b46b51a02355fa11df6c3c5972b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 29 May 2011 14:38:35 -0600 Subject: [PATCH 23/84] Change default toolbar to make it a little more newbie on small screen/non maximized window friendly --- src/calibre/gui2/__init__.py | 7 ++++--- src/calibre/gui2/layout.py | 1 - src/calibre/gui2/preferences/look_feel.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 2cb18f3bda..8499e304c3 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -48,8 +48,9 @@ else: gprefs.defaults['action-layout-menubar-device'] = () gprefs.defaults['action-layout-toolbar'] = ( 'Add Books', 'Edit Metadata', None, 'Convert Books', 'View', None, - 'Choose Library', 'Donate', None, 'Fetch News', 'Store', 'Save To Disk', - 'Connect Share', None, 'Remove Books', None, 'Help', 'Preferences', + 'Store', 'Donate', 'Fetch News', 'Help', None, + 'Remove Books', 'Choose Library', 'Save To Disk', + 'Connect Share', 'Preferences', ) gprefs.defaults['action-layout-toolbar-device'] = ( 'Add Books', 'Edit Metadata', None, 'Convert Books', 'View', @@ -75,7 +76,7 @@ gprefs.defaults['action-layout-context-menu-device'] = ( gprefs.defaults['show_splash_screen'] = True gprefs.defaults['toolbar_icon_size'] = 'medium' gprefs.defaults['automerge'] = 'ignore' -gprefs.defaults['toolbar_text'] = 'auto' +gprefs.defaults['toolbar_text'] = 'always' gprefs.defaults['font'] = None gprefs.defaults['tags_browser_partition_method'] = 'first letter' gprefs.defaults['tags_browser_collapse_at'] = 100 diff --git a/src/calibre/gui2/layout.py b/src/calibre/gui2/layout.py index 7d07463b87..76b9f5f9a2 100644 --- a/src/calibre/gui2/layout.py +++ b/src/calibre/gui2/layout.py @@ -238,7 +238,6 @@ class Spacer(QWidget): # {{{ self.l.addStretch(10) # }}} - class MainWindowMixin(object): # {{{ def __init__(self, db): diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 37e4588b9b..862636cb04 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -129,7 +129,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): (_('Medium'), 'medium'), (_('Large'), 'large')] r('toolbar_icon_size', gprefs, choices=choices) - choices = [(_('Automatic'), 'auto'), (_('Always'), 'always'), + choices = [(_('If there is enough room'), 'auto'), (_('Always'), 'always'), (_('Never'), 'never')] r('toolbar_text', gprefs, choices=choices) From dbdee0d46dcd1d43581f95f0ae9582a08d6fd243 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Sun, 29 May 2011 21:41:36 +0100 Subject: [PATCH 24/84] Add a context menu item to clear the template from a box --- src/calibre/gui2/dialogs/template_line_editor.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index 2e4a6595fd..90dec0ccf8 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -39,10 +39,18 @@ class TemplateLineEditor(QLineEdit): menu = self.createStandardContextMenu() menu.addSeparator() + action_clear_field = menu.addAction(_('Remove any template from the box')) + action_clear_field.triggered.connect(self.clear_field) action_open_editor = menu.addAction(_('Open Template Editor')) action_open_editor.triggered.connect(self.open_editor) menu.exec_(event.globalPos()) + def clear_field(self): + self.setText('') + self.txt = None + self.setReadOnly(False) + self.setStyleSheet('TemplateLineEditor { color: black }') + def open_editor(self): if self.txt: t = TemplateDialog(self, self.txt, self.mi) From 1035de793d7feb398966aa2c83c5e42b11a260c4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 29 May 2011 15:04:37 -0600 Subject: [PATCH 25/84] ... --- src/calibre/translations/calibre.pot | 945 ++++++++++++++++----------- 1 file changed, 547 insertions(+), 398 deletions(-) diff --git a/src/calibre/translations/calibre.pot b/src/calibre/translations/calibre.pot index a8273ccac2..50576b12ae 100644 --- a/src/calibre/translations/calibre.pot +++ b/src/calibre/translations/calibre.pot @@ -5,8 +5,8 @@ msgid "" msgstr "" "Project-Id-Version: calibre 0.8.3\n" -"POT-Creation-Date: 2011-05-27 10:15+MDT\n" -"PO-Revision-Date: 2011-05-27 10:15+MDT\n" +"POT-Creation-Date: 2011-05-29 15:03+MDT\n" +"PO-Revision-Date: 2011-05-29 15:03+MDT\n" "Last-Translator: Automatically generated\n" "Language-Team: LANGUAGE\n" "MIME-Version: 1.0\n" @@ -46,10 +46,10 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/ebooks/metadata/__init__.py:253 #: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:34 #: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:35 -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:89 -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:455 -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:460 -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:724 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:88 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:454 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:459 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:729 #: /home/kovid/work/calibre/src/calibre/ebooks/metadata/ereader.py:36 #: /home/kovid/work/calibre/src/calibre/ebooks/metadata/ereader.py:61 #: /home/kovid/work/calibre/src/calibre/ebooks/metadata/extz.py:23 @@ -123,8 +123,8 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/ebooks/pdf/writer.py:102 #: /home/kovid/work/calibre/src/calibre/ebooks/rtf/input.py:313 #: /home/kovid/work/calibre/src/calibre/ebooks/rtf/input.py:315 -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:347 -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:355 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:348 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:356 #: /home/kovid/work/calibre/src/calibre/gui2/actions/add.py:156 #: /home/kovid/work/calibre/src/calibre/gui2/actions/edit_metadata.py:364 #: /home/kovid/work/calibre/src/calibre/gui2/actions/edit_metadata.py:367 @@ -145,11 +145,11 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/email.py:152 #: /home/kovid/work/calibre/src/calibre/gui2/email.py:167 #: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:401 -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1012 -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1188 -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1191 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1018 #: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1194 -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1279 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1197 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1200 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1285 #: /home/kovid/work/calibre/src/calibre/gui2/metadata/basic_widgets.py:82 #: /home/kovid/work/calibre/src/calibre/gui2/metadata/basic_widgets.py:212 #: /home/kovid/work/calibre/src/calibre/gui2/metadata/basic_widgets.py:231 @@ -158,23 +158,23 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/metadata/single_download.py:160 #: /home/kovid/work/calibre/src/calibre/gui2/metadata/single_download.py:164 #: /home/kovid/work/calibre/src/calibre/gui2/store/google_books_plugin.py:90 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:156 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:163 #: /home/kovid/work/calibre/src/calibre/gui2/viewer/main.py:199 #: /home/kovid/work/calibre/src/calibre/library/cli.py:217 #: /home/kovid/work/calibre/src/calibre/library/database.py:914 #: /home/kovid/work/calibre/src/calibre/library/database2.py:506 #: /home/kovid/work/calibre/src/calibre/library/database2.py:514 #: /home/kovid/work/calibre/src/calibre/library/database2.py:525 -#: /home/kovid/work/calibre/src/calibre/library/database2.py:1804 -#: /home/kovid/work/calibre/src/calibre/library/database2.py:1941 -#: /home/kovid/work/calibre/src/calibre/library/database2.py:2948 -#: /home/kovid/work/calibre/src/calibre/library/database2.py:2950 -#: /home/kovid/work/calibre/src/calibre/library/database2.py:3083 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:1805 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:1942 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:2949 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:2951 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:3084 #: /home/kovid/work/calibre/src/calibre/library/server/mobile.py:233 #: /home/kovid/work/calibre/src/calibre/library/server/opds.py:156 #: /home/kovid/work/calibre/src/calibre/library/server/opds.py:159 #: /home/kovid/work/calibre/src/calibre/library/server/xml.py:79 -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:131 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:134 #: /home/kovid/work/calibre/src/calibre/utils/podofo/__init__.py:46 #: /home/kovid/work/calibre/src/calibre/utils/podofo/__init__.py:64 #: /home/kovid/work/calibre/src/calibre/utils/podofo/__init__.py:78 @@ -328,7 +328,7 @@ msgid "Change the way calibre behaves" msgstr "" #: /home/kovid/work/calibre/src/calibre/customize/builtins.py:906 -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:220 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:221 msgid "Add your own columns" msgstr "" @@ -801,7 +801,7 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/scheduler.py:445 #: /home/kovid/work/calibre/src/calibre/library/database2.py:302 #: /home/kovid/work/calibre/src/calibre/library/database2.py:315 -#: /home/kovid/work/calibre/src/calibre/library/database2.py:2812 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:2813 #: /home/kovid/work/calibre/src/calibre/library/field_metadata.py:159 msgid "News" msgstr "" @@ -809,8 +809,8 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/devices/apple/driver.py:2669 #: /home/kovid/work/calibre/src/calibre/gui2/catalog/catalog_epub_mobi.py:65 #: /home/kovid/work/calibre/src/calibre/library/catalog.py:643 -#: /home/kovid/work/calibre/src/calibre/library/database2.py:2772 -#: /home/kovid/work/calibre/src/calibre/library/database2.py:2790 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:2773 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:2791 msgid "Catalog" msgstr "" @@ -2304,27 +2304,32 @@ msgstr "" msgid "Extract common e-book formats from archives (zip/rar) files. Also try to autodetect if they are actually cbz/cbr files." msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:145 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:51 +msgid "Value: unknown field " +msgstr "" + +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:144 msgid "TEMPLATE ERROR" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:628 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:627 #: /home/kovid/work/calibre/src/calibre/gui2/custom_column_widgets.py:63 #: /home/kovid/work/calibre/src/calibre/gui2/custom_column_widgets.py:563 msgid "No" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:628 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:627 #: /home/kovid/work/calibre/src/calibre/gui2/custom_column_widgets.py:63 #: /home/kovid/work/calibre/src/calibre/gui2/custom_column_widgets.py:563 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:601 msgid "Yes" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:723 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:728 #: /home/kovid/work/calibre/src/calibre/ebooks/pdf/manipulate/info.py:45 #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/delete_matching_from_device.py:75 #: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:64 -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1017 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1023 #: /home/kovid/work/calibre/src/calibre/gui2/metadata/single_download.py:132 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/metadata_sources.py:152 #: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/models.py:23 @@ -2334,32 +2339,32 @@ msgstr "" msgid "Title" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:724 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:729 #: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:66 -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1018 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1024 #: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/models.py:23 msgid "Author(s)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:725 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:730 #: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:71 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/metadata_sources.py:149 msgid "Publisher" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:726 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:731 #: /home/kovid/work/calibre/src/calibre/ebooks/pdf/manipulate/info.py:49 msgid "Producer" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:727 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:732 #: /home/kovid/work/calibre/src/calibre/gui2/metadata/single.py:871 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/metadata_sources.py:147 #: /home/kovid/work/calibre/src/calibre/library/field_metadata.py:211 msgid "Comments" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:729 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:734 #: /home/kovid/work/calibre/src/calibre/ebooks/oeb/transforms/jacket.py:170 #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/tag_categories.py:60 #: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:72 @@ -2370,7 +2375,7 @@ msgstr "" msgid "Tags" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:731 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:736 #: /home/kovid/work/calibre/src/calibre/ebooks/oeb/transforms/jacket.py:168 #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/tag_categories.py:60 #: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:73 @@ -2380,16 +2385,16 @@ msgstr "" msgid "Series" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:732 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:737 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/metadata_sources.py:154 msgid "Language" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:734 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:739 msgid "Timestamp" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:736 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:741 #: /home/kovid/work/calibre/src/calibre/ebooks/oeb/transforms/jacket.py:167 #: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:69 #: /home/kovid/work/calibre/src/calibre/gui2/metadata/single_download.py:132 @@ -2397,7 +2402,7 @@ msgstr "" msgid "Published" msgstr "" -#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:738 +#: /home/kovid/work/calibre/src/calibre/ebooks/metadata/book/base.py:743 msgid "Rights" msgstr "" @@ -3086,131 +3091,131 @@ msgstr "" msgid "Do not remove font color from output. This is only useful when txt-output-formatting is set to textile. Textile is the only formatting that supports setting font color. If this option is not specified font color will not be set and default to the color displayed by the reader (generally this is black)." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:103 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:104 msgid "Send file to storage card instead of main memory by default" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:105 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:106 msgid "Confirm before deleting" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:107 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:108 msgid "Main window geometry" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:109 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:110 msgid "Notify when a new version is available" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:111 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:112 msgid "Use Roman numerals for series number" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:113 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:114 msgid "Sort tags list by name, popularity, or rating" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:115 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:116 msgid "Match tags by any or all." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:117 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:118 msgid "Number of covers to show in the cover browsing mode" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:119 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:120 msgid "Defaults for conversion to LRF" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:121 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:122 msgid "Options for the LRF ebook viewer" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:124 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:125 msgid "Formats that are viewed using the internal viewer" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:126 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:127 msgid "Columns to be displayed in the book list" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:127 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:128 msgid "Automatically launch content server on application startup" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:128 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:129 msgid "Oldest news kept in database" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:129 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:130 msgid "Show system tray icon" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:131 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:132 msgid "Upload downloaded news to device" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:133 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:134 msgid "Delete books from library after uploading to device" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:135 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:136 msgid "Show the cover flow in a separate window instead of in the main calibre window" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:137 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:138 msgid "Disable notifications from the system tray icon" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:139 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:140 msgid "Default action to perform when send to device button is clicked" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:144 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:145 msgid "Start searching as you type. If this is disabled then search will only take place when the Enter or Return key is pressed." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:147 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:148 msgid "When searching, show all books with search results highlighted instead of showing only the matches. You can use the N or F3 keys to go to the next match." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:165 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:166 msgid "Maximum number of simultaneous conversion/news download jobs. This number is twice the actual value for historical reasons." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:169 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:170 msgid "Download social metadata (tags/rating/etc.)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:171 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:172 msgid "Overwrite author and title with new metadata" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:173 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:174 msgid "Automatically download the cover, if available" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:175 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:176 msgid "Limit max simultaneous jobs to number of CPUs" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:177 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:178 msgid "The layout of the user interface" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:179 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:180 msgid "Show the average rating per item indication in the tag browser" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:181 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:182 msgid "Disable UI animations" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:186 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:187 msgid "tag browser categories not to display" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:461 +#: /home/kovid/work/calibre/src/calibre/gui2/__init__.py:462 msgid "Choose Files" msgstr "" @@ -3340,11 +3345,11 @@ msgstr "" msgid "Select books" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/actions/add.py:328 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/add.py:329 msgid "Merged some books" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/actions/add.py:329 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/add.py:330 msgid "The following duplicate books were found and incoming book formats were processed and merged into your Calibre database according to your automerge settings:" msgstr "" @@ -3364,9 +3369,9 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/actions/add.py:376 #: /home/kovid/work/calibre/src/calibre/gui2/actions/delete.py:127 -#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:78 -#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:97 -#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:106 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:83 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:102 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:111 #: /home/kovid/work/calibre/src/calibre/gui2/actions/tweak_epub.py:28 #: /home/kovid/work/calibre/src/calibre/gui2/actions/view.py:139 #: /home/kovid/work/calibre/src/calibre/gui2/actions/view.py:185 @@ -3644,7 +3649,7 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/actions/choose_library.py:405 #: /home/kovid/work/calibre/src/calibre/gui2/actions/copy_to_library.py:167 #: /home/kovid/work/calibre/src/calibre/gui2/actions/save_to_disk.py:101 -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:854 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:857 msgid "Not allowed" msgstr "" @@ -4071,7 +4076,7 @@ msgid "Move to next highlighted match" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/actions/next_match.py:13 -#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:373 +#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:388 msgid "N" msgstr "" @@ -4274,35 +4279,35 @@ msgstr "" msgid "Stores" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:38 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:43 #: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_dialog.py:18 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search.py:261 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search.py:270 msgid "Choose stores" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:78 -#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:97 -#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:106 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:83 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:102 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:111 msgid "Cannot search" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:125 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:130 msgid "Calibre helps you find the ebooks you want by searching the websites of various commercial and public domain book sources for you." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:129 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:134 msgid "Using the integrated search you can easily find which store has the book you are looking for, at the best price. You also get DRM status and other useful information." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:133 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:138 msgid "All transactions (paid or otherwise) are handled between you and the book seller. Calibre is not part of this process and any issues related to a purchase should be directed to the website you are buying from. Be sure to double check that any books you get will work with your e-book reader, especially if the book you are buying has DRM." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:143 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:148 msgid "Show this message again" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:144 +#: /home/kovid/work/calibre/src/calibre/gui2/actions/store.py:149 msgid "About Get Books" msgstr "" @@ -4569,7 +4574,7 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/preferences/toolbar_ui.py:110 #: /home/kovid/work/calibre/src/calibre/gui2/shortcuts_ui.py:80 #: /home/kovid/work/calibre/src/calibre/gui2/shortcuts_ui.py:85 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_widget_ui.py:57 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_widget_ui.py:79 #: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/store_dialog_ui.py:75 #: /home/kovid/work/calibre/src/calibre/gui2/store/search/search_ui.py:133 #: /home/kovid/work/calibre/src/calibre/gui2/store/search/search_ui.py:139 @@ -4606,7 +4611,7 @@ msgid "Book %s of %s" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/book_details.py:144 -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1021 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1027 msgid "Collections" msgstr "" @@ -4732,7 +4737,7 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/preferences/toolbar_ui.py:98 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/tweaks_ui.py:87 #: /home/kovid/work/calibre/src/calibre/gui2/store/basic_config_widget_ui.py:37 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_widget_ui.py:55 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_widget_ui.py:77 #: /home/kovid/work/calibre/src/calibre/gui2/store/config/search/search_widget_ui.py:98 #: /home/kovid/work/calibre/src/calibre/gui2/store/config/search_widget_ui.py:98 #: /home/kovid/work/calibre/src/calibre/gui2/wizard/send_email_ui.py:123 @@ -5333,7 +5338,7 @@ msgstr "" msgid "" "

    This wizard will help you choose an appropriate font size key for your needs. Just enter the base font size of the input document and then enter an input font size. The wizard will display what font size it will be mapped to, by the font rescaling algorithm. You can adjust the algorithm by adjusting the output base font size and font key below. When you find values suitable for you, click OK.

    \n" "

    By default, if the output base font size is zero and/or no font size key is specified, calibre will use the values from the current Output Profile.

    \n" -"

    See the User Manual for a discussion of how font size rescaling works.

    " +"

    See the User Manual for a discussion of how font size rescaling works.

    " msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/convert/font_key_ui.py:108 @@ -5396,7 +5401,7 @@ msgid "Modify the document text and structure using common patterns." msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/convert/heuristics_ui.py:113 -msgid "Heuristic processing means that calibre will scan your book for common patterns and fix them. As the name implies, this involves guesswork, which means that it could end up worsening the result of a conversion, if calibre guesses wrong. Therefore, it is disabled by default. Often, if a conversion does not turn out as you expect, turning on heuristics can improve matters. Read more about the various heuristic processing options in the User Manual." +msgid "Heuristic processing means that calibre will scan your book for common patterns and fix them. As the name implies, this involves guesswork, which means that it could end up worsening the result of a conversion, if calibre guesses wrong. Therefore, it is disabled by default. Often, if a conversion does not turn out as you expect, turning on heuristics can improve matters. Read more about the various heuristic processing options in the User Manual." msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/convert/heuristics_ui.py:114 @@ -5810,8 +5815,9 @@ msgid "PDB Output" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/convert/pdb_output_ui.py:48 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:215 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:195 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:225 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:186 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:205 msgid "&Format:" msgstr "" @@ -5970,7 +5976,7 @@ msgstr "" #: #: /home/kovid/work/calibre/src/calibre/gui2/convert/search_and_replace_ui.py:154 -msgid "

    Search and replace uses regular expressions. See the regular expressions tutorial to get started with regular expressions. Also clicking the wizard buttons below will allow you to test your regular expression against the current input document." +msgid "

    Search and replace uses regular expressions. See the regular expressions tutorial to get started with regular expressions. Also clicking the wizard buttons below will allow you to test your regular expression against the current input document." msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/convert/single.py:173 @@ -6286,7 +6292,7 @@ msgid "(A regular expression)" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/convert/xpath_wizard_ui.py:89 -msgid "

    For example, to match all h2 tags that have class=\"chapter\", set tag to h2, attribute to class and value to chapter.

    Leaving attribute blank will match any attribute and leaving value blank will match any value. Setting tag to * will match any tag.

    To learn more advanced usage of XPath see the XPath Tutorial." +msgid "

    For example, to match all h2 tags that have class=\"chapter\", set tag to h2, attribute to class and value to chapter.

    Leaving attribute blank will match any attribute and leaving value blank will match any value. Setting tag to * will match any tag.

    To learn more advanced usage of XPath see the XPath Tutorial." msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/cover_flow.py:128 @@ -6312,8 +6318,8 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:128 #: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:148 #: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:230 -#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:263 -#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:267 +#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:279 +#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:283 #: /home/kovid/work/calibre/src/calibre/gui2/metadata/basic_widgets.py:1139 msgid "Undefined" msgstr "" @@ -6569,7 +6575,7 @@ msgstr "" #: #: /home/kovid/work/calibre/src/calibre/gui2/device_drivers/configwidget.py:148 -#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:421 +#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:437 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/plugboard.py:273 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/save_template.py:61 msgid "Invalid template" @@ -6577,7 +6583,7 @@ msgstr "" #: #: /home/kovid/work/calibre/src/calibre/gui2/device_drivers/configwidget.py:149 -#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:422 +#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:438 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/plugboard.py:274 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/save_template.py:62 msgid "The template %s is invalid:" @@ -6937,7 +6943,8 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/comicconf_ui.py:97 #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:211 #: /home/kovid/work/calibre/src/calibre/gui2/metadata/basic_widgets.py:73 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:189 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:181 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:199 msgid "&Title:" msgstr "" @@ -6951,12 +6958,12 @@ msgid "&Profile:" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/comments_dialog.py:24 -#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_dialog.py:218 +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_dialog.py:222 msgid "&OK" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/comments_dialog.py:25 -#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_dialog.py:219 +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_dialog.py:223 #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/tweak_epub_ui.py:65 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/main.py:233 msgid "&Cancel" @@ -7011,7 +7018,7 @@ msgstr "" #: #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/delete_matching_from_device.py:76 #: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:68 -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1019 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1025 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:32 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:73 #: /home/kovid/work/calibre/src/calibre/library/field_metadata.py:321 @@ -8019,91 +8026,105 @@ msgid "Negate" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:198 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:196 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:176 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:206 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:168 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:186 msgid "Advanced Search" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:199 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:197 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:177 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:207 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:169 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:187 msgid "&What kind of match to use:" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:200 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:198 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:178 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:208 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:170 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:188 msgid "Contains: the word or phrase matches anywhere in the metadata field" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:201 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:199 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:179 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:209 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:171 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:189 msgid "Equals: the word or phrase must match the entire metadata field" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:202 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:200 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:180 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:210 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:172 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:190 msgid "Regular expression: the expression must match anywhere in the metadata field" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:203 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:201 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:181 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:211 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:173 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:191 msgid "Find entries that have..." msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:204 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:202 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:182 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:212 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:174 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:192 msgid "&All these words:" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:205 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:203 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:183 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:213 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:175 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:193 msgid "This exact &phrase:" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:206 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:204 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:184 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:214 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:176 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:194 msgid "&One or more of these words:" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:207 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:205 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:185 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:215 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:177 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:195 msgid "But dont show entries that have..." msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:208 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:206 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:186 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:216 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:178 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:196 msgid "Any of these &unwanted words:" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:209 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:207 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:187 -msgid "See the User Manual for more help" +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:217 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:197 +msgid "See the User Manual for more help" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:210 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:208 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:188 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:218 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:180 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:198 msgid "A&dvanced Search" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:212 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:210 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:190 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:220 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:182 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:200 msgid "Enter the title." msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:213 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:191 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:183 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:201 msgid "&Author:" msgstr "" @@ -8126,14 +8147,16 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:219 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/template_functions_ui.py:101 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:213 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:193 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:223 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:184 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:203 msgid "&Clear" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/search_ui.py:220 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:214 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:194 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:224 +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:185 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:204 msgid "Search only in specific fields:" msgstr "" @@ -8341,6 +8364,10 @@ msgstr "" msgid "Ctrl+S" msgstr "" +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_dialog.py:249 +msgid "EXCEPTION: " +msgstr "" + #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_dialog_ui.py:71 msgid "Function &name:" msgstr "" @@ -8355,53 +8382,90 @@ msgid "Python &code:" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:32 +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:36 msgid "Open Template Editor" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:35 +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:39 msgid "Open Tag Wizard" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:41 -#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:408 +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:45 +#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:424 msgid "Edit template" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:48 +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:52 msgid "Invalid text" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:49 +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:53 msgid "The text in the box was not generated by this wizard" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:60 +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:64 msgid "Tag Wizard" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:68 -msgid "Tags (more than one per box permitted)" +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:72 +msgid "Tags (see the popup help for more information)" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:69 -msgid "Color" +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:74 +msgid "You can enter more than one tag per box, separated by commas. The comparison ignores letter case.
    A tag value can be a regular expression. Check the box to turn them on. When using regular expressions, note that the wizard puts anchors (^ and $) around the expression, so you must ensure your expression matches from the beginning to the end of the tag.
    Regular expression examples:" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:115 +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:82 +msgid "

  • .* matches any tag. No empty tags are checked, so you don't need to worry about empty strings
  • A.* matches any tag beginning with A
  • .*mystery.* matches any tag containing the word \"mystery\"
  • " +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:89 +msgid "is RE" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:91 +msgid "Check this box if the tag box contains regular expressions" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:94 +msgid "Color if tag found" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:96 +msgid "At least one of the two color boxes must have a value. Leave one color box empty if you want the template to use the next line in this wizard. If both boxes are filled in, the rest of the lines in this wizard will be ignored." +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:101 +msgid "Color if tag not found" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:103 +msgid "This box is usually filled in only on the last test. If it is filled in before the last test, then the color for tag found box must be empty or all the rest of the tests will be ignored." +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:178 +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:183 msgid "Invalid color" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:116 +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:179 +#: /home/kovid/work/calibre/src/calibre/gui2/dialogs/template_line_editor.py:184 msgid "The color {0} is not valid" msgstr "" @@ -8623,7 +8687,7 @@ msgid "&Add feed" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/user_profiles_ui.py:286 -msgid "For help with writing advanced news recipes, please visit User Recipes" +msgid "For help with writing advanced news recipes, please visit User Recipes" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/dialogs/user_profiles_ui.py:287 @@ -8719,7 +8783,7 @@ msgstr "" msgid "" "
    \n" "

    Set a regular expression pattern to use when trying to guess ebook metadata from filenames.

    \n" -"

    A tutorial on using regular expressions is available.

    \n" +"

    A tutorial on using regular expressions is available.

    \n" "

    Use the Test functionality below to test your regular expression on a few sample filenames (remember to include the file extension). The group names for the various metadata entries are documented in tooltips.

    " msgstr "" @@ -8941,7 +9005,7 @@ msgid "Show books in the main memory of the device" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/layout.py:72 -#: /home/kovid/work/calibre/src/calibre/library/database2.py:1023 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:1024 msgid "Card A" msgstr "" @@ -8950,7 +9014,7 @@ msgid "Show books in storage card A" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/layout.py:74 -#: /home/kovid/work/calibre/src/calibre/library/database2.py:1025 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:1026 msgid "Card B" msgstr "" @@ -8990,7 +9054,7 @@ msgstr "" msgid "Copy current search text (instead of search name)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:373 +#: /home/kovid/work/calibre/src/calibre/gui2/library/delegates.py:388 msgid "Y" msgstr "" @@ -9008,75 +9072,75 @@ msgstr "" msgid "Modified" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:760 -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1317 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:766 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1323 #: /home/kovid/work/calibre/src/calibre/gui2/tag_view.py:797 msgid "The lookup/search name is \"{0}\"" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:766 -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1319 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:772 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1325 msgid "This book's UUID is \"{0}\"" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1016 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1022 msgid "In Library" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1020 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1026 #: /home/kovid/work/calibre/src/calibre/library/field_metadata.py:311 msgid "Size" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1297 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1303 msgid "Marked for deletion" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1300 +#: /home/kovid/work/calibre/src/calibre/gui2/library/models.py:1306 msgid "Double click to edit me

    " msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:158 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:159 msgid "Hide column %s" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:163 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:164 msgid "Sort on %s" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:164 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:165 msgid "Ascending" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:167 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:168 msgid "Descending" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:179 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:180 msgid "Change text alignment for %s" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:181 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:182 msgid "Left" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:181 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:182 msgid "Right" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:182 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:183 msgid "Center" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:201 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:202 msgid "Show column" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:213 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:214 msgid "Restore default layout" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:855 +#: /home/kovid/work/calibre/src/calibre/gui2/library/views.py:858 msgid "Dropping onto a device is not supported. First add the book to the calibre library." msgstr "" @@ -9995,7 +10059,7 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:41 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:66 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:73 -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:153 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:156 msgid "Yes/No" msgstr "" @@ -10027,7 +10091,7 @@ msgstr "" #: #: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:65 -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:152 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:155 #: /home/kovid/work/calibre/src/calibre/gui2/preferences/emailp.py:27 #: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:21 #: /home/kovid/work/calibre/src/calibre/library/field_metadata.py:124 @@ -10071,117 +10135,127 @@ msgid "Selected column is not a user-defined column" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:154 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:157 msgid "My Tags" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:155 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:158 msgid "My Series" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:156 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:159 msgid "My Rating" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:157 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:160 msgid "People" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:185 -msgid "No lookup name was provided" -msgstr "" - -#: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:189 -msgid "The lookup name must contain only lower case letters, digits and underscores, and start with a letter" +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:187 +msgid "Examples: The format {0:0>4d} gives a 4-digit number with leading zeros. The format {0:d} days prints the number then the word \"days\"" msgstr "" #: #: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:192 +msgid "Examples: The format {0:.1f} gives a floating point number with 1 digit after the decimal point. The format Price: $ {0:,.2f} prints \"Price $ \" then displays the number with 2 digits after the decimal point and thousands separated by commas." +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:201 +msgid "No lookup name was provided" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:205 +msgid "The lookup name must contain only lower case letters, digits and underscores, and start with a letter" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:208 msgid "Lookup names cannot end with _index, because these names are reserved for the index of a series column." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:202 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:218 msgid "No column heading was provided" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:212 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:228 msgid "The lookup name %s is already used" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:224 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:240 msgid "The heading %s is already used" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:235 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:251 msgid "You must enter a template for composite columns" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:244 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:260 msgid "You must enter at least one value for enumeration columns" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:248 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:264 msgid "You cannot provide the empty value, as it is included by default" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:252 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:268 msgid "The value \"{0}\" is in the list more than once" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:260 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:276 msgid "The colors box must be empty or contain the same number of items as the value box" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:265 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column.py:281 msgid "The color {0} is unknown" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:201 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:217 msgid "&Lookup name" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:202 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:218 msgid "Column &heading" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:203 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:219 msgid "Used for searching the column. Must contain only digits and lower case letters." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:204 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:220 msgid "Column heading in the library view and category name in the tag browser" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:205 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:221 msgid "&Column type" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:206 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:222 msgid "What kind of information will be kept in the column." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:207 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:223 msgid "" "Show check marks in the GUI. Values of 'yes', 'checked', and 'true'\n" "will show a green check. Values of 'no', 'unchecked', and 'false' will show a red X.\n" @@ -10189,22 +10263,22 @@ msgid "" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:210 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:226 msgid "Show checkmarks" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:211 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:227 msgid "Check this box if this column contains names, like the authors column." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:212 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:228 msgid "Contains names" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:213 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:229 msgid "" "

    Date format. Use 1-4 'd's for day, 1-4 'M's for month, and 2 or 4 'y's for year.

    \n" "

    For example:\n" @@ -10215,68 +10289,86 @@ msgid "" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:219 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:235 msgid "Use MMM yyyy for month + year, yyyy for year only" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:220 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:236 msgid "Default: dd MMM yyyy." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:221 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:237 +msgid "" +"

    The format specifier must begin with {0:\n" +"and end with } You can have text before and after the format specifier.\n" +" " +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:240 +msgid "

    Default: Not formatted. For format language details see the python documentation" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:241 msgid "Format for &dates" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:222 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:242 +msgid "Format for &numbers" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:243 msgid "&Template" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:223 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:244 msgid "Field template. Uses the same syntax as save templates." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:224 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:245 msgid "Similar to save templates. For example, {title} {isbn}" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:225 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:246 msgid "Default: (nothing)" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:226 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:247 msgid "&Sort/search column by" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:227 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:248 msgid "How this column should handled in the GUI when sorting and searching" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:228 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:249 msgid "If checked, this column will appear in the tags browser as a category" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:229 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:250 msgid "Show in tags browser" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:230 -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:235 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:251 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:256 msgid "Values" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:231 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:252 msgid "" "A comma-separated list of permitted values. The empty value is always\n" "included, and is the default. For example, the list 'one,two,three' has\n" @@ -10284,19 +10376,19 @@ msgid "" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:234 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:255 msgid "The empty string is always the first value" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:236 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:257 msgid "" "A list of color names to use when displaying an item. The\n" "list must be empty or contain a color for each value." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:238 +#: /home/kovid/work/calibre/src/calibre/gui2/preferences/create_custom_column_ui.py:259 msgid "Colors" msgstr "" @@ -10418,7 +10510,7 @@ msgid "Always" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/preferences/look_feel.py:132 -msgid "Automatic" +msgid "If there is enough room" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/preferences/look_feel.py:133 @@ -10438,7 +10530,7 @@ msgid "Partitioned" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/preferences/look_feel.py:163 -msgid "Here you can specify coloring rules for columns shown in the library view. Choose the column you wish to color, then supply a template that specifies the color to use based on the values in the column. There is a tutorial on using templates." +msgid "Here you can specify coloring rules for columns shown in the library view. Choose the column you wish to color, then supply a template that specifies the color to use based on the values in the column. There is a tutorial on using templates." msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/preferences/look_feel.py:170 @@ -10920,7 +11012,7 @@ msgid "Search for plugin" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/preferences/plugins.py:230 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search.py:297 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search.py:321 msgid "No matches" msgstr "" @@ -11561,7 +11653,7 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/search_box.py:95 #: /home/kovid/work/calibre/src/calibre/gui2/search_box.py:279 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_widget_ui.py:58 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_widget_ui.py:80 #: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/store_dialog_ui.py:76 #: /home/kovid/work/calibre/src/calibre/gui2/store/search/search_ui.py:134 #: /home/kovid/work/calibre/src/calibre/gui2/store/search_ui.py:109 @@ -11646,6 +11738,7 @@ msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/shortcuts.py:48 #: /home/kovid/work/calibre/src/calibre/gui2/shortcuts_ui.py:78 #: /home/kovid/work/calibre/src/calibre/gui2/shortcuts_ui.py:83 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_widget_ui.py:83 #: /home/kovid/work/calibre/src/calibre/gui2/store/search/search_ui.py:138 #: /home/kovid/work/calibre/src/calibre/gui2/store/search_ui.py:113 #: /home/kovid/work/calibre/src/calibre/gui2/widgets.py:351 @@ -11718,54 +11811,87 @@ msgid "Open store in external web browswer" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:209 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:219 msgid "&Name:" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:211 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:221 msgid "&Description:" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:212 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:222 msgid "&Headquarters:" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:216 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:226 msgid "Enabled:" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:217 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:227 msgid "DRM:" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:218 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:220 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:228 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:230 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:233 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:207 msgid "true" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:219 -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:221 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:229 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:231 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:234 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:208 msgid "false" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:222 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:232 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:206 +msgid "Affiliate:" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/adv_search_builder_ui.py:235 msgid "Nam&e/Description ..." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_widget_ui.py:56 +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_widget_ui.py:78 #: /home/kovid/work/calibre/src/calibre/gui2/store/search/search_ui.py:132 #: /home/kovid/work/calibre/src/calibre/gui2/store/search_ui.py:108 msgid "Query:" msgstr "" +#: +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_widget_ui.py:81 +msgid "Enable" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_widget_ui.py:82 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search_ui.py:136 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search_ui.py:111 +msgid "All" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/chooser_widget_ui.py:84 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search_ui.py:137 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search_ui.py:112 +msgid "Invert" +msgstr "" + +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:21 +msgid "Affiliate" +msgstr "" + #: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:21 msgid "Enabled" msgstr "" @@ -11779,33 +11905,44 @@ msgid "No DRM" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:108 -msgid "

    This store is currently diabled and cannot be used in other parts of calibre.

    " +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:129 +msgid "This store is currently diabled and cannot be used in other parts of calibre." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:110 -msgid "

    This store is currently enabled and can be used in other parts of calibre.

    " +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:131 +msgid "This store is currently enabled and can be used in other parts of calibre." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:115 -msgid "

    This store only distributes ebooks with DRM.

    " +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:136 +msgid "This store only distributes ebooks with DRM." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:117 -msgid "

    This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.

    " +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:138 +msgid "This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:119 -msgid "

    This store is headquartered in %s. This is a good indication of what market the store caters to. However, this does not necessarily mean that the store is limited to that market only.

    " +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:140 +msgid "This store is headquartered in %s. This is a good indication of what market the store caters to. However, this does not necessarily mean that the store is limited to that market only." msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:121 -msgid "

    This store distributes ebooks in the following formats: %s

    " +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:143 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:203 +msgid "Buying from this store supports the calibre developer: %s." +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/models.py:145 +msgid "This store distributes ebooks in the following formats: %s" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/store/config/chooser/results_view.py:47 +msgid "Configure..." msgstr "" #: @@ -11898,6 +12035,17 @@ msgstr "" msgid "Not Available" msgstr "" +#: +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:179 +msgid "See the User Manual for more help" +msgstr "" + +#: +#: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/adv_search_builder_ui.py:187 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:209 +msgid "Titl&e/Author/Price ..." +msgstr "" + #: #: /home/kovid/work/calibre/src/calibre/gui2/store/mobileread/cache_progress_dialog_ui.py:51 msgid "Updating book cache" @@ -11955,13 +12103,12 @@ msgid "Search:" msgstr "" #: -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:192 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:202 msgid "&Price:" msgstr "" -#: -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/adv_search_builder_ui.py:196 -msgid "Titl&e/Author/Price ..." +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:36 +msgid "" msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:36 @@ -11972,31 +12119,35 @@ msgstr "" msgid "Price" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:180 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:191 msgid "Detected price as: %s. Check with the store before making a purchase to verify this price is correct. This price often does not include promotions the store may be running." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:183 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:194 msgid "This book as been detected as having DRM restrictions. This book may not work with your reader and you will have limitations placed upon you as to what you can do with this book. Check with the store before making any purchases to ensure you can actually read this book." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:185 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:196 msgid "This book has been detected as being DRM Free. You should be able to use this book on any device provided it is in a format calibre supports for conversion. However, before making a purchase double check the DRM status with the store. The store may not be disclosing the use of DRM." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:187 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/models.py:198 msgid "The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search.py:252 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search.py:105 +msgid "Buying from this store supports the calibre developer: %s

    " +msgstr "" + +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search.py:261 msgid "Customize get books search" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search.py:262 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search.py:271 msgid "Configure search" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search.py:297 +#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search.py:321 msgid "Couldn't find any books matching your query." msgstr "" @@ -12005,16 +12156,6 @@ msgstr "" msgid "Get Books" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search_ui.py:136 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search_ui.py:111 -msgid "All" -msgstr "" - -#: /home/kovid/work/calibre/src/calibre/gui2/store/search/search_ui.py:137 -#: /home/kovid/work/calibre/src/calibre/gui2/store/search_ui.py:112 -msgid "Invert" -msgstr "" - #: /home/kovid/work/calibre/src/calibre/gui2/store/search/search_ui.py:140 msgid "Open a selected book in the system's web browser" msgstr "" @@ -12381,15 +12522,19 @@ msgstr "" msgid "%s has been updated to version %s. See the new features." msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/update.py:58 +#: /home/kovid/work/calibre/src/calibre/gui2/update.py:55 +msgid "Update only if one of the new features or bug fixes is important to you. If the current version works well for you, do not update." +msgstr "" + +#: /home/kovid/work/calibre/src/calibre/gui2/update.py:60 msgid "Update available!" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/update.py:63 +#: /home/kovid/work/calibre/src/calibre/gui2/update.py:65 msgid "Show this notification for future updates" msgstr "" -#: /home/kovid/work/calibre/src/calibre/gui2/update.py:68 +#: /home/kovid/work/calibre/src/calibre/gui2/update.py:70 msgid "&Get update" msgstr "" @@ -12960,7 +13105,7 @@ msgid "

    Demo videos

    Videos demonstrating the various features of calibre msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/wizard/finish_ui.py:51 -msgid "

    User Manual

    A User Manual is also available online." +msgid "

    User Manual

    A User Manual is also available online." msgstr "" #: /home/kovid/work/calibre/src/calibre/gui2/wizard/kindle_ui.py:49 @@ -13166,63 +13311,63 @@ msgid "Turn on the &content server" msgstr "" #: /home/kovid/work/calibre/src/calibre/library/caches.py:161 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:562 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:576 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:586 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:567 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:581 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:591 msgid "checked" msgstr "" #: /home/kovid/work/calibre/src/calibre/library/caches.py:161 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:562 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:576 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:586 -#: /home/kovid/work/calibre/src/calibre/library/save_to_disk.py:214 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:567 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:581 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:591 +#: /home/kovid/work/calibre/src/calibre/library/save_to_disk.py:216 msgid "yes" msgstr "" #: /home/kovid/work/calibre/src/calibre/library/caches.py:163 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:561 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:573 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:583 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:566 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:578 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:588 msgid "unchecked" msgstr "" #: /home/kovid/work/calibre/src/calibre/library/caches.py:163 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:561 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:573 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:583 -#: /home/kovid/work/calibre/src/calibre/library/save_to_disk.py:214 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:566 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:578 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:588 +#: /home/kovid/work/calibre/src/calibre/library/save_to_disk.py:216 msgid "no" msgstr "" -#: /home/kovid/work/calibre/src/calibre/library/caches.py:356 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:361 msgid "today" msgstr "" -#: /home/kovid/work/calibre/src/calibre/library/caches.py:359 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:364 msgid "yesterday" msgstr "" -#: /home/kovid/work/calibre/src/calibre/library/caches.py:362 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:367 msgid "thismonth" msgstr "" -#: /home/kovid/work/calibre/src/calibre/library/caches.py:365 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:366 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:370 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:371 msgid "daysago" msgstr "" -#: /home/kovid/work/calibre/src/calibre/library/caches.py:563 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:580 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:568 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:585 msgid "blank" msgstr "" -#: /home/kovid/work/calibre/src/calibre/library/caches.py:563 -#: /home/kovid/work/calibre/src/calibre/library/caches.py:580 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:568 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:585 msgid "empty" msgstr "" -#: /home/kovid/work/calibre/src/calibre/library/caches.py:564 +#: /home/kovid/work/calibre/src/calibre/library/caches.py:569 msgid "Invalid boolean query \"{0}\"" msgstr "" @@ -13980,19 +14125,19 @@ msgstr "" msgid "%sAverage rating is %3.1f" msgstr "" -#: /home/kovid/work/calibre/src/calibre/library/database2.py:1021 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:1022 msgid "Main" msgstr "" -#: /home/kovid/work/calibre/src/calibre/library/database2.py:3109 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:3110 msgid "

    Migrating old database to ebook library in %s

    " msgstr "" -#: /home/kovid/work/calibre/src/calibre/library/database2.py:3138 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:3139 msgid "Copying %s" msgstr "" -#: /home/kovid/work/calibre/src/calibre/library/database2.py:3155 +#: /home/kovid/work/calibre/src/calibre/library/database2.py:3156 msgid "Compacting database" msgstr "" @@ -14117,8 +14262,8 @@ msgstr "" msgid "Replace whitespace with underscores." msgstr "" -#: /home/kovid/work/calibre/src/calibre/library/save_to_disk.py:370 -#: /home/kovid/work/calibre/src/calibre/library/save_to_disk.py:398 +#: /home/kovid/work/calibre/src/calibre/library/save_to_disk.py:372 +#: /home/kovid/work/calibre/src/calibre/library/save_to_disk.py:400 msgid "Requested formats not available" msgstr "" @@ -14447,35 +14592,35 @@ msgstr "" msgid "syntax error - program ends before EOF" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:101 -msgid "unknown id " +#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:103 +msgid "Unknown identifier " msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:107 +#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:110 msgid "unknown function {0}" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:126 +#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:129 msgid "missing closing parenthesis" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:145 +#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:148 msgid "expression is not function or constant" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:179 +#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:182 msgid "format: type {0} requires an integer value, got {1}" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:185 +#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:188 msgid "format: type {0} requires a decimal (float) value, got {1}" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:296 +#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:299 msgid "%s: unknown function" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:343 +#: /home/kovid/work/calibre/src/calibre/utils/formatter.py:348 msgid "No such variable " msgstr "" @@ -14483,167 +14628,171 @@ msgstr "" msgid "No documentation provided" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:79 -msgid "Exception " -msgstr "" - -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:97 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:90 msgid "strcmp(x, y, lt, eq, gt) -- does a case-insensitive comparison of x and y as strings. Returns lt if x < y. Returns eq if x == y. Otherwise returns gt." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:112 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:105 msgid "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." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:127 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:120 msgid "strcat(a, b, ...) -- can take any number of arguments. Returns a string formed by concatenating all the arguments" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:140 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:133 msgid "add(x, y) -- returns x + y. Throws an exception if either x or y are not numbers." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:150 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:143 msgid "subtract(x, y) -- returns x - y. Throws an exception if either x or y are not numbers." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:160 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:153 msgid "multiply(x, y) -- returns x * y. Throws an exception if either x or y are not numbers." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:170 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:163 msgid "divide(x, y) -- returns x / y. Throws an exception if either x or y are not numbers." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:180 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:173 msgid "template(x) -- evaluates x as a template. The evaluation is done in its own context, meaning that variables are not shared between the caller and the template evaluation. Because the { and } characters are special, you must use [[ for the { character and ]] for the } character; they are converted automatically. For example, template('[[title_sort]]') will evaluate the template {title_sort} and return its value." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:195 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:188 msgid "eval(template) -- evaluates the template, passing the local variables (those 'assign'ed to) instead of the book metadata. This permits using the template processor to construct complex results from local variables." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:208 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:201 msgid "assign(id, val) -- assigns val to id, then returns val. id must be an identifier, not an expression" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:218 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:211 msgid "print(a, b, ...) -- prints the arguments to standard output. Unless you start calibre from the command line (calibre-debug -g), the output will go to a black hole." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:229 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:222 msgid "field(name) -- returns the metadata field named by name" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:237 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:230 msgid "raw_field(name) -- returns the metadata field named by name without applying any formatting." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:246 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:239 msgid "substr(str, start, end) -- returns the start'th through the end'th characters of str. The first character in str is the zero'th character. If end is negative, then it indicates that many characters counting from the right. If end is zero, then it indicates the last character. For example, substr('12345', 1, 0) returns '2345', and substr('12345', 1, -1) returns '234'." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:259 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:252 msgid "lookup(val, pattern, field, pattern, field, ..., else_field) -- like switch, except the arguments are field (metadata) names, not text. The value of the appropriate field will be fetched and used. Note that because composite columns are fields, you can use this function in one composite field to use the value of some other composite field. This is extremely useful when constructing variable save paths" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:274 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:267 msgid "lookup requires either 2 or an odd number of arguments" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:286 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:279 msgid "test(val, text if not empty, text if empty) -- return `text if not empty` if the field is not empty, otherwise return `text if empty`" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:298 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:291 msgid "contains(val, 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`" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:313 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:306 msgid "switch(val, 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" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:321 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:314 msgid "switch requires an odd number of arguments" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:333 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:326 msgid "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." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:349 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:342 +msgid "str_in_list(val, separator, string, found_val, not_found_val) -- treat val as a list of items separated by separator, comparing the string against each value in the list. If the string matches a value, return found_val, otherwise return not_found_val. If the string contains separators, then it is also treated as a list and each value is checked." +msgstr "" + +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:361 msgid "re(val, pattern, replacement) -- return the field after applying the regular expression. All instances of `pattern` are replaced with `replacement`. As in all of calibre, these are python-compatible regular expressions" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:360 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:372 msgid "ifempty(val, text if empty) -- return val if val is not empty, otherwise return `text if empty`" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:372 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:384 msgid "shorten(val, 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." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:397 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:409 msgid "count(val, 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(&)}" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:408 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:420 msgid "list_item(val, 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." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:428 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:440 msgid "select(val, key) -- interpret the value as a comma-separated list of items, with the items being \"id:value\". Find the pair with theid equal to key, and return the corresponding value." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:445 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:457 msgid "sublist(val, start_index, end_index, separator) -- interpret the value as a list of items separated by `separator`, returning a new list made from the `start_index`th to the `end_index`th item. The first item is number zero. If an index is negative, then it counts from the end of the list. As a special case, an end_index of zero is assumed to be the length of the list. Examples using basic template mode and assuming that the tags column (which is comma-separated) contains \"A, B, C\": {tags:sublist(0,1,\\,)} returns \"A\". {tags:sublist(-1,0,\\,)} returns \"C\". {tags:sublist(0,-1,\\,)} returns \"A, B\"." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:474 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:486 msgid "subitems(val, start_index, end_index) -- This function is used to break apart lists of items such as genres. It interprets the value as a comma-separated list of items, where each item is a period-separated list. Returns a new list made by first finding all the period-separated items, then for each such item extracting the start_index`th to the `end_index`th components, then combining the results back together. The first component in a period-separated list has an index of zero. If an index is negative, then it counts from the end of the list. As a special case, an end_index of zero is assumed to be the length of the list. Example using basic template mode and assuming a #genre value of \"A.B.C\": {#genre:subitems(0,1)} returns \"A\". {#genre:subitems(0,2)} returns \"A.B\". {#genre:subitems(1,0)} returns \"B.C\". Assuming a #genre value of \"A.B.C, D.E.F\", {#genre:subitems(0,1)} returns \"A, D\". {#genre:subitems(0,2)} returns \"A.B, D.E\"" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:511 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:523 msgid "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) dd : the day as number with a leading zero (01 to 31) ddd : the abbreviated localized day name (e.g. \"Mon\" to \"Sun\"). dddd : the long localized day name (e.g. \"Monday\" to \"Sunday\"). M : the month as number without a leading zero (1 to 12). MM : the month as number with a leading zero (01 to 12) MMM : the abbreviated localized month name (e.g. \"Jan\" to \"Dec\"). MMMM : the long localized month name (e.g. \"January\" to \"December\"). yy : the year as two digit number (00 to 99). yyyy : the year as four digit number. iso : the date with time and timezone. Must be the only format present" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:539 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:551 msgid "uppercase(val) -- return value of the field in upper case" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:547 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:559 msgid "lowercase(val) -- return value of the field in lower case" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:555 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:567 msgid "titlecase(val) -- return value of the field in title case" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:563 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:575 msgid "capitalize(val) -- return value of the field capitalized" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:571 -msgid "booksize() -- return value of the field capitalized" +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:583 +msgid "booksize() -- return value of the size field" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:584 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:596 +msgid "ondevice() -- return Yes if ondevice is set, otherwise return the empty string" +msgstr "" + +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:607 msgid "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." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:600 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:623 msgid "and(value, value, ...) -- returns the string \"1\" if all values are not empty, otherwise returns the empty string. This function works well with test or first_non_empty. You can have as many values as you want." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:616 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:639 msgid "or(value, value, ...) -- returns the string \"1\" if any value is not empty, otherwise returns the empty string. This function works well with test or first_non_empty. You can have as many values as you want." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:632 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:655 msgid "not(value) -- returns the string \"1\" if the value is empty, otherwise returns the empty string. This function works well with test or first_non_empty. You can have as many values as you want." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:648 +#: /home/kovid/work/calibre/src/calibre/utils/formatter_functions.py:671 msgid "merge_lists(list1, list2, separator) -- return a list made by merging the items in list1 and list2, removing duplicate items using a case-insensitive compare. If items differ in case, the one in list1 is used. The items in list1 and list2 are separated by separator, as are the items in the returned list." msgstr "" @@ -14663,147 +14812,147 @@ msgstr "" msgid "Working..." msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:95 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:98 msgid "Brazilian Portuguese" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:96 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:99 msgid "English (UK)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:97 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:100 msgid "Simplified Chinese" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:98 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:101 msgid "Chinese (HK)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:99 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:102 msgid "Traditional Chinese" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:100 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:103 msgid "English" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:101 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:104 msgid "English (Australia)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:102 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:105 msgid "English (New Zealand)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:103 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:106 msgid "English (Canada)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:104 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:107 msgid "English (India)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:105 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:108 msgid "English (Thailand)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:106 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:109 msgid "English (Cyprus)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:107 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:110 msgid "English (Czechoslovakia)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:108 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:111 msgid "English (Pakistan)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:109 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:112 msgid "English (Croatia)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:110 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:113 msgid "English (Indonesia)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:111 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:114 msgid "English (Israel)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:112 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:115 msgid "English (Singapore)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:113 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:116 msgid "English (Yemen)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:114 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:117 msgid "English (Ireland)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:115 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:118 msgid "English (China)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:116 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:119 msgid "Spanish (Paraguay)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:117 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:120 msgid "Spanish (Uruguay)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:118 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:121 msgid "Spanish (Argentina)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:119 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:122 msgid "Spanish (Mexico)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:120 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:123 msgid "Spanish (Cuba)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:121 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:124 msgid "Spanish (Chile)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:122 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:125 msgid "Spanish (Ecuador)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:123 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:126 msgid "Spanish (Honduras)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:124 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:127 msgid "Spanish (Venezuela)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:125 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:128 msgid "Spanish (Bolivia)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:126 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:129 msgid "Spanish (Nicaragua)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:127 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:130 msgid "German (AT)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:128 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:131 msgid "French (BE)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:129 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:132 msgid "Dutch (NL)" msgstr "" -#: /home/kovid/work/calibre/src/calibre/utils/localization.py:130 +#: /home/kovid/work/calibre/src/calibre/utils/localization.py:133 msgid "Dutch (BE)" msgstr "" From c319d4f6c567d418a881280ed417a71794011754 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 29 May 2011 22:52:36 -0600 Subject: [PATCH 26/84] Alt om Herning and Version2.dk by Rasmus Lauritsen --- recipes/alt_om_herning.recipe | 43 +++++++++++++++++++++ recipes/version2.recipe | 64 +++++++++++++++++++++++++++++++ resources/template-functions.json | 14 ++++--- 3 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 recipes/alt_om_herning.recipe create mode 100644 recipes/version2.recipe diff --git a/recipes/alt_om_herning.recipe b/recipes/alt_om_herning.recipe new file mode 100644 index 0000000000..c60d142a85 --- /dev/null +++ b/recipes/alt_om_herning.recipe @@ -0,0 +1,43 @@ +__license__ = 'GPL v3' +__copyright__ = '2011, Rasmus Lauritsen ' +''' +aoh.dk +''' + +from calibre.web.feeds.news import BasicNewsRecipe + +class aoh_dk(BasicNewsRecipe): + title = 'Alt om Herning' + __author__ = 'Rasmus Lauritsen' + description = 'Nyheder fra Herning om omegn' + publisher = 'Mediehuset Herning Folkeblad' + category = 'news, local, Denmark' + oldest_article = 14 + max_articles_per_feed = 50 + no_stylesheets = True + delay = 1 + encoding = 'utf8' + use_embedded_content = False + language = 'da' + extra_css = """ body{font-family: Verdana,Arial,sans-serif } + img{margin-bottom: 0.4em} + .txtContent,.stamp{font-size: small} + """ + + conversion_options = { + 'comment' : description + , 'tags' : category + , 'publisher' : publisher + , 'language' : language + } + + feeds = [(u'All news', u'http://aoh.dk/rss.xml')] + + keep_only_tags = [ + dict(name='h1') + ,dict(name='span', attrs={'class':['frontpage_body']}) + ] + + remove_tags = [ + dict(name=['object','link']) + ] diff --git a/recipes/version2.recipe b/recipes/version2.recipe new file mode 100644 index 0000000000..7dc257246a --- /dev/null +++ b/recipes/version2.recipe @@ -0,0 +1,64 @@ +import re + +__license__ = 'GPL v3' +__copyright__ = '2011, Rasmus Lauritsen ' +''' +version2.dk +''' + +from calibre.web.feeds.news import BasicNewsRecipe + +class version2(BasicNewsRecipe): + title = 'Version2.dk' + __author__ = 'Rasmus Lauritsen' + description = 'IT News' + publisher = 'version2.dk' + category = 'news, IT, hardware, software, Denmark' + oldest_article = 14 + max_articles_per_feed = 50 + no_stylesheets = True + remove_empty_feeds = True + use_embedded_content = False + encoding = 'iso-8859-1' + language = 'da' + + extra_css = """ + body {font-family: "Verdana",Times,serif} + .articleauthor{color: #9F9F9F; + font-family: Arial, sans-serif; + font-size: small; + text-transform: uppercase} + .rubric,.dd,h6#credit{color: #CD0021; + font-family: Arial, sans-serif; + font-size: small; + text-transform: uppercase} + .descender:first-letter{display: inline; font-size: xx-large; font-weight: bold} + .dd,h6#credit{color: gray} + .c{display: block} + .caption,h2#articleintro{font-style: italic} + .caption{font-size: small} + """ + + preprocess_regexps = [ (re.compile(r']*>'),lambda match: ''), + (re.compile(r']*article-link-id.*?'), lambda match: '')] + + keep_only_tags = [dict(name='div', attrs={'class':'article'})] + + remove_tags = [ + dict(name='p',attrs={'class':'meta links'}), + dict(name='div',attrs={'class':'float-right'}), + dict(name='span',attrs={'class':'article-link-id'}) + ] + + feeds = [ + (u'Seneste nyheder' , u'http://www.version2.dk/feeds/nyheder') + ,(u'Forretningssoftware' , u'http://www.version2.dk/feeds/forretningssoftware') + ,(u'Internet & styresystemer' , u'http://www.version2.dk/feeds/styresystemer') + ,(u'It-arkitektur' , u'http://www.version2.dk/feeds/it-arkitektur') + ,(u'It-styring & outsourcing' , u'http://www.version2.dk/feeds/it-styring') + ,(u'Job & karriere' , u'http://www.version2.dk/feeds/karriere') + ,(u'Mobil it & tele' , u'http://www.version2.dk/feeds/tele') + ,(u'Server/storage & netvÃĶrk' , u'http://www.version2.dk/feeds/server-storage') + ,(u'Sikkerhed' , u'http://www.version2.dk/feeds/sikkerhed') + ,(u'Softwareudvikling' , u'http://www.version2.dk/feeds/softwareudvikling') + ] diff --git a/resources/template-functions.json b/resources/template-functions.json index 9fdc1782ea..606b102d41 100644 --- a/resources/template-functions.json +++ b/resources/template-functions.json @@ -1,26 +1,27 @@ { "and": "def evaluate(self, formatter, kwargs, mi, locals, *args):\n i = 0\n while i < len(args):\n if not args[i]:\n return ''\n i += 1\n return '1'\n", - "contains": "def evaluate(self, formatter, kwargs, mi, locals,\n val, test, value_if_present, value_if_not):\n if re.search(test, val):\n return value_if_present\n else:\n return value_if_not\n", + "contains": "def evaluate(self, formatter, kwargs, mi, locals,\n val, test, value_if_present, value_if_not):\n if re.search(test, val, flags=re.I):\n return value_if_present\n else:\n return value_if_not\n", "divide": "def evaluate(self, formatter, kwargs, mi, locals, x, y):\n x = float(x if x else 0)\n y = float(y if y else 0)\n return unicode(x / y)\n", "uppercase": "def evaluate(self, formatter, kwargs, mi, locals, val):\n return val.upper()\n", "strcat": "def evaluate(self, formatter, kwargs, mi, locals, *args):\n i = 0\n res = ''\n for i in range(0, len(args)):\n res += args[i]\n return res\n", - "in_list": "def evaluate(self, formatter, kwargs, mi, locals, val, sep, pat, fv, nfv):\n l = [v.strip() for v in val.split(sep) if v.strip()]\n for v in l:\n if re.search(pat, v):\n return fv\n return nfv\n", + "in_list": "def evaluate(self, formatter, kwargs, mi, locals, val, sep, pat, fv, nfv):\n l = [v.strip() for v in val.split(sep) if v.strip()]\n if l:\n for v in l:\n if re.search(pat, v, flags=re.I):\n return fv\n return nfv\n", "multiply": "def evaluate(self, formatter, kwargs, mi, locals, x, y):\n x = float(x if x else 0)\n y = float(y if y else 0)\n return unicode(x * y)\n", "ifempty": "def evaluate(self, formatter, kwargs, mi, locals, val, value_if_empty):\n if val:\n return val\n else:\n return value_if_empty\n", "booksize": "def evaluate(self, formatter, kwargs, mi, locals):\n if mi.book_size is not None:\n try:\n return str(mi.book_size)\n except:\n pass\n return ''\n", "select": "def evaluate(self, formatter, kwargs, mi, locals, val, key):\n if not val:\n return ''\n vals = [v.strip() for v in val.split(',')]\n for v in vals:\n if v.startswith(key+':'):\n return v[len(key)+1:]\n return ''\n", "strcmp": "def evaluate(self, formatter, kwargs, mi, locals, x, y, lt, eq, gt):\n v = strcmp(x, y)\n if v < 0:\n return lt\n if v == 0:\n return eq\n return gt\n", "first_non_empty": "def evaluate(self, formatter, kwargs, mi, locals, *args):\n i = 0\n while i < len(args):\n if args[i]:\n return args[i]\n i += 1\n return ''\n", - "re": "def evaluate(self, formatter, kwargs, mi, locals, val, pattern, replacement):\n return re.sub(pattern, replacement, val)\n", + "re": "def evaluate(self, formatter, kwargs, mi, locals, val, pattern, replacement):\n return re.sub(pattern, replacement, val, flags=re.I)\n", "subtract": "def evaluate(self, formatter, kwargs, mi, locals, x, y):\n x = float(x if x else 0)\n y = float(y if y else 0)\n return unicode(x - y)\n", "list_item": "def evaluate(self, formatter, kwargs, mi, locals, val, index, sep):\n if not val:\n return ''\n index = int(index)\n val = val.split(sep)\n try:\n return val[index]\n except:\n return ''\n", "shorten": "def evaluate(self, formatter, kwargs, mi, locals,\n val, leading, center_string, trailing):\n l = max(0, int(leading))\n t = max(0, int(trailing))\n if len(val) > l + len(center_string) + t:\n return val[0:l] + center_string + ('' if t == 0 else val[-t:])\n else:\n return val\n", "field": "def evaluate(self, formatter, kwargs, mi, locals, name):\n return formatter.get_value(name, [], kwargs)\n", "add": "def evaluate(self, formatter, kwargs, mi, locals, x, y):\n x = float(x if x else 0)\n y = float(y if y else 0)\n return unicode(x + y)\n", - "lookup": "def evaluate(self, formatter, kwargs, mi, locals, val, *args):\n if len(args) == 2: # here for backwards compatibility\n if val:\n return formatter.vformat('{'+args[0].strip()+'}', [], kwargs)\n else:\n return formatter.vformat('{'+args[1].strip()+'}', [], kwargs)\n if (len(args) % 2) != 1:\n raise ValueError(_('lookup requires either 2 or an odd number of arguments'))\n i = 0\n while i < len(args):\n if i + 1 >= len(args):\n return formatter.vformat('{' + args[i].strip() + '}', [], kwargs)\n if re.search(args[i], val):\n return formatter.vformat('{'+args[i+1].strip() + '}', [], kwargs)\n i += 2\n", + "lookup": "def evaluate(self, formatter, kwargs, mi, locals, val, *args):\n if len(args) == 2: # here for backwards compatibility\n if val:\n return formatter.vformat('{'+args[0].strip()+'}', [], kwargs)\n else:\n return formatter.vformat('{'+args[1].strip()+'}', [], kwargs)\n if (len(args) % 2) != 1:\n raise ValueError(_('lookup requires either 2 or an odd number of arguments'))\n i = 0\n while i < len(args):\n if i + 1 >= len(args):\n return formatter.vformat('{' + args[i].strip() + '}', [], kwargs)\n if re.search(args[i], val, flags=re.I):\n return formatter.vformat('{'+args[i+1].strip() + '}', [], kwargs)\n i += 2\n", "template": "def evaluate(self, formatter, kwargs, mi, locals, template):\n template = template.replace('[[', '{').replace(']]', '}')\n return formatter.__class__().safe_format(template, kwargs, 'TEMPLATE', mi)\n", "print": "def evaluate(self, formatter, kwargs, mi, locals, *args):\n print args\n return None\n", "merge_lists": "def evaluate(self, formatter, kwargs, mi, locals, list1, list2, separator):\n l1 = [l.strip() for l in list1.split(separator) if l.strip()]\n l2 = [l.strip() for l in list2.split(separator) if l.strip()]\n lcl1 = set([icu_lower(l) for l in l1])\n res = []\n for i in l1:\n res.append(i)\n for i in l2:\n if icu_lower(i) not in lcl1:\n res.append(i)\n return ', '.join(sorted(res, key=sort_key))\n", + "str_in_list": "def evaluate(self, formatter, kwargs, mi, locals, val, sep, str, fv, nfv):\n l = [v.strip() for v in val.split(sep) if v.strip()]\n c = [v.strip() for v in str.split(sep) if v.strip()]\n if l:\n for v in l:\n for t in c:\n if strcmp(t, v) == 0:\n return fv\n return nfv\n", "titlecase": "def evaluate(self, formatter, kwargs, mi, locals, val):\n return titlecase(val)\n", "subitems": "def evaluate(self, formatter, kwargs, mi, locals, val, start_index, end_index):\n if not val:\n return ''\n si = int(start_index)\n ei = int(end_index)\n items = [v.strip() for v in val.split(',')]\n rv = set()\n for item in items:\n component = item.split('.')\n try:\n if ei == 0:\n rv.add('.'.join(component[si:]))\n else:\n rv.add('.'.join(component[si:ei]))\n except:\n pass\n return ', '.join(sorted(rv, key=sort_key))\n", "sublist": "def evaluate(self, formatter, kwargs, mi, locals, val, start_index, end_index, sep):\n if not val:\n return ''\n si = int(start_index)\n ei = int(end_index)\n val = val.split(sep)\n try:\n if ei == 0:\n return sep.join(val[si:])\n else:\n return sep.join(val[si:ei])\n except:\n return ''\n", @@ -32,9 +33,10 @@ "count": "def evaluate(self, formatter, kwargs, mi, locals, val, sep):\n return unicode(len(val.split(sep)))\n", "lowercase": "def evaluate(self, formatter, kwargs, mi, locals, val):\n return val.lower()\n", "substr": "def evaluate(self, formatter, kwargs, mi, locals, str_, start_, end_):\n return str_[int(start_): len(str_) if int(end_) == 0 else int(end_)]\n", - "assign": "def evaluate(self, formatter, kwargs, mi, locals, target, value):\n locals[target] = value\n return value\n", - "switch": "def evaluate(self, formatter, kwargs, mi, locals, val, *args):\n if (len(args) % 2) != 1:\n raise ValueError(_('switch requires an odd number of arguments'))\n i = 0\n while i < len(args):\n if i + 1 >= len(args):\n return args[i]\n if re.search(args[i], val):\n return args[i+1]\n i += 2\n", "or": "def evaluate(self, formatter, kwargs, mi, locals, *args):\n i = 0\n while i < len(args):\n if args[i]:\n return '1'\n i += 1\n return ''\n", + "switch": "def evaluate(self, formatter, kwargs, mi, locals, val, *args):\n if (len(args) % 2) != 1:\n raise ValueError(_('switch requires an odd number of arguments'))\n i = 0\n while i < len(args):\n if i + 1 >= len(args):\n return args[i]\n if re.search(args[i], val, flags=re.I):\n return args[i+1]\n i += 2\n", + "ondevice": "def evaluate(self, formatter, kwargs, mi, locals):\n if mi.ondevice_col:\n return _('Yes')\n return ''\n", + "assign": "def evaluate(self, formatter, kwargs, mi, locals, target, value):\n locals[target] = value\n return value\n", "raw_field": "def evaluate(self, formatter, kwargs, mi, locals, name):\n return unicode(getattr(mi, name, None))\n", "cmp": "def evaluate(self, formatter, kwargs, mi, locals, x, y, lt, eq, gt):\n x = float(x if x else 0)\n y = float(y if y else 0)\n if x < y:\n return lt\n if x == y:\n return eq\n return gt\n" } \ No newline at end of file From 56b239991cc6a61e71a8208257d3e8e4eb4197a1 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 30 May 2011 14:56:52 +0100 Subject: [PATCH 27/84] Clean up color preferences to make it less intimidating. Add an 'and' box to the wizard. Fix a couple of small bugs. --- .../gui2/dialogs/template_line_editor.py | 159 +++++++++---- src/calibre/gui2/preferences/look_feel.py | 73 ++++-- src/calibre/gui2/preferences/look_feel.ui | 216 ++++++++---------- 3 files changed, 266 insertions(+), 182 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index 90dec0ccf8..68eda27bf1 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -8,8 +8,8 @@ __docformat__ = 'restructuredtext en' from functools import partial from collections import defaultdict -from PyQt4.Qt import (QLineEdit, QDialog, QGridLayout, QLabel, QCheckBox, QIcon, - QDialogButtonBox, QColor, QComboBox, QPushButton) +from PyQt4.Qt import (Qt, QLineEdit, QDialog, QGridLayout, QLabel, QCheckBox, + QIcon, QDialogButtonBox, QColor, QComboBox, QPushButton) from calibre.ebooks.metadata.book.base import composite_formatter from calibre.gui2.dialogs.template_dialog import TemplateDialog @@ -58,10 +58,10 @@ class TemplateLineEditor(QLineEdit): t = TemplateDialog(self, self.text(), self.mi) t.setWindowTitle(_('Edit template')) if t.exec_(): - self.setText(t.textbox.toPlainText()) self.txt = None + self.setText(t.textbox.toPlainText()) - def show_wizard_button(self, txt): + def enable_wizard_button(self, txt): if not txt or txt.startswith('program:\n#tag wizard'): return True return False @@ -129,23 +129,37 @@ class TagWizard(QDialog): self.completion_values[k]['v'] = [v[1] for v in f()] if k in self.completion_values: - self.completion_values[k]['m'] = m['is_multiple'] + if k == 'authors': + self.completion_values[k]['m'] = None + else: + self.completion_values[k]['m'] = m['is_multiple'] self.columns.sort(key=sort_key) self.columns.insert(0, '') l = QGridLayout() self.setLayout(l) - l.setColumnStretch(1, 10) - l.setColumnMinimumWidth(1, 300) + l.setColumnStretch(2, 10) + l.setColumnMinimumWidth(2, 300) + + h = QLabel(_('And')) + h.setToolTip('

    ' + + _('Set this box to indicate that the two conditions must both ' + 'be true to return the "color if value found". For example, you ' + 'can check if two tags are present, if the book has a tag ' + 'and a #read custom column is checked, or if a book has ' + 'some tag and has a particular format.')) + l.addWidget(h, 0, 0, 1, 1) h = QLabel(_('Column')) - l.addWidget(h, 0, 0, 1, 1) + h.setAlignment(Qt.AlignCenter) + l.addWidget(h, 0, 1, 1, 1) h = QLabel(_('Values (see the popup help for more information)')) h.setToolTip('

    ' + _('You can enter more than one value per box, separated by commas. ' - 'The comparison ignores letter case.
    ' + 'The comparison ignores letter case. Special note: you can ' + 'enter at most one author.
    ' 'A value can be a regular expression. Check the box to turn ' 'them on. When using regular expressions, note that the wizard ' 'puts anchors (^ and $) around the expression, so you ' @@ -158,12 +172,12 @@ class TagWizard(QDialog): '

  • A.* matches anything beginning with A
  • ' '
  • .*mystery.* matches anything containing ' 'the word "mystery"
  • ') + '

    ') - l.addWidget(h , 0, 1, 1, 1) + l.addWidget(h , 0, 2, 1, 1) c = QLabel(_('is RE')) c.setToolTip('

    ' + _('Check this box if the values box contains regular expressions') + '

    ') - l.addWidget(c, 0, 2, 1, 1) + l.addWidget(c, 0, 3, 1, 1) c = QLabel(_('Color if value found')) c.setToolTip('

    ' + @@ -171,13 +185,15 @@ class TagWizard(QDialog): 'one color box empty if you want the template to use the next ' 'line in this wizard. If both boxes are filled in, the rest of ' 'the lines in this wizard will be ignored.') + '

    ') - l.addWidget(c, 0, 3, 1, 1) + l.addWidget(c, 0, 4, 1, 1) c = QLabel(_('Color if value not found')) c.setToolTip('

    ' + _('This box is usually filled in only on the last test. If it is ' 'filled in before the last test, then the color for value found box ' 'must be empty or all the rest of the tests will be ignored.') + '

    ') - l.addWidget(c, 0, 4, 1, 1) + l.addWidget(c, 0, 5, 1, 1) + + self.andboxes = [] self.tagboxes = [] self.colorboxes = [] self.nfcolorboxes = [] @@ -185,31 +201,42 @@ class TagWizard(QDialog): self.colboxes = [] self.colors = [unicode(s) for s in list(QColor.colorNames())] self.colors.insert(0, '') - for i in range(0, 10): - w = QComboBox() + + maxlines = 10 + for i in range(1, maxlines+1): + ab = QCheckBox(self) + self.andboxes.append(ab) + if i != maxlines: + # let the last box float in space + l.addWidget(ab, i, 0, 2, 1) + ab.stateChanged.connect(partial(self.and_box_changed, line=i-1)) + else: + ab.setVisible(False) + + w = QComboBox(self) w.addItems(self.columns) - l.addWidget(w, i+1, 0, 1, 1) + l.addWidget(w, i, 1, 1, 1) self.colboxes.append(w) tb = MultiCompleteLineEdit(self) tb.set_separator(', ') self.tagboxes.append(tb) - l.addWidget(tb, i+1, 1, 1, 1) + l.addWidget(tb, i, 2, 1, 1) w.currentIndexChanged[str].connect(partial(self.column_changed, valbox=tb)) w = QCheckBox(self) self.reboxes.append(w) - l.addWidget(w, i+1, 2, 1, 1) + l.addWidget(w, i, 3, 1, 1) w = QComboBox(self) w.addItems(self.colors) self.colorboxes.append(w) - l.addWidget(w, i+1, 3, 1, 1) + l.addWidget(w, i, 4, 1, 1) w = QComboBox(self) w.addItems(self.colors) self.nfcolorboxes.append(w) - l.addWidget(w, i+1, 4, 1, 1) + l.addWidget(w, i, 5, 1, 1) if txt: lines = txt.split('\n')[3:] @@ -222,25 +249,29 @@ class TagWizard(QDialog): nc = '' re = False f = 'tags' + a = False else: - t,c,f,nc,re = vals + t,c,f,nc,re,a = vals try: - self.colorboxes[i].setCurrentIndex(self.colorboxes[i].findText(c)) - self.nfcolorboxes[i].setCurrentIndex(self.nfcolorboxes[i].findText(nc)) + self.colboxes[i].setCurrentIndex(self.colboxes[i].findText(f)) + self.colorboxes[i].setCurrentIndex( + self.colorboxes[i].findText(c)) + self.nfcolorboxes[i].setCurrentIndex( + self.nfcolorboxes[i].findText(nc)) self.tagboxes[i].setText(t) self.reboxes[i].setChecked(re == '2') - self.colboxes[i].setCurrentIndex(self.colboxes[i].findText(f)) + self.andboxes[i].setChecked(a == '2') + i += 1 except: pass - i += 1 w = QLabel(_('Preview')) - l.addWidget(w, 99, 0, 1, 1) + l.addWidget(w, 99, 1, 1, 1) w = self.test_box = QLineEdit(self) w.setReadOnly(True) - l.addWidget(w, 99, 1, 1, 1) + l.addWidget(w, 99, 2, 1, 1) w = QPushButton(_('Test')) - l.addWidget(w, 99, 3, 1, 1) + l.addWidget(w, 99, 4, 1, 1) w.clicked.connect(self.preview) bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel, parent=self) @@ -272,8 +303,11 @@ class TagWizard(QDialog): res = ("program:\n#tag wizard -- do not directly edit\n" " first_non_empty(\n") lines = [] - for tb, cb, fb, nfcb, reb in zip(self.tagboxes, self.colorboxes, - self.colboxes, self.nfcolorboxes, self.reboxes): + was_and = False + had_line = False + + for l, (tb, cb, fb, nfcb, reb, ab) in enumerate(zip(self.tagboxes, self.colorboxes, + self.colboxes, self.nfcolorboxes, self.reboxes, self.andboxes)): f = unicode(fb.currentText()) if not f: continue @@ -281,6 +315,8 @@ class TagWizard(QDialog): c = unicode(cb.currentText()).strip() nfc = unicode(nfcb.currentText()).strip() re = reb.checkState() + a = ab.checkState() + if m: tags = [t.strip() for t in unicode(tb.text()).split(',') if t.strip()] if re == 2: @@ -289,9 +325,15 @@ class TagWizard(QDialog): tags = ','.join(tags) else: tags = unicode(tb.text()).strip() + if f == 'authors': + tags.replace(',', '|') + + if (tags or f) and not (tags and f and (a == 2 or c)): + error_dialog(self, _('Invalid line'), + _('Line number {0} is not valid').format(l), + show=True, show_copy_button=False) + return False - if not tags or not (c or nfc): - continue if c not in self.colors: error_dialog(self, _('Invalid color'), _('The color {0} is not valid').format(c), @@ -302,26 +344,41 @@ class TagWizard(QDialog): _('The color {0} is not valid').format(nfc), show=True, show_copy_button=False) return False + + if not was_and: + if had_line: + lines[-1] += ',' + had_line = True + lines.append(" test(and(") + else: + lines[-1] += ',' + if re == 2: if m: - lines.append(" in_list(field('{3}'), ',', '^{0}$', '{1}', '{2}')".\ - format(tags, c, nfc, f)) + lines.append(" in_list(field('{1}'), ',', '^{0}$', '1', '')".\ + format(tags, f)) else: - lines.append(" contains(field('{3}'), '{0}', '{1}', '{2}')".\ - format(tags, c, nfc, f)) + lines.append(" contains(field('{1}'), '{0}', '1', '')".\ + format(tags, f)) else: if m: - lines.append(" str_in_list(field('{3}'), ',', '{0}', '{1}', '{2}')".\ - format(tags, c, nfc, f)) + lines.append(" str_in_list(field('{1}'), ',', '{0}', '1', '')".\ + format(tags, f)) else: - lines.append(" strcmp(field('{3}'), '{0}', '{2}', '{1}', '{2}')".\ - format(tags, c, nfc, f)) - res += ',\n'.join(lines) + lines.append(" strcmp(field('{1}'), '{0}', '', '1', '')".\ + format(tags, f)) + if a == 2: + was_and = True + else: + was_and = False + lines.append(" ), '{0}', '{1}')".format(c, nfc)) + + res += '\n'.join(lines) res += ')\n' self.template = res res = '' - for tb, cb, fb, nfcb, reb in zip(self.tagboxes, self.colorboxes, - self.colboxes, self.nfcolorboxes, self.reboxes): + for tb, cb, fb, nfcb, reb, ab in zip(self.tagboxes, self.colorboxes, + self.colboxes, self.nfcolorboxes, self.reboxes, self.andboxes): t = unicode(tb.text()).strip() if t.endswith(','): t = t[:-1] @@ -329,11 +386,23 @@ class TagWizard(QDialog): f = unicode(fb.currentText()) nfc = unicode(nfcb.currentText()).strip() re = unicode(reb.checkState()) - if f and t and c: - res += '#' + t + ':|:' + c + ':|:' + f +':|:' + nfc + ':|:' + re + '\n' + a = unicode(ab.checkState()) + if f and t and (a == '2' or c): + res += '#' + t + ':|:' + c + ':|:' + f + ':|:' + \ + nfc + ':|:' + re + ':|:' + a + '\n' self.template += res return True + def and_box_changed(self, state, line=None): + if state == 2: + self.colorboxes[line].setCurrentIndex(0) + self.colorboxes[line].setEnabled(False) + self.nfcolorboxes[line].setCurrentIndex(0) + self.nfcolorboxes[line].setEnabled(False) + else: + self.colorboxes[line].setEnabled(True) + self.nfcolorboxes[line].setEnabled(True) + def accepted(self): if self.generate_program(): self.accept() diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index bde590f30b..7a8c1fb69c 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -5,12 +5,15 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' +from functools import partial + from PyQt4.Qt import (QApplication, QFont, QFontInfo, QFontDialog, - QAbstractListModel, Qt, QColor, QIcon) + QAbstractListModel, Qt, QColor, QIcon, QToolButton, QComboBox) from calibre.gui2.preferences import ConfigWidgetBase, test_widget, CommaSeparatedList from calibre.gui2.preferences.look_feel_ui import Ui_Form from calibre.gui2 import config, gprefs, qt_app +from calibre.gui2.dialogs.template_line_editor import TemplateLineEditor from calibre.utils.localization import (available_translations, get_language, get_lang) from calibre.utils.config import prefs @@ -170,10 +173,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): _('If you want to color a field based on contents of columns, ' 'then click the button next to an empty line to open the wizard. ' 'It will build a template for you. You can later edit that ' - 'template with the same wizard.') + + 'template with the same wizard. This is by far the easiest ' + 'way to specify a template.') + '

    ' + - _('The template must evaluate to one of the color names shown ' - 'below. You can use any legal template expression. ' + _('If you manually construct a template, then the template must ' + 'evaluate to a valid color name shown in the color names box.' + '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 the color named in the custom column ' @@ -199,6 +204,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): 'of values", it is often easier to specify the ' 'colors in the column definition dialog. There you can ' 'provide a color for each value without using a template.')+ '

    ') + self.color_help_scrollArea.setVisible(False) + self.color_help_button.clicked.connect(self.change_help_text) + self.colors_scrollArea.setVisible(False) + self.colors_label.setVisible(False) + self.colors_button.clicked.connect(self.change_colors_text) + choices = db.field_metadata.displayable_field_keys() choices.sort(key=sort_key) choices.insert(0, '') @@ -211,22 +222,58 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): except: pass + l = self.column_color_layout for i in range(1, self.column_color_count): + ccn = QComboBox(parent=self) + setattr(self, 'opt_column_color_name_'+str(i), ccn) + l.addWidget(ccn, i, 0, 1, 1) + + wtb = QToolButton(parent=self) + setattr(self, 'opt_column_color_wizard_'+str(i), wtb) + wtb.setIcon(QIcon(I('wizard.png'))) + l.addWidget(wtb, i, 1, 1, 1) + + ttb = QToolButton(parent=self) + setattr(self, 'opt_column_color_tpledit_'+str(i), ttb) + ttb.setIcon(QIcon(I('edit_input.png'))) + l.addWidget(ttb, i, 2, 1, 1) + + tpl = TemplateLineEditor(parent=self) + setattr(self, 'opt_column_color_template_'+str(i), tpl) + tpl.textChanged.connect(partial(self.tpl_edit_text_changed, ctrl=i)) + tpl.set_db(db) + tpl.set_mi(mi) + l.addWidget(tpl, i, 3, 1, 1) + + wtb.clicked.connect(tpl.tag_wizard) + ttb.clicked.connect(tpl.open_editor) + r('column_color_name_'+str(i), db.prefs, choices=choices) r('column_color_template_'+str(i), db.prefs) txt = db.prefs.get('column_color_template_'+str(i), None) - tpl = getattr(self, 'opt_column_color_template_'+str(i)) - tpl.set_db(db) - tpl.set_mi(mi) - toolbutton = getattr(self, 'opt_column_color_wizard_'+str(i)) - if tpl.show_wizard_button(txt): - toolbutton.clicked.connect(tpl.tag_wizard) - else: - toolbutton.clicked.connect(tpl.open_editor) - toolbutton.setIcon(QIcon(I('edit_input.png'))) + + wtb.setEnabled(tpl.enable_wizard_button(txt)) + ttb.setEnabled(not tpl.enable_wizard_button(txt) or not txt) + all_colors = [unicode(s) for s in list(QColor.colorNames())] self.colors_box.setText(', '.join(all_colors)) + def change_help_text(self): + self.color_help_scrollArea.setVisible(not self.color_help_scrollArea.isVisible()) + + def change_colors_text(self): + self.colors_scrollArea.setVisible(not self.colors_scrollArea.isVisible()) + self.colors_label.setVisible(not self.colors_label.isVisible()) + + def tpl_edit_text_changed(self, ign, ctrl=None): + tpl = getattr(self, 'opt_column_color_template_'+str(ctrl)) + txt = unicode(tpl.text()) + wtb = getattr(self, 'opt_column_color_wizard_'+str(ctrl)) + ttb = getattr(self, 'opt_column_color_tpledit_'+str(ctrl)) + wtb.setEnabled(tpl.enable_wizard_button(txt)) + ttb.setEnabled(not tpl.enable_wizard_button(txt) or not txt) + tpl.setFocus() + def initialize(self): ConfigWidgetBase.initialize(self) font = gprefs['font'] diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index fe6134f235..def1bdd41c 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -416,114 +416,95 @@ then the tags will be displayed each on their own line. Column Coloring - + Column to color - - - - Color selection template - - - - - - - - - - - - - - :/images/wizard.png:/images/wizard.png - - - Open the tags wizard. - - - - - - - - - - - - - - :/images/wizard.png:/images/wizard.png - - - Open the tags wizard. - - - - - - - - - - - - - - :/images/wizard.png:/images/wizard.png - - - Open the tags wizard. - - - - - - - - - - - - - - :/images/wizard.png:/images/wizard.png - - - Open the tags wizard. - - - - - - - - - - - - - - :/images/wizard.png:/images/wizard.png - - - Open the tags wizard. - - + + + + + + Color selection template + + + + 10 + 0 + + + + + + + + The template wizard is easiest to use + + + + + + + Show/hide help text + + + + + + + Show/hide colors + + + + - + Color names - - + + + + + 16777215 + 300 + + + + true + + + + + 0 + 0 + 687 + 61 + + + + + + + true + + + Qt::AlignLeft|Qt::AlignTop + + + + + + + + + 0 @@ -534,7 +515,7 @@ then the tags will be displayed each on their own line. true - Qt::AlignCenter + Qt::AlignLeft|Qt::AlignTop @@ -560,37 +541,24 @@ then the tags will be displayed each on their own line. - - - + + + + + 0 + 10 + + + + Qt::Vertical + + - 16777215 - 120 + 0 + 0 - - true - - - - - 0 - 0 - 687 - 61 - - - - - - - true - - - - - - + From ed6656e9742e649a3284661cc174d7be11a85976 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 30 May 2011 15:35:02 +0100 Subject: [PATCH 28/84] Add a 'not' box. --- .../gui2/dialogs/template_line_editor.py | 92 +++++++++++++------ 1 file changed, 63 insertions(+), 29 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index 68eda27bf1..b24328f0ad 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -140,7 +140,7 @@ class TagWizard(QDialog): l = QGridLayout() self.setLayout(l) l.setColumnStretch(2, 10) - l.setColumnMinimumWidth(2, 300) + l.setColumnMinimumWidth(3, 300) h = QLabel(_('And')) h.setToolTip('

    ' + @@ -155,7 +155,21 @@ class TagWizard(QDialog): h.setAlignment(Qt.AlignCenter) l.addWidget(h, 0, 1, 1, 1) + h = QLabel(_('Not')) + h.setToolTip('

    ' + + _('Set this box to indicate that the value must not match ' + 'to return the "color if value found". For example, you ' + 'can check if a tag does not exist by entering that tag ' + 'and checking this box. You can check if tags are empty by ' + 'checking this box, entering .* (period asterisk) for the text, ' + 'then checking the RE box. The .* regular expression matches ' + 'anything, so if this box is checked, it matches nothing. ' + 'This box is particularly useful when using the AND box.')) + h.setAlignment(Qt.AlignCenter) + l.addWidget(h, 0, 2, 1, 1) + h = QLabel(_('Values (see the popup help for more information)')) + h.setAlignment(Qt.AlignCenter) h.setToolTip('

    ' + _('You can enter more than one value per box, separated by commas. ' 'The comparison ignores letter case. Special note: you can ' @@ -172,12 +186,12 @@ class TagWizard(QDialog): '

  • A.* matches anything beginning with A
  • ' '
  • .*mystery.* matches anything containing ' 'the word "mystery"
  • ') + '

    ') - l.addWidget(h , 0, 2, 1, 1) + l.addWidget(h , 0, 3, 1, 1) c = QLabel(_('is RE')) c.setToolTip('

    ' + _('Check this box if the values box contains regular expressions') + '

    ') - l.addWidget(c, 0, 3, 1, 1) + l.addWidget(c, 0, 4, 1, 1) c = QLabel(_('Color if value found')) c.setToolTip('

    ' + @@ -185,15 +199,16 @@ class TagWizard(QDialog): 'one color box empty if you want the template to use the next ' 'line in this wizard. If both boxes are filled in, the rest of ' 'the lines in this wizard will be ignored.') + '

    ') - l.addWidget(c, 0, 4, 1, 1) + l.addWidget(c, 0, 5, 1, 1) c = QLabel(_('Color if value not found')) c.setToolTip('

    ' + _('This box is usually filled in only on the last test. If it is ' 'filled in before the last test, then the color for value found box ' 'must be empty or all the rest of the tests will be ignored.') + '

    ') - l.addWidget(c, 0, 5, 1, 1) + l.addWidget(c, 0, 6, 1, 1) self.andboxes = [] + self.notboxes = [] self.tagboxes = [] self.colorboxes = [] self.nfcolorboxes = [] @@ -218,26 +233,30 @@ class TagWizard(QDialog): l.addWidget(w, i, 1, 1, 1) self.colboxes.append(w) + nb = QCheckBox(self) + self.notboxes.append(nb) + l.addWidget(nb, i, 2, 1, 1) + tb = MultiCompleteLineEdit(self) tb.set_separator(', ') self.tagboxes.append(tb) - l.addWidget(tb, i, 2, 1, 1) + l.addWidget(tb, i, 3, 1, 1) w.currentIndexChanged[str].connect(partial(self.column_changed, valbox=tb)) w = QCheckBox(self) self.reboxes.append(w) - l.addWidget(w, i, 3, 1, 1) - - w = QComboBox(self) - w.addItems(self.colors) - self.colorboxes.append(w) l.addWidget(w, i, 4, 1, 1) w = QComboBox(self) w.addItems(self.colors) - self.nfcolorboxes.append(w) + self.colorboxes.append(w) l.addWidget(w, i, 5, 1, 1) + w = QComboBox(self) + w.addItems(self.colors) + self.nfcolorboxes.append(w) + l.addWidget(w, i, 6, 1, 1) + if txt: lines = txt.split('\n')[3:] i = 0 @@ -250,8 +269,9 @@ class TagWizard(QDialog): re = False f = 'tags' a = False + n = False else: - t,c,f,nc,re,a = vals + t,c,f,nc,re,a,n = vals try: self.colboxes[i].setCurrentIndex(self.colboxes[i].findText(f)) self.colorboxes[i].setCurrentIndex( @@ -261,6 +281,7 @@ class TagWizard(QDialog): self.tagboxes[i].setText(t) self.reboxes[i].setChecked(re == '2') self.andboxes[i].setChecked(a == '2') + self.notboxes[i].setChecked(n == '2') i += 1 except: pass @@ -269,9 +290,9 @@ class TagWizard(QDialog): l.addWidget(w, 99, 1, 1, 1) w = self.test_box = QLineEdit(self) w.setReadOnly(True) - l.addWidget(w, 99, 2, 1, 1) + l.addWidget(w, 99, 3, 1, 1) w = QPushButton(_('Test')) - l.addWidget(w, 99, 4, 1, 1) + l.addWidget(w, 99, 5, 1, 1) w.clicked.connect(self.preview) bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel, parent=self) @@ -306,8 +327,10 @@ class TagWizard(QDialog): was_and = False had_line = False - for l, (tb, cb, fb, nfcb, reb, ab) in enumerate(zip(self.tagboxes, self.colorboxes, - self.colboxes, self.nfcolorboxes, self.reboxes, self.andboxes)): + line = 0 + for tb, cb, fb, nfcb, reb, ab, nb in zip( + self.tagboxes, self.colorboxes, self.colboxes, + self.nfcolorboxes, self.reboxes, self.andboxes, self.notboxes): f = unicode(fb.currentText()) if not f: continue @@ -316,6 +339,15 @@ class TagWizard(QDialog): nfc = unicode(nfcb.currentText()).strip() re = reb.checkState() a = ab.checkState() + n = nb.checkState() + line += 1 + + if n == 2: + tval = '' + fval = '1' + else: + tval = '1' + fval = '' if m: tags = [t.strip() for t in unicode(tb.text()).split(',') if t.strip()] @@ -330,7 +362,7 @@ class TagWizard(QDialog): if (tags or f) and not (tags and f and (a == 2 or c)): error_dialog(self, _('Invalid line'), - _('Line number {0} is not valid').format(l), + _('Line number {0} is not valid').format(line), show=True, show_copy_button=False) return False @@ -355,18 +387,18 @@ class TagWizard(QDialog): if re == 2: if m: - lines.append(" in_list(field('{1}'), ',', '^{0}$', '1', '')".\ - format(tags, f)) + lines.append(" in_list(field('{1}'), ',', '^{0}$', '{2}', '{3}')".\ + format(tags, f, tval, fval)) else: - lines.append(" contains(field('{1}'), '{0}', '1', '')".\ - format(tags, f)) + lines.append(" contains(field('{1}'), '{0}', '{2}', '{3}')".\ + format(tags, f, tval, fval)) else: if m: - lines.append(" str_in_list(field('{1}'), ',', '{0}', '1', '')".\ - format(tags, f)) + lines.append(" str_in_list(field('{1}'), ',', '{0}', '{2}', '{3}')".\ + format(tags, f, tval, fval)) else: - lines.append(" strcmp(field('{1}'), '{0}', '', '1', '')".\ - format(tags, f)) + lines.append(" strcmp(field('{1}'), '{0}', '{3}', '{2}', '{3}')".\ + format(tags, f, tval, fval)) if a == 2: was_and = True else: @@ -377,8 +409,9 @@ class TagWizard(QDialog): res += ')\n' self.template = res res = '' - for tb, cb, fb, nfcb, reb, ab in zip(self.tagboxes, self.colorboxes, - self.colboxes, self.nfcolorboxes, self.reboxes, self.andboxes): + for tb, cb, fb, nfcb, reb, ab, nb in zip( + self.tagboxes, self.colorboxes, self.colboxes, + self.nfcolorboxes, self.reboxes, self.andboxes, self.notboxes): t = unicode(tb.text()).strip() if t.endswith(','): t = t[:-1] @@ -387,9 +420,10 @@ class TagWizard(QDialog): nfc = unicode(nfcb.currentText()).strip() re = unicode(reb.checkState()) a = unicode(ab.checkState()) + n = unicode(nb.checkState()) if f and t and (a == '2' or c): res += '#' + t + ':|:' + c + ':|:' + f + ':|:' + \ - nfc + ':|:' + re + ':|:' + a + '\n' + nfc + ':|:' + re + ':|:' + a + ':|:' + n + '\n' self.template += res return True From 7f3d6f6b155d13d5bc240d3e47fe2fb303f64c4d Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 30 May 2011 15:53:04 +0100 Subject: [PATCH 29/84] Add missing reverse apostrophe in search documentation --- src/calibre/manual/gui.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/manual/gui.rst b/src/calibre/manual/gui.rst index a4e18c2e07..e2758bc257 100644 --- a/src/calibre/manual/gui.rst +++ b/src/calibre/manual/gui.rst @@ -352,7 +352,7 @@ The syntax for searching for dates is:: If the date is ambiguous, the current locale is used for date comparison. For example, in an mm/dd/yyyy locale, 2/1/2009 is interpreted as 1 Feb 2009. In a dd/mm/yyyy locale, it is interpreted as 2 Jan 2009. Some special date strings are available. The string ``today`` translates to today's date, whatever it is. The -strings `yesterday`` and ``thismonth`` also work. In addition, the string ``daysago`` can be used to compare +strings ``yesterday`` and ``thismonth`` also work. In addition, the string ``daysago`` can be used to compare to a date some number of days ago, for example: date:>10daysago, date:<=45daysago. You can search for books that have a format of a certain size like this:: From e27a3638d222bef6e7692d83a340ae5757a5376b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 30 May 2011 11:35:37 -0600 Subject: [PATCH 30/84] Metro UK by Dave Asbury --- recipes/metro_uk.recipe | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 recipes/metro_uk.recipe diff --git a/recipes/metro_uk.recipe b/recipes/metro_uk.recipe new file mode 100644 index 0000000000..26133edbd9 --- /dev/null +++ b/recipes/metro_uk.recipe @@ -0,0 +1,26 @@ +from calibre.web.feeds.news import BasicNewsRecipe + +class AdvancedUserRecipe1306097511(BasicNewsRecipe): + title = u'Metro UK' + + no_stylesheets = True + oldest_article = 1 + max_articles_per_feed = 200 + + __author__ = 'Dave Asbury' + language = 'en_GB' + simultaneous_downloads= 3 + + masthead_url = 'http://e-edition.metro.co.uk/images/metro_logo.gif' + + keep_only_tags = [ + dict(name='h1', attrs={'':''}), + dict(name='h2', attrs={'class':'h2'}), + dict(name='div', attrs={'class':'art-lft'}) + ] + remove_tags = [dict(name='div', attrs={'class':[ 'metroCommentFormWrap', + 'commentForm', 'metroCommentInnerWrap', + 'art-rgt','pluck-app pluck-comm','news m12 clrd clr-l p5t', 'flt-r' ]})] + + feeds = [ + (u'News', u'http://www.metro.co.uk/rss/news/'), (u'Money', u'http://www.metro.co.uk/rss/money/'), (u'Sport', u'http://www.metro.co.uk/rss/sport/'), (u'Film', u'http://www.metro.co.uk/rss/metrolife/film/'), (u'Music', u'http://www.metro.co.uk/rss/metrolife/music/'), (u'TV', u'http://www.metro.co.uk/rss/tv/'), (u'Showbiz', u'http://www.metro.co.uk/rss/showbiz/'), (u'Weird News', u'http://www.metro.co.uk/rss/weird/'), (u'Travel', u'http://www.metro.co.uk/rss/travel/'), (u'Lifestyle', u'http://www.metro.co.uk/rss/lifestyle/'), (u'Books', u'http://www.metro.co.uk/rss/lifestyle/books/'), (u'Food', u'http://www.metro.co.uk/rss/lifestyle/restaurants/')] From cb2a5e5d963f093656eeb71e9e29eb25b02ff76f Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 30 May 2011 19:21:42 +0100 Subject: [PATCH 31/84] Cache metadata used for coloring. Set times on extracted zip files. --- src/calibre/gui2/library/models.py | 15 ++++++++++++++- src/calibre/utils/zipfile.py | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 554b104c34..cac0346761 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -87,6 +87,7 @@ class BooksModel(QAbstractTableModel): # {{{ self.column_map = [] self.headers = {} self.alignment_map = {} + self.mi_cache = {} self.buffer_size = buffer self.metadata_backup = None self.bool_yes_icon = QIcon(I('ok.png')) @@ -172,11 +173,13 @@ class BooksModel(QAbstractTableModel): # {{{ def refresh_ids(self, ids, current_row=-1): + self.mi_cache = {} rows = self.db.refresh_ids(ids) if rows: self.refresh_rows(rows, current_row=current_row) def refresh_rows(self, rows, current_row=-1): + self.mi_cache = {} for row in rows: if row == current_row: self.new_bookdisplay_data.emit( @@ -206,6 +209,7 @@ class BooksModel(QAbstractTableModel): # {{{ return ret def count_changed(self, *args): + self.mi_cache = {} self.count_changed_signal.emit(self.db.count()) def row_indices(self, index): @@ -336,6 +340,10 @@ class BooksModel(QAbstractTableModel): # {{{ self.db.refresh(field=None) self.resort(reset=reset) + def reset(self): + self.mi_cache = {} + QAbstractTableModel.reset(self) + def resort(self, reset=True): if not self.db: return @@ -718,7 +726,12 @@ class BooksModel(QAbstractTableModel): # {{{ 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) + id_ = self.id(index) + if id_ in self.mi_cache: + mi = self.mi_cache[id_] + else: + mi = self.db.get_metadata(self.id(index), index_is_id=True) + self.mi_cache[id_] = mi fmt = self.column_color_map[key] try: color = composite_formatter.safe_format(fmt, mi, '', mi) diff --git a/src/calibre/utils/zipfile.py b/src/calibre/utils/zipfile.py index e0f453452c..33ee19bf4f 100644 --- a/src/calibre/utils/zipfile.py +++ b/src/calibre/utils/zipfile.py @@ -1123,6 +1123,9 @@ class ZipFile: targetpath = os.sep.join(components) with open(targetpath, 'wb') as target: shutil.copyfileobj(source, target) + mtime = time.localtime() + mtime = time.mktime(member.date_time + (0, 0) + (mtime.tm_isdst,)) + os.utime(targetpath, (mtime, mtime)) self.extract_mapping[member.filename] = targetpath return targetpath From 61b86494cb1386d4cf37df2d341b617500ef9acc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 30 May 2011 12:38:44 -0600 Subject: [PATCH 32/84] ... --- recipes/mediapart.recipe | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/mediapart.recipe b/recipes/mediapart.recipe index 0cf8f21032..4540879f72 100644 --- a/recipes/mediapart.recipe +++ b/recipes/mediapart.recipe @@ -71,7 +71,7 @@ class Mediapart(BasicNewsRecipe): br = BasicNewsRecipe.get_browser() if self.username is not None and self.password is not None: br.open('http://www.mediapart.fr/') - br.select_form(nr=1) + br.select_form(nr=0) br['name'] = self.username br['pass'] = self.password br.submit() From 1237db4c87685548d8613d63a5c34a6f82ba6939 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 30 May 2011 19:47:30 +0100 Subject: [PATCH 33/84] Use the cache for the rest of the calls to get_metadata. --- src/calibre/gui2/library/models.py | 37 +++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index cac0346761..906d2979fa 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -173,10 +173,12 @@ class BooksModel(QAbstractTableModel): # {{{ def refresh_ids(self, ids, current_row=-1): - self.mi_cache = {} rows = self.db.refresh_ids(ids) if rows: self.refresh_rows(rows, current_row=current_row) + else: + self.mi_cache = {} + def refresh_rows(self, rows, current_row=-1): self.mi_cache = {} @@ -367,8 +369,20 @@ class BooksModel(QAbstractTableModel): # {{{ def count(self): return self.rowCount(None) + def get_and_cache_metadata(self, idx, index_is_id = False, get_cover=False, + get_user_categories=True): + if not index_is_id: + idx = self.db.id(idx) + if idx in self.mi_cache: + mi = self.mi_cache[idx] + else: + mi = self.db.get_metadata(idx, index_is_id=True, get_cover=get_cover, + get_user_categories=get_user_categories) + self.mi_cache[idx] = mi + return mi + def get_book_display_info(self, idx): - mi = self.db.get_metadata(idx) + mi = self.get_and_cache_metadata(idx) mi.size = mi.book_size mi.cover_data = ('jpg', self.cover(idx)) mi.id = self.db.id(idx) @@ -395,7 +409,7 @@ class BooksModel(QAbstractTableModel): # {{{ def metadata_for(self, ids): ans = [] for id in ids: - mi = self.db.get_metadata(id, index_is_id=True, get_cover=True) + mi = self.get_and_cache_metadata(id, index_is_id=True, get_cover=True) ans.append(mi) return ans @@ -404,7 +418,7 @@ class BooksModel(QAbstractTableModel): # {{{ if not rows_are_ids: rows = [self.db.id(row.row()) for row in rows] for id in rows: - mi = self.db.get_metadata(id, index_is_id=True) + mi = self.get_and_cache_metadata(id, index_is_id=True) _full_metadata.append(mi) au = authors_to_string(mi.authors if mi.authors else [_('Unknown')]) tags = mi.tags if mi.tags else [] @@ -460,8 +474,9 @@ class BooksModel(QAbstractTableModel): # {{{ pt.seek(0) if set_metadata: try: - _set_metadata(pt, self.db.get_metadata(id, get_cover=True, index_is_id=True), - format) + _set_metadata(pt, self.get_and_cache_metadata(id, + get_cover=True, index_is_id=True), + format) except: traceback.print_exc() pt.close() @@ -505,7 +520,7 @@ class BooksModel(QAbstractTableModel): # {{{ pt.flush() pt.seek(0) if set_metadata: - _set_metadata(pt, self.db.get_metadata(row, get_cover=True), + _set_metadata(pt, self.get_and_cache_metadata(row, get_cover=True), format) pt.close() if paths else pt.seek(0) ans.append(pt) @@ -726,12 +741,8 @@ class BooksModel(QAbstractTableModel): # {{{ elif role == Qt.ForegroundRole: key = self.column_map[col] if key in self.column_color_map: - id_ = self.id(index) - if id_ in self.mi_cache: - mi = self.mi_cache[id_] - else: - mi = self.db.get_metadata(self.id(index), index_is_id=True) - self.mi_cache[id_] = mi + mi = self.get_and_cache_metadata(index.row(), + get_user_categories=False) fmt = self.column_color_map[key] try: color = composite_formatter.safe_format(fmt, mi, '', mi) From 07d2c984c45278f46126eaf7f2f89bf8358dd40f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 30 May 2011 13:05:02 -0600 Subject: [PATCH 34/84] ... --- src/calibre/manual/template_lang.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index f1d2844d37..ef44b0a5c9 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -122,7 +122,7 @@ The functions available are: * ``uppercase()`` -- return the value of the field in upper case. * ``titlecase()`` -- return the value of the field in title case. * ``capitalize()`` -- return the value with the first letter upper case and the rest lower case. - * ``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`. + * ``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`. * ``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`. From e21d45824e98e0732027998a1bba5da9fc654007 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 30 May 2011 20:52:26 +0100 Subject: [PATCH 35/84] Change to cache colors instead of metadata. --- src/calibre/gui2/library/models.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index cac0346761..5e703a524f 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -7,6 +7,7 @@ __docformat__ = 'restructuredtext en' import shutil, functools, re, os, traceback from contextlib import closing +from collections import defaultdict from PyQt4.Qt import (QAbstractTableModel, Qt, pyqtSignal, QIcon, QImage, QModelIndex, QVariant, QDate, QColor) @@ -87,7 +88,7 @@ class BooksModel(QAbstractTableModel): # {{{ self.column_map = [] self.headers = {} self.alignment_map = {} - self.mi_cache = {} + self.color_cache = defaultdict(dict) self.buffer_size = buffer self.metadata_backup = None self.bool_yes_icon = QIcon(I('ok.png')) @@ -173,13 +174,13 @@ class BooksModel(QAbstractTableModel): # {{{ def refresh_ids(self, ids, current_row=-1): - self.mi_cache = {} + self.color_cache = defaultdict(dict) rows = self.db.refresh_ids(ids) if rows: self.refresh_rows(rows, current_row=current_row) def refresh_rows(self, rows, current_row=-1): - self.mi_cache = {} + self.color_cache = defaultdict(dict) for row in rows: if row == current_row: self.new_bookdisplay_data.emit( @@ -209,7 +210,7 @@ class BooksModel(QAbstractTableModel): # {{{ return ret def count_changed(self, *args): - self.mi_cache = {} + self.color_cache = defaultdict(dict) self.count_changed_signal.emit(self.db.count()) def row_indices(self, index): @@ -341,7 +342,7 @@ class BooksModel(QAbstractTableModel): # {{{ self.resort(reset=reset) def reset(self): - self.mi_cache = {} + self.color_cache = defaultdict(dict) QAbstractTableModel.reset(self) def resort(self, reset=True): @@ -727,18 +728,19 @@ class BooksModel(QAbstractTableModel): # {{{ key = self.column_map[col] if key in self.column_color_map: id_ = self.id(index) - if id_ in self.mi_cache: - mi = self.mi_cache[id_] - else: - mi = self.db.get_metadata(self.id(index), index_is_id=True) - self.mi_cache[id_] = mi + if id_ in self.color_cache: + if key in self.color_cache[id_]: + return self.color_cache[id_][key] + 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) if color in self.colors: color = QColor(color) if color.isValid(): - return QVariant(color) + color = QVariant(color) + self.color_cache[id_][key] = color + return color except: return NONE elif self.is_custom_column(key) and \ From dd745a8e3b15e4893231eea0688f241725171aba Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 30 May 2011 14:54:05 -0600 Subject: [PATCH 36/84] ... --- recipes/metro_uk.recipe | 7 +++++-- src/calibre/ebooks/metadata/book/base.py | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/recipes/metro_uk.recipe b/recipes/metro_uk.recipe index 26133edbd9..deced5976b 100644 --- a/recipes/metro_uk.recipe +++ b/recipes/metro_uk.recipe @@ -1,5 +1,4 @@ from calibre.web.feeds.news import BasicNewsRecipe - class AdvancedUserRecipe1306097511(BasicNewsRecipe): title = u'Metro UK' @@ -14,7 +13,9 @@ class AdvancedUserRecipe1306097511(BasicNewsRecipe): masthead_url = 'http://e-edition.metro.co.uk/images/metro_logo.gif' keep_only_tags = [ - dict(name='h1', attrs={'':''}), + dict(attrs={'class':['img-cnt figure']}), + dict(attrs={'class':['art-img']}), + dict(name='h1'), dict(name='h2', attrs={'class':'h2'}), dict(name='div', attrs={'class':'art-lft'}) ] @@ -24,3 +25,5 @@ class AdvancedUserRecipe1306097511(BasicNewsRecipe): feeds = [ (u'News', u'http://www.metro.co.uk/rss/news/'), (u'Money', u'http://www.metro.co.uk/rss/money/'), (u'Sport', u'http://www.metro.co.uk/rss/sport/'), (u'Film', u'http://www.metro.co.uk/rss/metrolife/film/'), (u'Music', u'http://www.metro.co.uk/rss/metrolife/music/'), (u'TV', u'http://www.metro.co.uk/rss/tv/'), (u'Showbiz', u'http://www.metro.co.uk/rss/showbiz/'), (u'Weird News', u'http://www.metro.co.uk/rss/weird/'), (u'Travel', u'http://www.metro.co.uk/rss/travel/'), (u'Lifestyle', u'http://www.metro.co.uk/rss/lifestyle/'), (u'Books', u'http://www.metro.co.uk/rss/lifestyle/books/'), (u'Food', u'http://www.metro.co.uk/rss/lifestyle/restaurants/')] + + diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index 3e2201f6a4..69407dcb2e 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -74,7 +74,7 @@ class Metadata(object): Metadata from custom columns should be accessed via the get() method, passing in the lookup name for the column, for example: "#mytags". - Use the :meth:`is_null` method to test if a filed is null. + Use the :meth:`is_null` method to test if a field is null. This object also has functions to format fields into strings. @@ -105,7 +105,7 @@ class Metadata(object): def is_null(self, field): ''' - Return True if the value of filed is null in this object. + Return True if the value of field is null in this object. 'null' means it is unknown or evaluates to False. So a title of _('Unknown') is null or a language of 'und' is null. From 2db4f11ad0ea899370921526b210965c0dbda4cc Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Mon, 30 May 2011 22:51:46 +0100 Subject: [PATCH 37/84] Change library.models.py to iterate through the colors list instead of using a dict. --- src/calibre/gui2/library/models.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 5e703a524f..d79c92befa 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -99,7 +99,7 @@ class BooksModel(QAbstractTableModel): # {{{ self.ids_to_highlight_set = set() self.current_highlighted_idx = None self.highlight_only = False - self.column_color_map = {} + self.column_color_list = [] self.colors = [unicode(c) for c in QColor.colorNames()] self.read_config() @@ -546,12 +546,12 @@ class BooksModel(QAbstractTableModel): # {{{ return img def set_color_templates(self, reset=True): - self.column_color_map = {} + self.column_color_list = [] 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.column_color_list.append((name, + self.db.prefs.get('column_color_template_'+str(i)))) if reset: self.reset() @@ -726,13 +726,14 @@ class BooksModel(QAbstractTableModel): # {{{ return QVariant(QColor('lightgreen')) elif role == Qt.ForegroundRole: key = self.column_map[col] - if key in self.column_color_map: + for k,fmt in self.column_color_list: + if k != key: + continue id_ = self.id(index) if id_ in self.color_cache: if key in self.color_cache[id_]: return self.color_cache[id_][key] 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) if color in self.colors: @@ -743,7 +744,7 @@ class BooksModel(QAbstractTableModel): # {{{ return color except: return NONE - elif self.is_custom_column(key) and \ + if 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', []) From 32bcac2147ffa344fb58bcc97859b9452ee99ff8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 30 May 2011 22:49:13 -0600 Subject: [PATCH 38/84] When deleting all formats except ..., do not delete if it leaves a book with no formats --- src/calibre/gui2/actions/delete.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/actions/delete.py b/src/calibre/gui2/actions/delete.py index 718f0737b3..619a8a1031 100644 --- a/src/calibre/gui2/actions/delete.py +++ b/src/calibre/gui2/actions/delete.py @@ -161,9 +161,12 @@ class DeleteAction(InterfaceAction): continue bfmts = set([x.lower() for x in bfmts.split(',')]) rfmts = bfmts - set(fmts) - for fmt in rfmts: - self.gui.library_view.model().db.remove_format(id, fmt, - index_is_id=True, notify=False) + if bfmts - rfmts: + # Do not delete if it will leave the book with no + # formats + for fmt in rfmts: + self.gui.library_view.model().db.remove_format(id, fmt, + index_is_id=True, notify=False) self.gui.library_view.model().refresh_ids(ids) self.gui.library_view.model().current_changed(self.gui.library_view.currentIndex(), self.gui.library_view.currentIndex()) From 775c63bd39497eb7c5933b9ddaf91758e4ce20e8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 30 May 2011 22:53:15 -0600 Subject: [PATCH 39/84] ... --- src/calibre/gui2/actions/delete.py | 3 ++- src/calibre/gui2/dialogs/select_formats.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/actions/delete.py b/src/calibre/gui2/actions/delete.py index 619a8a1031..43465512e0 100644 --- a/src/calibre/gui2/actions/delete.py +++ b/src/calibre/gui2/actions/delete.py @@ -152,7 +152,8 @@ class DeleteAction(InterfaceAction): if not ids: return fmts = self._get_selected_formats( - '

    '+_('Choose formats not to be deleted'), ids) + '

    '+_('Choose formats not to be deleted.

    Note that ' + 'this will never remove all formats from a book.'), ids) if fmts is None: return for id in ids: diff --git a/src/calibre/gui2/dialogs/select_formats.py b/src/calibre/gui2/dialogs/select_formats.py index 5934c8c0f9..aea56ad196 100644 --- a/src/calibre/gui2/dialogs/select_formats.py +++ b/src/calibre/gui2/dialogs/select_formats.py @@ -44,7 +44,7 @@ class SelectFormats(QDialog): self.setLayout(self._l) self.setWindowTitle(_('Choose formats')) self._m = QLabel(msg) - self._m.setWordWrap = True + self._m.setWordWrap(True) self._l.addWidget(self._m) self.formats = Formats(fmt_list) self.fview = QListView(self) From cdeb8ade3d36fc14bf2f84fbd774c617b4e277ae Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Tue, 31 May 2011 12:13:08 +0100 Subject: [PATCH 40/84] Yet another improvement on the color wizard. Make 'None' compare to zero in the formatter function 'cmp'. --- .../gui2/dialogs/template_line_editor.py | 327 ++++++++++-------- src/calibre/utils/formatter_functions.py | 4 +- 2 files changed, 187 insertions(+), 144 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index b24328f0ad..6a0b07200e 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -46,8 +46,8 @@ class TemplateLineEditor(QLineEdit): menu.exec_(event.globalPos()) def clear_field(self): - self.setText('') self.txt = None + self.setText('') self.setReadOnly(False) self.setStyleSheet('TemplateLineEditor { color: black }') @@ -95,6 +95,39 @@ class TemplateLineEditor(QLineEdit): class TagWizard(QDialog): + text_template = " strcmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')" + text_empty_template = " test(field('{f}'), '{fv}', '{tv}')" + text_re_template = " contains(field('{f}'), '{v}', '{tv}', '{fv}')" + + templates = { + 'text.mult' : " str_in_list(field('{f}'), '{mult}', '{v}', '{tv}', '{fv}')", + 'text.mult.re' : " in_list(field('{f}'), '{mult}', '^{v}$', '{tv}', '{fv}')", + 'text.mult.empty' : " test(field('{f}'), '{fv}', '{tv}')", + 'text' : text_template, + 'text.re' : text_re_template, + 'text.empty' : text_empty_template, + 'rating' : " cmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')", + 'rating.empty' : text_empty_template, + 'int' : " cmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')", + 'int.empty' : text_empty_template, + 'float' : " cmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')", + 'float.empty' : text_empty_template, + 'bool' : " strcmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')", + 'bool.empty' : text_empty_template, + 'series' : text_template, + 'series.re' : text_re_template, + 'series.empty' : text_empty_template, + 'composite' : text_template, + 'composite.re' : text_re_template, + 'composite.empty' : text_empty_template, + 'enumeration' : text_template, + 'enumeration.re' : text_re_template, + 'enumeration.empty' : text_empty_template, + 'comments' : text_template, + 'comments.re' : text_re_template, + 'comments.empty' : text_empty_template, + } + def __init__(self, parent, db, txt, mi): QDialog.__init__(self, parent) self.setWindowTitle(_('Coloring Wizard')) @@ -106,11 +139,19 @@ class TagWizard(QDialog): self.completion_values = defaultdict(dict) for k in db.all_field_keys(): m = db.metadata_for_field(k) - if m['datatype'] in ('text', 'enumeration', 'series') and \ - m['is_category'] and k not in ('identifiers'): + if k.endswith('_index') or ( + m['kind'] == 'field' and m['name'] and + k not in ('ondevice', 'path', 'size', 'sort') and + m['datatype'] not in ('datetime')): self.columns.append(k) + self.completion_values[k]['dt'] = m['datatype'] if m['is_custom']: - self.completion_values[k]['v'] = db.all_custom(m['label']) + if m['datatype'] in ('int', 'float'): + self.completion_values[k]['v'] = [] + elif m['datatype'] == 'bool': + self.completion_values[k]['v'] = [_('Yes'), _('No')] + else: + self.completion_values[k]['v'] = db.all_custom(m['label']) elif k == 'tags': self.completion_values[k]['v'] = db.all_tags() elif k == 'formats': @@ -127,12 +168,15 @@ class TagWizard(QDialog): replace('|', ',') for v in f()] else: self.completion_values[k]['v'] = [v[1] for v in f()] + else: + self.completion_values[k]['v'] = [] if k in self.completion_values: if k == 'authors': - self.completion_values[k]['m'] = None + mult = '&' else: - self.completion_values[k]['m'] = m['is_multiple'] + mult = ',' if m['is_multiple'] == '|' else m['is_multiple'] + self.completion_values[k]['m'] = mult self.columns.sort(key=sort_key) self.columns.insert(0, '') @@ -140,12 +184,12 @@ class TagWizard(QDialog): l = QGridLayout() self.setLayout(l) l.setColumnStretch(2, 10) - l.setColumnMinimumWidth(3, 300) + l.setColumnMinimumWidth(5, 300) h = QLabel(_('And')) h.setToolTip('

    ' + _('Set this box to indicate that the two conditions must both ' - 'be true to return the "color if value found". For example, you ' + 'be true to use the color. For example, you ' 'can check if two tags are present, if the book has a tag ' 'and a #read custom column is checked, or if a book has ' 'some tag and has a particular format.')) @@ -155,107 +199,106 @@ class TagWizard(QDialog): h.setAlignment(Qt.AlignCenter) l.addWidget(h, 0, 1, 1, 1) - h = QLabel(_('Not')) - h.setToolTip('

    ' + - _('Set this box to indicate that the value must not match ' - 'to return the "color if value found". For example, you ' - 'can check if a tag does not exist by entering that tag ' - 'and checking this box. You can check if tags are empty by ' - 'checking this box, entering .* (period asterisk) for the text, ' - 'then checking the RE box. The .* regular expression matches ' - 'anything, so if this box is checked, it matches nothing. ' - 'This box is particularly useful when using the AND box.')) + h = QLabel(_('is')) h.setAlignment(Qt.AlignCenter) l.addWidget(h, 0, 2, 1, 1) - h = QLabel(_('Values (see the popup help for more information)')) + h = QLabel(_('not')) + h.setToolTip('

    ' + + _('Check this box to indicate that the value must not match ' + 'to use the color. For example, you can check if a tag does ' + 'not exist by entering that tag and checking this box.') + '

    ') + h.setAlignment(Qt.AlignCenter) + l.addWidget(h, 0, 3, 1, 1) + + c = QLabel(_('empty')) + c.setToolTip('

    ' + + _('Check this box to check if the column is empty') + '

    ') + l.addWidget(c, 0, 4, 1, 1) + + h = QLabel(_('Values')) h.setAlignment(Qt.AlignCenter) h.setToolTip('

    ' + _('You can enter more than one value per box, separated by commas. ' - 'The comparison ignores letter case. Special note: you can ' - 'enter at most one author.
    ' + 'The comparison ignores letter case. Special note: authors are ' + 'separated by ampersands (&).
    ' 'A value can be a regular expression. Check the box to turn ' 'them on. When using regular expressions, note that the wizard ' 'puts anchors (^ and $) around the expression, so you ' 'must ensure your expression matches from the beginning ' - 'to the end of the column you are checking.
    ' + 'to the end of the column/value you are checking.
    ' 'Regular expression examples:') + '

      ' + - _('
    • .* matches anything in the column. No ' - 'empty values are checked, so you don\'t need to worry about ' - 'empty strings
    • ' + _('
    • .* matches anything in the column.
    • ' '
    • A.* matches anything beginning with A
    • ' '
    • .*mystery.* matches anything containing ' 'the word "mystery"
    • ') + '

    ') - l.addWidget(h , 0, 3, 1, 1) + l.addWidget(h , 0, 5, 1, 1) c = QLabel(_('is RE')) c.setToolTip('

    ' + _('Check this box if the values box contains regular expressions') + '

    ') - l.addWidget(c, 0, 4, 1, 1) - - c = QLabel(_('Color if value found')) - c.setToolTip('

    ' + - _('At least one of the two color boxes must have a value. Leave ' - 'one color box empty if you want the template to use the next ' - 'line in this wizard. If both boxes are filled in, the rest of ' - 'the lines in this wizard will be ignored.') + '

    ') - l.addWidget(c, 0, 5, 1, 1) - c = QLabel(_('Color if value not found')) - c.setToolTip('

    ' + - _('This box is usually filled in only on the last test. If it is ' - 'filled in before the last test, then the color for value found box ' - 'must be empty or all the rest of the tests will be ignored.') + '

    ') l.addWidget(c, 0, 6, 1, 1) - self.andboxes = [] - self.notboxes = [] - self.tagboxes = [] - self.colorboxes = [] - self.nfcolorboxes = [] - self.reboxes = [] - self.colboxes = [] + c = QLabel(_('color')) + c.setAlignment(Qt.AlignCenter) + c.setToolTip('

    ' + + _('Use this color if the column matches the tests.') + '

    ') + l.addWidget(c, 0, 7, 1, 1) + + self.andboxes = [] + self.notboxes = [] + self.tagboxes = [] + self.colorboxes = [] + self.reboxes = [] + self.colboxes = [] + self.emptyboxes = [] + self.colors = [unicode(s) for s in list(QColor.colorNames())] self.colors.insert(0, '') + def create_widget(klass, box, layout, row, col, items, + align=Qt.AlignCenter, rowspan=False): + w = klass(self) + if box is not None: + box.append(w) + if rowspan: + layout.addWidget(w, row, col, 2, 1, alignment=Qt.Alignment(align)) + else: + layout.addWidget(w, row, col, 1, 1, alignment=Qt.Alignment(align)) + if items: + w.addItems(items) + return w + maxlines = 10 for i in range(1, maxlines+1): - ab = QCheckBox(self) - self.andboxes.append(ab) - if i != maxlines: - # let the last box float in space - l.addWidget(ab, i, 0, 2, 1) - ab.stateChanged.connect(partial(self.and_box_changed, line=i-1)) - else: - ab.setVisible(False) + w = create_widget(QCheckBox, self.andboxes, l, i, 0, None, rowspan=True) + w.stateChanged.connect(partial(self.and_box_changed, line=i-1)) + if i == maxlines: + # last box is invisible + w.setVisible(False) - w = QComboBox(self) - w.addItems(self.columns) - l.addWidget(w, i, 1, 1, 1) - self.colboxes.append(w) + w = create_widget(QComboBox, self.colboxes, l, i, 1, self.columns) + w.currentIndexChanged[str].connect(partial(self.column_changed, line=i-1)) - nb = QCheckBox(self) - self.notboxes.append(nb) - l.addWidget(nb, i, 2, 1, 1) + w = QLabel(self) + w.setText(_('is')) + l.addWidget(w, i, 2, 1, 1) - tb = MultiCompleteLineEdit(self) - tb.set_separator(', ') - self.tagboxes.append(tb) - l.addWidget(tb, i, 3, 1, 1) - w.currentIndexChanged[str].connect(partial(self.column_changed, valbox=tb)) + create_widget(QCheckBox, self.notboxes, l, i, 3, None) - w = QCheckBox(self) - self.reboxes.append(w) - l.addWidget(w, i, 4, 1, 1) + w = create_widget(QCheckBox, self.emptyboxes, l, i, 4, None) + w.stateChanged.connect(partial(self.empty_box_changed, line=i-1)) - w = QComboBox(self) - w.addItems(self.colors) - self.colorboxes.append(w) - l.addWidget(w, i, 5, 1, 1) + create_widget(MultiCompleteLineEdit, self.tagboxes, l, i, 5, None, align=0) + create_widget(QCheckBox, self.reboxes, l, i, 6, None) + create_widget(QComboBox, self.colorboxes, l, i, 7, self.colors) - w = QComboBox(self) - w.addItems(self.colors) - self.nfcolorboxes.append(w) - l.addWidget(w, i, 6, 1, 1) + w = create_widget(QLabel, None, l, maxlines+1, 5, None) + w.setText(_('If none of the tests match, set the color to')) + self.elsebox = create_widget(QComboBox, None, l, maxlines+1, 7, self.colors) + self.elsebox.setToolTip('

    ' + + _('If this box contains a color, it will be used if none ' + 'of the above rules match.') + '

    ') if txt: lines = txt.split('\n')[3:] @@ -263,25 +306,27 @@ class TagWizard(QDialog): for line in lines: if line.startswith('#'): vals = line[1:].split(':|:') + if len(vals) == 1 and line.startswith('#else:'): + try: + self.elsebox.setCurrentIndex(self.elsebox.findText(line[6:])) + except: + pass + continue if len(vals) == 2: t, c = vals - nc = '' - re = False f = 'tags' - a = False - n = False + a = n = e = re = False else: - t,c,f,nc,re,a,n = vals + t,c,f,re,a,n,e = vals try: self.colboxes[i].setCurrentIndex(self.colboxes[i].findText(f)) self.colorboxes[i].setCurrentIndex( self.colorboxes[i].findText(c)) - self.nfcolorboxes[i].setCurrentIndex( - self.nfcolorboxes[i].findText(nc)) self.tagboxes[i].setText(t) self.reboxes[i].setChecked(re == '2') self.andboxes[i].setChecked(a == '2') self.notboxes[i].setChecked(n == '2') + self.emptyboxes[i].setChecked(e == '2') i += 1 except: pass @@ -290,13 +335,17 @@ class TagWizard(QDialog): l.addWidget(w, 99, 1, 1, 1) w = self.test_box = QLineEdit(self) w.setReadOnly(True) - l.addWidget(w, 99, 3, 1, 1) + l.addWidget(w, 99, 2, 1, 5) w = QPushButton(_('Test')) - l.addWidget(w, 99, 5, 1, 1) + w.setToolTip('

    ' + + _('Press this button to see what color this template will ' + 'produce for the book that was selected when you ' + 'entered the preferences dialog.')) + l.addWidget(w, 99, 7, 1, 1) w.clicked.connect(self.preview) bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel, parent=self) - l.addWidget(bb, 100, 3, 1, 2) + l.addWidget(bb, 100, 5, 1, 3) bb.accepted.connect(self.accepted) bb.rejected.connect(self.reject) self.template = '' @@ -308,14 +357,22 @@ class TagWizard(QDialog): _('EXCEPTION'), self.mi) self.test_box.setText(t) - def column_changed(self, s, valbox=None): + def column_changed(self, s, line=None): k = unicode(s) if k in self.completion_values: + valbox = self.tagboxes[line] valbox.update_items_cache(self.completion_values[k]['v']) if self.completion_values[k]['m']: valbox.set_separator(', ') else: valbox.set_separator(None) + + dt = self.completion_values[k]['dt'] + if dt in ('int', 'float', 'rating', 'bool'): + self.reboxes[line].setChecked(0) + self.reboxes[line].setEnabled(False) + else: + self.reboxes[line].setEnabled(True) else: valbox.update_items_cache([]) valbox.set_separator(None) @@ -324,59 +381,44 @@ class TagWizard(QDialog): res = ("program:\n#tag wizard -- do not directly edit\n" " first_non_empty(\n") lines = [] - was_and = False - had_line = False + was_and = had_line = False line = 0 - for tb, cb, fb, nfcb, reb, ab, nb in zip( - self.tagboxes, self.colorboxes, self.colboxes, - self.nfcolorboxes, self.reboxes, self.andboxes, self.notboxes): + for tb, cb, fb, reb, ab, nb, eb in zip( + self.tagboxes, self.colorboxes, self.colboxes, + self.reboxes, self.andboxes, self.notboxes, self.emptyboxes): f = unicode(fb.currentText()) if not f: continue m = self.completion_values[f]['m'] + dt = self.completion_values[f]['dt'] c = unicode(cb.currentText()).strip() - nfc = unicode(nfcb.currentText()).strip() re = reb.checkState() a = ab.checkState() n = nb.checkState() + e = eb.checkState() line += 1 - if n == 2: - tval = '' - fval = '1' - else: - tval = '1' - fval = '' + tval = '' if n == 2 else '1' + fval = '1' if n == 2 else '' if m: - tags = [t.strip() for t in unicode(tb.text()).split(',') if t.strip()] + tags = [t.strip() for t in unicode(tb.text()).split(m) if t.strip()] if re == 2: tags = '$|^'.join(tags) else: - tags = ','.join(tags) + tags = m.join(tags) + if m == '&': + tags = tags.replace(',', '|') else: tags = unicode(tb.text()).strip() - if f == 'authors': - tags.replace(',', '|') - if (tags or f) and not (tags and f and (a == 2 or c)): + if (tags or f) and not ((tags or e) and f and (a == 2 or c)): error_dialog(self, _('Invalid line'), _('Line number {0} is not valid').format(line), show=True, show_copy_button=False) return False - 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 - if nfc not in self.colors: - error_dialog(self, _('Invalid color'), - _('The color {0} is not valid').format(nfc), - show=True, show_copy_button=False) - return False - if not was_and: if had_line: lines[-1] += ',' @@ -385,57 +427,58 @@ class TagWizard(QDialog): else: lines[-1] += ',' - if re == 2: - if m: - lines.append(" in_list(field('{1}'), ',', '^{0}$', '{2}', '{3}')".\ - format(tags, f, tval, fval)) - else: - lines.append(" contains(field('{1}'), '{0}', '{2}', '{3}')".\ - format(tags, f, tval, fval)) - else: - if m: - lines.append(" str_in_list(field('{1}'), ',', '{0}', '{2}', '{3}')".\ - format(tags, f, tval, fval)) - else: - lines.append(" strcmp(field('{1}'), '{0}', '{3}', '{2}', '{3}')".\ - format(tags, f, tval, fval)) + key = dt + ('.mult' if m else '') + ('.empty' if e else '') + ('.re' if re else '') + template = self.templates[key] + lines.append(template.format(v=tags, f=f, tv=tval, fv=fval, mult=m)) + if a == 2: was_and = True else: was_and = False - lines.append(" ), '{0}', '{1}')".format(c, nfc)) + lines.append(" ), '{0}', '')".format(c)) res += '\n'.join(lines) + else_txt = unicode(self.elsebox.currentText()) + if else_txt: + res += ",\n '" + else_txt + "'" res += ')\n' self.template = res res = '' - for tb, cb, fb, nfcb, reb, ab, nb in zip( - self.tagboxes, self.colorboxes, self.colboxes, - self.nfcolorboxes, self.reboxes, self.andboxes, self.notboxes): + for tb, cb, fb, reb, ab, nb, eb in zip( + self.tagboxes, self.colorboxes, self.colboxes, + self.reboxes, self.andboxes, self.notboxes, self.emptyboxes): t = unicode(tb.text()).strip() if t.endswith(','): t = t[:-1] c = unicode(cb.currentText()).strip() f = unicode(fb.currentText()) - nfc = unicode(nfcb.currentText()).strip() re = unicode(reb.checkState()) a = unicode(ab.checkState()) n = unicode(nb.checkState()) - if f and t and (a == '2' or c): - res += '#' + t + ':|:' + c + ':|:' + f + ':|:' + \ - nfc + ':|:' + re + ':|:' + a + ':|:' + n + '\n' + e = unicode(eb.checkState()) + if f and (t or e) and (a == '2' or c): + res += '#' + t + ':|:' + c + ':|:' + f + ':|:' + re + ':|:' + \ + a + ':|:' + n + ':|:' + e + '\n' + res += '#else:' + else_txt + '\n' self.template += res return True + def empty_box_changed(self, state, line=None): + if state == 2: + self.tagboxes[line].setText('') + self.tagboxes[line].setEnabled(False) + self.reboxes[line].setChecked(0) + self.reboxes[line].setEnabled(False) + else: + self.reboxes[line].setEnabled(True) + self.tagboxes[line].setEnabled(True) + def and_box_changed(self, state, line=None): if state == 2: self.colorboxes[line].setCurrentIndex(0) self.colorboxes[line].setEnabled(False) - self.nfcolorboxes[line].setCurrentIndex(0) - self.nfcolorboxes[line].setEnabled(False) else: self.colorboxes[line].setEnabled(True) - self.nfcolorboxes[line].setEnabled(True) def accepted(self): if self.generate_program(): diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index b66aec2cb9..7b9a2ac51c 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -106,8 +106,8 @@ class BuiltinCmp(BuiltinFormatterFunction): 'numbers. Returns lt if x < y. Returns eq if x == y. Otherwise returns gt.') def evaluate(self, formatter, kwargs, mi, locals, x, y, lt, eq, gt): - x = float(x if x else 0) - y = float(y if y else 0) + x = float(x if x and x != 'None' else 0) + y = float(y if y and y != 'None' else 0) if x < y: return lt if x == y: From f4affb57e3479d5ba811442a4c0654591966e2a7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 31 May 2011 09:12:40 -0600 Subject: [PATCH 41/84] Driver for Motorola Defy --- src/calibre/devices/android/driver.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/devices/android/driver.py b/src/calibre/devices/android/driver.py index 1cdf394c24..3c6ea243e2 100644 --- a/src/calibre/devices/android/driver.py +++ b/src/calibre/devices/android/driver.py @@ -109,7 +109,8 @@ class ANDROID(USBMS): 'SGH-T849', '_MB300', 'A70S', 'S_ANDROID', 'A101IT', 'A70H', 'IDEOS_TABLET', 'MYTOUCH_4G', 'UMS_COMPOSITE', 'SCH-I800_CARD', '7', 'A956', 'A955', 'A43', 'ANDROID_PLATFORM', 'TEGRA_2', - 'MB860', 'MULTI-CARD', 'MID7015A', 'INCREDIBLE', 'A7EB', 'STREAK'] + 'MB860', 'MULTI-CARD', 'MID7015A', 'INCREDIBLE', 'A7EB', 'STREAK', + 'MB525'] WINDOWS_CARD_A_MEM = ['ANDROID_PHONE', 'GT-I9000_CARD', 'SGH-I897', 'FILE-STOR_GADGET', 'SGH-T959', 'SAMSUNG_ANDROID', 'GT-P1000_CARD', 'A70S', 'A101IT', '7', 'INCREDIBLE', 'A7EB', 'SGH-T849_CARD'] From 37ddce40741d4249efcc047ab28089cacee77ec3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 31 May 2011 10:40:27 -0600 Subject: [PATCH 42/84] Improve documentation of template functions --- src/calibre/manual/template_lang.rst | 37 +--- src/calibre/manual/template_ref.rst | 266 +++++++++++++++++++++++ src/calibre/utils/formatter_functions.py | 87 ++++---- 3 files changed, 320 insertions(+), 70 deletions(-) create mode 100644 src/calibre/manual/template_ref.rst diff --git a/src/calibre/manual/template_lang.rst b/src/calibre/manual/template_lang.rst index ef44b0a5c9..079af59286 100644 --- a/src/calibre/manual/template_lang.rst +++ b/src/calibre/manual/template_lang.rst @@ -268,20 +268,14 @@ The following functions are available in addition to those described in single-f * ``subtract(x, y)`` -- returns x - y. Throws an exception if either x or y are not numbers. * ``template(x)`` -- evaluates x as a template. The evaluation is done in its own context, meaning that variables are not shared between the caller and the template evaluation. Because the `{` and `}` characters are special, you must use `[[` for the `{` character and `]]` for the '}' character; they are converted automatically. For example, ``template('[[title_sort]]') will evaluate the template ``{title_sort}`` and return its value. -Function classification summary: +Function classification +--------------------------- + +.. toctree:: + :maxdepth: 3 + + template_ref - * Get values from metadata: ``field``. ``raw_field``. In some situations, ``lookup`` can be used in place of ``field``. - * Arithmetic: ``add``, ``subtract``, ``multiply``, ``divide`` - * Boolean: ``and``, ``or``, ``not``. The function ``if_empty`` is similar to ``and`` called with one argument. - * If-then-else: ``contains``, ``test`` - * Iterating over values: ``first_non_empty``, ``lookup``, ``switch`` - * List lookup: ``in_list``, ``list_item``, ``select``, ``str_in_list`` - * List manipulation: ``count``, ``merge_lists``, ``sublist``, ``subitems`` - * Recursion: ``eval``, ``template`` - * Relational: ``cmp`` (for numbers), ``strcmp`` (for strings) - * String case changes: ``lowercase``, ``uppercase``, ``titlecase``, ``capitalize`` - * String manipulation: ``re``, ``shorten``, ``substr`` - * Other: ``assign``, ``booksize``, ``format_date``, ``ondevice`` ``print`` .. _general_mode: @@ -425,20 +419,9 @@ You might find the following tips useful. * Templates can use other templates by referencing a composite custom column. * In a plugboard, you can set a field to empty (or whatever is equivalent to empty) by using the special template ``{null}``. This template will always evaluate to an empty string. * The technique described above to show numbers even if they have a zero value works with the standard field series_index. - -API of the Metadata objects ----------------------------- -.. module:: calibre.ebooks.metadata.book.base +.. toctree:: + :hidden: -.. autoclass:: Metadata - :members: - :member-order: bysource - -.. data:: STANDARD_METADATA_FIELDS - - The set of standard metadata fields. - -.. literalinclude:: ../ebooks/metadata/book/__init__.py - :lines: 7- + template_ref diff --git a/src/calibre/manual/template_ref.rst b/src/calibre/manual/template_ref.rst new file mode 100644 index 0000000000..670a7ba791 --- /dev/null +++ b/src/calibre/manual/template_ref.rst @@ -0,0 +1,266 @@ +.. include:: global.rst + +.. _templaterefcalibre: + +Reference for all builtin template language functions +======================================================== + +Here, we document all the builtin functions available in the |app| template language. Every function is implemented as a class in python and you can click the source links to see the source code, in case the documentation is insufficient. The functions are arranged in logical groups by type. + +.. contents:: + :depth: 2 + :local: + +.. module:: calibre.utils.formatter_functions + +Get values from metadata +-------------------------- + +field(name) +^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinField + +raw_field(name) +^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinRaw_field + +booksize() +^^^^^^^^^^^^ + +.. autoclass:: BuiltinBooksize + +format_date(val, format_string) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinFormat_date + +ondevice() +^^^^^^^^^^^ + +.. autoclass:: BuiltinOndevice + +Arithmetic +------------- + +add(x, y) +^^^^^^^^^^^^^ +.. autoclass:: BuiltinAdd + +subtract(x, y) +^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinSubtract + +multiply(x, y) +^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinMultiply + +divide(x, y) +^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinDivide + +Boolean +------------ + +and(value1, value2, ...) +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinAnd + +or(value1, value2, ...) +^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinOr + +not(value) +^^^^^^^^^^^^^ + +.. autoclass:: BuiltinNot + +If-then-else +----------------- + +contains(val, pattern, text if match, text if not match) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinContains + +test(val, text if not empty, text if empty) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinTest + +ifempty(val, text if empty) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinIfempty + +Iterating over values +------------------------ + +first_non_empty(value, value, ...) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinFirstNonEmpty + +lookup(val, pattern, field, pattern, field, ..., else_field) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinLookup + +switch(val, pattern, value, pattern, value, ..., else_value) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinSwitch + +List Lookup +--------------- + +in_list(val, separator, pattern, found_val, not_found_val) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinInList + +str_in_list(val, separator, string, found_val, not_found_val) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinStrInList + +list_item(val, index, separator) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinListitem + +select(val, key) +^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinSelect + + +List Manipulation +------------------- + +count(val, separator) +^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinCount + +merge_lists(list1, list2, separator) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinMergeLists + +sublist(val, start_index, end_index, separator) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinSublist + +subitems(val, start_index, end_index) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinSubitems + +Recursion +------------- + +eval(template) +^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinEval + +template(x) +^^^^^^^^^^^^ + +.. autoclass:: BuiltinTemplate + +Relational +----------- + +cmp(x, y, lt, eq, gt) +^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinCmp + +strcmp(x, y, lt, eq, gt) +^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinStrcmp + +String case changes +--------------------- + +lowercase(val) +^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinLowercase + +uppercase(val) +^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinUppercase + +titlecase(val) +^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinTitlecase + +capitalize(val) +^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinCapitalize + +String Manipulation +--------------------- + +re(val, pattern, replacement) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinRe + +shorten(val, left chars, middle text, right chars) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinShorten + +substr(str, start, end) +^^^^^^^^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinSubstr + + +Other +-------- + +assign(id, val) +^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinAssign + +print(a, b, ...) +^^^^^^^^^^^^^^^^^ + +.. autoclass:: BuiltinPrint + + +API of the Metadata objects +---------------------------- + +The python implementation of the template functions is passed in a Metadata object. Knowing it's API is useful if you want to define your own template functions. + +.. module:: calibre.ebooks.metadata.book.base + +.. autoclass:: Metadata + :members: + :member-order: bysource + +.. data:: STANDARD_METADATA_FIELDS + + The set of standard metadata fields. + +.. literalinclude:: ../ebooks/metadata/book/__init__.py + :lines: 7- + diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 7b9a2ac51c..62764510e9 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -87,7 +87,7 @@ class BuiltinFormatterFunction(FormatterFunction): class BuiltinStrcmp(BuiltinFormatterFunction): name = 'strcmp' arg_count = 5 - doc = _('strcmp(x, y, lt, eq, gt) -- does a case-insensitive comparison of x ' + __doc__ = doc = _('strcmp(x, y, lt, eq, gt) -- does a case-insensitive comparison of x ' 'and y as strings. Returns lt if x < y. Returns eq if x == y. ' 'Otherwise returns gt.') @@ -102,7 +102,7 @@ class BuiltinStrcmp(BuiltinFormatterFunction): class BuiltinCmp(BuiltinFormatterFunction): name = 'cmp' arg_count = 5 - doc = _('cmp(x, y, lt, eq, gt) -- compares x and y after converting both to ' + __doc__ = doc = _('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.') def evaluate(self, formatter, kwargs, mi, locals, x, y, lt, eq, gt): @@ -117,7 +117,7 @@ class BuiltinCmp(BuiltinFormatterFunction): class BuiltinStrcat(BuiltinFormatterFunction): name = 'strcat' arg_count = -1 - doc = _('strcat(a, b, ...) -- can take any number of arguments. Returns a ' + __doc__ = doc = _('strcat(a, b, ...) -- can take any number of arguments. Returns a ' 'string formed by concatenating all the arguments') def evaluate(self, formatter, kwargs, mi, locals, *args): @@ -130,7 +130,7 @@ class BuiltinStrcat(BuiltinFormatterFunction): class BuiltinAdd(BuiltinFormatterFunction): name = 'add' arg_count = 2 - doc = _('add(x, y) -- returns x + y. Throws an exception if either x or y are not numbers.') + __doc__ = doc = _('add(x, y) -- returns x + y. Throws an exception if either x or y are not numbers.') def evaluate(self, formatter, kwargs, mi, locals, x, y): x = float(x if x else 0) @@ -140,7 +140,7 @@ class BuiltinAdd(BuiltinFormatterFunction): class BuiltinSubtract(BuiltinFormatterFunction): name = 'subtract' arg_count = 2 - doc = _('subtract(x, y) -- returns x - y. Throws an exception if either x or y are not numbers.') + __doc__ = doc = _('subtract(x, y) -- returns x - y. Throws an exception if either x or y are not numbers.') def evaluate(self, formatter, kwargs, mi, locals, x, y): x = float(x if x else 0) @@ -150,7 +150,7 @@ class BuiltinSubtract(BuiltinFormatterFunction): class BuiltinMultiply(BuiltinFormatterFunction): name = 'multiply' arg_count = 2 - doc = _('multiply(x, y) -- returns x * y. Throws an exception if either x or y are not numbers.') + __doc__ = doc = _('multiply(x, y) -- returns x * y. Throws an exception if either x or y are not numbers.') def evaluate(self, formatter, kwargs, mi, locals, x, y): x = float(x if x else 0) @@ -160,7 +160,7 @@ class BuiltinMultiply(BuiltinFormatterFunction): class BuiltinDivide(BuiltinFormatterFunction): name = 'divide' arg_count = 2 - doc = _('divide(x, y) -- returns x / y. Throws an exception if either x or y are not numbers.') + __doc__ = doc = _('divide(x, y) -- returns x / y. Throws an exception if either x or y are not numbers.') def evaluate(self, formatter, kwargs, mi, locals, x, y): x = float(x if x else 0) @@ -170,7 +170,7 @@ class BuiltinDivide(BuiltinFormatterFunction): class BuiltinTemplate(BuiltinFormatterFunction): name = 'template' arg_count = 1 - doc = _('template(x) -- evaluates x as a template. The evaluation is done ' + __doc__ = doc = _('template(x) -- evaluates x as a template. The evaluation is done ' 'in its own context, meaning that variables are not shared between ' 'the caller and the template evaluation. Because the { and } ' 'characters are special, you must use [[ for the { character and ' @@ -185,7 +185,7 @@ class BuiltinTemplate(BuiltinFormatterFunction): class BuiltinEval(BuiltinFormatterFunction): name = 'eval' arg_count = 1 - doc = _('eval(template) -- evaluates the template, passing the local ' + __doc__ = doc = _('eval(template) -- evaluates the template, passing the local ' 'variables (those \'assign\'ed to) instead of the book metadata. ' ' This permits using the template processor to construct complex ' 'results from local variables.') @@ -198,7 +198,7 @@ class BuiltinEval(BuiltinFormatterFunction): class BuiltinAssign(BuiltinFormatterFunction): name = 'assign' arg_count = 2 - doc = _('assign(id, val) -- assigns val to id, then returns val. ' + __doc__ = doc = _('assign(id, val) -- assigns val to id, then returns val. ' 'id must be an identifier, not an expression') def evaluate(self, formatter, kwargs, mi, locals, target, value): @@ -208,7 +208,7 @@ class BuiltinAssign(BuiltinFormatterFunction): class BuiltinPrint(BuiltinFormatterFunction): name = 'print' arg_count = -1 - doc = _('print(a, b, ...) -- prints the arguments to standard output. ' + __doc__ = doc = _('print(a, b, ...) -- prints the arguments to standard output. ' 'Unless you start calibre from the command line (calibre-debug -g), ' 'the output will go to a black hole.') @@ -219,7 +219,7 @@ class BuiltinPrint(BuiltinFormatterFunction): class BuiltinField(BuiltinFormatterFunction): name = 'field' arg_count = 1 - doc = _('field(name) -- returns the metadata field named by name') + __doc__ = doc = _('field(name) -- returns the metadata field named by name') def evaluate(self, formatter, kwargs, mi, locals, name): return formatter.get_value(name, [], kwargs) @@ -227,7 +227,7 @@ class BuiltinField(BuiltinFormatterFunction): class BuiltinRaw_field(BuiltinFormatterFunction): name = 'raw_field' arg_count = 1 - doc = _('raw_field(name) -- returns the metadata field named by name ' + __doc__ = doc = _('raw_field(name) -- returns the metadata field named by name ' 'without applying any formatting.') def evaluate(self, formatter, kwargs, mi, locals, name): @@ -236,7 +236,7 @@ class BuiltinRaw_field(BuiltinFormatterFunction): class BuiltinSubstr(BuiltinFormatterFunction): name = 'substr' arg_count = 3 - doc = _('substr(str, start, end) -- returns the start\'th through the end\'th ' + __doc__ = doc = _('substr(str, start, end) -- returns the start\'th through the end\'th ' 'characters of str. The first character in str is the zero\'th ' 'character. If end is negative, then it indicates that many ' 'characters counting from the right. If end is zero, then it ' @@ -249,7 +249,7 @@ class BuiltinSubstr(BuiltinFormatterFunction): class BuiltinLookup(BuiltinFormatterFunction): name = 'lookup' arg_count = -1 - doc = _('lookup(val, pattern, field, pattern, field, ..., else_field) -- ' + __doc__ = doc = _('lookup(val, pattern, field, pattern, field, ..., else_field) -- ' 'like switch, except the arguments are field (metadata) names, not ' 'text. The value of the appropriate field will be fetched and used. ' 'Note that because composite columns are fields, you can use this ' @@ -276,7 +276,7 @@ class BuiltinLookup(BuiltinFormatterFunction): class BuiltinTest(BuiltinFormatterFunction): name = 'test' arg_count = 3 - doc = _('test(val, text if not empty, text if empty) -- return `text if not ' + __doc__ = doc = _('test(val, text if not empty, text if empty) -- return `text if not ' 'empty` if the field is not empty, otherwise return `text if empty`') def evaluate(self, formatter, kwargs, mi, locals, val, value_if_set, value_not_set): @@ -288,7 +288,7 @@ class BuiltinTest(BuiltinFormatterFunction): class BuiltinContains(BuiltinFormatterFunction): name = 'contains' arg_count = 4 - doc = _('contains(val, pattern, text if match, text if not match) -- checks ' + __doc__ = doc = _('contains(val, 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`') @@ -303,7 +303,7 @@ class BuiltinContains(BuiltinFormatterFunction): class BuiltinSwitch(BuiltinFormatterFunction): name = 'switch' arg_count = -1 - doc = _('switch(val, pattern, value, pattern, value, ..., else_value) -- ' + __doc__ = doc = _('switch(val, 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. ' @@ -323,7 +323,7 @@ class BuiltinSwitch(BuiltinFormatterFunction): class BuiltinInList(BuiltinFormatterFunction): name = 'in_list' arg_count = 5 - doc = _('in_list(val, separator, pattern, found_val, not_found_val) -- ' + __doc__ = 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 ' @@ -340,7 +340,7 @@ class BuiltinInList(BuiltinFormatterFunction): class BuiltinStrInList(BuiltinFormatterFunction): name = 'str_in_list' arg_count = 5 - doc = _('str_in_list(val, separator, string, found_val, not_found_val) -- ' + __doc__ = doc = _('str_in_list(val, separator, string, found_val, not_found_val) -- ' 'treat val as a list of items separated by separator, ' 'comparing the string against each value in the list. If the ' 'string matches a value, return found_val, otherwise return ' @@ -360,7 +360,7 @@ class BuiltinStrInList(BuiltinFormatterFunction): class BuiltinRe(BuiltinFormatterFunction): name = 're' arg_count = 3 - doc = _('re(val, pattern, replacement) -- return the field after applying ' + __doc__ = doc = _('re(val, pattern, replacement) -- return the field after applying ' 'the regular expression. All instances of `pattern` are replaced ' 'with `replacement`. As in all of calibre, these are ' 'python-compatible regular expressions') @@ -371,7 +371,7 @@ class BuiltinRe(BuiltinFormatterFunction): class BuiltinIfempty(BuiltinFormatterFunction): name = 'ifempty' arg_count = 2 - doc = _('ifempty(val, text if empty) -- return val if val is not empty, ' + __doc__ = doc = _('ifempty(val, text if empty) -- return val if val is not empty, ' 'otherwise return `text if empty`') def evaluate(self, formatter, kwargs, mi, locals, val, value_if_empty): @@ -383,7 +383,7 @@ class BuiltinIfempty(BuiltinFormatterFunction): class BuiltinShorten(BuiltinFormatterFunction): name = 'shorten' arg_count = 4 - doc = _('shorten(val, left chars, middle text, right chars) -- Return a ' + __doc__ = doc = _('shorten(val, 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 ' @@ -408,7 +408,7 @@ class BuiltinShorten(BuiltinFormatterFunction): class BuiltinCount(BuiltinFormatterFunction): name = 'count' arg_count = 2 - doc = _('count(val, separator) -- interprets the value as a list of items ' + __doc__ = doc = _('count(val, 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(&)}') @@ -419,7 +419,7 @@ class BuiltinCount(BuiltinFormatterFunction): class BuiltinListitem(BuiltinFormatterFunction): name = 'list_item' arg_count = 3 - doc = _('list_item(val, index, separator) -- interpret the value as a list of ' + __doc__ = doc = _('list_item(val, 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, ' @@ -439,7 +439,7 @@ class BuiltinListitem(BuiltinFormatterFunction): class BuiltinSelect(BuiltinFormatterFunction): name = 'select' arg_count = 2 - doc = _('select(val, key) -- interpret the value as a comma-separated list ' + __doc__ = doc = _('select(val, key) -- interpret the value as a comma-separated list ' 'of items, with the items being "id:value". Find the pair with the' 'id equal to key, and return the corresponding value.' ) @@ -456,9 +456,9 @@ class BuiltinSelect(BuiltinFormatterFunction): class BuiltinSublist(BuiltinFormatterFunction): name = 'sublist' arg_count = 4 - doc = _('sublist(val, start_index, end_index, separator) -- interpret the ' + __doc__ = doc = _('sublist(val, start_index, end_index, separator) -- interpret the ' 'value as a list of items separated by `separator`, returning a ' - 'new list made from the `start_index`th to the `end_index`th item. ' + 'new list made from the `start_index` to the `end_index` item. ' 'The first item is number zero. If an index is negative, then it ' 'counts from the end of the list. As a special case, an end_index ' 'of zero is assumed to be the length of the list. Examples using ' @@ -466,7 +466,8 @@ class BuiltinSublist(BuiltinFormatterFunction): 'comma-separated) contains "A, B, C": ' '{tags:sublist(0,1,\,)} returns "A". ' '{tags:sublist(-1,0,\,)} returns "C". ' - '{tags:sublist(0,-1,\,)} returns "A, B".') + '{tags:sublist(0,-1,\,)} returns "A, B".' + ) def evaluate(self, formatter, kwargs, mi, locals, val, start_index, end_index, sep): if not val: @@ -485,12 +486,12 @@ class BuiltinSublist(BuiltinFormatterFunction): class BuiltinSubitems(BuiltinFormatterFunction): name = 'subitems' arg_count = 3 - doc = _('subitems(val, start_index, end_index) -- This function is used to ' + __doc__ = doc = _('subitems(val, start_index, end_index) -- This function is used to ' 'break apart lists of items such as genres. It interprets the value ' 'as a comma-separated list of items, where each item is a period-' 'separated list. Returns a new list made by first finding all the ' 'period-separated items, then for each such item extracting the ' - 'start_index`th to the `end_index`th components, then combining ' + 'start_index` to the `end_index` components, then combining ' 'the results back together. The first component in a period-' 'separated list has an index of zero. If an index is negative, ' 'then it counts from the end of the list. As a special case, an ' @@ -522,7 +523,7 @@ class BuiltinSubitems(BuiltinFormatterFunction): class BuiltinFormat_date(BuiltinFormatterFunction): name = 'format_date' arg_count = 2 - doc = _('format_date(val, format_string) -- format the value, which must ' + __doc__ = doc = _('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) ' @@ -550,7 +551,7 @@ class BuiltinFormat_date(BuiltinFormatterFunction): class BuiltinUppercase(BuiltinFormatterFunction): name = 'uppercase' arg_count = 1 - doc = _('uppercase(val) -- return value of the field in upper case') + __doc__ = doc = _('uppercase(val) -- return value of the field in upper case') def evaluate(self, formatter, kwargs, mi, locals, val): return val.upper() @@ -558,7 +559,7 @@ class BuiltinUppercase(BuiltinFormatterFunction): class BuiltinLowercase(BuiltinFormatterFunction): name = 'lowercase' arg_count = 1 - doc = _('lowercase(val) -- return value of the field in lower case') + __doc__ = doc = _('lowercase(val) -- return value of the field in lower case') def evaluate(self, formatter, kwargs, mi, locals, val): return val.lower() @@ -566,7 +567,7 @@ class BuiltinLowercase(BuiltinFormatterFunction): class BuiltinTitlecase(BuiltinFormatterFunction): name = 'titlecase' arg_count = 1 - doc = _('titlecase(val) -- return value of the field in title case') + __doc__ = doc = _('titlecase(val) -- return value of the field in title case') def evaluate(self, formatter, kwargs, mi, locals, val): return titlecase(val) @@ -574,7 +575,7 @@ class BuiltinTitlecase(BuiltinFormatterFunction): class BuiltinCapitalize(BuiltinFormatterFunction): name = 'capitalize' arg_count = 1 - doc = _('capitalize(val) -- return value of the field capitalized') + __doc__ = doc = _('capitalize(val) -- return value of the field capitalized') def evaluate(self, formatter, kwargs, mi, locals, val): return capitalize(val) @@ -582,7 +583,7 @@ class BuiltinCapitalize(BuiltinFormatterFunction): class BuiltinBooksize(BuiltinFormatterFunction): name = 'booksize' arg_count = 0 - doc = _('booksize() -- return value of the size field') + __doc__ = doc = _('booksize() -- return value of the size field') def evaluate(self, formatter, kwargs, mi, locals): if mi.book_size is not None: @@ -595,7 +596,7 @@ class BuiltinBooksize(BuiltinFormatterFunction): class BuiltinOndevice(BuiltinFormatterFunction): name = 'ondevice' arg_count = 0 - doc = _('ondevice() -- return Yes if ondevice is set, otherwise return ' + __doc__ = doc = _('ondevice() -- return Yes if ondevice is set, otherwise return ' 'the empty string') def evaluate(self, formatter, kwargs, mi, locals): @@ -606,7 +607,7 @@ class BuiltinOndevice(BuiltinFormatterFunction): class BuiltinFirstNonEmpty(BuiltinFormatterFunction): name = 'first_non_empty' arg_count = -1 - doc = _('first_non_empty(value, value, ...) -- ' + __doc__ = 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.') @@ -622,7 +623,7 @@ class BuiltinFirstNonEmpty(BuiltinFormatterFunction): class BuiltinAnd(BuiltinFormatterFunction): name = 'and' arg_count = -1 - doc = _('and(value, value, ...) -- ' + __doc__ = doc = _('and(value, value, ...) -- ' 'returns the string "1" if all values are not empty, otherwise ' 'returns the empty string. This function works well with test or ' 'first_non_empty. You can have as many values as you want.') @@ -638,7 +639,7 @@ class BuiltinAnd(BuiltinFormatterFunction): class BuiltinOr(BuiltinFormatterFunction): name = 'or' arg_count = -1 - doc = _('or(value, value, ...) -- ' + __doc__ = doc = _('or(value, value, ...) -- ' 'returns the string "1" if any value is not empty, otherwise ' 'returns the empty string. This function works well with test or ' 'first_non_empty. You can have as many values as you want.') @@ -654,7 +655,7 @@ class BuiltinOr(BuiltinFormatterFunction): class BuiltinNot(BuiltinFormatterFunction): name = 'not' arg_count = 1 - doc = _('not(value) -- ' + __doc__ = doc = _('not(value) -- ' 'returns the string "1" if the value is empty, otherwise ' 'returns the empty string. This function works well with test or ' 'first_non_empty. You can have as many values as you want.') @@ -670,7 +671,7 @@ class BuiltinNot(BuiltinFormatterFunction): class BuiltinMergeLists(BuiltinFormatterFunction): name = 'merge_lists' arg_count = 3 - doc = _('merge_lists(list1, list2, separator) -- ' + __doc__ = doc = _('merge_lists(list1, list2, separator) -- ' 'return a list made by merging the items in list1 and list2, ' 'removing duplicate items using a case-insensitive compare. If ' 'items differ in case, the one in list1 is used. ' From 5c219da8d3bf393d9095975eb5592c10b58ff868 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 31 May 2011 11:28:37 -0600 Subject: [PATCH 43/84] EPUB Output: Fix crash caused by ids with non-ascii characters in them --- src/calibre/ebooks/oeb/transforms/split.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/oeb/transforms/split.py b/src/calibre/ebooks/oeb/transforms/split.py index 69de740ddc..0c9b492855 100644 --- a/src/calibre/ebooks/oeb/transforms/split.py +++ b/src/calibre/ebooks/oeb/transforms/split.py @@ -120,7 +120,19 @@ class Split(object): for i, x in enumerate(page_breaks): x.set('id', x.get('id', 'calibre_pb_%d'%i)) id = x.get('id') - page_breaks_.append((XPath('//*[@id=%r]'%id), + try: + xp = XPath('//*[@id="%s"]'%id) + except: + try: + xp = XPath("//*[@id='%s']"%id) + except: + # The id has both a quote and an apostrophe or some other + # Just replace it since I doubt its going to work anywhere else + # either + id = 'calibre_pb_%d'%i + x.set('id', id) + xp = XPath('//*[@id=%r]'%id) + page_breaks_.append((xp, x.get('pb_before', False))) page_break_ids.append(id) From db0c24624001e7c2a417566e6cf7538483a9cf64 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 31 May 2011 13:43:38 -0600 Subject: [PATCH 44/84] ... --- src/calibre/ebooks/epub/fix/container.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/epub/fix/container.py b/src/calibre/ebooks/epub/fix/container.py index 1669290a7b..691bf7132a 100644 --- a/src/calibre/ebooks/epub/fix/container.py +++ b/src/calibre/ebooks/epub/fix/container.py @@ -101,7 +101,7 @@ class Container(object): return None return existing[0] - def add_name_to_manifest(self, name): + def add_name_to_manifest(self, name, mt=None): item = self.manifest_item_for_name(name) if item is not None: return @@ -109,11 +109,27 @@ class Container(object): item = manifest.makeelement('{%s}item'%OPF_NS, nsmap={'opf':OPF_NS}, href=self.name_to_href(name, posixpath.dirname(self.opf_name)), id=self.generate_manifest_id()) - mt = guess_type(posixpath.basename(name))[0] + if not mt: + mt = guess_type(posixpath.basename(name))[0] if not mt: mt = 'application/octest-stream' item.set('media-type', mt) manifest.append(item) + self.fix_tail(item) + + def fix_tail(self, item): + ''' + Designed only to work with self closing elements after item has + just been inserted/appended + ''' + parent = item.getparent() + idx = parent.index(item) + if idx == 0: + item.tail = parent.text + else: + item.tail = parent[idx-1].tail + if idx == len(parent)-1: + parent[idx-1].tail = parent.text def generate_manifest_id(self): items = self.opf.xpath('//opf:manifest/opf:item[@id]', From 7fe53cd96b0a13d3d8cadd7429aa32db81698005 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 31 May 2011 17:46:12 -0600 Subject: [PATCH 45/84] Fix #790945 (Updated recipe for BBC News (fast)) --- recipes/bbc_fast.recipe | 78 +++++++++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/recipes/bbc_fast.recipe b/recipes/bbc_fast.recipe index 93ee11ce32..9bcbfb5f70 100644 --- a/recipes/bbc_fast.recipe +++ b/recipes/bbc_fast.recipe @@ -1,27 +1,30 @@ __license__ = 'GPL v3' -__copyright__ = '2010, Darko Miletic ' +__copyright__ = '2010 - 2011, Darko Miletic ' ''' news.bbc.co.uk ''' -import re from calibre.web.feeds.recipes import BasicNewsRecipe class BBC(BasicNewsRecipe): title = 'BBC News (fast)' __author__ = 'Darko Miletic, Starson17' - description = 'News from UK. A much faster version that does not download pictures' + description = 'Visit BBC News for up-to-the-minute news, breaking news, video, audio and feature stories. BBC News provides trusted World and UK news as well as local and regional perspectives. Also entertainment, business, science, technology and health news.' oldest_article = 2 max_articles_per_feed = 100 no_stylesheets = True - #delay = 1 use_embedded_content = False encoding = 'utf8' publisher = 'BBC' category = 'news, UK, world' language = 'en_GB' publication_type = 'newsportal' - extra_css = ' body{ font-family: Verdana,Helvetica,Arial,sans-serif } .introduction{font-weight: bold} .story-feature{display: block; padding: 0; border: 1px solid; width: 40%; font-size: small} .story-feature h2{text-align: center; text-transform: uppercase} ' - preprocess_regexps = [(re.compile(r'', re.DOTALL), lambda m: '')] + masthead_url = 'http://news.bbcimg.co.uk/img/1_0_1/cream/hi/news/news-blocks.gif' + extra_css = """ + body{ font-family: Verdana,Helvetica,Arial,sans-serif } + .introduction{font-weight: bold} + .story-feature{display: block; padding: 0; border: 1px solid; width: 40%; font-size: small} + .story-feature h2{text-align: center; text-transform: uppercase} + """ conversion_options = { 'comments' : description ,'tags' : category @@ -31,31 +34,54 @@ class BBC(BasicNewsRecipe): } keep_only_tags = [ - dict(name='div', attrs={'class':['layout-block-a layout-block']}) - ,dict(attrs={'class':['story-body','storybody']}) + dict(name='div', attrs={'class':['layout-block-a layout-block']}) + ,dict(attrs={'class':['story-body','storybody']}) + ,dict(attrs={'id':['meta-information','story-body']}) ] remove_tags = [ - dict(name='div', attrs={'class':['story-feature related narrow', 'share-help', 'embedded-hyper', \ - 'story-feature wide ', 'story-feature narrow']}) - , dict(name=['img']) - ] + dict(name='div', attrs={'class':['story-feature related narrow', \ + 'share-help', 'embedded-hyper', \ + 'story-feature wide ', \ + 'story-feature narrow', \ + 'hidden','story-actions', \ + 'embedded-hyper']}) + ,dict(name=['img','meta','link','object','embed','iframe','base']) + ,dict(attrs={'class':['hidden','videoInStoryC']}) + ,dict(attrs={'id':['bbccom_sponsor_section','toggle-controls', \ + 'toggle-images','toggle-title']}) + ] - remove_attributes = ['width','height'] + remove_attributes = ['width','height','xmlns:og','lang','clear'] feeds = [ - ('News Front Page', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml'), - ('Science/Nature', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/science/nature/rss.xml'), - ('Technology', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/technology/rss.xml'), - ('Entertainment', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/entertainment/rss.xml'), - ('Magazine', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/uk_news/magazine/rss.xml'), - ('Business', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/business/rss.xml'), - ('Health', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/health/rss.xml'), - ('Americas', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/americas/rss.xml'), - ('Europe', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/europe/rss.xml'), - ('South Asia', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/south_asia/rss.xml'), - ('UK', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/uk_news/rss.xml'), - ('Asia-Pacific', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/asia-pacific/rss.xml'), - ('Africa', 'http://newsrss.bbc.co.uk/rss/newsonline_world_edition/africa/rss.xml'), + ('Top Stories' , 'http://feeds.bbci.co.uk/news/rss.xml' ), + ('Science/Environment', 'http://feeds.bbci.co.uk/news/science_and_environment/rss.xml'), + ('Technology' , 'http://feeds.bbci.co.uk/news/technology/rss.xml' ), + ('Entertainment/Arts' , 'http://feeds.bbci.co.uk/news/entertainment_and_arts/rss.xml' ), + ('Magazine' , 'http://feeds.bbci.co.uk/news/magazine/rss.xml' ), + ('Business' , 'http://feeds.bbci.co.uk/news/business/rss.xml' ), + ('Politics' , 'http://feeds.bbci.co.uk/news/politics/rss.xml' ), + ('Health' , 'http://feeds.bbci.co.uk/news/health/rss.xml' ), + ('US&Canada' , 'http://feeds.bbci.co.uk/news/world/us_and_canada/rss.xml' ), + ('Latin America' , 'http://feeds.bbci.co.uk/news/world/latin_america/rss.xml' ), + ('Europe' , 'http://feeds.bbci.co.uk/news/world/europe/rss.xml' ), + ('South Asia' , 'http://feeds.bbci.co.uk/news/world/south_asia/rss.xml' ), + ('England' , 'http://feeds.bbci.co.uk/news/england/rss.xml' ), + ('Asia-Pacific' , 'http://feeds.bbci.co.uk/news/world/asia_pacific/rss.xml' ), + ('Africa' , 'http://feeds.bbci.co.uk/news/world/africa/rss.xml' ) ] + def preprocess_html(self, soup): + for item in soup.findAll(style=True): + del item['style'] + for item in soup.findAll('left'): + item.name='span' + for item in soup.findAll('a'): + if item.string is not None: + str = item.string + item.replaceWith(str) + else: + str = self.tag_to_string(item) + item.replaceWith(str) + return soup From 202c9b9d144052cd284ac68886f262d3eda560d8 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Wed, 1 Jun 2011 05:37:59 +0100 Subject: [PATCH 46/84] template box. --- .../gui2/dialogs/template_line_editor.py | 166 ++++++++++++------ src/calibre/utils/formatter_functions.py | 4 +- 2 files changed, 111 insertions(+), 59 deletions(-) diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index 6a0b07200e..af70a16d31 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -95,25 +95,27 @@ class TemplateLineEditor(QLineEdit): class TagWizard(QDialog): - text_template = " strcmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')" - text_empty_template = " test(field('{f}'), '{fv}', '{tv}')" - text_re_template = " contains(field('{f}'), '{v}', '{tv}', '{fv}')" + text_template = (" strcmp(field('{f}'), '{v}', '{ltv}', '{eqv}', '{gtv}')", True) + text_empty_template = (" test(field('{f}'), '{fv}', '{tv}')", False) + text_re_template = (" contains(field('{f}'), '{v}', '{tv}', '{fv}')", False) templates = { - 'text.mult' : " str_in_list(field('{f}'), '{mult}', '{v}', '{tv}', '{fv}')", - 'text.mult.re' : " in_list(field('{f}'), '{mult}', '^{v}$', '{tv}', '{fv}')", - 'text.mult.empty' : " test(field('{f}'), '{fv}', '{tv}')", + 'text.mult' : (" str_in_list(field('{f}'), '{mult}', '{v}', '{tv}', '{fv}')", False), + 'text.mult.re' : (" in_list(field('{f}'), '{mult}', '^{v}$', '{tv}', '{fv}')", False), + 'text.mult.empty' : (" test(field('{f}'), '{fv}', '{tv}')", False), 'text' : text_template, 'text.re' : text_re_template, 'text.empty' : text_empty_template, - 'rating' : " cmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')", + 'rating' : (" cmp(raw_field('{f}'), '{v}', '{ltv}', '{eqv}', '{gtv}')", True), 'rating.empty' : text_empty_template, - 'int' : " cmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')", + 'int' : (" cmp(raw_field('{f}'), '{v}', '{ltv}', '{eqv}', '{gtv}')", True), 'int.empty' : text_empty_template, - 'float' : " cmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')", + 'float' : (" cmp(raw_field('{f}'), '{v}', '{ltv}', '{eqv}', '{gtv}')", True), 'float.empty' : text_empty_template, - 'bool' : " strcmp(field('{f}'), '{v}', '{fv}', '{tv}', '{fv}')", + 'bool' : (" strcmp(field('{f}'), '{v}', '{ltv}', '{eqv}', '{gtv}')", True), 'bool.empty' : text_empty_template, + 'datetime' : (" strcmp(format_date(raw_field('{f}'), 'yyyyMMdd'), format_date('{v}', 'yyyyMMdd'), '{ltv}', '{eqv}', '{gtv}')", True), + 'datetime.empty' : text_empty_template, 'series' : text_template, 'series.re' : text_re_template, 'series.empty' : text_empty_template, @@ -128,6 +130,22 @@ class TagWizard(QDialog): 'comments.empty' : text_empty_template, } + relationals = ('=', '!=', '<', '>', '<=', '>=') + relational_truth_vals = { + '=': ('', '1', ''), + '!=': ('1', '', '1'), + '<': ('1', '', ''), + '>': ('', '', '1'), + '<=': ('1', '1', ''), + '>=': ('', '1', '1'), + } + + @staticmethod + def uses_this_wizard(txt): + if not txt or txt.startswith('program:\n#tag wizard'): + return True + return False + def __init__(self, parent, db, txt, mi): QDialog.__init__(self, parent) self.setWindowTitle(_('Coloring Wizard')) @@ -141,8 +159,7 @@ class TagWizard(QDialog): m = db.metadata_for_field(k) if k.endswith('_index') or ( m['kind'] == 'field' and m['name'] and - k not in ('ondevice', 'path', 'size', 'sort') and - m['datatype'] not in ('datetime')): + k not in ('ondevice', 'path', 'size', 'sort')): self.columns.append(k) self.completion_values[k]['dt'] = m['datatype'] if m['is_custom']: @@ -203,11 +220,12 @@ class TagWizard(QDialog): h.setAlignment(Qt.AlignCenter) l.addWidget(h, 0, 2, 1, 1) - h = QLabel(_('not')) + h = QLabel(_('op')) h.setToolTip('

    ' + - _('Check this box to indicate that the value must not match ' - 'to use the color. For example, you can check if a tag does ' - 'not exist by entering that tag and checking this box.') + '

    ') + _('Use this box to tell what comparison operation to use. Some ' + 'comparisons cannot be used with certain options. For example, ' + 'if regular expressions are used, only equals and not equals ' + 'are valid.') + '

    ') h.setAlignment(Qt.AlignCenter) l.addWidget(h, 0, 3, 1, 1) @@ -246,7 +264,7 @@ class TagWizard(QDialog): l.addWidget(c, 0, 7, 1, 1) self.andboxes = [] - self.notboxes = [] + self.opboxes = [] self.tagboxes = [] self.colorboxes = [] self.reboxes = [] @@ -284,13 +302,17 @@ class TagWizard(QDialog): w.setText(_('is')) l.addWidget(w, i, 2, 1, 1) - create_widget(QCheckBox, self.notboxes, l, i, 3, None) + w = create_widget(QComboBox, self.opboxes, l, i, 3, None) + w.setMaximumWidth(40) w = create_widget(QCheckBox, self.emptyboxes, l, i, 4, None) w.stateChanged.connect(partial(self.empty_box_changed, line=i-1)) create_widget(MultiCompleteLineEdit, self.tagboxes, l, i, 5, None, align=0) - create_widget(QCheckBox, self.reboxes, l, i, 6, None) + + w = create_widget(QCheckBox, self.reboxes, l, i, 6, None) + w.stateChanged.connect(partial(self.re_box_changed, line=i-1)) + create_widget(QComboBox, self.colorboxes, l, i, 7, self.colors) w = create_widget(QLabel, None, l, maxlines+1, 5, None) @@ -315,20 +337,23 @@ class TagWizard(QDialog): if len(vals) == 2: t, c = vals f = 'tags' - a = n = e = re = False + a = re = e = 0 + op = '=' else: - t,c,f,re,a,n,e = vals + t,c,f,re,a,op,e = vals try: self.colboxes[i].setCurrentIndex(self.colboxes[i].findText(f)) self.colorboxes[i].setCurrentIndex( self.colorboxes[i].findText(c)) self.tagboxes[i].setText(t) self.reboxes[i].setChecked(re == '2') - self.andboxes[i].setChecked(a == '2') - self.notboxes[i].setChecked(n == '2') self.emptyboxes[i].setChecked(e == '2') + self.andboxes[i].setChecked(a == '2') + self.opboxes[i].setCurrentIndex(self.opboxes[i].findText(op)) i += 1 except: + import traceback + traceback.print_exc() pass w = QLabel(_('Preview')) @@ -357,26 +382,6 @@ class TagWizard(QDialog): _('EXCEPTION'), self.mi) self.test_box.setText(t) - def column_changed(self, s, line=None): - k = unicode(s) - if k in self.completion_values: - valbox = self.tagboxes[line] - valbox.update_items_cache(self.completion_values[k]['v']) - if self.completion_values[k]['m']: - valbox.set_separator(', ') - else: - valbox.set_separator(None) - - dt = self.completion_values[k]['dt'] - if dt in ('int', 'float', 'rating', 'bool'): - self.reboxes[line].setChecked(0) - self.reboxes[line].setEnabled(False) - else: - self.reboxes[line].setEnabled(True) - else: - valbox.update_items_cache([]) - valbox.set_separator(None) - def generate_program(self): res = ("program:\n#tag wizard -- do not directly edit\n" " first_non_empty(\n") @@ -384,9 +389,9 @@ class TagWizard(QDialog): was_and = had_line = False line = 0 - for tb, cb, fb, reb, ab, nb, eb in zip( + for tb, cb, fb, reb, ab, ob, eb in zip( self.tagboxes, self.colorboxes, self.colboxes, - self.reboxes, self.andboxes, self.notboxes, self.emptyboxes): + self.reboxes, self.andboxes, self.opboxes, self.emptyboxes): f = unicode(fb.currentText()) if not f: continue @@ -394,14 +399,11 @@ class TagWizard(QDialog): dt = self.completion_values[f]['dt'] c = unicode(cb.currentText()).strip() re = reb.checkState() - a = ab.checkState() - n = nb.checkState() - e = eb.checkState() + a = ab.checkState() + op = unicode(ob.currentText()) + e = eb.checkState() line += 1 - tval = '' if n == 2 else '1' - fval = '1' if n == 2 else '' - if m: tags = [t.strip() for t in unicode(tb.text()).split(m) if t.strip()] if re == 2: @@ -428,8 +430,15 @@ class TagWizard(QDialog): lines[-1] += ',' key = dt + ('.mult' if m else '') + ('.empty' if e else '') + ('.re' if re else '') - template = self.templates[key] - lines.append(template.format(v=tags, f=f, tv=tval, fv=fval, mult=m)) + tval = '1' if op == '=' else '' + fval = '' if op == '=' else '1' + template, is_relational = self.templates[key] + if is_relational: + ltv, eqv, gtv = self.relational_truth_vals[op] + else: + ltv, eqv, gtv = (None, None, None) + lines.append(template.format(v=tags, f=f, tv=tval, fv=fval, mult=m, + ltv=ltv, eqv=eqv, gtv=gtv)) if a == 2: was_and = True @@ -444,9 +453,9 @@ class TagWizard(QDialog): res += ')\n' self.template = res res = '' - for tb, cb, fb, reb, ab, nb, eb in zip( + for tb, cb, fb, reb, ab, ob, eb in zip( self.tagboxes, self.colorboxes, self.colboxes, - self.reboxes, self.andboxes, self.notboxes, self.emptyboxes): + self.reboxes, self.andboxes, self.opboxes, self.emptyboxes): t = unicode(tb.text()).strip() if t.endswith(','): t = t[:-1] @@ -454,15 +463,57 @@ class TagWizard(QDialog): f = unicode(fb.currentText()) re = unicode(reb.checkState()) a = unicode(ab.checkState()) - n = unicode(nb.checkState()) + op = unicode(ob.currentText()) e = unicode(eb.checkState()) if f and (t or e) and (a == '2' or c): res += '#' + t + ':|:' + c + ':|:' + f + ':|:' + re + ':|:' + \ - a + ':|:' + n + ':|:' + e + '\n' + a + ':|:' + op + ':|:' + e + '\n' res += '#else:' + else_txt + '\n' self.template += res return True + def column_changed(self, s, line=None): + k = unicode(s) + valbox = self.tagboxes[line] + if k in self.completion_values: + valbox.update_items_cache(self.completion_values[k]['v']) + if self.completion_values[k]['m']: + valbox.set_separator(', ') + else: + valbox.set_separator(None) + + dt = self.completion_values[k]['dt'] + if dt in ('int', 'float', 'rating', 'bool'): + self.reboxes[line].setChecked(0) + self.reboxes[line].setEnabled(False) + else: + self.reboxes[line].setEnabled(True) + self.fill_in_opbox(line) + else: + valbox.update_items_cache([]) + valbox.set_separator(None) + + def fill_in_opbox(self, line): + opbox = self.opboxes[line] + opbox.clear() + k = unicode(self.colboxes[line].currentText()) + if not k: + return + if k in self.completion_values: + rebox = self.reboxes[line] + ebox = self.emptyboxes[line] + idx = opbox.currentIndex() + if self.completion_values[k]['m'] or \ + rebox.checkState() == 2 or ebox.checkState() == 2: + opbox.addItems(self.relationals[0:2]) + idx = idx if idx < 2 else 0 + else: + opbox.addItems(self.relationals) + opbox.setCurrentIndex(max(idx, 0)) + + def re_box_changed(self, state, line=None): + self.fill_in_opbox(line) + def empty_box_changed(self, state, line=None): if state == 2: self.tagboxes[line].setText('') @@ -472,6 +523,7 @@ class TagWizard(QDialog): else: self.reboxes[line].setEnabled(True) self.tagboxes[line].setEnabled(True) + self.fill_in_opbox(line) def and_box_changed(self, state, line=None): if state == 2: diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 7b9a2ac51c..805f22a503 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -523,7 +523,7 @@ class BuiltinFormat_date(BuiltinFormatterFunction): name = 'format_date' arg_count = 2 doc = _('format_date(val, format_string) -- format the value, which must ' - 'be a date field, using the format_string, returning a string. ' + 'be a date, using the format_string, returning a string. ' 'The formatting codes are: ' 'd : the day as number without a leading zero (1 to 31) ' 'dd : the day as number with a leading zero (01 to 31) ' @@ -538,7 +538,7 @@ class BuiltinFormat_date(BuiltinFormatterFunction): 'iso : the date with time and timezone. Must be the only format present') def evaluate(self, formatter, kwargs, mi, locals, val, format_string): - if not val: + if not val or val == 'None': return '' try: dt = parse_date(val) From b44a25174d5bfc0a1e3d780cefe4da616d679442 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Wed, 1 Jun 2011 06:46:01 +0100 Subject: [PATCH 47/84] Change name of BuiltinFormat_date to use camel case (BuiltinFormatDate) --- src/calibre/manual/template_ref.rst | 2 +- src/calibre/utils/formatter_functions.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/manual/template_ref.rst b/src/calibre/manual/template_ref.rst index 670a7ba791..de6c1fdb2c 100644 --- a/src/calibre/manual/template_ref.rst +++ b/src/calibre/manual/template_ref.rst @@ -34,7 +34,7 @@ booksize() format_date(val, format_string) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -.. autoclass:: BuiltinFormat_date +.. autoclass:: BuiltinFormatDate ondevice() ^^^^^^^^^^^ diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 755bb05cf1..b3e164ce9e 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -520,7 +520,7 @@ class BuiltinSubitems(BuiltinFormatterFunction): pass return ', '.join(sorted(rv, key=sort_key)) -class BuiltinFormat_date(BuiltinFormatterFunction): +class BuiltinFormatDate(BuiltinFormatterFunction): name = 'format_date' arg_count = 2 __doc__ = doc = _('format_date(val, format_string) -- format the value, ' @@ -704,7 +704,7 @@ builtin_divide = BuiltinDivide() builtin_eval = BuiltinEval() builtin_first_non_empty = BuiltinFirstNonEmpty() builtin_field = BuiltinField() -builtin_format_date = BuiltinFormat_date() +builtin_format_date = BuiltinFormatDate() builtin_ifempty = BuiltinIfempty() builtin_in_list = BuiltinInList() builtin_list_item = BuiltinListitem() From 88da0772f0522ebf726a9852cf559379e59ed5cd Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Wed, 1 Jun 2011 16:38:57 +0100 Subject: [PATCH 48/84] Fix regression in templates where id (and other non-standard attributes stuffed into mi) no longer work. --- src/calibre/ebooks/metadata/book/base.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index 69407dcb2e..2c96b8d3d3 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -44,11 +44,16 @@ class SafeFormat(TemplateFormatter): def get_value(self, orig_key, args, kwargs): if not orig_key: return '' - key = orig_key.lower() + orig_key = orig_key.lower() + key = orig_key if key != 'title_sort' and key not in TOP_LEVEL_IDENTIFIERS: key = field_metadata.search_term_to_field_key(key) - if key is None or (self.book and key not in self.book.all_field_keys()): - raise ValueError(_('Value: unknown field ') + orig_key) + if key is None or (self.book and + key not in self.book.all_field_keys()): + if hasattr(self.book, orig_key): + key = orig_key + else: + raise ValueError(_('Value: unknown field ') + orig_key) b = self.book.get_user_metadata(key, False) if b and b['datatype'] == 'int' and self.book.get(key, 0) == 0: v = '' From da66d40ea95b4765b614d6a54e90aea270e4d55c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 10:38:22 -0600 Subject: [PATCH 49/84] Fix #789990 (Series index overwritten when series download turned off) --- src/calibre/ebooks/metadata/sources/identify.py | 2 ++ src/calibre/gui2/actions/edit_metadata.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/calibre/ebooks/metadata/sources/identify.py b/src/calibre/ebooks/metadata/sources/identify.py index 0cc070c3c6..303bb2db6e 100644 --- a/src/calibre/ebooks/metadata/sources/identify.py +++ b/src/calibre/ebooks/metadata/sources/identify.py @@ -408,6 +408,8 @@ def identify(log, abort, # {{{ for f in plugin.prefs['ignore_fields']: if ':' not in f: setattr(result, f, getattr(dummy, f)) + if f == 'series': + result.series_index = dummy.series_index result.relevance_in_source = i result.has_cached_cover_url = (plugin.cached_cover_url_is_reliable and plugin.get_cached_cover_url(result.identifiers) is not diff --git a/src/calibre/gui2/actions/edit_metadata.py b/src/calibre/gui2/actions/edit_metadata.py index ac475cb027..384bf4c9be 100644 --- a/src/calibre/gui2/actions/edit_metadata.py +++ b/src/calibre/gui2/actions/edit_metadata.py @@ -482,6 +482,8 @@ class EditMetadataAction(InterfaceAction): if mi.identifiers: idents.update(mi.identifiers) mi.identifiers = idents + if mi.is_null('series'): + mi.series_index = None db.set_metadata(i, mi, commit=False, set_title=set_title, set_authors=set_authors, notify=False) self.applied_ids.append(i) From efac88d69afa869b94b805292c6a14af0d4bf592 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Wed, 1 Jun 2011 17:43:31 +0100 Subject: [PATCH 50/84] Permit zero-argument template functions. --- .../gui2/preferences/template_functions.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/preferences/template_functions.py b/src/calibre/gui2/preferences/template_functions.py index fcb4c87372..7f310dace0 100644 --- a/src/calibre/gui2/preferences/template_functions.py +++ b/src/calibre/gui2/preferences/template_functions.py @@ -7,7 +7,9 @@ __docformat__ = 'restructuredtext en' import json, traceback -from calibre.gui2 import error_dialog +from PyQt4.Qt import QDialogButtonBox + +from calibre.gui2 import error_dialog, warning_dialog from calibre.gui2.preferences import ConfigWidgetBase, test_widget from calibre.gui2.preferences.template_functions_ui import Ui_Form from calibre.gui2.widgets import PythonHighlighter @@ -152,10 +154,15 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): _('Name already used'), show=True) return if self.argument_count.value() == 0: - error_dialog(self.gui, _('Template functions'), - _('Argument count must be -1 or greater than zero'), - show=True) - return + box = warning_dialog(self.gui, _('Template functions'), + _('Argument count should be -1 or greater than zero.' + 'Setting it to zero means that this function cannot ' + 'be used in single function mode.'), det_msg = '', + show=False) + box.bb.setStandardButtons(box.bb.standardButtons() | QDialogButtonBox.Cancel) + box.det_msg_toggle.setVisible(False) + if not box.exec_(): + return try: prog = unicode(self.program.toPlainText()) cls = compile_user_function(name, unicode(self.documentation.toPlainText()), From 8769908316c095d831babdbf567c5edbe5e487e5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 12:34:35 -0600 Subject: [PATCH 51/84] Implement the wizard to create basic column coloring rules --- src/calibre/gui2/library/coloring.py | 500 +++++++++++++++++++++++++++ 1 file changed, 500 insertions(+) create mode 100644 src/calibre/gui2/library/coloring.py diff --git a/src/calibre/gui2/library/coloring.py b/src/calibre/gui2/library/coloring.py new file mode 100644 index 0000000000..64f5255780 --- /dev/null +++ b/src/calibre/gui2/library/coloring.py @@ -0,0 +1,500 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import (unicode_literals, division, absolute_import, + print_function) +from future_builtins import map + +__license__ = 'GPL v3' +__copyright__ = '2011, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + +import json, binascii, re +from textwrap import dedent + +from PyQt4.Qt import (QWidget, QDialog, QLabel, QGridLayout, QComboBox, + QLineEdit, QIntValidator, QDoubleValidator, QFrame, QColor, Qt, QIcon, + QScrollArea, QPushButton, QVBoxLayout, QDialogButtonBox) + +from calibre.utils.icu import sort_key +from calibre.gui2 import error_dialog + +class Rule(object): # {{{ + + SIGNATURE = '# BasicColorRule():' + + def __init__(self, fm): + self.color = None + self.fm = fm + self.conditions = [] + + def add_condition(self, col, action, val): + if col not in self.fm: + raise ValueError('%r is not a valid column name'%col) + v = self.validate_condition(col, action, val) + if v: + raise ValueError(v) + self.conditions.append((col, action, val)) + + def validate_condition(self, col, action, val): + m = self.fm[col] + dt = m['datatype'] + if (dt in ('int', 'float', 'rating') and action in ('lt', 'eq', 'gt')): + try: + int(val) if dt == 'int' else float(val) + except: + return '%r is not a valid numerical value'%val + + if (dt in ('comments', 'series', 'text', 'enumeration') and 'pattern' + in action): + try: + re.compile(val) + except: + return '%r is not a valid regular expression'%val + + @property + def signature(self): + args = (self.color, self.conditions) + sig = json.dumps(args, ensure_ascii=False) + return self.SIGNATURE + binascii.hexlify(sig.encode('utf-8')) + + @property + def template(self): + if not self.color or not self.conditions: + return None + conditions = map(self.apply_condition, self.conditions) + conditions = (',\n' + ' '*9).join(conditions) + return dedent('''\ + program: + {sig} + test(and('1', + {conditions} + ), {color}, '') + ''').format(sig=self.signature, conditions=conditions, + color=self.color) + + def apply_condition(self, condition): + col, action, val = condition + m = self.fm[col] + dt = m['datatype'] + + if dt == 'bool': + return self.bool_condition(col, action, val) + + if dt in ('int', 'float', 'rating'): + return self.number_condition(col, action, val) + + if dt == 'datetime': + return self.date_condition(col, action, val) + + if dt in ('comments', 'series', 'text', 'enumeration'): + ism = m.get('is_multiple', False) + if ism: + return self.multiple_condition(col, action, val, ism) + return self.text_condition(col, action, val) + + def bool_condition(self, col, action, val): + test = {'is true': 'True', + 'is false': 'False', + 'is undefined': 'None'}[action] + return "strcmp('%s', raw_field('%s'), '', '1', '')"%(test, col) + + def number_condition(self, col, action, val): + lt, eq, gt = { + 'eq': ('', '1', ''), + 'lt': ('1', '', ''), + 'gt': ('', '', '1') + }[action] + lt, eq, gt = '', '1', '' + return "cmp(field('%s'), %s, '%s', '%s', '%s')" % (col, val, lt, eq, gt) + + def date_condition(self, col, action, val): + lt, eq, gt = { + 'eq': ('', '1', ''), + 'lt': ('1', '', ''), + 'gt': ('', '', '1') + }[action] + return "cmp(format_date('%s', 'yyyy-MM-dd'), %s, '%s', '%s', '%s')" % (col, + val, lt, eq, gt) + + def multiple_condition(self, col, action, val, sep): + if action == 'is set': + return "test('%s', '1', '')"%col + if action == 'is not set': + return "test('%s', '', '1')"%col + if action == 'has': + return "str_in_list(field('%s'), '%s', \"%s\", '1', '')"%(col, sep, val) + if action == 'does not have': + return "str_in_list(field('%s'), '%s', \"%s\", '', '1')"%(col, sep, val) + if action == 'has pattern': + return "in_list(field('%s'), '%s', \"%s\", '1', '')"%(col, sep, val) + if action == 'does not have pattern': + return "in_list(field('%s'), '%s', \"%s\", '', '1')"%(col, sep, val) + + def text_condition(self, col, action, val): + if action == 'is set': + return "test('%s', '1', '')"%col + if action == 'is not set': + return "test('%s', '', '1')"%col + if action == 'is': + return "strcmp(field('%s'), \"%s\", '', '1', '')"%(col, val) + if action == 'is not': + return "strcmp(field('%s'), \"%s\", '1', '', '1')"%(col, val) + if action == 'matches pattern': + return "contains(field('%s'), \"%s\", '1', '')"%(col, val) + if action == 'does not match pattern': + return "contains(field('%s'), \"%s\", '', '1')"%(col, val) + +# }}} + +def rule_from_template(fm, template): + ok_lines = [] + for line in template.splitlines(): + if line.startswith(Rule.SIGNATURE): + raw = line[len(Rule.SIGNATURE):].strip() + try: + color, conditions = json.loads(binascii.unhexlify(raw).decode('utf-8')) + except: + continue + r = Rule(fm) + r.color = color + for c in conditions: + try: + r.add_condition(*c) + except: + continue + if r.color and r.conditions: + return r + else: + ok_lines.append(line) + return '\n'.join(ok_lines) + +def conditionable_columns(fm): + for key in fm: + m = fm[key] + dt = m['datatype'] + if m.get('name', False) and dt in ('bool', 'int', 'float', 'rating', 'series', + 'comments', 'text', 'enumeration', 'datetime'): + yield key + + +def displayable_columns(fm): + for key in fm.displayable_field_keys(): + if key not in ('sort', 'author_sort', 'comments', 'formats', + 'identifiers', 'path'): + yield key + +class ConditionEditor(QWidget): + + def __init__(self, fm, parent=None): + QWidget.__init__(self, parent) + self.fm = fm + + self.action_map = { + 'bool' : ( + (_('is true'), 'is true',), + (_('is false'), 'is false'), + (_('is undefined'), 'is undefined') + ), + 'int' : ( + (_('is equal to'), 'eq'), + (_('is less than'), 'lt'), + (_('is greater than'), 'gt') + ), + 'multiple' : ( + (_('has'), 'has'), + (_('does not have'), 'does not have'), + (_('has pattern'), 'has pattern'), + (_('does not have pattern'), 'does not have pattern'), + (_('is set'), 'is set'), + (_('is not set'), 'is not set'), + ), + 'single' : ( + (_('is'), 'is'), + (_('is not'), 'is not'), + (_('matches pattern'), 'matches pattern'), + (_('does not match pattern'), 'does not match pattern'), + (_('is set'), 'is set'), + (_('is not set'), 'is not set'), + ), + } + + for x in ('float', 'rating', 'datetime'): + self.action_map[x] = self.action_map['int'] + + self.l = l = QGridLayout(self) + self.setLayout(l) + + self.l1 = l1 = QLabel(_('If the ')) + l.addWidget(l1, 0, 0) + + self.column_box = QComboBox(self) + l.addWidget(self.column_box, 0, 1) + + self.l2 = l2 = QLabel(_(' column ')) + l.addWidget(l2, 0, 2) + + self.action_box = QComboBox(self) + l.addWidget(self.action_box, 0, 3) + + self.l3 = l3 = QLabel(_(' the value ')) + l.addWidget(l3, 0, 4) + + self.value_box = QLineEdit(self) + l.addWidget(self.value_box, 0, 5) + + self.column_box.addItem('', '') + for key in sorted( + conditionable_columns(fm), + key=lambda x:sort_key(fm[x]['name'])): + self.column_box.addItem(fm[key]['name'], key) + self.column_box.setCurrentIndex(0) + + self.column_box.currentIndexChanged.connect(self.init_action_box) + self.action_box.currentIndexChanged.connect(self.init_value_box) + + for b in (self.column_box, self.action_box): + b.setSizeAdjustPolicy(b.AdjustToMinimumContentsLengthWithIcon) + b.setMinimumContentsLength(15) + + @dynamic_property + def current_col(self): + def fget(self): + idx = self.column_box.currentIndex() + return unicode(self.column_box.itemData(idx).toString()) + def fset(self, val): + for idx in range(self.column_box.count()): + c = unicode(self.column_box.itemData(idx).toString()) + if c == val: + self.column_box.setCurrentIndex(idx) + return + raise ValueError('Column %r not found'%val) + return property(fget=fget, fset=fset) + + @dynamic_property + def current_action(self): + def fget(self): + idx = self.action_box.currentIndex() + return unicode(self.action_box.itemData(idx).toString()) + def fset(self, val): + for idx in range(self.action_box.count()): + c = unicode(self.action_box.itemData(idx).toString()) + if c == val: + self.action_box.setCurrentIndex(idx) + return + raise ValueError('Action %r not valid for current column'%val) + return property(fget=fget, fset=fset) + + @property + def current_val(self): + return unicode(self.value_box.text()).strip() + + @dynamic_property + def condition(self): + + def fget(self): + c, a, v = (self.current_col, self.current_action, + self.current_val) + if not c or not a: + return None + return (c, a, v) + + def fset(self, condition): + c, a, v = condition + if not v: + v = '' + v = v.strip() + self.current_col = c + self.current_action = a + self.value_box.setText(v) + + return property(fget=fget, fset=fset) + + def init_action_box(self): + self.action_box.blockSignals(True) + self.action_box.clear() + self.action_box.addItem('', '') + col = self.current_col + m = self.fm[col] + dt = m['datatype'] + if dt in self.action_map: + actions = self.action_map[dt] + else: + k = 'multiple' if m['is_multiple'] else 'single' + actions = self.action_map[k] + + for text, key in actions: + self.action_box.addItem(text, key) + self.action_box.setCurrentIndex(0) + self.action_box.blockSignals(False) + self.init_value_box() + + def init_value_box(self): + self.value_box.setEnabled(True) + self.value_box.setText('') + self.value_box.setInputMask('') + self.value_box.setValidator(None) + col = self.current_col + m = self.fm[col] + dt = m['datatype'] + action = self.current_action + if not col or not action: + return + tt = '' + if dt in ('int', 'float', 'rating'): + tt = _('Enter a number') + v = QIntValidator if dt == 'int' else QDoubleValidator + self.value_box.setValidator(v(self.value_box)) + elif dt == 'datetime': + self.value_box.setInputMask('9999-99-99') + tt = _('Enter a date in the format YYYY-MM-DD') + else: + tt = _('Enter a string') + if 'pattern' in action: + tt = _('Enter a regular expression') + self.value_box.setToolTip(tt) + if action in ('is set', 'is not set'): + self.value_box.setEnabled(False) + + +class RuleEditor(QDialog): + + def __init__(self, fm, parent=None): + QDialog.__init__(self, parent) + self.fm = fm + + self.setWindowIcon(QIcon(I('format-fill-color.png'))) + self.setWindowTitle(_('Create/edit a column coloring rule')) + + self.l = l = QGridLayout(self) + self.setLayout(l) + + self.l1 = l1 = QLabel(_('Create a coloring rule by' + ' filling in the boxes below')) + l.addWidget(l1, 0, 0, 1, 4) + + self.f1 = QFrame(self) + self.f1.setFrameShape(QFrame.HLine) + l.addWidget(self.f1, 1, 0, 1, 4) + + self.l2 = l2 = QLabel(_('Set the color of the column:')) + l.addWidget(l2, 2, 0) + + self.column_box = QComboBox(self) + l.addWidget(self.column_box, 2, 1) + + self.l3 = l3 = QLabel(_('to')) + l3.setAlignment(Qt.AlignHCenter) + l.addWidget(l3, 2, 2) + + self.color_box = QComboBox(self) + l.addWidget(self.color_box, 2, 3) + + self.l4 = l4 = QLabel( + _('Only if the following conditions are all satisfied:')) + l4.setAlignment(Qt.AlignHCenter) + l.addWidget(l4, 3, 0, 1, 4) + + self.scroll_area = sa = QScrollArea(self) + sa.setMinimumHeight(300) + sa.setMinimumWidth(950) + sa.setWidgetResizable(True) + l.addWidget(sa, 4, 0, 1, 4) + + self.add_button = b = QPushButton(QIcon(I('plus.png')), + _('Add another condition')) + l.addWidget(b, 5, 0, 1, 4) + b.clicked.connect(self.add_blank_condition) + + self.l5 = l5 = QLabel(_('You can disable a condition by' + ' blanking all of its boxes')) + l.addWidget(l5, 6, 0, 1, 4) + + self.bb = bb = QDialogButtonBox( + QDialogButtonBox.Ok|QDialogButtonBox.Cancel) + bb.accepted.connect(self.accept) + bb.rejected.connect(self.reject) + l.addWidget(bb, 7, 0, 1, 4) + + self.conditions_widget = QWidget(self) + sa.setWidget(self.conditions_widget) + self.conditions_widget.setLayout(QVBoxLayout()) + self.conditions = [] + + for b in (self.column_box, self.color_box): + b.setSizeAdjustPolicy(b.AdjustToMinimumContentsLengthWithIcon) + b.setMinimumContentsLength(15) + + for key in sorted( + displayable_columns(fm), + key=lambda x:sort_key(fm[x]['name'])): + name = fm[key]['name'] + if name: + self.column_box.addItem(name, key) + self.column_box.setCurrentIndex(0) + + self.color_box.addItems(QColor.colorNames()) + self.color_box.setCurrentIndex(0) + + self.resize(self.sizeHint()) + + def add_blank_condition(self): + c = ConditionEditor(self.fm, parent=self.conditions_widget) + self.conditions.append(c) + self.conditions_widget.layout().addWidget(c) + + def accept(self): + if self.validate(): + QDialog.accept(self) + + def validate(self): + r = Rule(self.fm) + for c in self.conditions: + condition = c.condition + if condition is not None: + try: + r.add_condition(*condition) + except Exception as e: + import traceback + error_dialog(self, _('Invalid condition'), + _('One of the conditions for this rule is' + ' invalid: %s')%e, + det_msg=traceback.format_exc(), show=True) + return False + if len(r.conditions) < 1: + error_dialog(self, _('No conditions'), + _('You must specify at least one non-empty condition' + ' for this rule'), show=True) + return False + return True + + @property + def rule(self): + r = Rule(self.fm) + r.color = unicode(self.color_box.currentText()) + idx = self.column_box.currentIndex() + col = unicode(self.column_box.itemData(idx).toString()) + for c in self.conditions: + condition = c.condition + if condition is not None: + r.add_condition(*condition) + + return col, r + + + +if __name__ == '__main__': + from PyQt4.Qt import QApplication + app = QApplication([]) + + from calibre.library import db + + d = RuleEditor(db().field_metadata) + d.add_blank_condition() + d.exec_() + + col, r = d.rule + + print ('Column to be colored:', col) + print ('Template:') + print (r.template) + From bb47a2eb59dcfce7ab390dc4258a00649289a5a7 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 12:37:03 -0600 Subject: [PATCH 52/84] ... --- src/calibre/gui2/library/coloring.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/library/coloring.py b/src/calibre/gui2/library/coloring.py index 64f5255780..9dd284481b 100644 --- a/src/calibre/gui2/library/coloring.py +++ b/src/calibre/gui2/library/coloring.py @@ -68,7 +68,7 @@ class Rule(object): # {{{ {sig} test(and('1', {conditions} - ), {color}, '') + ), {color}, ''); ''').format(sig=self.signature, conditions=conditions, color=self.color) From 9dac9bfbc31f7f387856197a33f9dd85fdbb5d5d Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Wed, 1 Jun 2011 19:44:08 +0100 Subject: [PATCH 53/84] Beginning of automatic generation of template_ref.rst --- src/calibre/manual/template_ref_generate.py | 93 +++++++++++++++++++++ src/calibre/utils/formatter_functions.py | 47 ++++++++++- 2 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 src/calibre/manual/template_ref_generate.py diff --git a/src/calibre/manual/template_ref_generate.py b/src/calibre/manual/template_ref_generate.py new file mode 100644 index 0000000000..8618eb9f07 --- /dev/null +++ b/src/calibre/manual/template_ref_generate.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai + +__license__ = 'GPL v3' +__copyright__ = '2008, Kovid Goyal ' + +from collections import defaultdict + +PREAMBLE = '''\ +.. include:: global.rst + +.. _templaterefcalibre: + +Reference for all builtin template language functions +======================================================== + +Here, we document all the builtin functions available in the |app| template language. Every function is implemented as a class in python and you can click the source links to see the source code, in case the documentation is insufficient. The functions are arranged in logical groups by type. + +.. contents:: + :depth: 2 + :local: + +.. module:: calibre.utils.formatter_functions + +''' + +CATEGORY_TEMPLATE = '''\ +{category} +{dashes} + +''' + +FUNCTION_TEMPLATE = '''\ +{fs} +{hats} + +.. autoclass:: {cn} + +''' + +POSTAMBLE = '''\ + +API of the Metadata objects +---------------------------- + +The python implementation of the template functions is passed in a Metadata object. Knowing it's API is useful if you want to define your own template functions. + +.. module:: calibre.ebooks.metadata.book.base + +.. autoclass:: Metadata + :members: + :member-order: bysource + +.. data:: STANDARD_METADATA_FIELDS + + The set of standard metadata fields. + +.. literalinclude:: ../ebooks/metadata/book/__init__.py + :lines: 7- +''' + + +def generate_template_language_help(): + from calibre.utils.formatter_functions import all_builtin_functions + + funcs = defaultdict(dict) + + for func in all_builtin_functions: + class_name = func.__class__.__name__ + func_sig = getattr(func, 'doc') + x = func_sig.find(' -- ') + if x < 0: + print 'No sig for ', class_name + continue + func_sig = func_sig[:x] + func_cat = getattr(func, 'category') + funcs[func_cat][func_sig] = class_name + + output = PREAMBLE + cats = sorted(funcs.keys()) + for cat in cats: + output += CATEGORY_TEMPLATE.format(category=cat, dashes='-'*len(cat)) + entries = [k for k in sorted(funcs[cat].keys())] + for entry in entries: + output += FUNCTION_TEMPLATE.format(fs = entry, cn=funcs[cat][entry], + hats='^'*len(entry)) + + output += POSTAMBLE + print output + return output # and hope that something good happens to it + +if __name__ == '__main__': + generate_template_language_help() \ No newline at end of file diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index b3e164ce9e..78ed4fa306 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -57,6 +57,7 @@ class FormatterFunction(object): doc = _('No documentation provided') name = 'no name provided' + category = 'Unknown' arg_count = 0 def evaluate(self, formatter, kwargs, mi, locals, *args): @@ -87,6 +88,7 @@ class BuiltinFormatterFunction(FormatterFunction): class BuiltinStrcmp(BuiltinFormatterFunction): name = 'strcmp' arg_count = 5 + category = 'Relational' __doc__ = doc = _('strcmp(x, y, lt, eq, gt) -- does a case-insensitive comparison of x ' 'and y as strings. Returns lt if x < y. Returns eq if x == y. ' 'Otherwise returns gt.') @@ -101,6 +103,7 @@ class BuiltinStrcmp(BuiltinFormatterFunction): class BuiltinCmp(BuiltinFormatterFunction): name = 'cmp' + category = 'Relational' arg_count = 5 __doc__ = doc = _('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.') @@ -117,6 +120,7 @@ class BuiltinCmp(BuiltinFormatterFunction): class BuiltinStrcat(BuiltinFormatterFunction): name = 'strcat' arg_count = -1 + category = 'String Manipulation' __doc__ = doc = _('strcat(a, b, ...) -- can take any number of arguments. Returns a ' 'string formed by concatenating all the arguments') @@ -130,6 +134,7 @@ class BuiltinStrcat(BuiltinFormatterFunction): class BuiltinAdd(BuiltinFormatterFunction): name = 'add' arg_count = 2 + category = 'Arithmetic' __doc__ = doc = _('add(x, y) -- returns x + y. Throws an exception if either x or y are not numbers.') def evaluate(self, formatter, kwargs, mi, locals, x, y): @@ -140,6 +145,7 @@ class BuiltinAdd(BuiltinFormatterFunction): class BuiltinSubtract(BuiltinFormatterFunction): name = 'subtract' arg_count = 2 + category = 'Arithmetic' __doc__ = doc = _('subtract(x, y) -- returns x - y. Throws an exception if either x or y are not numbers.') def evaluate(self, formatter, kwargs, mi, locals, x, y): @@ -150,6 +156,7 @@ class BuiltinSubtract(BuiltinFormatterFunction): class BuiltinMultiply(BuiltinFormatterFunction): name = 'multiply' arg_count = 2 + category = 'Arithmetic' __doc__ = doc = _('multiply(x, y) -- returns x * y. Throws an exception if either x or y are not numbers.') def evaluate(self, formatter, kwargs, mi, locals, x, y): @@ -160,6 +167,7 @@ class BuiltinMultiply(BuiltinFormatterFunction): class BuiltinDivide(BuiltinFormatterFunction): name = 'divide' arg_count = 2 + category = 'Arithmetic' __doc__ = doc = _('divide(x, y) -- returns x / y. Throws an exception if either x or y are not numbers.') def evaluate(self, formatter, kwargs, mi, locals, x, y): @@ -170,6 +178,8 @@ class BuiltinDivide(BuiltinFormatterFunction): class BuiltinTemplate(BuiltinFormatterFunction): name = 'template' arg_count = 1 + category = 'Recursion' + __doc__ = doc = _('template(x) -- evaluates x as a template. The evaluation is done ' 'in its own context, meaning that variables are not shared between ' 'the caller and the template evaluation. Because the { and } ' @@ -185,6 +195,7 @@ class BuiltinTemplate(BuiltinFormatterFunction): class BuiltinEval(BuiltinFormatterFunction): name = 'eval' arg_count = 1 + category = 'Recursion' __doc__ = doc = _('eval(template) -- evaluates the template, passing the local ' 'variables (those \'assign\'ed to) instead of the book metadata. ' ' This permits using the template processor to construct complex ' @@ -198,6 +209,7 @@ class BuiltinEval(BuiltinFormatterFunction): class BuiltinAssign(BuiltinFormatterFunction): name = 'assign' arg_count = 2 + category = 'Other' __doc__ = doc = _('assign(id, val) -- assigns val to id, then returns val. ' 'id must be an identifier, not an expression') @@ -208,6 +220,7 @@ class BuiltinAssign(BuiltinFormatterFunction): class BuiltinPrint(BuiltinFormatterFunction): name = 'print' arg_count = -1 + category = 'Other' __doc__ = doc = _('print(a, b, ...) -- prints the arguments to standard output. ' 'Unless you start calibre from the command line (calibre-debug -g), ' 'the output will go to a black hole.') @@ -219,14 +232,16 @@ class BuiltinPrint(BuiltinFormatterFunction): class BuiltinField(BuiltinFormatterFunction): name = 'field' arg_count = 1 + category = 'Get values from metadata' __doc__ = doc = _('field(name) -- returns the metadata field named by name') def evaluate(self, formatter, kwargs, mi, locals, name): return formatter.get_value(name, [], kwargs) -class BuiltinRaw_field(BuiltinFormatterFunction): +class BuiltinRawField(BuiltinFormatterFunction): name = 'raw_field' arg_count = 1 + category = 'Get values from metadata' __doc__ = doc = _('raw_field(name) -- returns the metadata field named by name ' 'without applying any formatting.') @@ -236,6 +251,7 @@ class BuiltinRaw_field(BuiltinFormatterFunction): class BuiltinSubstr(BuiltinFormatterFunction): name = 'substr' arg_count = 3 + category = 'String Manipulation' __doc__ = doc = _('substr(str, start, end) -- returns the start\'th through the end\'th ' 'characters of str. The first character in str is the zero\'th ' 'character. If end is negative, then it indicates that many ' @@ -249,6 +265,7 @@ class BuiltinSubstr(BuiltinFormatterFunction): class BuiltinLookup(BuiltinFormatterFunction): name = 'lookup' arg_count = -1 + category = 'Iterating over values' __doc__ = doc = _('lookup(val, pattern, field, pattern, field, ..., else_field) -- ' 'like switch, except the arguments are field (metadata) names, not ' 'text. The value of the appropriate field will be fetched and used. ' @@ -276,6 +293,7 @@ class BuiltinLookup(BuiltinFormatterFunction): class BuiltinTest(BuiltinFormatterFunction): name = 'test' arg_count = 3 + category = 'If-then-else' __doc__ = doc = _('test(val, text if not empty, text if empty) -- return `text if not ' 'empty` if the field is not empty, otherwise return `text if empty`') @@ -288,6 +306,7 @@ class BuiltinTest(BuiltinFormatterFunction): class BuiltinContains(BuiltinFormatterFunction): name = 'contains' arg_count = 4 + category = 'If-then-else' __doc__ = doc = _('contains(val, 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 ' @@ -303,6 +322,7 @@ class BuiltinContains(BuiltinFormatterFunction): class BuiltinSwitch(BuiltinFormatterFunction): name = 'switch' arg_count = -1 + category = 'Iterating over values' __doc__ = doc = _('switch(val, 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 ' @@ -323,6 +343,7 @@ class BuiltinSwitch(BuiltinFormatterFunction): class BuiltinInList(BuiltinFormatterFunction): name = 'in_list' arg_count = 5 + category = 'List Lookup' __doc__ = 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 ' @@ -340,6 +361,8 @@ class BuiltinInList(BuiltinFormatterFunction): class BuiltinStrInList(BuiltinFormatterFunction): name = 'str_in_list' arg_count = 5 + category = 'List Lookup' + category = 'Iterating over values' __doc__ = doc = _('str_in_list(val, separator, string, found_val, not_found_val) -- ' 'treat val as a list of items separated by separator, ' 'comparing the string against each value in the list. If the ' @@ -360,6 +383,7 @@ class BuiltinStrInList(BuiltinFormatterFunction): class BuiltinRe(BuiltinFormatterFunction): name = 're' arg_count = 3 + category = 'String Manipulation' __doc__ = doc = _('re(val, pattern, replacement) -- return the field after applying ' 'the regular expression. All instances of `pattern` are replaced ' 'with `replacement`. As in all of calibre, these are ' @@ -371,6 +395,7 @@ class BuiltinRe(BuiltinFormatterFunction): class BuiltinIfempty(BuiltinFormatterFunction): name = 'ifempty' arg_count = 2 + category = 'If-then-else' __doc__ = doc = _('ifempty(val, text if empty) -- return val if val is not empty, ' 'otherwise return `text if empty`') @@ -383,6 +408,7 @@ class BuiltinIfempty(BuiltinFormatterFunction): class BuiltinShorten(BuiltinFormatterFunction): name = 'shorten' arg_count = 4 + category = 'String Manipulation' __doc__ = doc = _('shorten(val, 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 ' @@ -408,6 +434,7 @@ class BuiltinShorten(BuiltinFormatterFunction): class BuiltinCount(BuiltinFormatterFunction): name = 'count' arg_count = 2 + category = 'List Manipulation' __doc__ = doc = _('count(val, 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 ' @@ -419,6 +446,7 @@ class BuiltinCount(BuiltinFormatterFunction): class BuiltinListitem(BuiltinFormatterFunction): name = 'list_item' arg_count = 3 + category = 'List Lookup' __doc__ = doc = _('list_item(val, 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 ' @@ -439,6 +467,7 @@ class BuiltinListitem(BuiltinFormatterFunction): class BuiltinSelect(BuiltinFormatterFunction): name = 'select' arg_count = 2 + category = 'List Lookup' __doc__ = doc = _('select(val, key) -- interpret the value as a comma-separated list ' 'of items, with the items being "id:value". Find the pair with the' 'id equal to key, and return the corresponding value.' @@ -456,6 +485,7 @@ class BuiltinSelect(BuiltinFormatterFunction): class BuiltinSublist(BuiltinFormatterFunction): name = 'sublist' arg_count = 4 + category = 'List Manipulation' __doc__ = doc = _('sublist(val, start_index, end_index, separator) -- interpret the ' 'value as a list of items separated by `separator`, returning a ' 'new list made from the `start_index` to the `end_index` item. ' @@ -486,6 +516,7 @@ class BuiltinSublist(BuiltinFormatterFunction): class BuiltinSubitems(BuiltinFormatterFunction): name = 'subitems' arg_count = 3 + category = 'List Manipulation' __doc__ = doc = _('subitems(val, start_index, end_index) -- This function is used to ' 'break apart lists of items such as genres. It interprets the value ' 'as a comma-separated list of items, where each item is a period-' @@ -523,6 +554,7 @@ class BuiltinSubitems(BuiltinFormatterFunction): class BuiltinFormatDate(BuiltinFormatterFunction): name = 'format_date' arg_count = 2 + category = 'Get values from metadata' __doc__ = doc = _('format_date(val, format_string) -- format the value, ' 'which must be a date, using the format_string, returning a string. ' 'The formatting codes are: ' @@ -551,6 +583,7 @@ class BuiltinFormatDate(BuiltinFormatterFunction): class BuiltinUppercase(BuiltinFormatterFunction): name = 'uppercase' arg_count = 1 + category = 'String case changes' __doc__ = doc = _('uppercase(val) -- return value of the field in upper case') def evaluate(self, formatter, kwargs, mi, locals, val): @@ -559,6 +592,7 @@ class BuiltinUppercase(BuiltinFormatterFunction): class BuiltinLowercase(BuiltinFormatterFunction): name = 'lowercase' arg_count = 1 + category = 'String case changes' __doc__ = doc = _('lowercase(val) -- return value of the field in lower case') def evaluate(self, formatter, kwargs, mi, locals, val): @@ -567,6 +601,7 @@ class BuiltinLowercase(BuiltinFormatterFunction): class BuiltinTitlecase(BuiltinFormatterFunction): name = 'titlecase' arg_count = 1 + category = 'String case changes' __doc__ = doc = _('titlecase(val) -- return value of the field in title case') def evaluate(self, formatter, kwargs, mi, locals, val): @@ -575,6 +610,7 @@ class BuiltinTitlecase(BuiltinFormatterFunction): class BuiltinCapitalize(BuiltinFormatterFunction): name = 'capitalize' arg_count = 1 + category = 'String case changes' __doc__ = doc = _('capitalize(val) -- return value of the field capitalized') def evaluate(self, formatter, kwargs, mi, locals, val): @@ -583,6 +619,7 @@ class BuiltinCapitalize(BuiltinFormatterFunction): class BuiltinBooksize(BuiltinFormatterFunction): name = 'booksize' arg_count = 0 + category = 'Get values from metadata' __doc__ = doc = _('booksize() -- return value of the size field') def evaluate(self, formatter, kwargs, mi, locals): @@ -596,6 +633,7 @@ class BuiltinBooksize(BuiltinFormatterFunction): class BuiltinOndevice(BuiltinFormatterFunction): name = 'ondevice' arg_count = 0 + category = 'Get values from metadata' __doc__ = doc = _('ondevice() -- return Yes if ondevice is set, otherwise return ' 'the empty string') @@ -607,6 +645,7 @@ class BuiltinOndevice(BuiltinFormatterFunction): class BuiltinFirstNonEmpty(BuiltinFormatterFunction): name = 'first_non_empty' arg_count = -1 + category = 'Iterating over values' __doc__ = 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.' @@ -623,6 +662,7 @@ class BuiltinFirstNonEmpty(BuiltinFormatterFunction): class BuiltinAnd(BuiltinFormatterFunction): name = 'and' arg_count = -1 + category = 'Boolean' __doc__ = doc = _('and(value, value, ...) -- ' 'returns the string "1" if all values are not empty, otherwise ' 'returns the empty string. This function works well with test or ' @@ -639,6 +679,7 @@ class BuiltinAnd(BuiltinFormatterFunction): class BuiltinOr(BuiltinFormatterFunction): name = 'or' arg_count = -1 + category = 'Boolean' __doc__ = doc = _('or(value, value, ...) -- ' 'returns the string "1" if any value is not empty, otherwise ' 'returns the empty string. This function works well with test or ' @@ -655,6 +696,7 @@ class BuiltinOr(BuiltinFormatterFunction): class BuiltinNot(BuiltinFormatterFunction): name = 'not' arg_count = 1 + category = 'Boolean' __doc__ = doc = _('not(value) -- ' 'returns the string "1" if the value is empty, otherwise ' 'returns the empty string. This function works well with test or ' @@ -671,6 +713,7 @@ class BuiltinNot(BuiltinFormatterFunction): class BuiltinMergeLists(BuiltinFormatterFunction): name = 'merge_lists' arg_count = 3 + category = 'List Manipulation' __doc__ = doc = _('merge_lists(list1, list2, separator) -- ' 'return a list made by merging the items in list1 and list2, ' 'removing duplicate items using a case-insensitive compare. If ' @@ -716,7 +759,7 @@ builtin_not = BuiltinNot() builtin_ondevice = BuiltinOndevice() builtin_or = BuiltinOr() builtin_print = BuiltinPrint() -builtin_raw_field = BuiltinRaw_field() +builtin_raw_field = BuiltinRawField() builtin_re = BuiltinRe() builtin_select = BuiltinSelect() builtin_shorten = BuiltinShorten() From a1afc8b7eb5dcb7f65d82e6e7252bb3b070afa2e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 14:23:09 -0600 Subject: [PATCH 54/84] ... --- src/calibre/gui2/library/coloring.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/calibre/gui2/library/coloring.py b/src/calibre/gui2/library/coloring.py index 9dd284481b..7fb45d9ba6 100644 --- a/src/calibre/gui2/library/coloring.py +++ b/src/calibre/gui2/library/coloring.py @@ -66,7 +66,7 @@ class Rule(object): # {{{ return dedent('''\ program: {sig} - test(and('1', + test(and( {conditions} ), {color}, ''); ''').format(sig=self.signature, conditions=conditions, @@ -113,7 +113,7 @@ class Rule(object): # {{{ 'lt': ('1', '', ''), 'gt': ('', '', '1') }[action] - return "cmp(format_date('%s', 'yyyy-MM-dd'), %s, '%s', '%s', '%s')" % (col, + return "cmp(format_date(raw_field('%s'), 'yyyy-MM-dd'), %s, '%s', '%s', '%s')" % (col, val, lt, eq, gt) def multiple_condition(self, col, action, val, sep): @@ -246,7 +246,7 @@ class ConditionEditor(QWidget): for key in sorted( conditionable_columns(fm), key=lambda x:sort_key(fm[x]['name'])): - self.column_box.addItem(fm[key]['name'], key) + self.column_box.addItem(key, key) self.column_box.setCurrentIndex(0) self.column_box.currentIndexChanged.connect(self.init_action_box) @@ -352,7 +352,8 @@ class ConditionEditor(QWidget): if 'pattern' in action: tt = _('Enter a regular expression') self.value_box.setToolTip(tt) - if action in ('is set', 'is not set'): + if action in ('is set', 'is not set', 'is true', 'is false', + 'is undefined'): self.value_box.setEnabled(False) @@ -418,6 +419,7 @@ class RuleEditor(QDialog): self.conditions_widget = QWidget(self) sa.setWidget(self.conditions_widget) self.conditions_widget.setLayout(QVBoxLayout()) + self.conditions_widget.layout().setAlignment(Qt.AlignTop) self.conditions = [] for b in (self.column_box, self.color_box): @@ -429,7 +431,7 @@ class RuleEditor(QDialog): key=lambda x:sort_key(fm[x]['name'])): name = fm[key]['name'] if name: - self.column_box.addItem(name, key) + self.column_box.addItem(key, key) self.column_box.setCurrentIndex(0) self.color_box.addItems(QColor.colorNames()) From 739693060d2373cccf0f091fa7100842b3cb2ab2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 15:18:49 -0600 Subject: [PATCH 55/84] Autogen the template function docs --- src/calibre/manual/custom.py | 12 +- src/calibre/manual/template_ref.rst | 266 -------------------- src/calibre/manual/template_ref_generate.py | 5 +- 3 files changed, 13 insertions(+), 270 deletions(-) delete mode 100644 src/calibre/manual/template_ref.rst diff --git a/src/calibre/manual/custom.py b/src/calibre/manual/custom.py index f5db6dd0c2..4788889972 100644 --- a/src/calibre/manual/custom.py +++ b/src/calibre/manual/custom.py @@ -240,11 +240,21 @@ def cli_docs(app): raw += '\n'+'\n'.join(lines) update_cli_doc(os.path.join('cli', cmd+'.rst'), raw, info) +def generate_docs(app): + cli_docs(app) + template_docs(app) + +def template_docs(app): + from template_ref_generate import generate_template_language_help + info = app.builder.info + raw = generate_template_language_help() + update_cli_doc('template_ref.rst', raw, info) + def setup(app): app.add_config_value('epub_cover', None, False) app.add_builder(EPUBHelpBuilder) app.connect('doctree-read', substitute) - app.connect('builder-inited', cli_docs) + app.connect('builder-inited', generate_docs) app.connect('build-finished', finished) def finished(app, exception): diff --git a/src/calibre/manual/template_ref.rst b/src/calibre/manual/template_ref.rst deleted file mode 100644 index de6c1fdb2c..0000000000 --- a/src/calibre/manual/template_ref.rst +++ /dev/null @@ -1,266 +0,0 @@ -.. include:: global.rst - -.. _templaterefcalibre: - -Reference for all builtin template language functions -======================================================== - -Here, we document all the builtin functions available in the |app| template language. Every function is implemented as a class in python and you can click the source links to see the source code, in case the documentation is insufficient. The functions are arranged in logical groups by type. - -.. contents:: - :depth: 2 - :local: - -.. module:: calibre.utils.formatter_functions - -Get values from metadata --------------------------- - -field(name) -^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinField - -raw_field(name) -^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinRaw_field - -booksize() -^^^^^^^^^^^^ - -.. autoclass:: BuiltinBooksize - -format_date(val, format_string) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinFormatDate - -ondevice() -^^^^^^^^^^^ - -.. autoclass:: BuiltinOndevice - -Arithmetic -------------- - -add(x, y) -^^^^^^^^^^^^^ -.. autoclass:: BuiltinAdd - -subtract(x, y) -^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinSubtract - -multiply(x, y) -^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinMultiply - -divide(x, y) -^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinDivide - -Boolean ------------- - -and(value1, value2, ...) -^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinAnd - -or(value1, value2, ...) -^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinOr - -not(value) -^^^^^^^^^^^^^ - -.. autoclass:: BuiltinNot - -If-then-else ------------------ - -contains(val, pattern, text if match, text if not match) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinContains - -test(val, text if not empty, text if empty) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinTest - -ifempty(val, text if empty) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinIfempty - -Iterating over values ------------------------- - -first_non_empty(value, value, ...) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinFirstNonEmpty - -lookup(val, pattern, field, pattern, field, ..., else_field) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinLookup - -switch(val, pattern, value, pattern, value, ..., else_value) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinSwitch - -List Lookup ---------------- - -in_list(val, separator, pattern, found_val, not_found_val) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinInList - -str_in_list(val, separator, string, found_val, not_found_val) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinStrInList - -list_item(val, index, separator) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinListitem - -select(val, key) -^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinSelect - - -List Manipulation -------------------- - -count(val, separator) -^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinCount - -merge_lists(list1, list2, separator) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinMergeLists - -sublist(val, start_index, end_index, separator) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinSublist - -subitems(val, start_index, end_index) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinSubitems - -Recursion -------------- - -eval(template) -^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinEval - -template(x) -^^^^^^^^^^^^ - -.. autoclass:: BuiltinTemplate - -Relational ------------ - -cmp(x, y, lt, eq, gt) -^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinCmp - -strcmp(x, y, lt, eq, gt) -^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinStrcmp - -String case changes ---------------------- - -lowercase(val) -^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinLowercase - -uppercase(val) -^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinUppercase - -titlecase(val) -^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinTitlecase - -capitalize(val) -^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinCapitalize - -String Manipulation ---------------------- - -re(val, pattern, replacement) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinRe - -shorten(val, left chars, middle text, right chars) -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinShorten - -substr(str, start, end) -^^^^^^^^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinSubstr - - -Other --------- - -assign(id, val) -^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinAssign - -print(a, b, ...) -^^^^^^^^^^^^^^^^^ - -.. autoclass:: BuiltinPrint - - -API of the Metadata objects ----------------------------- - -The python implementation of the template functions is passed in a Metadata object. Knowing it's API is useful if you want to define your own template functions. - -.. module:: calibre.ebooks.metadata.book.base - -.. autoclass:: Metadata - :members: - :member-order: bysource - -.. data:: STANDARD_METADATA_FIELDS - - The set of standard metadata fields. - -.. literalinclude:: ../ebooks/metadata/book/__init__.py - :lines: 7- - diff --git a/src/calibre/manual/template_ref_generate.py b/src/calibre/manual/template_ref_generate.py index 8618eb9f07..742ab1fd54 100644 --- a/src/calibre/manual/template_ref_generate.py +++ b/src/calibre/manual/template_ref_generate.py @@ -86,8 +86,7 @@ def generate_template_language_help(): hats='^'*len(entry)) output += POSTAMBLE - print output - return output # and hope that something good happens to it + return output if __name__ == '__main__': - generate_template_language_help() \ No newline at end of file + generate_template_language_help() From cff2fcb6eb1caf0529159a65aa68d78aec5dd9da Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 15:19:24 -0600 Subject: [PATCH 56/84] ... --- .bzrignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.bzrignore b/.bzrignore index 005391bf46..d2a2d592dd 100644 --- a/.bzrignore +++ b/.bzrignore @@ -4,6 +4,7 @@ src/calibre/plugins resources/images.qrc src/calibre/manual/.build/ src/calibre/manual/cli/ +src/calibre/manual/template_ref.rst build dist docs @@ -31,4 +32,4 @@ nbproject/ .pydevproject .settings/ *.DS_Store -calibre_plugins/ \ No newline at end of file +calibre_plugins/ From 04c5fcc2eee8152840f723137497156dfa11b98b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 15:24:49 -0600 Subject: [PATCH 57/84] Split non-GUI part of the coloring code into a non GUI module --- src/calibre/gui2/library/coloring.py | 171 +------------------------ src/calibre/library/coloring.py | 178 +++++++++++++++++++++++++++ 2 files changed, 180 insertions(+), 169 deletions(-) create mode 100644 src/calibre/library/coloring.py diff --git a/src/calibre/gui2/library/coloring.py b/src/calibre/gui2/library/coloring.py index 7fb45d9ba6..4c8d678b19 100644 --- a/src/calibre/gui2/library/coloring.py +++ b/src/calibre/gui2/library/coloring.py @@ -2,186 +2,19 @@ # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai from __future__ import (unicode_literals, division, absolute_import, print_function) -from future_builtins import map __license__ = 'GPL v3' __copyright__ = '2011, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import json, binascii, re -from textwrap import dedent - from PyQt4.Qt import (QWidget, QDialog, QLabel, QGridLayout, QComboBox, QLineEdit, QIntValidator, QDoubleValidator, QFrame, QColor, Qt, QIcon, QScrollArea, QPushButton, QVBoxLayout, QDialogButtonBox) from calibre.utils.icu import sort_key from calibre.gui2 import error_dialog - -class Rule(object): # {{{ - - SIGNATURE = '# BasicColorRule():' - - def __init__(self, fm): - self.color = None - self.fm = fm - self.conditions = [] - - def add_condition(self, col, action, val): - if col not in self.fm: - raise ValueError('%r is not a valid column name'%col) - v = self.validate_condition(col, action, val) - if v: - raise ValueError(v) - self.conditions.append((col, action, val)) - - def validate_condition(self, col, action, val): - m = self.fm[col] - dt = m['datatype'] - if (dt in ('int', 'float', 'rating') and action in ('lt', 'eq', 'gt')): - try: - int(val) if dt == 'int' else float(val) - except: - return '%r is not a valid numerical value'%val - - if (dt in ('comments', 'series', 'text', 'enumeration') and 'pattern' - in action): - try: - re.compile(val) - except: - return '%r is not a valid regular expression'%val - - @property - def signature(self): - args = (self.color, self.conditions) - sig = json.dumps(args, ensure_ascii=False) - return self.SIGNATURE + binascii.hexlify(sig.encode('utf-8')) - - @property - def template(self): - if not self.color or not self.conditions: - return None - conditions = map(self.apply_condition, self.conditions) - conditions = (',\n' + ' '*9).join(conditions) - return dedent('''\ - program: - {sig} - test(and( - {conditions} - ), {color}, ''); - ''').format(sig=self.signature, conditions=conditions, - color=self.color) - - def apply_condition(self, condition): - col, action, val = condition - m = self.fm[col] - dt = m['datatype'] - - if dt == 'bool': - return self.bool_condition(col, action, val) - - if dt in ('int', 'float', 'rating'): - return self.number_condition(col, action, val) - - if dt == 'datetime': - return self.date_condition(col, action, val) - - if dt in ('comments', 'series', 'text', 'enumeration'): - ism = m.get('is_multiple', False) - if ism: - return self.multiple_condition(col, action, val, ism) - return self.text_condition(col, action, val) - - def bool_condition(self, col, action, val): - test = {'is true': 'True', - 'is false': 'False', - 'is undefined': 'None'}[action] - return "strcmp('%s', raw_field('%s'), '', '1', '')"%(test, col) - - def number_condition(self, col, action, val): - lt, eq, gt = { - 'eq': ('', '1', ''), - 'lt': ('1', '', ''), - 'gt': ('', '', '1') - }[action] - lt, eq, gt = '', '1', '' - return "cmp(field('%s'), %s, '%s', '%s', '%s')" % (col, val, lt, eq, gt) - - def date_condition(self, col, action, val): - lt, eq, gt = { - 'eq': ('', '1', ''), - 'lt': ('1', '', ''), - 'gt': ('', '', '1') - }[action] - return "cmp(format_date(raw_field('%s'), 'yyyy-MM-dd'), %s, '%s', '%s', '%s')" % (col, - val, lt, eq, gt) - - def multiple_condition(self, col, action, val, sep): - if action == 'is set': - return "test('%s', '1', '')"%col - if action == 'is not set': - return "test('%s', '', '1')"%col - if action == 'has': - return "str_in_list(field('%s'), '%s', \"%s\", '1', '')"%(col, sep, val) - if action == 'does not have': - return "str_in_list(field('%s'), '%s', \"%s\", '', '1')"%(col, sep, val) - if action == 'has pattern': - return "in_list(field('%s'), '%s', \"%s\", '1', '')"%(col, sep, val) - if action == 'does not have pattern': - return "in_list(field('%s'), '%s', \"%s\", '', '1')"%(col, sep, val) - - def text_condition(self, col, action, val): - if action == 'is set': - return "test('%s', '1', '')"%col - if action == 'is not set': - return "test('%s', '', '1')"%col - if action == 'is': - return "strcmp(field('%s'), \"%s\", '', '1', '')"%(col, val) - if action == 'is not': - return "strcmp(field('%s'), \"%s\", '1', '', '1')"%(col, val) - if action == 'matches pattern': - return "contains(field('%s'), \"%s\", '1', '')"%(col, val) - if action == 'does not match pattern': - return "contains(field('%s'), \"%s\", '', '1')"%(col, val) - -# }}} - -def rule_from_template(fm, template): - ok_lines = [] - for line in template.splitlines(): - if line.startswith(Rule.SIGNATURE): - raw = line[len(Rule.SIGNATURE):].strip() - try: - color, conditions = json.loads(binascii.unhexlify(raw).decode('utf-8')) - except: - continue - r = Rule(fm) - r.color = color - for c in conditions: - try: - r.add_condition(*c) - except: - continue - if r.color and r.conditions: - return r - else: - ok_lines.append(line) - return '\n'.join(ok_lines) - -def conditionable_columns(fm): - for key in fm: - m = fm[key] - dt = m['datatype'] - if m.get('name', False) and dt in ('bool', 'int', 'float', 'rating', 'series', - 'comments', 'text', 'enumeration', 'datetime'): - yield key - - -def displayable_columns(fm): - for key in fm.displayable_field_keys(): - if key not in ('sort', 'author_sort', 'comments', 'formats', - 'identifiers', 'path'): - yield key +from calibre.library.coloring import (Rule, conditionable_columns, + displayable_columns) class ConditionEditor(QWidget): diff --git a/src/calibre/library/coloring.py b/src/calibre/library/coloring.py new file mode 100644 index 0000000000..7e2b0f67c6 --- /dev/null +++ b/src/calibre/library/coloring.py @@ -0,0 +1,178 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import (unicode_literals, division, absolute_import, + print_function) +from future_builtins import map + +__license__ = 'GPL v3' +__copyright__ = '2011, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + +import binascii, re, json +from textwrap import dedent + +class Rule(object): # {{{ + + SIGNATURE = '# BasicColorRule():' + + def __init__(self, fm, color=None): + self.color = color + self.fm = fm + self.conditions = [] + + def add_condition(self, col, action, val): + if col not in self.fm: + raise ValueError('%r is not a valid column name'%col) + v = self.validate_condition(col, action, val) + if v: + raise ValueError(v) + self.conditions.append((col, action, val)) + + def validate_condition(self, col, action, val): + m = self.fm[col] + dt = m['datatype'] + if (dt in ('int', 'float', 'rating') and action in ('lt', 'eq', 'gt')): + try: + int(val) if dt == 'int' else float(val) + except: + return '%r is not a valid numerical value'%val + + if (dt in ('comments', 'series', 'text', 'enumeration') and 'pattern' + in action): + try: + re.compile(val) + except: + return '%r is not a valid regular expression'%val + + @property + def signature(self): + args = (self.color, self.conditions) + sig = json.dumps(args, ensure_ascii=False) + return self.SIGNATURE + binascii.hexlify(sig.encode('utf-8')) + + @property + def template(self): + if not self.color or not self.conditions: + return None + conditions = map(self.apply_condition, self.conditions) + conditions = (',\n' + ' '*9).join(conditions) + return dedent('''\ + program: + {sig} + test(and( + {conditions} + ), {color}, ''); + ''').format(sig=self.signature, conditions=conditions, + color=self.color) + + def apply_condition(self, condition): + col, action, val = condition + m = self.fm[col] + dt = m['datatype'] + + if dt == 'bool': + return self.bool_condition(col, action, val) + + if dt in ('int', 'float', 'rating'): + return self.number_condition(col, action, val) + + if dt == 'datetime': + return self.date_condition(col, action, val) + + if dt in ('comments', 'series', 'text', 'enumeration'): + ism = m.get('is_multiple', False) + if ism: + return self.multiple_condition(col, action, val, ism) + return self.text_condition(col, action, val) + + def bool_condition(self, col, action, val): + test = {'is true': 'True', + 'is false': 'False', + 'is undefined': 'None'}[action] + return "strcmp('%s', raw_field('%s'), '', '1', '')"%(test, col) + + def number_condition(self, col, action, val): + lt, eq, gt = { + 'eq': ('', '1', ''), + 'lt': ('1', '', ''), + 'gt': ('', '', '1') + }[action] + lt, eq, gt = '', '1', '' + return "cmp(field('%s'), %s, '%s', '%s', '%s')" % (col, val, lt, eq, gt) + + def date_condition(self, col, action, val): + lt, eq, gt = { + 'eq': ('', '1', ''), + 'lt': ('1', '', ''), + 'gt': ('', '', '1') + }[action] + return "cmp(format_date(raw_field('%s'), 'yyyy-MM-dd'), %s, '%s', '%s', '%s')" % (col, + val, lt, eq, gt) + + def multiple_condition(self, col, action, val, sep): + if action == 'is set': + return "test('%s', '1', '')"%col + if action == 'is not set': + return "test('%s', '', '1')"%col + if action == 'has': + return "str_in_list(field('%s'), '%s', \"%s\", '1', '')"%(col, sep, val) + if action == 'does not have': + return "str_in_list(field('%s'), '%s', \"%s\", '', '1')"%(col, sep, val) + if action == 'has pattern': + return "in_list(field('%s'), '%s', \"%s\", '1', '')"%(col, sep, val) + if action == 'does not have pattern': + return "in_list(field('%s'), '%s', \"%s\", '', '1')"%(col, sep, val) + + def text_condition(self, col, action, val): + if action == 'is set': + return "test('%s', '1', '')"%col + if action == 'is not set': + return "test('%s', '', '1')"%col + if action == 'is': + return "strcmp(field('%s'), \"%s\", '', '1', '')"%(col, val) + if action == 'is not': + return "strcmp(field('%s'), \"%s\", '1', '', '1')"%(col, val) + if action == 'matches pattern': + return "contains(field('%s'), \"%s\", '1', '')"%(col, val) + if action == 'does not match pattern': + return "contains(field('%s'), \"%s\", '', '1')"%(col, val) + +# }}} + +def rule_from_template(fm, template): + ok_lines = [] + for line in template.splitlines(): + if line.startswith(Rule.SIGNATURE): + raw = line[len(Rule.SIGNATURE):].strip() + try: + color, conditions = json.loads(binascii.unhexlify(raw).decode('utf-8')) + except: + continue + r = Rule(fm) + r.color = color + for c in conditions: + try: + r.add_condition(*c) + except: + continue + if r.color and r.conditions: + return r + else: + ok_lines.append(line) + return '\n'.join(ok_lines) + +def conditionable_columns(fm): + for key in fm: + m = fm[key] + dt = m['datatype'] + if m.get('name', False) and dt in ('bool', 'int', 'float', 'rating', 'series', + 'comments', 'text', 'enumeration', 'datetime'): + yield key + + +def displayable_columns(fm): + for key in fm.displayable_field_keys(): + if key not in ('sort', 'author_sort', 'comments', 'formats', + 'identifiers', 'path'): + yield key + From fcc6ec5de59a7424eaf685c2c709530b4ec5b7c2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 15:28:54 -0600 Subject: [PATCH 58/84] ... --- src/calibre/gui2/library/coloring.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/library/coloring.py b/src/calibre/gui2/library/coloring.py index 4c8d678b19..98ac7380a5 100644 --- a/src/calibre/gui2/library/coloring.py +++ b/src/calibre/gui2/library/coloring.py @@ -16,7 +16,7 @@ from calibre.gui2 import error_dialog from calibre.library.coloring import (Rule, conditionable_columns, displayable_columns) -class ConditionEditor(QWidget): +class ConditionEditor(QWidget): # {{{ def __init__(self, fm, parent=None): QWidget.__init__(self, parent) @@ -188,9 +188,9 @@ class ConditionEditor(QWidget): if action in ('is set', 'is not set', 'is true', 'is false', 'is undefined'): self.value_box.setEnabled(False) +# }}} - -class RuleEditor(QDialog): +class RuleEditor(QDialog): # {{{ def __init__(self, fm, parent=None): QDialog.__init__(self, parent) @@ -314,8 +314,13 @@ class RuleEditor(QDialog): r.add_condition(*condition) return col, r +# }}} +class EditRules(QWidget): + def __init__(self, db, parent=None): + QWidget.__init__(self, parent) + self.db = db if __name__ == '__main__': from PyQt4.Qt import QApplication From d559f7df719643ac46101ed4ce157ac0549ceae9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 15:29:31 -0600 Subject: [PATCH 59/84] ... --- src/calibre/gui2/{library => preferences}/coloring.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/calibre/gui2/{library => preferences}/coloring.py (100%) diff --git a/src/calibre/gui2/library/coloring.py b/src/calibre/gui2/preferences/coloring.py similarity index 100% rename from src/calibre/gui2/library/coloring.py rename to src/calibre/gui2/preferences/coloring.py From fc8f268ee9ce4ce77f1c4050f2da554b0a226e03 Mon Sep 17 00:00:00 2001 From: John Schember Date: Wed, 1 Jun 2011 18:22:55 -0400 Subject: [PATCH 60/84] Store: EpubBud store. --- src/calibre/customize/builtins.py | 10 +++ src/calibre/gui2/store/epubbud_plugin.py | 81 ++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 src/calibre/gui2/store/epubbud_plugin.py diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 5cde30f72e..9ebec5e7e8 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -1227,6 +1227,15 @@ class StoreEHarlequinStore(StoreBase): formats = ['EPUB', 'PDF'] affiliate = True +class StoreEpubBudStore(StoreBase): + name = 'ePub Bud' + description = 'Well, it\'s pretty much just "YouTube for Children\'s eBooks. A not-for-profit organization devoted to brining self published childrens books to the world.' + actual_plugin = 'calibre.gui2.store.epubbud_plugin:EpubBudStore' + + drm_free_only = True + headquarters = 'US' + formats = ['EPUB'] + class StoreFeedbooksStore(StoreBase): name = 'Feedbooks' 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.' @@ -1422,6 +1431,7 @@ plugins += [ StoreEBookShoppeUKStore, StoreEPubBuyDEStore, StoreEHarlequinStore, + StoreEpubBudStore, StoreFeedbooksStore, StoreFoylesUKStore, StoreGandalfStore, diff --git a/src/calibre/gui2/store/epubbud_plugin.py b/src/calibre/gui2/store/epubbud_plugin.py new file mode 100644 index 0000000000..6c20f5150d --- /dev/null +++ b/src/calibre/gui2/store/epubbud_plugin.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- + +from __future__ import (unicode_literals, division, absolute_import, print_function) + +__license__ = 'GPL 3' +__copyright__ = '2011, John Schember ' +__docformat__ = 'restructuredtext en' + +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 EpubBudStore(BasicStoreConfig, StorePlugin): + + def open(self, parent=None, detail_item=None, external=False): + url = 'http://epubbud.com/' + + if detail_item: + url = 'http://epubbud.com/book.php?g=' + detail_item + + if external or self.config.get('open_external', False): + open_url(QUrl(url_slash_cleaner(detail_item if detail_item else url))) + else: + d = WebStoreDialog(self.gui, url, parent, detail_item) + d.setWindowTitle(self.name) + d.set_tags(self.config.get('tags', '')) + d.exec_() + + def search(self, query, max_results=10, timeout=60): + ''' + OPDS based search. + + We really should get the catelog from http://pragprog.com/catalog.opds + and look for the application/opensearchdescription+xml entry. + Then get the opensearch description to get the search url and + format. However, we are going to be lazy and hard code it. + ''' + url = 'http://www.epubbud.com/search.php?format=atom&q=' + urllib.quote_plus(query) + + br = browser() + + counter = max_results + with closing(br.open(url, timeout=timeout)) as f: + # Use html instead of etree as html allows us + # to ignore the namespace easily. + doc = html.fromstring(f.read()) + for data in doc.xpath('//entry'): + if counter <= 0: + break + + id = ''.join(data.xpath('.//id/text()')) + if not id: + continue + + cover_url = ''.join(data.xpath('.//link[@rel="http://opds-spec.org/thumbnail"]/@href')) + + title = u''.join(data.xpath('.//title/text()')) + author = u''.join(data.xpath('.//author/name/text()')) + + counter -= 1 + + s = SearchResult() + s.cover_url = cover_url + s.title = title.strip() + s.author = author.strip() + s.price = '$0.00' + s.detail_item = id.strip() + s.drm = SearchResult.DRM_UNLOCKED + s.formats = 'EPUB' + + yield s From 7e2e3cbb87fd5d00e285e90826b5155d2771040c Mon Sep 17 00:00:00 2001 From: John Schember Date: Wed, 1 Jun 2011 18:25:09 -0400 Subject: [PATCH 61/84] Store: EpubBud store, fix detail url --- src/calibre/gui2/store/epubbud_plugin.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/calibre/gui2/store/epubbud_plugin.py b/src/calibre/gui2/store/epubbud_plugin.py index 6c20f5150d..d6193f6ae0 100644 --- a/src/calibre/gui2/store/epubbud_plugin.py +++ b/src/calibre/gui2/store/epubbud_plugin.py @@ -24,9 +24,6 @@ class EpubBudStore(BasicStoreConfig, StorePlugin): def open(self, parent=None, detail_item=None, external=False): url = 'http://epubbud.com/' - - if detail_item: - url = 'http://epubbud.com/book.php?g=' + detail_item if external or self.config.get('open_external', False): open_url(QUrl(url_slash_cleaner(detail_item if detail_item else url))) From 7de5b6e166dc2a7cc162b33cdcc00794a80da940 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 19:28:36 -0600 Subject: [PATCH 62/84] ... --- src/calibre/gui2/actions/convert.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/actions/convert.py b/src/calibre/gui2/actions/convert.py index ed0a064e88..17fa0ad622 100644 --- a/src/calibre/gui2/actions/convert.py +++ b/src/calibre/gui2/actions/convert.py @@ -171,10 +171,9 @@ class ConvertAction(InterfaceAction): raise Exception(_('Empty output file, ' 'probably the conversion process crashed')) - data = open(temp_files[-1].name, 'rb') - self.gui.library_view.model().db.add_format(book_id, \ + with open(temp_files[-1].name, 'rb') as data: + self.gui.library_view.model().db.add_format(book_id, \ fmt, data, index_is_id=True) - data.close() self.gui.status_bar.show_message(job.description + \ (' completed'), 2000) finally: From 91d499e5b7e4a59541c97e680bfcddd75574ad5b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 20:49:38 -0600 Subject: [PATCH 63/84] ... --- src/calibre/gui2/metadata/single_download.py | 7 +- src/calibre/gui2/preferences/coloring.py | 225 ++++++++++++++++++- 2 files changed, 217 insertions(+), 15 deletions(-) diff --git a/src/calibre/gui2/metadata/single_download.py b/src/calibre/gui2/metadata/single_download.py index cc89ef2259..013ab42684 100644 --- a/src/calibre/gui2/metadata/single_download.py +++ b/src/calibre/gui2/metadata/single_download.py @@ -35,8 +35,9 @@ from calibre import force_unicode class RichTextDelegate(QStyledItemDelegate): # {{{ - def __init__(self, parent=None): + def __init__(self, parent=None, max_width=160): QStyledItemDelegate.__init__(self, parent) + self.max_width = max_width def to_doc(self, index): doc = QTextDocument() @@ -46,8 +47,8 @@ class RichTextDelegate(QStyledItemDelegate): # {{{ def sizeHint(self, option, index): doc = self.to_doc(index) ans = doc.size().toSize() - if ans.width() > 150: - ans.setWidth(160) + if ans.width() > self.max_width - 10: + ans.setWidth(self.max_width) ans.setHeight(ans.height()+10) return ans diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index 98ac7380a5..53f11a95bd 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -7,14 +7,16 @@ __license__ = 'GPL v3' __copyright__ = '2011, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from PyQt4.Qt import (QWidget, QDialog, QLabel, QGridLayout, QComboBox, +from PyQt4.Qt import (QWidget, QDialog, QLabel, QGridLayout, QComboBox, QSize, QLineEdit, QIntValidator, QDoubleValidator, QFrame, QColor, Qt, QIcon, - QScrollArea, QPushButton, QVBoxLayout, QDialogButtonBox) + QScrollArea, QPushButton, QVBoxLayout, QDialogButtonBox, QToolButton, + QListView, QAbstractListModel) from calibre.utils.icu import sort_key from calibre.gui2 import error_dialog +from calibre.gui2.metadata.single_download import RichTextDelegate from calibre.library.coloring import (Rule, conditionable_columns, - displayable_columns) + displayable_columns, rule_from_template) class ConditionEditor(QWidget): # {{{ @@ -277,6 +279,27 @@ class RuleEditor(QDialog): # {{{ self.conditions.append(c) self.conditions_widget.layout().addWidget(c) + def apply_rule(self, col, rule): + for i in range(self.column_box.count()): + c = unicode(self.column_box.itemData(i).toString()) + if col == c: + self.column_box.setCurrentIndex(i) + break + if rule.color: + idx = self.color_box.findText(rule.color) + if idx >= 0: + self.color_box.setCurrentIndex(idx) + for c in rule.conditions: + ce = ConditionEditor(self.fm, parent=self.conditions_widget) + self.conditions.append(ce) + self.conditions_widget.layout().addWidget(ce) + try: + ce.condition = c + except: + import traceback + traceback.print_exc() + + def accept(self): if self.validate(): QDialog.accept(self) @@ -316,11 +339,178 @@ class RuleEditor(QDialog): # {{{ return col, r # }}} +class RulesModel(QAbstractListModel): + + def __init__(self, prefs, fm, parent=None): + QAbstractListModel.__init__(self, parent) + + self.fm = fm + rules = list(prefs['column_color_rules']) + self.rules = [] + for col, template in rules: + try: + rule = rule_from_template(self.fm, template) + except: + rule = template + self.rules.append((col, rule)) + + def rowCount(self, *args): + return len(self.rules) + + def data(self, index, role): + row = index.row() + try: + col, rule = self.rules[row] + except: + return None + + if role == Qt.DisplayRole: + return self.rule_to_html(col, rule) + if role == Qt.UserRole: + return (col, rule) + + def add_rule(self, col, rule): + self.rules.append((col, rule)) + self.reset() + return self.index(len(self.rules)-1) + + def replace_rule(self, index, col, r): + self.rules[index.row()] = (col, r) + self.dataChanged.emit(index, index) + + def remove_rule(self, index): + self.rules.remove(self.rules[index.row()]) + self.reset() + + def commit(self, prefs): + rules = [] + for col, r in self.rules: + if isinstance(r, Rule): + r = r.template + if r is not None: + rules.append((col, r)) + prefs['column_color_rules'] = rules + + def rule_to_html(self, col, rule): + if isinstance(rule, basestring): + return _(''' +

    Advanced Rule for column: %s +

    %s
    + ''')%(col, rule) + conditions = [self.condition_to_html(c) for c in rule.conditions] + return _('''\ +

    Set the color of %s to %s if the following + conditions are met:

    +
      %s
    + ''') % (col, rule.color, ''.join(conditions)) + + def condition_to_html(self, condition): + return ( + _('
  • If the %s column %s the value: %s') % + tuple(condition)) + class EditRules(QWidget): - def __init__(self, db, parent=None): + def __init__(self, parent=None): QWidget.__init__(self, parent) - self.db = db + + self.l = l = QGridLayout(self) + self.setLayout(l) + + self.l1 = l1 = QLabel(_( + 'You can control the color of columns in the' + ' book list by creating "rules" that tell calibre' + ' what color to use. Click the Add Rule button below' + ' to get started. You can change an existing rule by double' + ' clicking it.')) + l1.setWordWrap(True) + l.addWidget(l1, 0, 0, 1, 2) + + self.add_button = QPushButton(QIcon(I('plus.png')), _('Add Rule'), + self) + self.remove_button = QPushButton(QIcon(I('minus.png')), + _('Remove Rule'), self) + self.add_button.clicked.connect(self.add_rule) + self.remove_button.clicked.connect(self.remove_rule) + l.addWidget(self.add_button, 1, 0) + l.addWidget(self.remove_button, 1, 1) + + self.g = g = QGridLayout() + self.rules_view = QListView(self) + self.rules_view.activated.connect(self.edit_rule) + self.rules_view.setSelectionMode(self.rules_view.SingleSelection) + self.rules_view.setAlternatingRowColors(True) + self.rtfd = RichTextDelegate(parent=self.rules_view, max_width=400) + self.rules_view.setItemDelegate(self.rtfd) + g.addWidget(self.rules_view, 0, 0, 2, 1) + + self.up_button = b = QToolButton(self) + b.setIcon(QIcon(I('arrow-up.png'))) + b.setToolTip(_('Move the selected rule up')) + b.clicked.connect(self.move_up) + g.addWidget(b, 0, 1, 1, 1, Qt.AlignTop) + self.down_button = b = QToolButton(self) + b.setIcon(QIcon(I('arrow-down.png'))) + b.setToolTip(_('Move the selected rule down')) + b.clicked.connect(self.move_down) + g.addWidget(b, 1, 1, 1, 1, Qt.AlignBottom) + + l.addLayout(g, 2, 0, 1, 2) + l.setRowStretch(2, 10) + + self.add_advanced_button = b = QPushButton(QIcon(I('plus.png')), + _('Add Advanced Rule'), self) + b.clicked.connect(self.add_advanced) + l.addWidget(b, 3, 0, 1, 2) + + def initialize(self, fm, prefs): + self.model = RulesModel(prefs, fm) + self.rules_view.setModel(self.model) + + def add_rule(self): + d = RuleEditor(db.field_metadata) + d.add_blank_condition() + if d.exec_() == d.Accepted: + col, r = d.rule + if r is not None and col: + idx = self.model.add_rule(col, r) + self.rules_view.scrollTo(idx) + + def edit_rule(self, index): + try: + col, rule = self.model.data(index, Qt.UserRole) + except: + return + if isinstance(rule, Rule): + d = RuleEditor(db.field_metadata) + d.apply_rule(col, rule) + if d.exec_() == d.Accepted: + col, r = d.rule + if r is not None and col: + self.model.replace_rule(index, col, r) + self.rules_view.scrollTo(index) + else: + pass # TODO + + def add_advanced(self): + pass + + def remove_rule(self): + sm = self.rules_view.selectionModel() + rows = list(sm.selectedRows()) + if not rows: + return error_dialog(self, _('No rule selected'), + _('No rule selected for removal.'), show=True) + self.model.remove_rule(rows[0]) + + def move_up(self): + pass + + def move_down(self): + pass + + def commit(self, prefs): + self.model.commit(prefs) if __name__ == '__main__': from PyQt4.Qt import QApplication @@ -328,13 +518,24 @@ if __name__ == '__main__': from calibre.library import db - d = RuleEditor(db().field_metadata) - d.add_blank_condition() - d.exec_() + db = db() - col, r = d.rule + if False: + d = RuleEditor(db.field_metadata) + d.add_blank_condition() + d.exec_() + + col, r = d.rule + + print ('Column to be colored:', col) + print ('Template:') + print (r.template) + else: + d = EditRules() + d.resize(QSize(800, 600)) + d.initialize(db.field_metadata, db.prefs) + d.show() + app.exec_() + d.commit(db.prefs) - print ('Column to be colored:', col) - print ('Template:') - print (r.template) From f6f89636533f0ef512b2c21969161ce4c5341894 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 20:58:00 -0600 Subject: [PATCH 64/84] ... --- src/calibre/gui2/preferences/coloring.py | 43 ++++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index 53f11a95bd..a8a9f666b9 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -391,6 +391,17 @@ class RulesModel(QAbstractListModel): rules.append((col, r)) prefs['column_color_rules'] = rules + def move(self, idx, delta): + row = idx.row() + delta + if row >= 0 and row < len(self.rules): + t = self.rules[row] + self.rules[row] = self.rules[row-delta] + self.rules[row-delta] = t + self.dataChanged.emit(idx, idx) + idx = self.index(row) + self.dataChanged.emit(idx, idx) + return idx + def rule_to_html(self, col, rule): if isinstance(rule, basestring): return _(''' @@ -437,7 +448,7 @@ class EditRules(QWidget): self.g = g = QGridLayout() self.rules_view = QListView(self) - self.rules_view.activated.connect(self.edit_rule) + self.rules_view.doubleClicked.connect(self.edit_rule) self.rules_view.setSelectionMode(self.rules_view.SingleSelection) self.rules_view.setAlternatingRowColors(True) self.rtfd = RichTextDelegate(parent=self.rules_view, max_width=400) @@ -495,19 +506,37 @@ class EditRules(QWidget): def add_advanced(self): pass - def remove_rule(self): + def get_selected_row(self, txt): sm = self.rules_view.selectionModel() rows = list(sm.selectedRows()) if not rows: - return error_dialog(self, _('No rule selected'), - _('No rule selected for removal.'), show=True) - self.model.remove_rule(rows[0]) + error_dialog(self, _('No rule selected'), + _('No rule selected for %s.')%txt, show=True) + return None + return rows[0] + + def remove_rule(self): + row = self.get_selected_row(_('removal')) + if row is not None: + self.model.remove_rule(row) def move_up(self): - pass + idx = self.rules_view.currentIndex() + if idx.isValid(): + idx = self.model.move(idx, -1) + if idx is not None: + sm = self.rules_view.selectionModel() + sm.select(idx, sm.ClearAndSelect) + self.rules_view.setCurrentIndex(idx) def move_down(self): - pass + idx = self.rules_view.currentIndex() + if idx.isValid(): + idx = self.model.move(idx, 1) + if idx is not None: + sm = self.rules_view.selectionModel() + sm.select(idx, sm.ClearAndSelect) + self.rules_view.setCurrentIndex(idx) def commit(self, prefs): self.model.commit(prefs) From 6b8a1442c1249fb2d5c9e3e18657367748b50d20 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 21:47:03 -0600 Subject: [PATCH 65/84] New preferences interface for column coloring. Note that editing of advanced rules is not yet implemented. --- src/calibre/gui2/library/models.py | 22 +-- src/calibre/gui2/preferences/coloring.py | 36 ++++- src/calibre/gui2/preferences/look_feel.py | 134 ++---------------- src/calibre/gui2/preferences/look_feel.ui | 162 +--------------------- src/calibre/library/coloring.py | 15 +- src/calibre/library/database2.py | 22 ++- 6 files changed, 79 insertions(+), 312 deletions(-) diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index d79c92befa..72c8e0629f 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -99,8 +99,7 @@ class BooksModel(QAbstractTableModel): # {{{ self.ids_to_highlight_set = set() self.current_highlighted_idx = None self.highlight_only = False - self.column_color_list = [] - self.colors = [unicode(c) for c in QColor.colorNames()] + self.colors = frozenset([unicode(c) for c in QColor.colorNames()]) self.read_config() def change_alignment(self, colname, alignment): @@ -156,7 +155,6 @@ 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() @@ -545,16 +543,6 @@ class BooksModel(QAbstractTableModel): # {{{ img = self.default_image return img - def set_color_templates(self, reset=True): - self.column_color_list = [] - 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_list.append((name, - self.db.prefs.get('column_color_template_'+str(i)))) - if reset: - self.reset() - def build_data_convertors(self): def authors(r, idx=-1): au = self.db.data[r][idx] @@ -726,14 +714,16 @@ class BooksModel(QAbstractTableModel): # {{{ return QVariant(QColor('lightgreen')) elif role == Qt.ForegroundRole: key = self.column_map[col] - for k,fmt in self.column_color_list: + mi = None + for k, fmt in self.db.prefs['column_color_rules']: if k != key: continue id_ = self.id(index) if id_ in self.color_cache: if key in self.color_cache[id_]: return self.color_cache[id_][key] - mi = self.db.get_metadata(self.id(index), index_is_id=True) + if mi is None: + mi = self.db.get_metadata(id_, index_is_id=True) try: color = composite_formatter.safe_format(fmt, mi, '', mi) if color in self.colors: @@ -743,7 +733,7 @@ class BooksModel(QAbstractTableModel): # {{{ self.color_cache[id_][key] = color return color except: - return NONE + continue if self.is_custom_column(key) and \ self.custom_columns[key]['datatype'] == 'enumeration': cc = self.custom_columns[self.column_map[col]]['display'] diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index a8a9f666b9..ec5fef1304 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -10,10 +10,11 @@ __docformat__ = 'restructuredtext en' from PyQt4.Qt import (QWidget, QDialog, QLabel, QGridLayout, QComboBox, QSize, QLineEdit, QIntValidator, QDoubleValidator, QFrame, QColor, Qt, QIcon, QScrollArea, QPushButton, QVBoxLayout, QDialogButtonBox, QToolButton, - QListView, QAbstractListModel) + QListView, QAbstractListModel, pyqtSignal) from calibre.utils.icu import sort_key from calibre.gui2 import error_dialog +from calibre.gui2.dialogs.template_dialog import TemplateDialog from calibre.gui2.metadata.single_download import RichTextDelegate from calibre.library.coloring import (Rule, conditionable_columns, displayable_columns, rule_from_template) @@ -402,6 +403,10 @@ class RulesModel(QAbstractListModel): self.dataChanged.emit(idx, idx) return idx + def clear(self): + self.rules = [] + self.reset() + def rule_to_html(self, col, rule): if isinstance(rule, basestring): return _(''' @@ -422,6 +427,8 @@ class RulesModel(QAbstractListModel): class EditRules(QWidget): + changed = pyqtSignal() + def __init__(self, parent=None): QWidget.__init__(self, parent) @@ -479,13 +486,20 @@ class EditRules(QWidget): self.rules_view.setModel(self.model) def add_rule(self): - d = RuleEditor(db.field_metadata) + d = RuleEditor(self.model.fm) d.add_blank_condition() if d.exec_() == d.Accepted: col, r = d.rule if r is not None and col: idx = self.model.add_rule(col, r) self.rules_view.scrollTo(idx) + self.changed.emit() + + def add_advanced(self): + td = TemplateDialog(self, '', None) + if td.exec_() == td.Accepted: + self.changed.emit() + pass # TODO def edit_rule(self, index): try: @@ -493,18 +507,19 @@ class EditRules(QWidget): except: return if isinstance(rule, Rule): - d = RuleEditor(db.field_metadata) + d = RuleEditor(self.model.fm) d.apply_rule(col, rule) if d.exec_() == d.Accepted: col, r = d.rule if r is not None and col: self.model.replace_rule(index, col, r) self.rules_view.scrollTo(index) + self.changed.emit() else: - pass # TODO - - def add_advanced(self): - pass + td = TemplateDialog(self, rule, None) + if td.exec_() == td.Accepted: + self.changed.emit() + pass # TODO def get_selected_row(self, txt): sm = self.rules_view.selectionModel() @@ -519,6 +534,7 @@ class EditRules(QWidget): row = self.get_selected_row(_('removal')) if row is not None: self.model.remove_rule(row) + self.changed.emit() def move_up(self): idx = self.rules_view.currentIndex() @@ -528,6 +544,7 @@ class EditRules(QWidget): sm = self.rules_view.selectionModel() sm.select(idx, sm.ClearAndSelect) self.rules_view.setCurrentIndex(idx) + self.changed.emit() def move_down(self): idx = self.rules_view.currentIndex() @@ -537,6 +554,11 @@ class EditRules(QWidget): sm = self.rules_view.selectionModel() sm.select(idx, sm.ClearAndSelect) self.rules_view.setCurrentIndex(idx) + self.changed.emit() + + def clear(self): + self.model.clear() + self.changed.emit() def commit(self, prefs): self.model.commit(prefs) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index 7a8c1fb69c..feaf3dd677 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -5,21 +5,19 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from functools import partial - from PyQt4.Qt import (QApplication, QFont, QFontInfo, QFontDialog, - QAbstractListModel, Qt, QColor, QIcon, QToolButton, QComboBox) + QAbstractListModel, Qt, QIcon) from calibre.gui2.preferences import ConfigWidgetBase, test_widget, CommaSeparatedList from calibre.gui2.preferences.look_feel_ui import Ui_Form from calibre.gui2 import config, gprefs, qt_app -from calibre.gui2.dialogs.template_line_editor import TemplateLineEditor from calibre.utils.localization import (available_translations, get_language, get_lang) from calibre.utils.config import prefs from calibre.utils.icu import sort_key from calibre.gui2 import NONE from calibre.gui2.book_details import get_field_list +from calibre.gui2.preferences.coloring import EditRules class DisplayedFields(QAbstractListModel): # {{{ @@ -162,117 +160,11 @@ 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.setText('

    ' + - _('Here you can specify coloring rules for columns shown in the ' - 'library view. Choose the column you wish to color, then ' - 'supply a template that specifies the color to use based on ' - 'the values in the column. There is a ' - '' - 'tutorial on using templates.') + - '

    ' + - _('If you want to color a field based on contents of columns, ' - 'then click the button next to an empty line to open the wizard. ' - 'It will build a template for you. You can later edit that ' - 'template with the same wizard. This is by far the easiest ' - 'way to specify a template.') + - '

    ' + - _('If you manually construct a template, then the template must ' - 'evaluate to a valid color name shown in the color names box.' - '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 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')
    ") + - '

    ' + - _('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 often easier to specify the ' - 'colors in the column definition dialog. There you can ' - 'provide a color for each value without using a template.')+ '

    ') - self.color_help_scrollArea.setVisible(False) - self.color_help_button.clicked.connect(self.change_help_text) - self.colors_scrollArea.setVisible(False) - self.colors_label.setVisible(False) - self.colors_button.clicked.connect(self.change_colors_text) - - choices = db.field_metadata.displayable_field_keys() - choices.sort(key=sort_key) - choices.insert(0, '') - self.column_color_count = db.column_color_count+1 - - mi=None - try: - idx = gui.library_view.currentIndex().row() - mi = db.get_metadata(idx, index_is_id=False) - except: - pass - - l = self.column_color_layout - for i in range(1, self.column_color_count): - ccn = QComboBox(parent=self) - setattr(self, 'opt_column_color_name_'+str(i), ccn) - l.addWidget(ccn, i, 0, 1, 1) - - wtb = QToolButton(parent=self) - setattr(self, 'opt_column_color_wizard_'+str(i), wtb) - wtb.setIcon(QIcon(I('wizard.png'))) - l.addWidget(wtb, i, 1, 1, 1) - - ttb = QToolButton(parent=self) - setattr(self, 'opt_column_color_tpledit_'+str(i), ttb) - ttb.setIcon(QIcon(I('edit_input.png'))) - l.addWidget(ttb, i, 2, 1, 1) - - tpl = TemplateLineEditor(parent=self) - setattr(self, 'opt_column_color_template_'+str(i), tpl) - tpl.textChanged.connect(partial(self.tpl_edit_text_changed, ctrl=i)) - tpl.set_db(db) - tpl.set_mi(mi) - l.addWidget(tpl, i, 3, 1, 1) - - wtb.clicked.connect(tpl.tag_wizard) - ttb.clicked.connect(tpl.open_editor) - - r('column_color_name_'+str(i), db.prefs, choices=choices) - r('column_color_template_'+str(i), db.prefs) - txt = db.prefs.get('column_color_template_'+str(i), None) - - wtb.setEnabled(tpl.enable_wizard_button(txt)) - ttb.setEnabled(not tpl.enable_wizard_button(txt) or not txt) - - all_colors = [unicode(s) for s in list(QColor.colorNames())] - self.colors_box.setText(', '.join(all_colors)) - - def change_help_text(self): - self.color_help_scrollArea.setVisible(not self.color_help_scrollArea.isVisible()) - - def change_colors_text(self): - self.colors_scrollArea.setVisible(not self.colors_scrollArea.isVisible()) - self.colors_label.setVisible(not self.colors_label.isVisible()) - - def tpl_edit_text_changed(self, ign, ctrl=None): - tpl = getattr(self, 'opt_column_color_template_'+str(ctrl)) - txt = unicode(tpl.text()) - wtb = getattr(self, 'opt_column_color_wizard_'+str(ctrl)) - ttb = getattr(self, 'opt_column_color_tpledit_'+str(ctrl)) - wtb.setEnabled(tpl.enable_wizard_button(txt)) - ttb.setEnabled(not tpl.enable_wizard_button(txt) or not txt) - tpl.setFocus() + self.edit_rules = EditRules(self.tabWidget) + self.edit_rules.changed.connect(self.changed_signal) + self.tabWidget.addTab(self.edit_rules, + QIcon(I('format-fill-color.png')), _('Column coloring')) + self.tabWidget.setCurrentIndex(0) def initialize(self): ConfigWidgetBase.initialize(self) @@ -283,6 +175,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.current_font = self.initial_font = font self.update_font_display() self.display_model.initialize() + db = self.gui.current_db + self.edit_rules.initialize(db.field_metadata, db.prefs) def restore_defaults(self): ConfigWidgetBase.restore_defaults(self) @@ -292,6 +186,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.changed_signal.emit() self.update_font_display() self.display_model.restore_defaults() + self.edit_rules.clear() self.changed_signal.emit() def build_font_obj(self): @@ -341,12 +236,6 @@ 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)) - 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 @@ -356,10 +245,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): QApplication.setFont(self.font_display.font()) rr = True self.display_model.commit() + self.edit_rules.commit(self.gui.current_db.prefs) return rr def refresh_gui(self, gui): - gui.library_view.model().set_color_templates() + gui.library_view.model().reset() 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 def1bdd41c..cc9133a36f 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -6,7 +6,7 @@ 0 0 - 717 + 820 519 @@ -407,161 +407,6 @@ then the tags will be displayed each on their own line. - - - - :/images/format-fill-color.png:/images/format-fill-color.png - - - Column Coloring - - - - - - Column to color - - - - - - - - - Color selection template - - - - 10 - 0 - - - - - - - - The template wizard is easiest to use - - - - - - - Show/hide help text - - - - - - - Show/hide colors - - - - - - - - - Color names - - - - - - - - 16777215 - 300 - - - - true - - - - - 0 - 0 - 687 - 61 - - - - - - - true - - - Qt::AlignLeft|Qt::AlignTop - - - - - - - - - - - - 0 - 200 - - - - true - - - Qt::AlignLeft|Qt::AlignTop - - - - - 0 - 0 - 687 - 194 - - - - - - - true - - - true - - - - - - - - - - - - 0 - 10 - - - - Qt::Vertical - - - - 0 - 0 - - - - - - @@ -572,11 +417,6 @@ then the tags will be displayed each on their own line. QLineEdit
    calibre/gui2/complete.h
    - - TemplateLineEditor - QLineEdit -
    calibre/gui2/dialogs/template_line_editor.h
    -
    diff --git a/src/calibre/library/coloring.py b/src/calibre/library/coloring.py index 7e2b0f67c6..80e748473a 100644 --- a/src/calibre/library/coloring.py +++ b/src/calibre/library/coloring.py @@ -61,7 +61,7 @@ class Rule(object): # {{{ {sig} test(and( {conditions} - ), {color}, ''); + ), '{color}', ''); ''').format(sig=self.signature, conditions=conditions, color=self.color) @@ -169,10 +169,21 @@ def conditionable_columns(fm): 'comments', 'text', 'enumeration', 'datetime'): yield key - def displayable_columns(fm): for key in fm.displayable_field_keys(): if key not in ('sort', 'author_sort', 'comments', 'formats', 'identifiers', 'path'): yield key +def migrate_old_rule(fm, template): + if template.startswith('program:\n#tag wizard'): + rules = [] + for line in template.splitlines(): + if line.startswith('#') and ':|:' in line: + value, color = line[1:].split(':|:') + r = Rule(fm, color=color) + r.add_condition('tags', 'has', value) + rules.append(r.template) + return rules + return template + diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index df465c919e..b3c584534e 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -211,10 +211,7 @@ 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)] = '' + defs['column_color_rules'] = [] # Migrate the bool tristate tweak defs['bools_are_tristate'] = \ @@ -222,6 +219,23 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): if self.prefs.get('bools_are_tristate') is None: self.prefs.set('bools_are_tristate', defs['bools_are_tristate']) + # Migrate column coloring rules + if self.prefs.get('column_color_name_1', None) is not None: + from calibre.library.coloring import migrate_old_rule + old_rules = [] + for i in range(1, 5): + col = self.prefs.get('column_color_name_'+str(i), None) + templ = self.prefs.get('column_color_template_'+str(i), None) + if col and templ: + try: + del self.prefs['column_color_name_'+str(i)] + templ = migrate_old_rule(self.field_metadata, templ) + old_rules.append((col, templ)) + except: + pass + if old_rules: + self.prefs['column_color_rules'] += old_rules + # Migrate saved search and user categories to db preference scheme def migrate_preference(key, default): oldval = prefs[key] From cf037a16fc0356b2851db251cd494a0be1ee740a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 21:50:30 -0600 Subject: [PATCH 66/84] ... --- src/calibre/gui2/preferences/coloring.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index ec5fef1304..a8825ec582 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -340,7 +340,7 @@ class RuleEditor(QDialog): # {{{ return col, r # }}} -class RulesModel(QAbstractListModel): +class RulesModel(QAbstractListModel): # {{{ def __init__(self, prefs, fm, parent=None): QAbstractListModel.__init__(self, parent) @@ -425,7 +425,9 @@ class RulesModel(QAbstractListModel): _('
  • If the %s column %s the value: %s') % tuple(condition)) -class EditRules(QWidget): +# }}} + +class EditRules(QWidget): # {{{ changed = pyqtSignal() @@ -563,6 +565,8 @@ class EditRules(QWidget): def commit(self, prefs): self.model.commit(prefs) +# }}} + if __name__ == '__main__': from PyQt4.Qt import QApplication app = QApplication([]) From 2010cf26710b78d20fa01056bccc74cda7fe2fef Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Jun 2011 21:54:23 -0600 Subject: [PATCH 67/84] ... --- src/calibre/library/coloring.py | 2 +- src/calibre/library/database2.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/calibre/library/coloring.py b/src/calibre/library/coloring.py index 80e748473a..db13da9532 100644 --- a/src/calibre/library/coloring.py +++ b/src/calibre/library/coloring.py @@ -185,5 +185,5 @@ def migrate_old_rule(fm, template): r.add_condition('tags', 'has', value) rules.append(r.template) return rules - return template + return [template] diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index b3c584534e..c78f13d698 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -229,8 +229,9 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): if col and templ: try: del self.prefs['column_color_name_'+str(i)] - templ = migrate_old_rule(self.field_metadata, templ) - old_rules.append((col, templ)) + rules = migrate_old_rule(self.field_metadata, templ) + for templ in rules: + old_rules.append((col, templ)) except: pass if old_rules: From 26d90debf09cd78d5d75ef18e3d001a523763629 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 2 Jun 2011 07:18:25 +0100 Subject: [PATCH 68/84] Fix exception in get_categories caused by quotes in identifier names --- src/calibre/library/database2.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index df465c919e..050ef5ea42 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -1556,13 +1556,13 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): if ids is not None: count = self.conn.get('''SELECT COUNT(id) FROM data - WHERE format="%s" AND - books_list_filter(book)'''%fmt, + WHERE format=? AND + books_list_filter(book)''', (fmt,), all=False) else: count = self.conn.get('''SELECT COUNT(id) FROM data - WHERE format="%s"'''%fmt, + WHERE format=?''', (fmt,), all=False) if count > 0: categories['formats'].append(Tag(fmt, count=count, icon=icon, @@ -1584,13 +1584,13 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): if ids is not None: count = self.conn.get('''SELECT COUNT(book) FROM identifiers - WHERE type="%s" AND - books_list_filter(book)'''%ident, + WHERE type=? AND + books_list_filter(book)''', (ident,), all=False) else: count = self.conn.get('''SELECT COUNT(id) FROM identifiers - WHERE type="%s"'''%ident, + WHERE type=?''', (ident,), all=False) if count > 0: categories['identifiers'].append(Tag(ident, count=count, icon=icon, From 6c33b59cd7fc347038f265b372887b18ccd6015d Mon Sep 17 00:00:00 2001 From: GRiker Date: Thu, 2 Jun 2011 03:40:52 -0600 Subject: [PATCH 69/84] Added diagnostic in _launch_iTunes to assist in identifying failure in ticket #791530 --- src/calibre/devices/apple/driver.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/devices/apple/driver.py b/src/calibre/devices/apple/driver.py index 66c2819e28..d15f4070a7 100644 --- a/src/calibre/devices/apple/driver.py +++ b/src/calibre/devices/apple/driver.py @@ -3023,6 +3023,8 @@ class ITUNES_ASYNC(ITUNES): pythoncom.CoInitialize() self._launch_iTunes() except: + import traceback + traceback.print_exc() raise UserFeedback('unable to launch iTunes', details=None, level=UserFeedback.WARN) finally: pythoncom.CoUninitialize() From 2b44c67af6fb9ebbef00ee0229903c22fe2f1b02 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 2 Jun 2011 11:52:06 +0100 Subject: [PATCH 70/84] Changes for new coloring system --- src/calibre/ebooks/metadata/book/base.py | 5 +- src/calibre/gui2/dialogs/template_dialog.py | 50 +- src/calibre/gui2/dialogs/template_dialog.ui | 36 +- .../gui2/dialogs/template_line_editor.py | 502 +----------------- src/calibre/gui2/library/delegates.py | 2 +- src/calibre/gui2/preferences/coloring.py | 46 +- src/calibre/gui2/preferences/look_feel.py | 7 +- src/calibre/library/coloring.py | 5 +- src/calibre/library/database2.py | 2 +- src/calibre/library/field_metadata.py | 4 + src/calibre/utils/formatter_functions.py | 30 +- 11 files changed, 141 insertions(+), 548 deletions(-) diff --git a/src/calibre/ebooks/metadata/book/base.py b/src/calibre/ebooks/metadata/book/base.py index 2c96b8d3d3..378d4ab5f0 100644 --- a/src/calibre/ebooks/metadata/book/base.py +++ b/src/calibre/ebooks/metadata/book/base.py @@ -54,7 +54,10 @@ class SafeFormat(TemplateFormatter): key = orig_key else: raise ValueError(_('Value: unknown field ') + orig_key) - b = self.book.get_user_metadata(key, False) + try: + b = self.book.get_user_metadata(key, False) + except: + b = None if b and b['datatype'] == 'int' and self.book.get(key, 0) == 0: v = '' elif b and b['datatype'] == 'float' and self.book.get(key, 0.0) == 0.0: diff --git a/src/calibre/gui2/dialogs/template_dialog.py b/src/calibre/gui2/dialogs/template_dialog.py index 083dacbf00..852bbcc221 100644 --- a/src/calibre/gui2/dialogs/template_dialog.py +++ b/src/calibre/gui2/dialogs/template_dialog.py @@ -5,13 +5,15 @@ __license__ = 'GPL v3' import json -from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QSyntaxHighlighter, - QRegExp, QApplication, - QTextCharFormat, QFont, QColor, QCursor) +from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QSyntaxHighlighter, QFont, + QRegExp, QApplication, QTextCharFormat, QColor, QCursor) +from calibre.gui2 import error_dialog from calibre.gui2.dialogs.template_dialog_ui import Ui_TemplateDialog from calibre.utils.formatter_functions import formatter_functions -from calibre.ebooks.metadata.book.base import composite_formatter +from calibre.ebooks.metadata.book.base import composite_formatter, Metadata +from calibre.library.coloring import (displayable_columns) + class ParenPosition: @@ -195,12 +197,24 @@ class TemplateHighlighter(QSyntaxHighlighter): class TemplateDialog(QDialog, Ui_TemplateDialog): - def __init__(self, parent, text, mi): + def __init__(self, parent, text, mi=None, fm=None, color_field=None): QDialog.__init__(self, parent) Ui_TemplateDialog.__init__(self) self.setupUi(self) - self.mi = mi + self.coloring = color_field is not None + if self.coloring: + cols = sorted([k for k in displayable_columns(fm)]) + self.colored_field.addItems(cols) + self.colored_field.setCurrentIndex(self.colored_field.findText(color_field)) + else: + self.colored_field.setVisible(False) + self.colored_field_label.setVisible(False) + + if mi: + self.mi = mi + else: + self.mi = Metadata(None, None) # Remove help icon on title bar icon = self.windowIcon() @@ -238,24 +252,26 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): self.function.setCurrentIndex(0) self.function.currentIndexChanged[str].connect(self.function_changed) self.textbox_changed() + self.rule = (None, '') 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() + self.text_cursor_changed() self.template_value.setText( composite_formatter.safe_format(cur_text, self.mi, _('EXCEPTION: '), self.mi)) 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, + if position > 0 and position <= len(t): + block_number = cursor.blockNumber() + pos_in_block = cursor.positionInBlock() - 1 + self.highlighter.check_cursor_pos(t[position-1], block_number, pos_in_block) def function_changed(self, toWhat): @@ -270,3 +286,17 @@ class TemplateDialog(QDialog, Ui_TemplateDialog): else: self.source_code.setPlainText(self.funcs[name].program_text) + def accept(self): + txt = unicode(self.textbox.toPlainText()).rstrip() + if self.coloring: + if self.colored_field.currentIndex() == -1: + error_dialog(self, _('No column chosen'), + _('You must specify a column to be colored'), show=True) + return + if not txt: + error_dialog(self, _('No template provided'), + _('The template box cannot be empty'), show=True) + return + + self.rule = (unicode(self.colored_field.currentText()), txt) + QDialog.accept(self) \ No newline at end of file diff --git a/src/calibre/gui2/dialogs/template_dialog.ui b/src/calibre/gui2/dialogs/template_dialog.ui index d36cbbd3d4..13586e7049 100644 --- a/src/calibre/gui2/dialogs/template_dialog.ui +++ b/src/calibre/gui2/dialogs/template_dialog.ui @@ -20,12 +20,30 @@ Edit Comments + + + + + + Set the color of the column: + + + colored_field + + + + + + + + + - + Template value: @@ -38,14 +56,14 @@ - + true - + Qt::Horizontal @@ -55,7 +73,7 @@ - + Function &name: @@ -65,10 +83,10 @@ - + - + &Documentation: @@ -81,7 +99,7 @@ - + Python &code: @@ -94,7 +112,7 @@ - + @@ -104,7 +122,7 @@ - + diff --git a/src/calibre/gui2/dialogs/template_line_editor.py b/src/calibre/gui2/dialogs/template_line_editor.py index af70a16d31..02293e4df7 100644 --- a/src/calibre/gui2/dialogs/template_line_editor.py +++ b/src/calibre/gui2/dialogs/template_line_editor.py @@ -5,17 +5,10 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' -from functools import partial -from collections import defaultdict -from PyQt4.Qt import (Qt, QLineEdit, QDialog, QGridLayout, QLabel, QCheckBox, - QIcon, QDialogButtonBox, QColor, QComboBox, QPushButton) +from PyQt4.Qt import QLineEdit -from calibre.ebooks.metadata.book.base import composite_formatter from calibre.gui2.dialogs.template_dialog import TemplateDialog -from calibre.gui2.complete import MultiCompleteLineEdit -from calibre.gui2 import error_dialog -from calibre.utils.icu import sort_key class TemplateLineEditor(QLineEdit): @@ -25,16 +18,11 @@ class TemplateLineEditor(QLineEdit): def __init__(self, parent): QLineEdit.__init__(self, parent) - self.tags = None self.mi = None - self.txt = None def set_mi(self, mi): self.mi = mi - def set_db(self, db): - self.db = db - def contextMenuEvent(self, event): menu = self.createStandardContextMenu() menu.addSeparator() @@ -46,494 +34,10 @@ class TemplateLineEditor(QLineEdit): menu.exec_(event.globalPos()) def clear_field(self): - self.txt = None self.setText('') - self.setReadOnly(False) - self.setStyleSheet('TemplateLineEditor { color: black }') def open_editor(self): - if self.txt: - t = TemplateDialog(self, self.txt, self.mi) - else: - t = TemplateDialog(self, self.text(), self.mi) + t = TemplateDialog(self, self.text(), mi=self.mi) t.setWindowTitle(_('Edit template')) if t.exec_(): - self.txt = None - self.setText(t.textbox.toPlainText()) - - def enable_wizard_button(self, txt): - if not txt or txt.startswith('program:\n#tag wizard'): - return True - return False - - def setText(self, txt): - txt = unicode(txt) - if txt and txt.startswith('program:\n#tag wizard'): - self.txt = txt - self.setReadOnly(True) - QLineEdit.setText(self, '') - QLineEdit.setText(self, _('Template generated by the wizard')) - self.setStyleSheet('TemplateLineEditor { color: gray }') - else: - QLineEdit.setText(self, txt) - - def tag_wizard(self): - txt = unicode(self.text()) - if txt and not self.txt: - 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.db, unicode(self.txt), self.mi) - if d.exec_(): - self.setText(d.template) - - def text(self): - if self.txt: - return self.txt - return QLineEdit.text(self) - -class TagWizard(QDialog): - - text_template = (" strcmp(field('{f}'), '{v}', '{ltv}', '{eqv}', '{gtv}')", True) - text_empty_template = (" test(field('{f}'), '{fv}', '{tv}')", False) - text_re_template = (" contains(field('{f}'), '{v}', '{tv}', '{fv}')", False) - - templates = { - 'text.mult' : (" str_in_list(field('{f}'), '{mult}', '{v}', '{tv}', '{fv}')", False), - 'text.mult.re' : (" in_list(field('{f}'), '{mult}', '^{v}$', '{tv}', '{fv}')", False), - 'text.mult.empty' : (" test(field('{f}'), '{fv}', '{tv}')", False), - 'text' : text_template, - 'text.re' : text_re_template, - 'text.empty' : text_empty_template, - 'rating' : (" cmp(raw_field('{f}'), '{v}', '{ltv}', '{eqv}', '{gtv}')", True), - 'rating.empty' : text_empty_template, - 'int' : (" cmp(raw_field('{f}'), '{v}', '{ltv}', '{eqv}', '{gtv}')", True), - 'int.empty' : text_empty_template, - 'float' : (" cmp(raw_field('{f}'), '{v}', '{ltv}', '{eqv}', '{gtv}')", True), - 'float.empty' : text_empty_template, - 'bool' : (" strcmp(field('{f}'), '{v}', '{ltv}', '{eqv}', '{gtv}')", True), - 'bool.empty' : text_empty_template, - 'datetime' : (" strcmp(format_date(raw_field('{f}'), 'yyyyMMdd'), format_date('{v}', 'yyyyMMdd'), '{ltv}', '{eqv}', '{gtv}')", True), - 'datetime.empty' : text_empty_template, - 'series' : text_template, - 'series.re' : text_re_template, - 'series.empty' : text_empty_template, - 'composite' : text_template, - 'composite.re' : text_re_template, - 'composite.empty' : text_empty_template, - 'enumeration' : text_template, - 'enumeration.re' : text_re_template, - 'enumeration.empty' : text_empty_template, - 'comments' : text_template, - 'comments.re' : text_re_template, - 'comments.empty' : text_empty_template, - } - - relationals = ('=', '!=', '<', '>', '<=', '>=') - relational_truth_vals = { - '=': ('', '1', ''), - '!=': ('1', '', '1'), - '<': ('1', '', ''), - '>': ('', '', '1'), - '<=': ('1', '1', ''), - '>=': ('', '1', '1'), - } - - @staticmethod - def uses_this_wizard(txt): - if not txt or txt.startswith('program:\n#tag wizard'): - return True - return False - - def __init__(self, parent, db, txt, mi): - QDialog.__init__(self, parent) - self.setWindowTitle(_('Coloring Wizard')) - self.setWindowIcon(QIcon(I('wizard.png'))) - - self.mi = mi - - self.columns = [] - self.completion_values = defaultdict(dict) - for k in db.all_field_keys(): - m = db.metadata_for_field(k) - if k.endswith('_index') or ( - m['kind'] == 'field' and m['name'] and - k not in ('ondevice', 'path', 'size', 'sort')): - self.columns.append(k) - self.completion_values[k]['dt'] = m['datatype'] - if m['is_custom']: - if m['datatype'] in ('int', 'float'): - self.completion_values[k]['v'] = [] - elif m['datatype'] == 'bool': - self.completion_values[k]['v'] = [_('Yes'), _('No')] - else: - self.completion_values[k]['v'] = db.all_custom(m['label']) - elif k == 'tags': - self.completion_values[k]['v'] = db.all_tags() - elif k == 'formats': - self.completion_values[k]['v'] = db.all_formats() - else: - if k in ('publisher'): - ck = k + 's' - else: - ck = k - f = getattr(db, 'all_' + ck, None) - if f: - if k == 'authors': - self.completion_values[k]['v'] = [v[1].\ - replace('|', ',') for v in f()] - else: - self.completion_values[k]['v'] = [v[1] for v in f()] - else: - self.completion_values[k]['v'] = [] - - if k in self.completion_values: - if k == 'authors': - mult = '&' - else: - mult = ',' if m['is_multiple'] == '|' else m['is_multiple'] - self.completion_values[k]['m'] = mult - - self.columns.sort(key=sort_key) - self.columns.insert(0, '') - - l = QGridLayout() - self.setLayout(l) - l.setColumnStretch(2, 10) - l.setColumnMinimumWidth(5, 300) - - h = QLabel(_('And')) - h.setToolTip('

    ' + - _('Set this box to indicate that the two conditions must both ' - 'be true to use the color. For example, you ' - 'can check if two tags are present, if the book has a tag ' - 'and a #read custom column is checked, or if a book has ' - 'some tag and has a particular format.')) - l.addWidget(h, 0, 0, 1, 1) - - h = QLabel(_('Column')) - h.setAlignment(Qt.AlignCenter) - l.addWidget(h, 0, 1, 1, 1) - - h = QLabel(_('is')) - h.setAlignment(Qt.AlignCenter) - l.addWidget(h, 0, 2, 1, 1) - - h = QLabel(_('op')) - h.setToolTip('

    ' + - _('Use this box to tell what comparison operation to use. Some ' - 'comparisons cannot be used with certain options. For example, ' - 'if regular expressions are used, only equals and not equals ' - 'are valid.') + '

    ') - h.setAlignment(Qt.AlignCenter) - l.addWidget(h, 0, 3, 1, 1) - - c = QLabel(_('empty')) - c.setToolTip('

    ' + - _('Check this box to check if the column is empty') + '

    ') - l.addWidget(c, 0, 4, 1, 1) - - h = QLabel(_('Values')) - h.setAlignment(Qt.AlignCenter) - h.setToolTip('

    ' + - _('You can enter more than one value per box, separated by commas. ' - 'The comparison ignores letter case. Special note: authors are ' - 'separated by ampersands (&).
    ' - 'A value can be a regular expression. Check the box to turn ' - 'them on. When using regular expressions, note that the wizard ' - 'puts anchors (^ and $) around the expression, so you ' - 'must ensure your expression matches from the beginning ' - 'to the end of the column/value you are checking.
    ' - 'Regular expression examples:') + '

      ' + - _('
    • .* matches anything in the column.
    • ' - '
    • A.* matches anything beginning with A
    • ' - '
    • .*mystery.* matches anything containing ' - 'the word "mystery"
    • ') + '

    ') - l.addWidget(h , 0, 5, 1, 1) - - c = QLabel(_('is RE')) - c.setToolTip('

    ' + - _('Check this box if the values box contains regular expressions') + '

    ') - l.addWidget(c, 0, 6, 1, 1) - - c = QLabel(_('color')) - c.setAlignment(Qt.AlignCenter) - c.setToolTip('

    ' + - _('Use this color if the column matches the tests.') + '

    ') - l.addWidget(c, 0, 7, 1, 1) - - self.andboxes = [] - self.opboxes = [] - self.tagboxes = [] - self.colorboxes = [] - self.reboxes = [] - self.colboxes = [] - self.emptyboxes = [] - - self.colors = [unicode(s) for s in list(QColor.colorNames())] - self.colors.insert(0, '') - - def create_widget(klass, box, layout, row, col, items, - align=Qt.AlignCenter, rowspan=False): - w = klass(self) - if box is not None: - box.append(w) - if rowspan: - layout.addWidget(w, row, col, 2, 1, alignment=Qt.Alignment(align)) - else: - layout.addWidget(w, row, col, 1, 1, alignment=Qt.Alignment(align)) - if items: - w.addItems(items) - return w - - maxlines = 10 - for i in range(1, maxlines+1): - w = create_widget(QCheckBox, self.andboxes, l, i, 0, None, rowspan=True) - w.stateChanged.connect(partial(self.and_box_changed, line=i-1)) - if i == maxlines: - # last box is invisible - w.setVisible(False) - - w = create_widget(QComboBox, self.colboxes, l, i, 1, self.columns) - w.currentIndexChanged[str].connect(partial(self.column_changed, line=i-1)) - - w = QLabel(self) - w.setText(_('is')) - l.addWidget(w, i, 2, 1, 1) - - w = create_widget(QComboBox, self.opboxes, l, i, 3, None) - w.setMaximumWidth(40) - - w = create_widget(QCheckBox, self.emptyboxes, l, i, 4, None) - w.stateChanged.connect(partial(self.empty_box_changed, line=i-1)) - - create_widget(MultiCompleteLineEdit, self.tagboxes, l, i, 5, None, align=0) - - w = create_widget(QCheckBox, self.reboxes, l, i, 6, None) - w.stateChanged.connect(partial(self.re_box_changed, line=i-1)) - - create_widget(QComboBox, self.colorboxes, l, i, 7, self.colors) - - w = create_widget(QLabel, None, l, maxlines+1, 5, None) - w.setText(_('If none of the tests match, set the color to')) - self.elsebox = create_widget(QComboBox, None, l, maxlines+1, 7, self.colors) - self.elsebox.setToolTip('

    ' + - _('If this box contains a color, it will be used if none ' - 'of the above rules match.') + '

    ') - - if txt: - lines = txt.split('\n')[3:] - i = 0 - for line in lines: - if line.startswith('#'): - vals = line[1:].split(':|:') - if len(vals) == 1 and line.startswith('#else:'): - try: - self.elsebox.setCurrentIndex(self.elsebox.findText(line[6:])) - except: - pass - continue - if len(vals) == 2: - t, c = vals - f = 'tags' - a = re = e = 0 - op = '=' - else: - t,c,f,re,a,op,e = vals - try: - self.colboxes[i].setCurrentIndex(self.colboxes[i].findText(f)) - self.colorboxes[i].setCurrentIndex( - self.colorboxes[i].findText(c)) - self.tagboxes[i].setText(t) - self.reboxes[i].setChecked(re == '2') - self.emptyboxes[i].setChecked(e == '2') - self.andboxes[i].setChecked(a == '2') - self.opboxes[i].setCurrentIndex(self.opboxes[i].findText(op)) - i += 1 - except: - import traceback - traceback.print_exc() - pass - - w = QLabel(_('Preview')) - l.addWidget(w, 99, 1, 1, 1) - w = self.test_box = QLineEdit(self) - w.setReadOnly(True) - l.addWidget(w, 99, 2, 1, 5) - w = QPushButton(_('Test')) - w.setToolTip('

    ' + - _('Press this button to see what color this template will ' - 'produce for the book that was selected when you ' - 'entered the preferences dialog.')) - l.addWidget(w, 99, 7, 1, 1) - w.clicked.connect(self.preview) - - bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel, parent=self) - l.addWidget(bb, 100, 5, 1, 3) - bb.accepted.connect(self.accepted) - bb.rejected.connect(self.reject) - self.template = '' - - def preview(self): - if not self.generate_program(): - return - t = composite_formatter.safe_format(self.template, self.mi, - _('EXCEPTION'), self.mi) - self.test_box.setText(t) - - def generate_program(self): - res = ("program:\n#tag wizard -- do not directly edit\n" - " first_non_empty(\n") - lines = [] - was_and = had_line = False - - line = 0 - for tb, cb, fb, reb, ab, ob, eb in zip( - self.tagboxes, self.colorboxes, self.colboxes, - self.reboxes, self.andboxes, self.opboxes, self.emptyboxes): - f = unicode(fb.currentText()) - if not f: - continue - m = self.completion_values[f]['m'] - dt = self.completion_values[f]['dt'] - c = unicode(cb.currentText()).strip() - re = reb.checkState() - a = ab.checkState() - op = unicode(ob.currentText()) - e = eb.checkState() - line += 1 - - if m: - tags = [t.strip() for t in unicode(tb.text()).split(m) if t.strip()] - if re == 2: - tags = '$|^'.join(tags) - else: - tags = m.join(tags) - if m == '&': - tags = tags.replace(',', '|') - else: - tags = unicode(tb.text()).strip() - - if (tags or f) and not ((tags or e) and f and (a == 2 or c)): - error_dialog(self, _('Invalid line'), - _('Line number {0} is not valid').format(line), - show=True, show_copy_button=False) - return False - - if not was_and: - if had_line: - lines[-1] += ',' - had_line = True - lines.append(" test(and(") - else: - lines[-1] += ',' - - key = dt + ('.mult' if m else '') + ('.empty' if e else '') + ('.re' if re else '') - tval = '1' if op == '=' else '' - fval = '' if op == '=' else '1' - template, is_relational = self.templates[key] - if is_relational: - ltv, eqv, gtv = self.relational_truth_vals[op] - else: - ltv, eqv, gtv = (None, None, None) - lines.append(template.format(v=tags, f=f, tv=tval, fv=fval, mult=m, - ltv=ltv, eqv=eqv, gtv=gtv)) - - if a == 2: - was_and = True - else: - was_and = False - lines.append(" ), '{0}', '')".format(c)) - - res += '\n'.join(lines) - else_txt = unicode(self.elsebox.currentText()) - if else_txt: - res += ",\n '" + else_txt + "'" - res += ')\n' - self.template = res - res = '' - for tb, cb, fb, reb, ab, ob, eb in zip( - self.tagboxes, self.colorboxes, self.colboxes, - self.reboxes, self.andboxes, self.opboxes, self.emptyboxes): - t = unicode(tb.text()).strip() - if t.endswith(','): - t = t[:-1] - c = unicode(cb.currentText()).strip() - f = unicode(fb.currentText()) - re = unicode(reb.checkState()) - a = unicode(ab.checkState()) - op = unicode(ob.currentText()) - e = unicode(eb.checkState()) - if f and (t or e) and (a == '2' or c): - res += '#' + t + ':|:' + c + ':|:' + f + ':|:' + re + ':|:' + \ - a + ':|:' + op + ':|:' + e + '\n' - res += '#else:' + else_txt + '\n' - self.template += res - return True - - def column_changed(self, s, line=None): - k = unicode(s) - valbox = self.tagboxes[line] - if k in self.completion_values: - valbox.update_items_cache(self.completion_values[k]['v']) - if self.completion_values[k]['m']: - valbox.set_separator(', ') - else: - valbox.set_separator(None) - - dt = self.completion_values[k]['dt'] - if dt in ('int', 'float', 'rating', 'bool'): - self.reboxes[line].setChecked(0) - self.reboxes[line].setEnabled(False) - else: - self.reboxes[line].setEnabled(True) - self.fill_in_opbox(line) - else: - valbox.update_items_cache([]) - valbox.set_separator(None) - - def fill_in_opbox(self, line): - opbox = self.opboxes[line] - opbox.clear() - k = unicode(self.colboxes[line].currentText()) - if not k: - return - if k in self.completion_values: - rebox = self.reboxes[line] - ebox = self.emptyboxes[line] - idx = opbox.currentIndex() - if self.completion_values[k]['m'] or \ - rebox.checkState() == 2 or ebox.checkState() == 2: - opbox.addItems(self.relationals[0:2]) - idx = idx if idx < 2 else 0 - else: - opbox.addItems(self.relationals) - opbox.setCurrentIndex(max(idx, 0)) - - def re_box_changed(self, state, line=None): - self.fill_in_opbox(line) - - def empty_box_changed(self, state, line=None): - if state == 2: - self.tagboxes[line].setText('') - self.tagboxes[line].setEnabled(False) - self.reboxes[line].setChecked(0) - self.reboxes[line].setEnabled(False) - else: - self.reboxes[line].setEnabled(True) - self.tagboxes[line].setEnabled(True) - self.fill_in_opbox(line) - - def and_box_changed(self, state, line=None): - if state == 2: - self.colorboxes[line].setCurrentIndex(0) - self.colorboxes[line].setEnabled(False) - else: - self.colorboxes[line].setEnabled(True) - - def accepted(self): - if self.generate_program(): - self.accept() - else: - self.template = '' + self.setText(t.rule[1]) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 94c3deb403..b97cb3074a 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -426,7 +426,7 @@ class CcTemplateDelegate(QStyledItemDelegate): # {{{ editor.textbox.setTabStopWidth(20) d = editor.exec_() if d: - m.setData(index, QVariant(editor.textbox.toPlainText()), Qt.EditRole) + m.setData(index, QVariant(editor.rule[1]), Qt.EditRole) return None def setModelData(self, editor, model, index): diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index a8825ec582..aa4c930194 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -410,7 +410,7 @@ class RulesModel(QAbstractListModel): # {{{ def rule_to_html(self, col, rule): if isinstance(rule, basestring): return _(''' -

    Advanced Rule for column: %s +

    Advanced Rule for column %s:

    %s
    ''')%(col, rule) conditions = [self.condition_to_html(c) for c in rule.conditions] @@ -483,25 +483,28 @@ class EditRules(QWidget): # {{{ b.clicked.connect(self.add_advanced) l.addWidget(b, 3, 0, 1, 2) - def initialize(self, fm, prefs): + def initialize(self, fm, prefs, mi): self.model = RulesModel(prefs, fm) self.rules_view.setModel(self.model) + self.fm = fm + self.mi = mi - def add_rule(self): - d = RuleEditor(self.model.fm) - d.add_blank_condition() - if d.exec_() == d.Accepted: - col, r = d.rule - if r is not None and col: + def _add_rule(self, dlg): + if dlg.exec_() == dlg.Accepted: + col, r = dlg.rule + if r and col: idx = self.model.add_rule(col, r) self.rules_view.scrollTo(idx) self.changed.emit() + def add_rule(self): + d = RuleEditor(self.model.fm) + d.add_blank_condition() + self._add_rule(d) + def add_advanced(self): - td = TemplateDialog(self, '', None) - if td.exec_() == td.Accepted: - self.changed.emit() - pass # TODO + td = TemplateDialog(self, '', mi=self.mi, fm=self.fm, color_field='') + self._add_rule(td) def edit_rule(self, index): try: @@ -511,17 +514,14 @@ class EditRules(QWidget): # {{{ if isinstance(rule, Rule): d = RuleEditor(self.model.fm) d.apply_rule(col, rule) - if d.exec_() == d.Accepted: - col, r = d.rule - if r is not None and col: - self.model.replace_rule(index, col, r) - self.rules_view.scrollTo(index) - self.changed.emit() else: - td = TemplateDialog(self, rule, None) - if td.exec_() == td.Accepted: + d = TemplateDialog(self, rule, mi=self.mi, fm=self.fm, color_field=col) + if d.exec_() == d.Accepted: + col, r = d.rule + if r is not None and col: + self.model.replace_rule(index, col, r) + self.rules_view.scrollTo(index) self.changed.emit() - pass # TODO def get_selected_row(self, txt): sm = self.rules_view.selectionModel() @@ -575,7 +575,7 @@ if __name__ == '__main__': db = db() - if False: + if True: d = RuleEditor(db.field_metadata) d.add_blank_condition() d.exec_() @@ -588,7 +588,7 @@ if __name__ == '__main__': else: d = EditRules() d.resize(QSize(800, 600)) - d.initialize(db.field_metadata, db.prefs) + d.initialize(db.field_metadata, db.prefs, None) d.show() app.exec_() d.commit(db.prefs) diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index feaf3dd677..a2850679f1 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -176,7 +176,12 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.update_font_display() self.display_model.initialize() db = self.gui.current_db - self.edit_rules.initialize(db.field_metadata, db.prefs) + try: + idx = self.gui.library_view.currentIndex().row() + mi = db.get_metadata(idx, index_is_id=False) + except: + mi=None + self.edit_rules.initialize(db.field_metadata, db.prefs, mi) def restore_defaults(self): ConfigWidgetBase.restore_defaults(self) diff --git a/src/calibre/library/coloring.py b/src/calibre/library/coloring.py index db13da9532..0a6f5f7960 100644 --- a/src/calibre/library/coloring.py +++ b/src/calibre/library/coloring.py @@ -167,7 +167,10 @@ def conditionable_columns(fm): dt = m['datatype'] if m.get('name', False) and dt in ('bool', 'int', 'float', 'rating', 'series', 'comments', 'text', 'enumeration', 'datetime'): - yield key + if key == 'sort': + yield 'title_sort' + else: + yield key def displayable_columns(fm): for key in fm.displayable_field_keys(): diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index 14f8d05e8e..a1a012a822 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -223,7 +223,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): if self.prefs.get('column_color_name_1', None) is not None: from calibre.library.coloring import migrate_old_rule old_rules = [] - for i in range(1, 5): + for i in range(1, 6): col = self.prefs.get('column_color_name_'+str(i), None) templ = self.prefs.get('column_color_template_'+str(i), None) if col and templ: diff --git a/src/calibre/library/field_metadata.py b/src/calibre/library/field_metadata.py index 979e98a819..c884542241 100644 --- a/src/calibre/library/field_metadata.py +++ b/src/calibre/library/field_metadata.py @@ -374,6 +374,8 @@ class FieldMetadata(dict): self.get = self._tb_cats.get def __getitem__(self, key): + if key == 'title_sort': + return self._tb_cats['sort'] return self._tb_cats[key] def __setitem__(self, key, val): @@ -390,6 +392,8 @@ class FieldMetadata(dict): return self.has_key(key) def has_key(self, key): + if key == 'title_sort': + return True return key in self._tb_cats def keys(self): diff --git a/src/calibre/utils/formatter_functions.py b/src/calibre/utils/formatter_functions.py index 78ed4fa306..1a8867b44e 100644 --- a/src/calibre/utils/formatter_functions.py +++ b/src/calibre/utils/formatter_functions.py @@ -361,8 +361,7 @@ class BuiltinInList(BuiltinFormatterFunction): class BuiltinStrInList(BuiltinFormatterFunction): name = 'str_in_list' arg_count = 5 - category = 'List Lookup' - category = 'Iterating over values' + category = 'List lookup' __doc__ = doc = _('str_in_list(val, separator, string, found_val, not_found_val) -- ' 'treat val as a list of items separated by separator, ' 'comparing the string against each value in the list. If the ' @@ -380,6 +379,32 @@ class BuiltinStrInList(BuiltinFormatterFunction): return fv return nfv +class BuiltinIdentifierInList(BuiltinFormatterFunction): + name = 'identifier_in_list' + arg_count = 4 + category = 'List lookup' + __doc__ = doc = _('identifier_in_list(val, id, found_val, not_found_val) -- ' + 'treat val as a list of identifiers separated by commas, ' + 'comparing the string against each value in the list. An identifier ' + 'has the format "identifier:value". The id parameter should be ' + 'either "id" or "id:regexp". The first case matches if there is any ' + 'identifier with that id. The second case matches if the regexp ' + 'matches the identifier\'s value. If there is a match, ' + 'return found_val, otherwise return not_found_val.') + + def evaluate(self, formatter, kwargs, mi, locals, val, ident, fv, nfv): + l = [v.strip() for v in val.split(',') if v.strip()] + (id, _, regexp) = ident.partition(':') + if not id: + return nfv + id += ':' + if l: + for v in l: + if v.startswith(id): + if not regexp or re.search(regexp, v[len(id):], flags=re.I): + return fv + return nfv + class BuiltinRe(BuiltinFormatterFunction): name = 're' arg_count = 3 @@ -748,6 +773,7 @@ builtin_eval = BuiltinEval() builtin_first_non_empty = BuiltinFirstNonEmpty() builtin_field = BuiltinField() builtin_format_date = BuiltinFormatDate() +builtin_identifier_in_list = BuiltinIdentifierInList() builtin_ifempty = BuiltinIfempty() builtin_in_list = BuiltinInList() builtin_list_item = BuiltinListitem() From d02342fd0c00aeffcab8d02ea649900222a5ee1f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2011 09:33:02 -0600 Subject: [PATCH 71/84] Driver for Samsung Galaxy SII I9100 --- src/calibre/devices/android/driver.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/devices/android/driver.py b/src/calibre/devices/android/driver.py index 3c6ea243e2..b557ac3526 100644 --- a/src/calibre/devices/android/driver.py +++ b/src/calibre/devices/android/driver.py @@ -52,6 +52,7 @@ class ANDROID(USBMS): 0x04e8 : { 0x681d : [0x0222, 0x0223, 0x0224, 0x0400], 0x681c : [0x0222, 0x0224, 0x0400], 0x6640 : [0x0100], + 0x685e : [0x0400], 0x6877 : [0x0400], }, @@ -113,7 +114,8 @@ class ANDROID(USBMS): 'MB525'] WINDOWS_CARD_A_MEM = ['ANDROID_PHONE', 'GT-I9000_CARD', 'SGH-I897', 'FILE-STOR_GADGET', 'SGH-T959', 'SAMSUNG_ANDROID', 'GT-P1000_CARD', - 'A70S', 'A101IT', '7', 'INCREDIBLE', 'A7EB', 'SGH-T849_CARD'] + 'A70S', 'A101IT', '7', 'INCREDIBLE', 'A7EB', 'SGH-T849_CARD', + '__UMS_COMPOSITE'] OSX_MAIN_MEM = 'Android Device Main Memory' From 464499418967180e150a0cd41d0e3cd34d8d8af8 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2011 10:52:07 -0600 Subject: [PATCH 72/84] Fix template generation for ondevice, identifiers and number columns --- src/calibre/gui2/preferences/coloring.py | 52 ++++++++++++++++-------- src/calibre/library/coloring.py | 19 ++++++++- 2 files changed, 53 insertions(+), 18 deletions(-) diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index 61844a3176..a69cb802a2 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -10,7 +10,7 @@ __docformat__ = 'restructuredtext en' from PyQt4.Qt import (QWidget, QDialog, QLabel, QGridLayout, QComboBox, QSize, QLineEdit, QIntValidator, QDoubleValidator, QFrame, QColor, Qt, QIcon, QScrollArea, QPushButton, QVBoxLayout, QDialogButtonBox, QToolButton, - QListView, QAbstractListModel, pyqtSignal) + QListView, QAbstractListModel, pyqtSignal, QSizePolicy, QSpacerItem) from calibre.utils.icu import sort_key from calibre.gui2 import error_dialog @@ -31,6 +31,14 @@ class ConditionEditor(QWidget): # {{{ (_('is false'), 'is false'), (_('is undefined'), 'is undefined') ), + 'ondevice' : ( + (_('is true'), 'is set',), + (_('is false'), 'is not set'), + ), + 'identifiers' : ( + (_('has id'), 'has id'), + (_('does not have id'), 'does not have id'), + ), 'int' : ( (_('is equal to'), 'eq'), (_('is less than'), 'lt'), @@ -72,7 +80,7 @@ class ConditionEditor(QWidget): # {{{ self.action_box = QComboBox(self) l.addWidget(self.action_box, 0, 3) - self.l3 = l3 = QLabel(_(' the value ')) + self.l3 = l3 = QLabel(_(' value ')) l.addWidget(l3, 0, 4) self.value_box = QLineEdit(self) @@ -81,7 +89,7 @@ class ConditionEditor(QWidget): # {{{ self.column_box.addItem('', '') for key in sorted( conditionable_columns(fm), - key=lambda x:sort_key(fm[x]['name'])): + key=sort_key): self.column_box.addItem(key, key) self.column_box.setCurrentIndex(0) @@ -155,7 +163,12 @@ class ConditionEditor(QWidget): # {{{ if dt in self.action_map: actions = self.action_map[dt] else: - k = 'multiple' if m['is_multiple'] else 'single' + if col == 'ondevice': + k = 'ondevice' + elif col == 'identifiers': + k = 'identifiers' + else: + k = 'multiple' if m['is_multiple'] else 'single' actions = self.action_map[k] for text, key in actions: @@ -176,7 +189,10 @@ class ConditionEditor(QWidget): # {{{ if not col or not action: return tt = '' - if dt in ('int', 'float', 'rating'): + if col == 'identifiers': + tt = _('Enter either an identifier type or an ' + 'identifier type and value of the form identifier:value') + elif dt in ('int', 'float', 'rating'): tt = _('Enter a number') v = QIntValidator if dt == 'int' else QDoubleValidator self.value_box.setValidator(v(self.value_box)) @@ -184,9 +200,12 @@ class ConditionEditor(QWidget): # {{{ self.value_box.setInputMask('9999-99-99') tt = _('Enter a date in the format YYYY-MM-DD') else: - tt = _('Enter a string') + tt = _('Enter a string.') if 'pattern' in action: tt = _('Enter a regular expression') + elif m.get('is_multiple', False): + tt += '\n' + _('You can match multiple values by separating' + ' them with %s')%m['is_multiple'] self.value_box.setToolTip(tt) if action in ('is set', 'is not set', 'is true', 'is false', 'is undefined'): @@ -207,11 +226,11 @@ class RuleEditor(QDialog): # {{{ self.l1 = l1 = QLabel(_('Create a coloring rule by' ' filling in the boxes below')) - l.addWidget(l1, 0, 0, 1, 4) + l.addWidget(l1, 0, 0, 1, 5) self.f1 = QFrame(self) self.f1.setFrameShape(QFrame.HLine) - l.addWidget(self.f1, 1, 0, 1, 4) + l.addWidget(self.f1, 1, 0, 1, 5) self.l2 = l2 = QLabel(_('Set the color of the column:')) l.addWidget(l2, 2, 0) @@ -220,37 +239,36 @@ class RuleEditor(QDialog): # {{{ l.addWidget(self.column_box, 2, 1) self.l3 = l3 = QLabel(_('to')) - l3.setAlignment(Qt.AlignHCenter) l.addWidget(l3, 2, 2) self.color_box = QComboBox(self) l.addWidget(self.color_box, 2, 3) + l.addItem(QSpacerItem(10, 10, QSizePolicy.Expanding), 2, 4) self.l4 = l4 = QLabel( _('Only if the following conditions are all satisfied:')) - l4.setAlignment(Qt.AlignHCenter) - l.addWidget(l4, 3, 0, 1, 4) + l.addWidget(l4, 3, 0, 1, 5) self.scroll_area = sa = QScrollArea(self) sa.setMinimumHeight(300) sa.setMinimumWidth(950) sa.setWidgetResizable(True) - l.addWidget(sa, 4, 0, 1, 4) + l.addWidget(sa, 4, 0, 1, 5) self.add_button = b = QPushButton(QIcon(I('plus.png')), _('Add another condition')) - l.addWidget(b, 5, 0, 1, 4) + l.addWidget(b, 5, 0, 1, 5) b.clicked.connect(self.add_blank_condition) self.l5 = l5 = QLabel(_('You can disable a condition by' ' blanking all of its boxes')) - l.addWidget(l5, 6, 0, 1, 4) + l.addWidget(l5, 6, 0, 1, 5) self.bb = bb = QDialogButtonBox( QDialogButtonBox.Ok|QDialogButtonBox.Cancel) bb.accepted.connect(self.accept) bb.rejected.connect(self.reject) - l.addWidget(bb, 7, 0, 1, 4) + l.addWidget(bb, 7, 0, 1, 5) self.conditions_widget = QWidget(self) sa.setWidget(self.conditions_widget) @@ -264,7 +282,7 @@ class RuleEditor(QDialog): # {{{ for key in sorted( displayable_columns(fm), - key=lambda x:sort_key(fm[x]['name'])): + key=sort_key): name = fm[key]['name'] if name: self.column_box.addItem(key, key) @@ -422,7 +440,7 @@ class RulesModel(QAbstractListModel): # {{{ def condition_to_html(self, condition): return ( - _('
  • If the %s column %s the value: %s') % + _('
  • If the %s column %s value: %s') % tuple(condition)) # }}} diff --git a/src/calibre/library/coloring.py b/src/calibre/library/coloring.py index 0a6f5f7960..7db19bc50d 100644 --- a/src/calibre/library/coloring.py +++ b/src/calibre/library/coloring.py @@ -70,6 +70,12 @@ class Rule(object): # {{{ m = self.fm[col] dt = m['datatype'] + if col == 'ondevice': + return self.ondevice_condition(col, action, val) + + if col == 'identifiers': + return self.identifiers_condition(col, action, val) + if dt == 'bool': return self.bool_condition(col, action, val) @@ -85,6 +91,17 @@ class Rule(object): # {{{ return self.multiple_condition(col, action, val, ism) return self.text_condition(col, action, val) + def identifiers_condition(self, col, action, val): + if action == 'has id': + return "identifier_in_list(field('identifiers'), '%s', '1', '')" + return "identifier_in_list(field('identifiers'), '%s', '', '1')" + + def ondevice_condition(self, col, action, val): + if action == 'is set': + return "test('%s', '1', '')"%col + if action == 'is not set': + return "test('%s', '', '1')"%col + def bool_condition(self, col, action, val): test = {'is true': 'True', 'is false': 'False', @@ -98,7 +115,7 @@ class Rule(object): # {{{ 'gt': ('', '', '1') }[action] lt, eq, gt = '', '1', '' - return "cmp(field('%s'), %s, '%s', '%s', '%s')" % (col, val, lt, eq, gt) + return "cmp(raw_field('%s'), %s, '%s', '%s', '%s')" % (col, val, lt, eq, gt) def date_condition(self, col, action, val): lt, eq, gt = { From b42f0127643f6dfb7c7cde3d3dc81b97e622b7c3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2011 11:00:56 -0600 Subject: [PATCH 73/84] Fix #791216 (Add support for device: miBuk GAMMA 6.2 touch & wifi) --- src/calibre/devices/eb600/driver.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/devices/eb600/driver.py b/src/calibre/devices/eb600/driver.py index dbccd72ee9..ca7e0ce373 100644 --- a/src/calibre/devices/eb600/driver.py +++ b/src/calibre/devices/eb600/driver.py @@ -35,8 +35,8 @@ class EB600(USBMS): PRODUCT_ID = [0x1688] BCD = [0x110] - VENDOR_NAME = 'NETRONIX' - WINDOWS_MAIN_MEM = 'EBOOK' + VENDOR_NAME = ['NETRONIX', 'WOLDER'] + WINDOWS_MAIN_MEM = ['EBOOK', 'MIBUK_GAMMA_6.2'] WINDOWS_CARD_A_MEM = 'EBOOK' OSX_MAIN_MEM = 'EB600 Internal Storage Media' From 397e4750ce18e5663929f52bd2a077282b3fa798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20D=C5=82ugosz?= Date: Thu, 2 Jun 2011 19:04:44 +0200 Subject: [PATCH 74/84] drop runa recipe --- recipes/runa.recipe | 52 --------------------------------------------- 1 file changed, 52 deletions(-) delete mode 100644 recipes/runa.recipe diff --git a/recipes/runa.recipe b/recipes/runa.recipe deleted file mode 100644 index fe30041581..0000000000 --- a/recipes/runa.recipe +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python - -__license__ = 'GPL v3' -__author__ = 'Mori' -__version__ = 'v. 0.1' -''' -www.runa.pl/blog -''' - -from calibre.web.feeds.news import BasicNewsRecipe -import re - -class FantazmatyRecipe(BasicNewsRecipe): - __author__ = 'Mori' - language = 'pl' - - title = u'Fantazmaty' - publisher = u'Agencja Wydawnicza Runa' - description = u'Blog Agencji Wydawniczej Runa' - - no_stylesheets = True - remove_javascript = True - encoding = 'utf-8' - - oldest_article = 100 - max_articles_per_feed = 100 - - extra_css = ''' - img{float: left; padding-right: 10px; padding-bottom: 5px;} - ''' - - feeds = [ - (u'Fantazmaty', u'http://www.runa.pl/blog/rss.xml') - ] - - remove_tags = [ - dict(name = 'div', attrs = {'class' : 'path'}), - dict(name = 'div', attrs = {'class' : 'drdot'}), - dict(name = 'div', attrs = {'class' : 'picture'}) - ] - - remove_tags_after = [ - dict(name = 'div', attrs = {'class' : 'content'}) - ] - - preprocess_regexps = [ - (re.compile(i[0], re.IGNORECASE | re.DOTALL), i[1]) for i in - [ - (r'.*?
    ', lambda match: '') - ] - ] \ No newline at end of file From 4264660c51dd2010eade58bea36068609f57f7e2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2011 11:08:17 -0600 Subject: [PATCH 75/84] ... --- recipes/cnn.recipe | 72 +++--------------------- src/calibre/gui2/preferences/coloring.py | 2 +- 2 files changed, 10 insertions(+), 64 deletions(-) diff --git a/recipes/cnn.recipe b/recipes/cnn.recipe index 8c3cfa6de8..a2b6665033 100644 --- a/recipes/cnn.recipe +++ b/recipes/cnn.recipe @@ -4,75 +4,28 @@ __copyright__ = '2008, Kovid Goyal ' Profile to download CNN ''' from calibre.web.feeds.news import BasicNewsRecipe -from calibre.ebooks.BeautifulSoup import BeautifulSoup class CNN(BasicNewsRecipe): title = 'CNN' description = 'Global news' timefmt = ' [%d %b %Y]' - __author__ = 'Krittika Goyal and Sujata Raman' + __author__ = 'Kovid Goyal' language = 'en' no_stylesheets = True use_embedded_content = False oldest_article = 15 - recursions = 1 - match_regexps = [r'http://sportsillustrated.cnn.com/.*/[1-9].html'] + #recursions = 1 + #match_regexps = [r'http://sportsillustrated.cnn.com/.*/[1-9].html'] max_articles_per_feed = 25 - extra_css = ''' - .cnn_strycntntlft{font-family :Arial,Helvetica,sans-serif;} - h2{font-family :Arial,Helvetica,sans-serif; font-size:x-small} - .cnnTxtCmpnt{font-family :Arial,Helvetica,sans-serif; font-size:x-small} - .cnnTMcontent{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#575757} - .storytext{font-family :Arial,Helvetica,sans-serif; font-size:small} - .storybyline{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#575757} - .credit{font-family :Arial,Helvetica,sans-serif; font-size:xx-small; color:#575757} - .storyBrandingBanner{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#575757} - .storytimestamp{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#575757} - .timestamp{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#575757} - .cnn_strytmstmp{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#666666;} - .cnn_stryimg640caption{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#666666;} - .cnn_strylccimg300cntr{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#666666;} - .cnn_stryichgfcpt{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#666666;} - .cnnByline{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#666666;} - .cnn_bulletbin cnnStryHghLght{ font-size:xx-small;} - .subhead p{font-family :Arial,Helvetica,sans-serif; font-size:x-small;} - .cnnStoryContent{font-family :Arial,Helvetica,sans-serif; font-size:x-small} - .cnnContentContainer{font-family :Arial,Helvetica,sans-serif; font-size:x-small} - .col1{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#666666;} - .col3{color:#333333; font-family :Arial,Helvetica,sans-serif; font-size:x-small;font-weight:bold;} - .cnnInlineT1Caption{font-family :Arial,Helvetica,sans-serif; font-size:x-small;font-weight:bold;} - .cnnInlineT1Credit{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#333333;} - .col10{color:#5A637E;} - .cnnInlineRailBulletList{color:black;} - .cnnLine0{font-family :Arial,Helvetica,sans-serif; color:#666666;font-weight:bold;} - .cnnTimeStamp{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#333333;} - .galleryhedDek{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#575757;} - .galleryWidgetHeader{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#004276;} - .article-content{font-family :Arial,Helvetica,sans-serif; font-size:x-small} - .cnnRecapStory{font-family :Arial,Helvetica,sans-serif; font-size:x-small} - h1{font-family :Arial,Helvetica,sans-serif; font-size:x-large} - .captionname{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#575757;} - inStoryIE{{font-family :Arial,Helvetica,sans-serif; font-size:x-small;} - ''' - - #remove_tags_before = dict(name='h1', attrs={'class':'heading'}) - #remove_tags_after = dict(name='td', attrs={'class':'newptool1'}) - remove_tags = [ - dict(name='iframe'), - dict(name='div', attrs={'class':['cnnEndOfStory', 'cnnShareThisItem', 'cnn_strylctcntr cnn_strylctcqrelt', 'cnnShareBoxContent', 'cnn_strybtmcntnt', 'cnn_strycntntrgt']}), - dict(name='div', attrs={'id':['IEContainer', 'clickIncludeBox']}), - #dict(name='ul', attrs={'class':'article-tools'}), - #dict(name='ul', attrs={'class':'articleTools'}), - ] feeds = [ ('Top News', 'http://rss.cnn.com/rss/cnn_topstories.rss'), ('World', 'http://rss.cnn.com/rss/cnn_world.rss'), ('U.S.', 'http://rss.cnn.com/rss/cnn_us.rss'), - #('Sports', 'http://rss.cnn.com/rss/si_topstories.rss'), + ('Sports', 'http://rss.cnn.com/rss/si_topstories.rss'), ('Business', 'http://rss.cnn.com/rss/money_latest.rss'), ('Politics', 'http://rss.cnn.com/rss/cnn_allpolitics.rss'), ('Law', 'http://rss.cnn.com/rss/cnn_law.rss'), @@ -84,15 +37,8 @@ class CNN(BasicNewsRecipe): ('Offbeat', 'http://rss.cnn.com/rss/cnn_offbeat.rss'), ('Most Popular', 'http://rss.cnn.com/rss/cnn_mostpopular.rss') ] - def preprocess_html(self, soup): - story = soup.find(name='div', attrs={'class':'cnnBody_Left'}) - if story is None: - story = soup.find(name='div', attrs={'id':'cnnContentContainer'}) - soup = BeautifulSoup('t') - body = soup.find(name='body') - body.insert(0, story) - else: - soup = BeautifulSoup('t') - body = soup.find(name='body') - body.insert(0, story) - return soup + + def get_article_url(self, article): + ans = BasicNewsRecipe.get_article_url(self, article) + return ans.partition('?')[0] + diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index a69cb802a2..695adabed8 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -593,7 +593,7 @@ if __name__ == '__main__': db = db() - if True: + if False: d = RuleEditor(db.field_metadata) d.add_blank_condition() d.exec_() From f5f35cd1edeaa2cbe2018c79f32dee7dc49e014a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2011 11:41:59 -0600 Subject: [PATCH 76/84] Fix #791481 (CNN News fails to download as of 5/31 (previous version)) --- recipes/cnn.recipe | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/recipes/cnn.recipe b/recipes/cnn.recipe index a2b6665033..ccf47e26d8 100644 --- a/recipes/cnn.recipe +++ b/recipes/cnn.recipe @@ -3,6 +3,8 @@ __copyright__ = '2008, Kovid Goyal ' ''' Profile to download CNN ''' + +import re from calibre.web.feeds.news import BasicNewsRecipe class CNN(BasicNewsRecipe): @@ -20,12 +22,25 @@ class CNN(BasicNewsRecipe): #match_regexps = [r'http://sportsillustrated.cnn.com/.*/[1-9].html'] max_articles_per_feed = 25 + preprocess_regexps = [ + (re.compile(r'', re.DOTALL), lambda m: ''), + (re.compile(r'', re.DOTALL), lambda m: ''), + (re.compile(r'', re.DOTALL), lambda m: ''), + ] + + keep_only_tags = [dict(id='cnnContentContainer')] + remove_tags = [ + {'class':['cnn_strybtntools', 'cnn_strylftcntnt', + 'cnn_strybtntools', 'cnn_strybtntoolsbttm', 'cnn_strybtmcntnt', + 'cnn_strycntntrgt']}, + ] + feeds = [ ('Top News', 'http://rss.cnn.com/rss/cnn_topstories.rss'), ('World', 'http://rss.cnn.com/rss/cnn_world.rss'), ('U.S.', 'http://rss.cnn.com/rss/cnn_us.rss'), - ('Sports', 'http://rss.cnn.com/rss/si_topstories.rss'), + #('Sports', 'http://rss.cnn.com/rss/si_topstories.rss'), ('Business', 'http://rss.cnn.com/rss/money_latest.rss'), ('Politics', 'http://rss.cnn.com/rss/cnn_allpolitics.rss'), ('Law', 'http://rss.cnn.com/rss/cnn_law.rss'), From ce1ed1ff09aea4e91bfe4c88a8456b596f5b6f71 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2011 11:54:50 -0600 Subject: [PATCH 77/84] Fix typo in NOOK TSR driver that prevented it from working on windows --- src/calibre/devices/nook/driver.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/calibre/devices/nook/driver.py b/src/calibre/devices/nook/driver.py index 3c30b88568..aaa68891ba 100644 --- a/src/calibre/devices/nook/driver.py +++ b/src/calibre/devices/nook/driver.py @@ -115,5 +115,6 @@ class NOOK_TSR(NOOK): BCD = [0x216] EBOOK_DIR_MAIN = EBOOK_DIR_CARD_A = 'My Files/Books' + WINDOWS_MAIN_MEM = WINDOWS_CARD_A_MEM = 'EBOOK_DISK' From c460bcc30dd6564be7b77101a49c3e78b60d5aa9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2011 12:10:03 -0600 Subject: [PATCH 78/84] Fix ondevice template --- src/calibre/library/coloring.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/library/coloring.py b/src/calibre/library/coloring.py index 7db19bc50d..6e5e2216e0 100644 --- a/src/calibre/library/coloring.py +++ b/src/calibre/library/coloring.py @@ -98,9 +98,9 @@ class Rule(object): # {{{ def ondevice_condition(self, col, action, val): if action == 'is set': - return "test('%s', '1', '')"%col + return "test(ondevice(), '1', '')" if action == 'is not set': - return "test('%s', '', '1')"%col + return "test(ondevice(), '', '1')" def bool_condition(self, col, action, val): test = {'is true': 'True', From facae420cbdc8d070dfc3b2a59112920a0a529f3 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2011 12:38:46 -0600 Subject: [PATCH 79/84] Fix #791806 (Metadata causes freeze) --- src/calibre/library/database2.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/calibre/library/database2.py b/src/calibre/library/database2.py index a1a012a822..2106fcad8f 100644 --- a/src/calibre/library/database2.py +++ b/src/calibre/library/database2.py @@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en' The database used to store ebook metadata ''' import os, sys, shutil, cStringIO, glob, time, functools, traceback, re, \ - json, uuid + json, uuid, tempfile import threading, random from itertools import repeat from math import ceil @@ -591,11 +591,13 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns): f.write(cdata) for format in formats: # Get data as string (can't use file as source and target files may be the same) - f = self.format(id, format, index_is_id=True, as_file=False) - if not f: + f = self.format(id, format, index_is_id=True, as_file=True) + if f is None: continue - stream = cStringIO.StringIO(f) - self.add_format(id, format, stream, index_is_id=True, + with tempfile.SpooledTemporaryFile(max_size=100*(1024**2)) as stream: + shutil.copyfileobj(f, stream) + stream.seek(0) + self.add_format(id, format, stream, index_is_id=True, path=tpath, notify=False) self.conn.execute('UPDATE books SET path=? WHERE id=?', (path, id)) self.dirtied([id], commit=False) From 40b1266e7c9a6f2aa12ccd7e327eea01a4305b2b Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2011 12:42:59 -0600 Subject: [PATCH 80/84] ... --- src/calibre/ebooks/oeb/iterator.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/oeb/iterator.py b/src/calibre/ebooks/oeb/iterator.py index 299c77af10..92a4febb6c 100644 --- a/src/calibre/ebooks/oeb/iterator.py +++ b/src/calibre/ebooks/oeb/iterator.py @@ -18,7 +18,7 @@ from calibre.ebooks.chardet import xml_to_unicode from calibre.utils.zipfile import safe_replace from calibre.utils.config import DynamicConfig from calibre.utils.logging import Log -from calibre import guess_type, prints +from calibre import guess_type, prints, prepare_string_for_xml from calibre.ebooks.oeb.transforms.cover import CoverManager TITLEPAGE = CoverManager.SVG_TEMPLATE.decode('utf-8').replace(\ @@ -229,8 +229,8 @@ class EbookIterator(object): cover = self.opf.cover if self.ebook_ext in ('lit', 'mobi', 'prc', 'opf', 'fb2') and cover: cfile = os.path.join(self.base, 'calibre_iterator_cover.html') - chtml = (TITLEPAGE%os.path.relpath(cover, self.base).replace(os.sep, - '/')).encode('utf-8') + rcpath = os.path.relpath(cover, self.base).replace(os.sep, '/') + chtml = (TITLEPAGE%prepare_string_for_xml(rcpath, True)).encode('utf-8') open(cfile, 'wb').write(chtml) self.spine[0:0] = [SpineItem(cfile, mime_type='application/xhtml+xml')] From 7122410cfc2469c7d84cb503a7036b1985596483 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2011 12:54:54 -0600 Subject: [PATCH 81/84] ... --- src/calibre/manual/portable.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/calibre/manual/portable.rst b/src/calibre/manual/portable.rst index 76776e3603..a9c9679512 100644 --- a/src/calibre/manual/portable.rst +++ b/src/calibre/manual/portable.rst @@ -11,6 +11,7 @@ You can "install" calibre onto a USB stick that you can take with you and use on * Run a Mobile Calibre installation with both the Calibre binaries and your ebook library resident on a USB disk or other portable media. In particular it is not necessary to have Calibre installed on the Windows PC that is to run Calibre. This batch file also does not care what drive letter is assigned when you plug in the USB device. It also will not affect any settings on the host machine being a completely self-contained Calibre installation. * Run a networked Calibre installation optimised for performance when the ebook files are located on a networked share. +If you find setting up the bat file too challenging, there is a third party portable calibre build available at `portableapps.com http://portableapps.com`_. This calibre-portable.bat file is intended for use on Windows based systems, but the principles are easily adapted for use on Linux or OS X based systems. Note that calibre requires the Microsoft Visual C++ 2008 runtimes to run. Most windows computers have them installed already, but it may be a good idea to have the installer for installing them on your USB stick. The installer is available from `Microsoft `_. @@ -73,4 +74,4 @@ Precautions Portable media can occasionally fail so you should make periodic backups of you Calibre library. This can be done by making a copy of the CalibreLibrary folder and all its contents. There are many freely available tools around that can optimise such back processes, well known ones being RoboCopy and RichCopy. However you can simply use a Windows copy facility if you cannot be bothered to use a specialised tools. -Using the environment variable CALIBRE_OVERRIDE_DATABASE_PATH disables multiple-library support in |app|. Avoid setting this variable in calibre-portable.bat unless you really need it. \ No newline at end of file +Using the environment variable CALIBRE_OVERRIDE_DATABASE_PATH disables multiple-library support in |app|. Avoid setting this variable in calibre-portable.bat unless you really need it. From 538a01440afdeec72fd428446045b37cf8b91b62 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2011 14:24:13 -0600 Subject: [PATCH 82/84] Fix #792014 (Configure download select all/clear all not enabling Apply) --- src/calibre/gui2/preferences/metadata_sources.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/gui2/preferences/metadata_sources.py b/src/calibre/gui2/preferences/metadata_sources.py index f7465fb0ee..961d0dd0a4 100644 --- a/src/calibre/gui2/preferences/metadata_sources.py +++ b/src/calibre/gui2/preferences/metadata_sources.py @@ -283,7 +283,9 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.fields_model.dataChanged.connect(self.changed_signal) self.select_all_button.clicked.connect(self.fields_model.select_all) + self.select_all_button.clicked.connect(self.changed_signal) self.clear_all_button.clicked.connect(self.fields_model.clear_all) + self.clear_all_button.clicked.connect(self.changed_signal) def configure_plugin(self): for index in self.sources_view.selectionModel().selectedRows(): From 0f0e624fcc823cfc53f179918f167253491e1403 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 2 Jun 2011 16:33:15 -0600 Subject: [PATCH 83/84] ... --- src/calibre/library/coloring.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/library/coloring.py b/src/calibre/library/coloring.py index 6e5e2216e0..c8cafcf9eb 100644 --- a/src/calibre/library/coloring.py +++ b/src/calibre/library/coloring.py @@ -93,8 +93,8 @@ class Rule(object): # {{{ def identifiers_condition(self, col, action, val): if action == 'has id': - return "identifier_in_list(field('identifiers'), '%s', '1', '')" - return "identifier_in_list(field('identifiers'), '%s', '', '1')" + return "identifier_in_list(field('identifiers'), '%s', '1', '')"%val + return "identifier_in_list(field('identifiers'), '%s', '', '1')"%val def ondevice_condition(self, col, action, val): if action == 'is set': From 12ecdaea48801e5266fa71888e386bddb9057fe8 Mon Sep 17 00:00:00 2001 From: John Schember Date: Thu, 2 Jun 2011 20:12:14 -0400 Subject: [PATCH 84/84] Fix bug #791788: Store search not able to handle unicode characters. --- src/calibre/gui2/store/gandalf_plugin.py | 2 +- src/calibre/gui2/store/gutenberg_plugin.py | 4 ++-- src/calibre/gui2/store/legimi_plugin.py | 2 +- src/calibre/gui2/store/manybooks_plugin.py | 4 ++-- src/calibre/gui2/store/nexto_plugin.py | 2 +- src/calibre/gui2/store/search/search.py | 2 +- src/calibre/gui2/store/virtualo_plugin.py | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/calibre/gui2/store/gandalf_plugin.py b/src/calibre/gui2/store/gandalf_plugin.py index 4bd8e9e747..52e1d296fa 100644 --- a/src/calibre/gui2/store/gandalf_plugin.py +++ b/src/calibre/gui2/store/gandalf_plugin.py @@ -37,7 +37,7 @@ class GandalfStore(BasicStoreConfig, StorePlugin): def search(self, query, max_results=10, timeout=60): url = 'http://www.gandalf.com.pl/s/' values={ - 'search': query.encode('iso8859_2'), + 'search': query.decode('utf-8').encode('iso8859_2'), 'dzialx':'11' } diff --git a/src/calibre/gui2/store/gutenberg_plugin.py b/src/calibre/gui2/store/gutenberg_plugin.py index d820a44f8d..85d1f3966a 100644 --- a/src/calibre/gui2/store/gutenberg_plugin.py +++ b/src/calibre/gui2/store/gutenberg_plugin.py @@ -6,7 +6,7 @@ __license__ = 'GPL 3' __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' -import urllib2 +import urllib from contextlib import closing from lxml import html @@ -42,7 +42,7 @@ class GutenbergStore(BasicStoreConfig, StorePlugin): def search(self, query, max_results=10, timeout=60): # Gutenberg's website does not allow searching both author and title. # Using a google search so we can search on both fields at once. - url = 'http://www.google.com/xhtml?q=site:gutenberg.org+' + urllib2.quote(query) + url = 'http://www.google.com/xhtml?q=site:gutenberg.org+' + urllib.quote_plus(query) br = browser() diff --git a/src/calibre/gui2/store/legimi_plugin.py b/src/calibre/gui2/store/legimi_plugin.py index 7212f0f394..2f69da24e5 100644 --- a/src/calibre/gui2/store/legimi_plugin.py +++ b/src/calibre/gui2/store/legimi_plugin.py @@ -40,7 +40,7 @@ class LegimiStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://www.legimi.com/pl/ebooks/?price=any&lang=pl&search=' + urllib.quote_plus(query.encode('utf-8')) + '&sort=relevance' + url = 'http://www.legimi.com/pl/ebooks/?price=any&lang=pl&search=' + urllib.quote_plus(query) + '&sort=relevance' br = browser() diff --git a/src/calibre/gui2/store/manybooks_plugin.py b/src/calibre/gui2/store/manybooks_plugin.py index e990accc86..efd8d21e68 100644 --- a/src/calibre/gui2/store/manybooks_plugin.py +++ b/src/calibre/gui2/store/manybooks_plugin.py @@ -7,7 +7,7 @@ __copyright__ = '2011, John Schember ' __docformat__ = 'restructuredtext en' import re -import urllib2 +import urllib from contextlib import closing from lxml import html @@ -43,7 +43,7 @@ class ManyBooksStore(BasicStoreConfig, StorePlugin): # It also doesn't do a clear job of references authors and # secondary titles. Google is also faster. # Using a google search so we can search on both fields at once. - url = 'http://www.google.com/xhtml?q=site:manybooks.net+' + urllib2.quote(query) + url = 'http://www.google.com/xhtml?q=site:manybooks.net+' + urllib.quote_plus(query) br = browser() diff --git a/src/calibre/gui2/store/nexto_plugin.py b/src/calibre/gui2/store/nexto_plugin.py index 0009f39b1b..fa152f958c 100644 --- a/src/calibre/gui2/store/nexto_plugin.py +++ b/src/calibre/gui2/store/nexto_plugin.py @@ -44,7 +44,7 @@ class NextoStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://www.nexto.pl/szukaj.xml?search-clause=' + urllib.quote_plus(query.encode('utf-8')) + '&scid=1015' + url = 'http://www.nexto.pl/szukaj.xml?search-clause=' + urllib.quote_plus(query) + '&scid=1015' br = browser() diff --git a/src/calibre/gui2/store/search/search.py b/src/calibre/gui2/store/search/search.py index e1ad24943d..8289c89b96 100644 --- a/src/calibre/gui2/store/search/search.py +++ b/src/calibre/gui2/store/search/search.py @@ -186,7 +186,7 @@ class SearchDialog(QDialog, Ui_Dialog): # Remove excess whitespace. query = re.sub(r'\s{2,}', ' ', query) query = query.strip() - return query + return query.encode('utf-8') def save_state(self): self.config['geometry'] = bytearray(self.saveGeometry()) diff --git a/src/calibre/gui2/store/virtualo_plugin.py b/src/calibre/gui2/store/virtualo_plugin.py index c6d6fc70d8..74e8104924 100644 --- a/src/calibre/gui2/store/virtualo_plugin.py +++ b/src/calibre/gui2/store/virtualo_plugin.py @@ -35,7 +35,7 @@ class VirtualoStore(BasicStoreConfig, StorePlugin): d.exec_() def search(self, query, max_results=10, timeout=60): - url = 'http://virtualo.pl/c2/?q=' + urllib.quote(query.encode('utf-8')) + url = 'http://virtualo.pl/c2/?q=' + urllib.quote(query) br = browser()