[Sync] Sync with trunk. Revision 9361

This commit is contained in:
Li Fanxi 2011-06-01 01:13:39 +08:00
commit 32e61fae78
82 changed files with 3102 additions and 923 deletions

View File

@ -478,7 +478,7 @@
type: major
description : >
"You can now save your frequently used searches and access them with a single click. For details
see http://calibre-ebook.com/user_manual/gui.html#search-sort"
see http://manual.calibre-ebook.com/gui.html#search-sort"
- title: "Add searching by date/published date"
tickets: [5244]

View File

@ -584,7 +584,7 @@
- title: "FB2 Output: Option to set the FB2 genre explicitly."
tickets: [743178]
- title: "Plugin developers: calibre now has a new plugin API, see http://calibre-ebook.com/user_manual/creating_plugins.html. Your existing plugins should continue to work, but it would be good to test them to make sure."
- title: "Plugin developers: calibre now has a new plugin API, see http://manual.calibre-ebook.com/creating_plugins.html. Your existing plugins should continue to work, but it would be good to test them to make sure."
bug fixes:
- title: "Fix text color in the search bar set to black instead of the system font color"
@ -969,7 +969,7 @@
new features:
- title: "Tag Browser: Support the creation of nested User Categories"
description: "See http://calibre-ebook.com/user_manual/gui.html#tag-browser for details"
description: "See http://manual.calibre-ebook.com/gui.html#tag-browser for details"
type: major
- title: "Disable Kent District Library plugin to download series information. The website could not handle the load calibre's 2 million users put on it. You can manually re-enable it if you really want series information, but it is very slow"
@ -3842,7 +3842,7 @@
type: major
description: >
"You can now change the icons used in the User Interface and other static resources. Details on how to
do this are at: http://calibre-ebook.com/user_manual/customize.html#overriding-icons-templates-etcetera"
do this are at: http://manual.calibre-ebook.com/customize.html#overriding-icons-templates-etcetera"
- title: "Split the 'Send to device' button into two buttons, 'Connect/share' and 'Send to device'. The new 'Send to device' button will now only be available when a device is connected."

View File

@ -3,7 +3,7 @@ calibre supports installation from source, only on Linux.
Note that you *do not* need to install from source to hack on
the calibre source code. To get started with calibre development,
use a normal calibre install and follow the instructions at
http://calibre-ebook.com/user_manual/develop.html
http://manual.calibre-ebook.com/develop.html
On Linux, there are two kinds of installation from source possible.
Note that both kinds require lots of dependencies as well as a

4
README
View File

@ -6,8 +6,8 @@ reading. It is cross platform, running on Linux, Windows and OS X.
For screenshots: https://calibre-ebook.com/demo
For installation/usage instructions please see
http://calibre-ebook.com/user_manual
For usage instructions please see
http://manual.calibre-ebook.com
For source code access:
bzr branch lp:calibre

BIN
icons/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

View File

@ -0,0 +1,43 @@
__license__ = 'GPL v3'
__copyright__ = '2011, Rasmus Lauritsen <rasmus at lauritsen.info>'
'''
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'])
]

View File

@ -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)

View File

@ -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()

29
recipes/metro_uk.recipe Normal file
View File

@ -0,0 +1,29 @@
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(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'})
]
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/')]

View File

@ -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

64
recipes/version2.recipe Normal file
View File

@ -0,0 +1,64 @@
import re
__license__ = 'GPL v3'
__copyright__ = '2011, Rasmus Lauritsen <rasmus at lauritsen.info>'
'''
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'</?a[^>]*>'),lambda match: ''),
(re.compile(r'<span[^>]*article-link-id.*?<br\s*\/?><br\s*\/?>'), 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')
]

View File

@ -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"
}

View File

@ -17,6 +17,7 @@
IncludeMaximum="yes"
OnlyDetect="no"
Language="1033"
MigrateFeatures="yes"
Property="OLDPRODUCTFOUND"/>
<UpgradeVersion Minimum="{version}"
IncludeMinimum="no"
@ -69,7 +70,7 @@
WorkingDirectory="APPLICATIONROOTDIRECTORY" />
<util:InternetShortcut Id="OnlineDocumentationShortcut"
Name="User Manual" Type="url"
Target="http://calibre-ebook.com/user_manual"/>
Target="http://manual.calibre-ebook.com"/>
<util:InternetShortcut Id="GetInvolvedS"
Name="Get Involved" Type="url"
Target="http://calibre-ebook.com/get-involved"/>

View File

@ -16,7 +16,7 @@ from setup import Command, __version__, installer_name, __appname__
PREFIX = "/var/www/calibre-ebook.com"
DOWNLOADS = PREFIX+"/htdocs/downloads"
BETAS = DOWNLOADS +'/betas'
USER_MANUAL = PREFIX+'/htdocs/user_manual'
USER_MANUAL = '/var/www/localhost/htdocs/'
HTML2LRF = "calibre/ebooks/lrf/html/demo"
TXT2LRF = "src/calibre/ebooks/lrf/txt/demo"
MOBILEREAD = 'ftp://dev.mobileread.com/calibre/'
@ -365,7 +365,7 @@ class UploadUserManual(Command): # {{{
self.build_plugin_example(x)
check_call(' '.join(['scp', '-r', 'src/calibre/manual/.build/html/*',
'divok:%s'%USER_MANUAL]), shell=True)
'bugs:%s'%USER_MANUAL]), shell=True)
# }}}
class UploadDemo(Command): # {{{

View File

@ -623,6 +623,8 @@ class StoreBase(Plugin): # {{{
headquarters = ''
# All formats the store distributes ebooks in.
formats = []
# Is this store on an affiliate program?
affiliate = False
def load_actual_plugin(self, gui):
'''

View File

@ -1108,9 +1108,9 @@ class StoreAmazonKindleStore(StoreBase):
description = u'Kindle books from Amazon.'
actual_plugin = 'calibre.gui2.store.amazon_plugin:AmazonKindleStore'
drm_free_only = False
headquarters = 'US'
formats = ['KINDLE']
affiliate = True
class StoreAmazonDEKindleStore(StoreBase):
name = 'Amazon DE Kindle'
@ -1118,9 +1118,9 @@ class StoreAmazonDEKindleStore(StoreBase):
description = u'Kindle Bücher von Amazon.'
actual_plugin = 'calibre.gui2.store.amazon_de_plugin:AmazonDEKindleStore'
drm_free_only = False
headquarters = 'DE'
formats = ['KINDLE']
affiliate = True
class StoreAmazonUKKindleStore(StoreBase):
name = 'Amazon UK Kindle'
@ -1128,9 +1128,9 @@ class StoreAmazonUKKindleStore(StoreBase):
description = u'Kindle books from Amazon\'s UK web site. Also, includes French language ebooks.'
actual_plugin = 'calibre.gui2.store.amazon_uk_plugin:AmazonUKKindleStore'
drm_free_only = False
headquarters = 'UK'
formats = ['KINDLE']
affiliate = True
class StoreArchiveOrgStore(StoreBase):
name = 'Archive.org'
@ -1155,9 +1155,9 @@ class StoreBNStore(StoreBase):
description = u'The world\'s largest book seller. As the ultimate destination for book lovers, Barnes & Noble.com offers an incredible array of content.'
actual_plugin = 'calibre.gui2.store.bn_plugin:BNStore'
drm_free_only = False
headquarters = 'US'
formats = ['NOOK']
affiliate = True
class StoreBeamEBooksDEStore(StoreBase):
name = 'Beam EBooks DE'
@ -1168,6 +1168,7 @@ class StoreBeamEBooksDEStore(StoreBase):
drm_free_only = True
headquarters = 'DE'
formats = ['EPUB', 'MOBI', 'PDF']
affiliate = True
class StoreBeWriteStore(StoreBase):
name = 'BeWrite Books'
@ -1183,18 +1184,18 @@ class StoreDieselEbooksStore(StoreBase):
description = u'Instant access to over 2.4 million titles from hundreds of publishers including Harlequin, HarperCollins, John Wiley & Sons, McGraw-Hill, Simon & Schuster and Random House.'
actual_plugin = 'calibre.gui2.store.diesel_ebooks_plugin:DieselEbooksStore'
drm_free_only = False
headquarters = 'US'
formats = ['EPUB', 'PDF']
affiliate = True
class StoreEbookscomStore(StoreBase):
name = 'eBooks.com'
description = u'Sells books in multiple electronic formats in all categories. Technical infrastructure is cutting edge, robust and scalable, with servers in the US and Europe.'
actual_plugin = 'calibre.gui2.store.ebooks_com_plugin:EbookscomStore'
drm_free_only = False
headquarters = 'US'
formats = ['EPUB', 'LIT', 'MOBI', 'PDF']
affiliate = True
class StoreEPubBuyDEStore(StoreBase):
name = 'EPUBBuy DE'
@ -1205,22 +1206,32 @@ class StoreEPubBuyDEStore(StoreBase):
drm_free_only = True
headquarters = 'DE'
formats = ['EPUB']
affiliate = True
class StoreEBookShoppeUKStore(StoreBase):
name = 'ebookShoppe UK'
author = u'Charles Haley'
description = u'We made this website in an attempt to offer the widest range of UK eBooks possible across and as many formats as we could manage.'
actual_plugin = 'calibre.gui2.store.ebookshoppe_uk_plugin:EBookShoppeUKStore'
headquarters = 'UK'
formats = ['EPUB', 'PDF']
affiliate = True
class StoreEHarlequinStore(StoreBase):
name = 'eHarlequin'
description = u'A global leader in series romance and one of the world\'s leading publishers of books for women. Offers women a broad range of reading from romance to bestseller fiction, from young adult novels to erotic literature, from nonfiction to fantasy, from African-American novels to inspirational romance, and more.'
actual_plugin = 'calibre.gui2.store.eharlequin_plugin:EHarlequinStore'
drm_free_only = False
headquarters = 'CA'
formats = ['EPUB', 'PDF']
affiliate = True
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.'
actual_plugin = 'calibre.gui2.store.feedbooks_plugin:FeedbooksStore'
drm_free_only = False
headquarters = 'FR'
formats = ['EPUB', 'MOBI', 'PDF']
@ -1230,9 +1241,9 @@ class StoreFoylesUKStore(StoreBase):
description = u'Foyles of London\'s ebook store. Provides extensive range covering all subjects.'
actual_plugin = 'calibre.gui2.store.foyles_uk_plugin:FoylesUKStore'
drm_free_only = False
headquarters = 'UK'
formats = ['EPUB', 'PDF']
affiliate = True
class StoreGandalfStore(StoreBase):
name = 'Gandalf'
@ -1240,7 +1251,6 @@ class StoreGandalfStore(StoreBase):
description = u'Księgarnia internetowa Gandalf.'
actual_plugin = 'calibre.gui2.store.gandalf_plugin:GandalfStore'
drm_free_only = False
headquarters = 'PL'
formats = ['EPUB', 'PDF']
@ -1249,7 +1259,6 @@ class StoreGoogleBooksStore(StoreBase):
description = u'Google Books'
actual_plugin = 'calibre.gui2.store.google_books_plugin:GoogleBooksStore'
drm_free_only = False
headquarters = 'US'
formats = ['EPUB', 'PDF', 'TXT']
@ -1267,9 +1276,9 @@ class StoreKoboStore(StoreBase):
description = u'With over 2.3 million eBooks to browse we have engaged readers in over 200 countries in Kobo eReading. Our eBook listings include New York Times Bestsellers, award winners, classics and more!'
actual_plugin = 'calibre.gui2.store.kobo_plugin:KoboStore'
drm_free_only = False
headquarters = 'CA'
formats = ['EPUB']
affiliate = True
class StoreLegimiStore(StoreBase):
name = 'Legimi'
@ -1277,7 +1286,6 @@ class StoreLegimiStore(StoreBase):
description = u'Tanie oraz darmowe ebooki, egazety i blogi w formacie EPUB, wprost na Twój e-czytnik, iPhone, iPad, Android i komputer'
actual_plugin = 'calibre.gui2.store.legimi_plugin:LegimiStore'
drm_free_only = False
headquarters = 'PL'
formats = ['EPUB']
@ -1305,9 +1313,9 @@ class StoreNextoStore(StoreBase):
description = u'Największy w Polsce sklep internetowy z audiobookami mp3, ebookami pdf oraz prasą do pobrania on-line.'
actual_plugin = 'calibre.gui2.store.nexto_plugin:NextoStore'
drm_free_only = False
headquarters = 'PL'
formats = ['EPUB', 'PDF']
affiliate = True
class StoreOpenLibraryStore(StoreBase):
name = 'Open Library'
@ -1344,6 +1352,7 @@ class StoreSmashwordsStore(StoreBase):
drm_free_only = True
headquarters = 'US'
formats = ['EPUB', 'HTML', 'LRF', 'MOBI', 'PDB', 'RTF', 'TXT']
affiliate = True
class StoreVirtualoStore(StoreBase):
name = 'Virtualo'
@ -1351,7 +1360,6 @@ class StoreVirtualoStore(StoreBase):
description = u'Księgarnia internetowa, która oferuje bezpieczny i szeroki dostęp do książek w formie cyfrowej.'
actual_plugin = 'calibre.gui2.store.virtualo_plugin:VirtualoStore'
drm_free_only = False
headquarters = 'PL'
formats = ['EPUB', 'PDF']
@ -1361,7 +1369,6 @@ class StoreWaterstonesUKStore(StoreBase):
description = u'Waterstone\'s mission is to be the leading Bookseller on the High Street and online providing customers the widest choice, great value and expert advice from a team passionate about Bookselling.'
actual_plugin = 'calibre.gui2.store.waterstones_uk_plugin:WaterstonesUKStore'
drm_free_only = False
headquarters = 'UK'
formats = ['EPUB', 'PDF']
@ -1374,6 +1381,15 @@ class StoreWeightlessBooksStore(StoreBase):
headquarters = 'US'
formats = ['EPUB', 'HTML', 'LIT', 'MOBI', 'PDF']
class StoreWHSmithUKStore(StoreBase):
name = 'WH Smith UK'
author = 'Charles Haley'
description = u"Shop for savings on Books, discounted Magazine subscriptions and great prices on Stationery, Toys & Games"
actual_plugin = 'calibre.gui2.store.whsmith_uk_plugin:WHSmithUKStore'
headquarters = 'UK'
formats = ['EPUB', 'PDF']
class StoreWizardsTowerBooksStore(StoreBase):
name = 'Wizards Tower Books'
description = u'A science fiction and fantasy publisher. Concentrates mainly on making out-of-print works available once more as e-books, and helping other small presses exploit the e-book market. Also publishes a small number of limited-print-run anthologies with a view to encouraging diversity in the science fiction and fantasy field.'
@ -1389,7 +1405,6 @@ class StoreWoblinkStore(StoreBase):
description = u'Czytanie zdarza się wszędzie!'
actual_plugin = 'calibre.gui2.store.woblink_plugin:WoblinkStore'
drm_free_only = False
headquarters = 'PL'
formats = ['EPUB']
@ -1404,6 +1419,7 @@ plugins += [
StoreBeWriteStore,
StoreDieselEbooksStore,
StoreEbookscomStore,
StoreEBookShoppeUKStore,
StoreEPubBuyDEStore,
StoreEHarlequinStore,
StoreFeedbooksStore,
@ -1421,8 +1437,9 @@ plugins += [
StorePragmaticBookshelfStore,
StoreSmashwordsStore,
StoreVirtualoStore,
#StoreWaterstonesUKStore,
StoreWaterstonesUKStore,
StoreWeightlessBooksStore,
StoreWHSmithUKStore,
StoreWizardsTowerBooksStore,
StoreWoblinkStore
]

View File

@ -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']

View File

@ -40,7 +40,7 @@ To get help on them specify the input and output file and then use the -h \
option.
For full documentation of the conversion system see
''') + 'http://calibre-ebook.com/user_manual/conversion.html'
''') + 'http://manual.calibre-ebook.com/conversion.html'
HEURISTIC_OPTIONS = ['markup_chapter_headings',
'italicize_common_cases', 'fix_indents',

View File

@ -41,27 +41,26 @@ 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):
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)
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:
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()
@ -75,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.
@ -106,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.
@ -628,6 +627,12 @@ class Metadata(object):
res = _('Yes') if res else _('No')
elif datatype == 'rating':
res = res/2.0
elif datatype in ['int', 'float']:
try:
fmt = cmeta['display'].get('number_format', None)
res = fmt.format(res)
except:
pass
return (name, unicode(res), orig_res, cmeta)
# convert top-level ids into their value

View File

@ -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

View File

@ -317,6 +317,7 @@ class AddAction(InterfaceAction):
_('Uploading books to device.'), 2000)
if getattr(self._adder, 'number_of_books_added', 0) > 0:
self.gui.library_view.model().books_added(self._adder.number_of_books_added)
self.gui.library_view.set_current_row(0)
if hasattr(self.gui, 'db_images'):
self.gui.db_images.reset()
self.gui.tags_view.recount()
@ -338,7 +339,6 @@ class AddAction(InterfaceAction):
self.gui.library_view.model().current_changed(current_idx,
current_idx)
if getattr(self._adder, 'critical', None):
det_msg = []
for name, log in self._adder.critical.items():

View File

@ -152,7 +152,8 @@ class DeleteAction(InterfaceAction):
if not ids:
return
fmts = self._get_selected_formats(
'<p>'+_('Choose formats <b>not</b> to be deleted'), ids)
'<p>'+_('Choose formats <b>not</b> to be deleted.<p>Note that '
'this will never remove all formats from a book.'), ids)
if fmts is None:
return
for id in ids:
@ -161,9 +162,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())

View File

@ -19,7 +19,7 @@ class HelpAction(InterfaceAction):
self.qaction.triggered.connect(self.show_help)
def show_help(self, *args):
open_url(QUrl('http://calibre-ebook.com/user_manual'))
open_url(QUrl('http://manual.calibre-ebook.com'))

View File

@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
from functools import partial
from PyQt4.Qt import QMenu
from PyQt4.Qt import QMenu, QIcon, QSize
from calibre.gui2 import error_dialog
from calibre.gui2.actions import InterfaceAction
@ -32,8 +32,13 @@ class StoreAction(InterfaceAction):
self.store_menu.addAction(_('Search for this book'), self.search_author_title)
self.store_menu.addSeparator()
self.store_list_menu = self.store_menu.addMenu(_('Stores'))
icon = QIcon()
icon.addFile(I('donate.png'), QSize(16, 16))
for n, p in sorted(self.gui.istores.items(), key=lambda x: x[0].lower()):
self.store_list_menu.addAction(n, partial(self.open_store, p))
if p.base_plugin.affiliate:
self.store_list_menu.addAction(icon, n, partial(self.open_store, p))
else:
self.store_list_menu.addAction(n, partial(self.open_store, p))
self.store_menu.addSeparator()
self.store_menu.addAction(_('Choose stores'), self.choose)
self.qaction.setMenu(self.store_menu)

View File

@ -33,7 +33,7 @@
<property name="text">
<string>&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;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. &lt;/p&gt;
&lt;p&gt;See the &lt;a href=&quot;http://calibre-ebook.com/user_manual/conversion.html#font-size-rescaling&quot;&gt;User Manual&lt;/a&gt; for a discussion of how font size rescaling works.&lt;/p&gt;</string>
&lt;p&gt;See the &lt;a href=&quot;http://manual.calibre-ebook.com/conversion.html#font-size-rescaling&quot;&gt;User Manual&lt;/a&gt; for a discussion of how font size rescaling works.&lt;/p&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -17,7 +17,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;b&gt;Heuristic processing&lt;/b&gt; 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 &lt;a href=&quot;http://calibre-ebook.com/user_manual/conversion.html#heuristic-processing&quot;&gt;User Manual&lt;/a&gt;.</string>
<string>&lt;b&gt;Heuristic processing&lt;/b&gt; 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 &lt;a href=&quot;http://manual.calibre-ebook.com/conversion.html#heuristic-processing&quot;&gt;User Manual&lt;/a&gt;.</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -188,7 +188,7 @@
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>&lt;p&gt;Search and replace uses &lt;i&gt;regular expressions&lt;/i&gt;. See the &lt;a href=&quot;http://calibre-ebook.com/user_manual/regexp.html&quot;&gt;regular expressions tutorial&lt;/a&gt; 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.</string>
<string>&lt;p&gt;Search and replace uses &lt;i&gt;regular expressions&lt;/i&gt;. See the &lt;a href=&quot;http://manual.calibre-ebook.com/regexp.html&quot;&gt;regular expressions tutorial&lt;/a&gt; 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.</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -127,7 +127,7 @@
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>&lt;p&gt;For example, to match all h2 tags that have class=&quot;chapter&quot;, set tag to &lt;i&gt;h2&lt;/i&gt;, attribute to &lt;i&gt;class&lt;/i&gt; and value to &lt;i&gt;chapter&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Leaving attribute blank will match any attribute and leaving value blank will match any value. Setting tag to * will match any tag.&lt;/p&gt;&lt;p&gt;To learn more advanced usage of XPath see the &lt;a href=&quot;http://calibre-ebook.com/user_manual/xpath.html&quot;&gt;XPath Tutorial&lt;/a&gt;.</string>
<string>&lt;p&gt;For example, to match all h2 tags that have class=&quot;chapter&quot;, set tag to &lt;i&gt;h2&lt;/i&gt;, attribute to &lt;i&gt;class&lt;/i&gt; and value to &lt;i&gt;chapter&lt;/i&gt;.&lt;/p&gt;&lt;p&gt;Leaving attribute blank will match any attribute and leaving value blank will match any value. Setting tag to * will match any tag.&lt;/p&gt;&lt;p&gt;To learn more advanced usage of XPath see the &lt;a href=&quot;http://manual.calibre-ebook.com/xpath.html&quot;&gt;XPath Tutorial&lt;/a&gt;.</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -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:

View File

@ -177,7 +177,7 @@
</size>
</property>
<property name="text">
<string>See the &lt;a href=&quot;http://calibre-ebook.com/user_manual/gui.html#the-search-interface&quot;&gt;User Manual&lt;/a&gt; for more help</string>
<string>See the &lt;a href=&quot;http://manual.calibre-ebook.com/gui.html#the-search-interface&quot;&gt;User Manual&lt;/a&gt; for more help</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>

View File

@ -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)

View File

@ -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()

View File

@ -23,19 +23,39 @@
<item>
<widget class="QPlainTextEdit" name="textbox"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel">
<property name="text">
<string>Template value:</string>
</property>
<property name="buddy">
<cstring>template_value</cstring>
</property>
<property name="toolTip">
<string>The value the of the template using the current book in the library view</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="template_value">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Function &amp;name:</string>
@ -45,10 +65,10 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="2" column="1">
<widget class="QComboBox" name="function"/>
</item>
<item row="1" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;Documentation:</string>
@ -61,7 +81,7 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Python &amp;code:</string>
@ -74,7 +94,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="3" column="1">
<widget class="QPlainTextEdit" name="documentation">
<property name="maximumSize">
<size>
@ -84,7 +104,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<widget class="QPlainTextEdit" name="source_code"/>
</item>
</layout>

View File

@ -5,12 +5,17 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from PyQt4.Qt import (QLineEdit, QDialog, QGridLayout, QLabel,
QDialogButtonBox, QColor, QComboBox, QIcon)
from functools import partial
from collections import defaultdict
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
from calibre.gui2.complete import MultiCompleteLineEdit
from calibre.gui2 import error_dialog
from calibre.utils.icu import sort_key
class TemplateLineEditor(QLineEdit):
@ -21,112 +26,462 @@ class TemplateLineEditor(QLineEdit):
def __init__(self, parent):
QLineEdit.__init__(self, parent)
self.tags = None
self.mi = None
self.txt = None
def set_tags(self, tags):
self.tags = tags
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()
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)
if self.tags:
action_tag_wizard = menu.addAction(_('Open Tag Wizard'))
action_tag_wizard.triggered.connect(self.tag_wizard)
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):
t = TemplateDialog(self, self.text())
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.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 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.tags, 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, tags, txt):
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(_('Tag Wizard'))
self.setWindowTitle(_('Coloring Wizard'))
self.setWindowIcon(QIcon(I('wizard.png')))
self.tags = tags
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') and
m['datatype'] not in ('datetime')):
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(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)
self.tagboxes = []
self.colorboxes = []
l.setColumnStretch(2, 10)
l.setColumnMinimumWidth(5, 300)
h = QLabel(_('And'))
h.setToolTip('<p>' +
_('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(_('not'))
h.setToolTip('<p>' +
_('Check this box to indicate that the value must <b>not</b> match '
'to use the color. For example, you can check if a tag does '
'not exist by entering that tag and checking this box.') + '</p>')
h.setAlignment(Qt.AlignCenter)
l.addWidget(h, 0, 3, 1, 1)
c = QLabel(_('empty'))
c.setToolTip('<p>' +
_('Check this box to check if the column is empty') + '</p>')
l.addWidget(c, 0, 4, 1, 1)
h = QLabel(_('Values'))
h.setAlignment(Qt.AlignCenter)
h.setToolTip('<p>' +
_('You can enter more than one value per box, separated by commas. '
'The comparison ignores letter case. Special note: authors are '
'separated by ampersands (&).<br>'
'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.<br>'
'Regular expression examples:') + '<ul>' +
_('<li><code><b>.*</b></code> matches anything in the column.</li>'
'<li><code><b>A.*</b></code> matches anything beginning with A</li>'
'<li><code><b>.*mystery.*</b></code> matches anything containing '
'the word "mystery"</li>') + '</ul></p>')
l.addWidget(h , 0, 5, 1, 1)
c = QLabel(_('is RE'))
c.setToolTip('<p>' +
_('Check this box if the values box contains regular expressions') + '</p>')
l.addWidget(c, 0, 6, 1, 1)
c = QLabel(_('color'))
c.setAlignment(Qt.AlignCenter)
c.setToolTip('<p>' +
_('Use this color if the column matches the tests.') + '</p>')
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, '')
for i in range(0, 10):
tb = MultiCompleteLineEdit(self)
tb.set_separator(', ')
tb.update_items_cache(self.tags)
self.tagboxes.append(tb)
l.addWidget(tb, i+1, 0, 1, 1)
cb = QComboBox(self)
cb.addItems(self.colors)
self.colorboxes.append(cb)
l.addWidget(cb, i+1, 1, 1, 1)
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)
create_widget(QCheckBox, self.notboxes, l, i, 3, None)
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)
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('<p>' +
_('If this box contains a color, it will be used if none '
'of the above rules match.') + '</p>')
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) == 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 = n = e = re = False
else:
t,c,f,re,a,n,e = vals
try:
self.colorboxes[i].setCurrentIndex(self.colorboxes[i].findText(c))
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')
i += 1
except:
pass
i += 1
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('<p>' +
_('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, 1, 1, 1)
l.addWidget(bb, 100, 5, 1, 3)
bb.accepted.connect(self.accepted)
bb.rejected.connect(self.reject)
self.template = ''
def accepted(self):
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, 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"
" t = field('tags');\n first_non_empty(\n")
" first_non_empty(\n")
lines = []
for tb, cb in zip(self.tagboxes, self.colorboxes):
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:
was_and = had_line = False
line = 0
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
if c not in self.colors:
error_dialog(self, _('Invalid color'),
_('The color {0} is not valid').format(c),
m = self.completion_values[f]['m']
dt = self.completion_values[f]['dt']
c = unicode(cb.currentText()).strip()
re = reb.checkState()
a = ab.checkState()
n = nb.checkState()
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:
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
lines.append(" in_list(t, ',', '^{0}$', '{1}', '')".format(tags, c))
res += ',\n'.join(lines)
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 '')
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}', '')".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 in zip(self.tagboxes, self.colorboxes):
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()
if t and c:
res += '#' + t + ':|:' + c + '\n'
f = unicode(fb.currentText())
re = unicode(reb.checkState())
a = unicode(ab.checkState())
n = unicode(nb.checkState())
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
self.accept()
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)
else:
self.colorboxes[line].setEnabled(True)
def accepted(self):
if self.generate_program():
self.accept()
else:
self.template = ''

View File

@ -386,7 +386,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>For help with writing advanced news recipes, please visit &lt;a href=&quot;http://__appname__-ebook.com/user_manual/news.html&quot;&gt;User Recipes&lt;/a&gt;</string>
<string>For help with writing advanced news recipes, please visit &lt;a href=&quot;http://manual.__appname__-ebook.com/news.html&quot;&gt;User Recipes&lt;/a&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -19,7 +19,7 @@
<property name="text">
<string>&lt;div style=&quot;font-size:10pt;&quot;&gt;
&lt;p&gt;Set a regular expression pattern to use when trying to guess ebook metadata from filenames. &lt;/p&gt;
&lt;p&gt;A &lt;a href=&quot;http://calibre-ebook.com/user_manual/regexp.html&quot;&gt;tutorial&lt;/a&gt; on using regular expressions is available.&lt;/p&gt;
&lt;p&gt;A &lt;a href=&quot;http://manual.calibre-ebook.com/regexp.html&quot;&gt;tutorial&lt;/a&gt; on using regular expressions is available.&lt;/p&gt;
&lt;p&gt;Use the &lt;b&gt;Test&lt;/b&gt; 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.&lt;/p&gt;&lt;/div&gt;</string>
</property>
<property name="textFormat">

View File

@ -238,7 +238,6 @@ class Spacer(QWidget): # {{{
self.l.addStretch(10)
# }}}
class MainWindowMixin(object): # {{{
def __init__(self, db):

View File

@ -249,6 +249,23 @@ class CcDateDelegate(QStyledItemDelegate): # {{{
# }}}
class CcTextDelegate(QStyledItemDelegate): # {{{
'''
Delegate for text data.
'''
def createEditor(self, parent, option, index):
m = index.model()
col = m.column_map[index.column()]
editor = MultiCompleteLineEdit(parent)
editor.set_separator(None)
complete_items = sorted(list(m.db.all_custom(label=m.db.field_metadata.key_to_label(col))),
key=sort_key)
editor.update_items_cache(complete_items)
return editor
# }}}
class CcNumberDelegate(QStyledItemDelegate): # {{{
'''
Delegate for text/int/float data.
'''
@ -256,25 +273,23 @@ class CcTextDelegate(QStyledItemDelegate): # {{{
def createEditor(self, parent, option, index):
m = index.model()
col = m.column_map[index.column()]
typ = m.custom_columns[col]['datatype']
if typ == 'int':
if m.custom_columns[col]['datatype'] == 'int':
editor = QSpinBox(parent)
editor.setRange(-100, 100000000)
editor.setSpecialValueText(_('Undefined'))
editor.setSingleStep(1)
elif typ == 'float':
else:
editor = QDoubleSpinBox(parent)
editor.setSpecialValueText(_('Undefined'))
editor.setRange(-100., 100000000)
editor.setDecimals(2)
else:
editor = MultiCompleteLineEdit(parent)
editor.set_separator(None)
complete_items = sorted(list(m.db.all_custom(label=m.db.field_metadata.key_to_label(col))),
key=sort_key)
editor.update_items_cache(complete_items)
return editor
def setEditorData(self, editor, index):
m = index.model()
val = m.db.data[index.row()][m.custom_columns[m.column_map[index.column()]]['rec_index']]
editor.setValue(val)
# }}}
class CcEnumDelegate(QStyledItemDelegate): # {{{
@ -403,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)

View File

@ -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,6 +88,7 @@ class BooksModel(QAbstractTableModel): # {{{
self.column_map = []
self.headers = {}
self.alignment_map = {}
self.color_cache = defaultdict(dict)
self.buffer_size = buffer
self.metadata_backup = None
self.bool_yes_icon = QIcon(I('ok.png'))
@ -97,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()
@ -172,11 +174,13 @@ class BooksModel(QAbstractTableModel): # {{{
def refresh_ids(self, ids, current_row=-1):
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.color_cache = defaultdict(dict)
for row in rows:
if row == current_row:
self.new_bookdisplay_data.emit(
@ -206,6 +210,7 @@ class BooksModel(QAbstractTableModel): # {{{
return ret
def count_changed(self, *args):
self.color_cache = defaultdict(dict)
self.count_changed_signal.emit(self.db.count())
def row_indices(self, index):
@ -336,6 +341,10 @@ class BooksModel(QAbstractTableModel): # {{{
self.db.refresh(field=None)
self.resort(reset=reset)
def reset(self):
self.color_cache = defaultdict(dict)
QAbstractTableModel.reset(self)
def resort(self, reset=True):
if not self.db:
return
@ -537,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()
@ -623,7 +632,12 @@ class BooksModel(QAbstractTableModel): # {{{
return None
return QVariant(text)
def number_type(r, idx=-1):
def number_type(r, idx=-1, fmt=None):
if fmt is not None:
try:
return QVariant(fmt.format(self.db.data[r][idx]))
except:
pass
return QVariant(self.db.data[r][idx])
self.dc = {
@ -674,7 +688,8 @@ class BooksModel(QAbstractTableModel): # {{{
bool_cols_are_tristate=
self.db.prefs.get('bools_are_tristate'))
elif datatype in ('int', 'float'):
self.dc[col] = functools.partial(number_type, idx=idx)
fmt = self.custom_columns[col]['display'].get('number_format', None)
self.dc[col] = functools.partial(number_type, idx=idx, fmt=fmt)
elif datatype == 'datetime':
self.dc[col] = functools.partial(datetime_type, idx=idx)
elif datatype == 'bool':
@ -711,18 +726,25 @@ 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:
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 \
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', [])

View File

@ -15,7 +15,7 @@ from PyQt4.Qt import QTableView, Qt, QAbstractItemView, QMenu, pyqtSignal, \
from calibre.gui2.library.delegates import RatingDelegate, PubDateDelegate, \
TextDelegate, DateDelegate, CompleteDelegate, CcTextDelegate, \
CcBoolDelegate, CcCommentsDelegate, CcDateDelegate, CcTemplateDelegate, \
CcEnumDelegate
CcEnumDelegate, CcNumberDelegate
from calibre.gui2.library.models import BooksModel, DeviceBooksModel
from calibre.utils.config import tweaks, prefs
from calibre.gui2 import error_dialog, gprefs
@ -89,6 +89,7 @@ class BooksView(QTableView): # {{{
self.cc_bool_delegate = CcBoolDelegate(self)
self.cc_comments_delegate = CcCommentsDelegate(self)
self.cc_template_delegate = CcTemplateDelegate(self)
self.cc_number_delegate = CcNumberDelegate(self)
self.display_parent = parent
self._model = modelcls(self)
self.setModel(self._model)
@ -501,8 +502,10 @@ class BooksView(QTableView): # {{{
self.tags_delegate)
else:
self.setItemDelegateForColumn(cm.index(colhead), self.cc_text_delegate)
elif cc['datatype'] in ('series', 'int', 'float'):
elif cc['datatype'] == 'series':
self.setItemDelegateForColumn(cm.index(colhead), self.cc_text_delegate)
elif cc['datatype'] in ('int', 'float'):
self.setItemDelegateForColumn(cm.index(colhead), self.cc_number_delegate)
elif cc['datatype'] == 'bool':
self.setItemDelegateForColumn(cm.index(colhead), self.cc_bool_delegate)
elif cc['datatype'] == 'rating':

View File

@ -127,6 +127,9 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
elif ct == 'enumeration':
self.enum_box.setText(','.join(c['display'].get('enum_values', [])))
self.enum_colors.setText(','.join(c['display'].get('enum_colors', [])))
elif ct in ['int', 'float']:
if c['display'].get('number_format', None):
self.number_format_box.setText(c['display'].get('number_format', ''))
self.datatype_changed()
if ct in ['text', 'composite', 'enumeration']:
self.use_decorations.setChecked(c['display'].get('use_decorations', False))
@ -171,6 +174,7 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
col_type = None
for x in ('box', 'default_label', 'label'):
getattr(self, 'date_format_'+x).setVisible(col_type == 'datetime')
getattr(self, 'number_format_'+x).setVisible(col_type in ['int', 'float'])
for x in ('box', 'default_label', 'label', 'sort_by', 'sort_by_label',
'make_category'):
getattr(self, 'composite_'+x).setVisible(col_type in ['composite', '*composite'])
@ -178,6 +182,18 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
getattr(self, 'enum_'+x).setVisible(col_type == 'enumeration')
self.use_decorations.setVisible(col_type in ['text', 'composite', 'enumeration'])
self.is_names.setVisible(col_type == '*text')
if col_type == 'int':
self.number_format_box.setToolTip('<p>' +
_('Examples: The format <code>{0:0>4d}</code> '
'gives a 4-digit number with leading zeros. The format '
'<code>{0:d}&nbsp;days</code> prints the number then the word "days"')+ '</p>')
elif col_type == 'float':
self.number_format_box.setToolTip('<p>' +
_('Examples: The format <code>{0:.1f}</code> gives a floating '
'point number with 1 digit after the decimal point. The format '
'<code>Price:&nbsp;$&nbsp;{0:,.2f}</code> prints '
'"Price&nbsp;$&nbsp;" then displays the number with 2 digits '
'after the decimal point and thousands separated by commas.') + '</p>')
def accept(self):
col = unicode(self.column_name_box.text()).strip()
@ -267,6 +283,11 @@ class CreateCustomColumn(QDialog, Ui_QCreateCustomColumn):
display_dict = {'enum_values': l, 'enum_colors': c}
elif col_type == 'text' and is_multiple:
display_dict = {'is_names': self.is_names.isChecked()}
elif col_type in ['int', 'float']:
if unicode(self.number_format_box.text()).strip():
display_dict = {'number_format':unicode(self.number_format_box.text()).strip()}
else:
display_dict = {'number_format': None}
if col_type in ['text', 'composite', 'enumeration'] and not is_multiple:
display_dict['use_decorations'] = self.use_decorations.checkState()

View File

@ -171,6 +171,16 @@ Everything else will show nothing.</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="number_format_box">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="date_format_default_label">
<property name="toolTip">
@ -181,6 +191,21 @@ Everything else will show nothing.</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="number_format_default_label">
<property name="toolTip">
<string>&lt;p&gt;The format specifier must begin with &lt;code&gt;{0:&lt;/code&gt;
and end with &lt;code&gt;}&lt;/code&gt; You can have text before and after the format specifier.
</string>
</property>
<property name="text">
<string>&lt;p&gt;Default: Not formatted. For format language details see &lt;a href="http://docs.python.org/library/string.html#format-string-syntax"&gt;the python documentation&lt;/a&gt;</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="0">
@ -193,6 +218,16 @@ Everything else will show nothing.</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="number_format_label">
<property name="text">
<string>Format for &amp;numbers</string>
</property>
<property name="buddy">
<cstring>number_format_box</cstring>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="composite_label">
<property name="text">

View File

@ -5,12 +5,15 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from functools import partial
from PyQt4.Qt import (QApplication, QFont, QFontInfo, QFontDialog,
QAbstractListModel, Qt, QColor)
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
@ -129,7 +132,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)
@ -164,17 +167,18 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
'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 '
'<a href="http://calibre-ebook.com/user_manual/template_lang.html">'
'<a href="http://manual.calibre-ebook.com/template_lang.html">'
'tutorial</a> on using templates.') +
'</p><p>' +
_('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. This is by far the easiest '
'way to specify a template.') +
'</p><p>' +
_('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 '
@ -200,21 +204,76 @@ 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.')+ '</p>')
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
tags = db.all_tags()
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)
tpl = getattr(self, 'opt_column_color_template_'+str(i))
tpl.set_tags(tags)
toolbutton = getattr(self, 'opt_column_color_wizard_'+str(i))
toolbutton.clicked.connect(tpl.tag_wizard)
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()
def initialize(self):
ConfigWidgetBase.initialize(self)
font = gprefs['font']

View File

@ -416,114 +416,95 @@ then the tags will be displayed each on their own line.</string>
<string>Column Coloring</string>
</attribute>
<layout class="QGridLayout" name="column_color_layout">
<item row="1" column="0">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Column to color</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Color selection template</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QComboBox" name="opt_column_color_name_1"/>
</item>
<item row="2" column="1">
<widget class="TemplateLineEditor" name="opt_column_color_template_1"/>
</item>
<item row="2" column="2">
<widget class="QToolButton" name="opt_column_color_wizard_1">
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
</property>
<property name="toolTip">
<string>Open the tags wizard.</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QComboBox" name="opt_column_color_name_2"/>
</item>
<item row="3" column="1">
<widget class="TemplateLineEditor" name="opt_column_color_template_2"/>
</item>
<item row="3" column="2">
<widget class="QToolButton" name="opt_column_color_wizard_2">
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
</property>
<property name="toolTip">
<string>Open the tags wizard.</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QComboBox" name="opt_column_color_name_3"/>
</item>
<item row="4" column="1">
<widget class="TemplateLineEditor" name="opt_column_color_template_3"/>
</item>
<item row="4" column="2">
<widget class="QToolButton" name="opt_column_color_wizard_3">
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
</property>
<property name="toolTip">
<string>Open the tags wizard.</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QComboBox" name="opt_column_color_name_4"/>
</item>
<item row="5" column="1">
<widget class="TemplateLineEditor" name="opt_column_color_template_4"/>
</item>
<item row="5" column="2">
<widget class="QToolButton" name="opt_column_color_wizard_4">
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
</property>
<property name="toolTip">
<string>Open the tags wizard.</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QComboBox" name="opt_column_color_name_5"/>
</item>
<item row="6" column="1">
<widget class="TemplateLineEditor" name="opt_column_color_template_5"/>
</item>
<item row="6" column="2">
<widget class="QToolButton" name="opt_column_color_wizard_5">
<property name="icon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/wizard.png</normaloff>:/images/wizard.png</iconset>
</property>
<property name="toolTip">
<string>Open the tags wizard.</string>
</property>
</widget>
<item row="0" column="3">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Color selection template</string>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>10</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>The template wizard is easiest to use</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="color_help_button">
<property name="text">
<string>Show/hide help text</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="colors_button">
<property name="text">
<string>Show/hide colors</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="20" column="0">
<widget class="QLabel" name="label">
<widget class="QLabel" name="colors_label">
<property name="text">
<string>Color names</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QScrollArea" name="scrollArea">
<item row="21" column="0" colspan="8">
<widget class="QScrollArea" name="colors_scrollArea">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>300</height>
</size>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>687</width>
<height>61</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="colors_box">
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="30" column="0" colspan="8">
<widget class="QScrollArea" name="color_help_scrollArea">
<property name="minimumSize">
<size>
<width>0</width>
@ -534,7 +515,7 @@ then the tags will be displayed each on their own line.</string>
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
@ -560,37 +541,24 @@ then the tags will be displayed each on their own line.</string>
</widget>
</widget>
</item>
<item row="21" column="0" colspan="3">
<widget class="QScrollArea" name="scrollArea_2">
<property name="maximumSize">
<item row="40" column="0">
<spacer>
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>10</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>16777215</width>
<height>120</height>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>687</width>
<height>61</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="colors_box">
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</spacer>
</item>
</layout>
</widget>

View File

@ -6,11 +6,17 @@ __license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import urllib
from contextlib import closing
from lxml import html
from PyQt4.Qt import QUrl
from calibre import browser
from calibre.gui2 import open_url
from calibre.gui2.store.amazon_plugin import AmazonKindleStore
from calibre.gui2.store.search_result import SearchResult
class AmazonUKKindleStore(AmazonKindleStore):
'''
@ -28,3 +34,81 @@ class AmazonUKKindleStore(AmazonKindleStore):
aff_id['asin'] = detail_item
store_link = 'http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&location=http://www.amazon.co.uk/dp/%(asin)s&tag=%(tag)s&linkCode=ur2&camp=1634&creative=6738' % aff_id
open_url(QUrl(store_link))
def search(self, query, max_results=10, timeout=60):
url = self.search_url + urllib.quote_plus(query)
br = browser()
counter = max_results
with closing(br.open(url, timeout=timeout)) as f:
doc = html.fromstring(f.read())
# Amazon has two results pages.
is_shot = doc.xpath('boolean(//div[@id="shotgunMainResults"])')
# Horizontal grid of books.
if is_shot:
data_xpath = '//div[contains(@class, "result")]'
cover_xpath = './/div[@class="productTitle"]//img/@src'
# Vertical list of books.
else:
data_xpath = '//div[contains(@class, "product")]'
cover_xpath = './div[@class="productImage"]/a/img/@src'
for data in doc.xpath(data_xpath):
if counter <= 0:
break
# We must have an asin otherwise we can't easily reference the
# book later.
asin = ''.join(data.xpath('./@name'))
if not asin:
continue
cover_url = ''.join(data.xpath(cover_xpath))
title = ''.join(data.xpath('.//div[@class="productTitle"]/a/text()'))
price = ''.join(data.xpath('.//div[@class="newPrice"]/span/text()'))
counter -= 1
s = SearchResult()
s.cover_url = cover_url.strip()
s.title = title.strip()
s.price = price.strip()
s.detail_item = asin.strip()
s.formats = 'Kindle'
if is_shot:
# Amazon UK does not include the author on the grid layout
s.author = ''
self.get_details(s, timeout)
else:
author = ''.join(data.xpath('.//div[@class="productTitle"]/span[@class="ptBrand"]/text()'))
s.author = author.split(' by ')[-1].strip()
yield s
def get_details(self, search_result, timeout):
# We might already have been called.
if search_result.drm:
return
url = self.details_url
br = browser()
with closing(br.open(url + search_result.detail_item, timeout=timeout)) as nf:
idata = html.fromstring(nf.read())
if not search_result.author:
search_result.author = ''.join(idata.xpath('//div[@class="buying" and contains(., "Author")]/a/text()'))
if idata.xpath('boolean(//div[@class="content"]//li/b[contains(text(), "' +
self.drm_search_text + '")])'):
if idata.xpath('boolean(//div[@class="content"]//li[contains(., "' +
self.drm_free_text + '") and contains(b, "' +
self.drm_search_text + '")])'):
search_result.drm = SearchResult.DRM_UNLOCKED
else:
search_result.drm = SearchResult.DRM_UNKNOWN
else:
search_result.drm = SearchResult.DRM_LOCKED
return True

View File

@ -45,8 +45,9 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
self.description_box.setText('')
self.headquarters_box.setText('')
self.format_box.setText('')
self.enabled_combo.setIndex(0)
self.drm_combo.setIndex(0)
self.enabled_combo.setCurrentIndex(0)
self.drm_combo.setCurrentIndex(0)
self.affiliate_combo.setCurrentIndex(0)
def tokens(self, raw):
phrases = re.findall(r'\s*".*?"\s*', raw)
@ -126,6 +127,9 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
drm = unicode(self.drm_combo.currentText()).strip()
if drm:
ans.append('drm:' + drm)
affiliate = unicode(self.affiliate_combo.currentText()).strip()
if affiliate:
ans.append('affiliate:' + affiliate)
if ans:
return ' and '.join(ans)
return ''

View File

@ -149,7 +149,7 @@
</size>
</property>
<property name="text">
<string>See the &lt;a href=&quot;http://calibre-ebook.com/user_manual/gui.html#the-search-interface&quot;&gt;User Manual&lt;/a&gt; for more help</string>
<string>See the &lt;a href=&quot;http://manual.calibre-ebook.com/gui.html#the-search-interface&quot;&gt;User Manual&lt;/a&gt; for more help</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
@ -226,7 +226,7 @@
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<item row="9" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="clear_button">
@ -244,7 +244,7 @@
</item>
</layout>
</item>
<item row="7" column="1">
<item row="8" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -335,6 +335,32 @@
</item>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Affiliate:</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="affiliate_combo">
<item>
<property name="text">
<string/>
</property>
</item>
<item>
<property name="text">
<string>true</string>
</property>
</item>
<item>
<property name="text">
<string>false</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</widget>

View File

@ -17,18 +17,20 @@ class StoreChooserWidget(QWidget, Ui_Form):
QWidget.__init__(self)
self.setupUi(self)
self.query.initialize('store_config_chooser_query')
self.adv_search_builder.setIcon(QIcon(I('search.png')))
self.search.clicked.connect(self.do_search)
self.adv_search_builder.clicked.connect(self.build_adv_search)
self.results_view.activated.connect(self.toggle_plugin)
self.enable_all.clicked.connect(self.results_view.model().enable_all)
self.enable_none.clicked.connect(self.results_view.model().enable_none)
self.enable_invert.clicked.connect(self.results_view.model().enable_invert)
self.results_view.activated.connect(self.results_view.model().toggle_plugin)
def do_search(self):
self.results_view.model().search(unicode(self.query.text()))
def toggle_plugin(self, index):
self.results_view.model().toggle_plugin(index)
def build_adv_search(self):
adv = AdvSearchBuilderDialog(self)
if adv.exec_() == QDialog.Accepted:

View File

@ -31,7 +31,14 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="query"/>
<widget class="HistoryLineEdit" name="query">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="search">
@ -73,6 +80,51 @@
</attribute>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="enable_all">
<property name="text">
<string>All</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="enable_none">
<property name="text">
<string>None</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="enable_invert">
<property name="text">
<string>Invert</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
@ -81,6 +133,11 @@
<extends>QTreeView</extends>
<header>results_view.h</header>
</customwidget>
<customwidget>
<class>HistoryLineEdit</class>
<extends>QLineEdit</extends>
<header>widgets.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>

View File

@ -6,7 +6,7 @@ __license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
from PyQt4.Qt import (Qt, QAbstractItemModel, QIcon, QVariant, QModelIndex)
from PyQt4.Qt import (Qt, QAbstractItemModel, QIcon, QVariant, QModelIndex, QSize)
from calibre.gui2 import NONE
from calibre.customize.ui import is_disabled, disable_plugin, enable_plugin
@ -18,13 +18,15 @@ from calibre.utils.search_query_parser import SearchQueryParser
class Matches(QAbstractItemModel):
HEADERS = [_('Enabled'), _('Name'), _('No DRM'), _('Headquarters'), _('Formats')]
HEADERS = [_('Enabled'), _('Name'), _('No DRM'), _('Headquarters'), _('Affiliate'), _('Formats')]
HTML_COLS = [1]
def __init__(self, plugins):
QAbstractItemModel.__init__(self)
self.NO_DRM_ICON = QIcon(I('ok.png'))
self.DONATE_ICON = QIcon()
self.DONATE_ICON.addFile(I('donate.png'), QSize(16, 16))
self.all_matches = plugins
self.matches = plugins
@ -53,6 +55,22 @@ class Matches(QAbstractItemModel):
self.layoutChanged.emit()
self.sort(self.sort_col, self.sort_order)
def enable_all(self):
for i in xrange(len(self.matches)):
index = self.createIndex(i, 0)
data = QVariant(True)
self.setData(index, data, Qt.CheckStateRole)
def enable_none(self):
for i in xrange(len(self.matches)):
index = self.createIndex(i, 0)
data = QVariant(False)
self.setData(index, data, Qt.CheckStateRole)
def enable_invert(self):
for i in xrange(len(self.matches)):
self.toggle_plugin(self.createIndex(i, 0))
def toggle_plugin(self, index):
new_index = self.createIndex(index.row(), 0)
data = QVariant(is_disabled(self.get_plugin(index)))
@ -91,12 +109,15 @@ class Matches(QAbstractItemModel):
return QVariant('<b>%s</b><br><i>%s</i>' % (result.name, result.description))
elif col == 3:
return QVariant(result.headquarters)
elif col == 4:
elif col == 5:
return QVariant(', '.join(result.formats).upper())
elif role == Qt.DecorationRole:
if col == 2:
if result.drm_free_only:
return QVariant(self.NO_DRM_ICON)
if col == 4:
if result.affiliate:
return QVariant(self.DONATE_ICON)
elif role == Qt.CheckStateRole:
if col == 0:
if is_disabled(result):
@ -105,20 +126,23 @@ class Matches(QAbstractItemModel):
elif role == Qt.ToolTipRole:
if col == 0:
if is_disabled(result):
return QVariant(_('<p>This store is currently diabled and cannot be used in other parts of calibre.</p>'))
return QVariant('<p>' + _('This store is currently diabled and cannot be used in other parts of calibre.') + '</p>')
else:
return QVariant(_('<p>This store is currently enabled and can be used in other parts of calibre.</p>'))
return QVariant('<p>' + _('This store is currently enabled and can be used in other parts of calibre.') + '</p>')
elif col == 1:
return QVariant('<p>%s</p>' % result.description)
elif col == 2:
if result.drm_free_only:
return QVariant(_('<p>This store only distributes ebooks with DRM.</p>'))
return QVariant('<p>' + _('This store only distributes ebooks with DRM.') + '</p>')
else:
return QVariant(_('<p>This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.</p>'))
return QVariant('<p>' + _('This store distributes ebooks with DRM. It may have some titles without DRM, but you will need to check on a per title basis.') + '</p>')
elif col == 3:
return QVariant(_('<p>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.</p>') % result.headquarters)
return QVariant('<p>' + _('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.') % result.headquarters + '</p>')
elif col == 4:
return QVariant(_('<p>This store distributes ebooks in the following formats: %s</p>') % ', '.join(result.formats))
if result.affiliate:
return QVariant('<p>' + _('Buying from this store supports the calibre developer: %s.') % result.author + '</p>')
elif col == 5:
return QVariant('<p>' + _('This store distributes ebooks in the following formats: %s') % ', '.join(result.formats) + '</p>')
return NONE
def setData(self, index, data, role):
@ -148,6 +172,8 @@ class Matches(QAbstractItemModel):
text = 'a' if getattr(match, 'drm_free_only', True) else 'b'
elif col == 3:
text = getattr(match, 'headquarters', '')
elif col == 4:
text = 'a' if getattr(match, 'affiliate', False) else 'b'
return text
def sort(self, col, order, reset=True):
@ -167,6 +193,7 @@ class SearchFilter(SearchQueryParser):
USABLE_LOCATIONS = [
'all',
'affiliate',
'description',
'drm',
'enabled',
@ -207,6 +234,7 @@ class SearchFilter(SearchQueryParser):
all_locs = set(self.USABLE_LOCATIONS) - set(['all'])
locations = all_locs if location == 'all' else [location]
q = {
'affiliate': lambda x: x.affiliate,
'description': lambda x: x.description.lower(),
'drm': lambda x: not x.drm_free_only,
'enabled': lambda x: not is_disabled(x),
@ -219,21 +247,21 @@ class SearchFilter(SearchQueryParser):
for locvalue in locations:
accessor = q[locvalue]
if query == 'true':
if locvalue in ('drm', 'enabled'):
if locvalue in ('affiliate', 'drm', 'enabled'):
if accessor(sr) == True:
matches.add(sr)
elif accessor(sr) is not None:
matches.add(sr)
continue
if query == 'false':
if locvalue in ('drm', 'enabled'):
if locvalue in ('affiliate', 'drm', 'enabled'):
if accessor(sr) == False:
matches.add(sr)
elif accessor(sr) is None:
matches.add(sr)
continue
# this is bool, so can't match below
if locvalue in ('drm', 'enabled'):
if locvalue in ('affiliate', 'drm', 'enabled'):
continue
try:
### Can't separate authors because comma is used for name sep and author sep

View File

@ -6,7 +6,9 @@ __license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
from PyQt4.Qt import (Qt, QTreeView, QSize)
from functools import partial
from PyQt4.Qt import (Qt, QTreeView, QSize, QMenu)
from calibre.customize.ui import store_plugins
from calibre.gui2.metadata.single_download import RichTextDelegate
@ -32,3 +34,20 @@ class ResultsView(QTreeView):
self.model().sort(1, Qt.AscendingOrder)
self.header().setSortIndicator(self.model().sort_col, self.model().sort_order)
def contextMenuEvent(self, event):
index = self.indexAt(event.pos())
if not index.isValid():
return
plugin = self.model().get_plugin(index)
menu = QMenu()
ca = menu.addAction(_('Configure...'), partial(self.configure_plugin, plugin))
if not plugin.is_customizable():
ca.setEnabled(False)
menu.exec_(event.globalPos())
def configure_plugin(self, plugin):
plugin.do_user_config(self)

View File

@ -0,0 +1,87 @@
# -*- coding: utf-8 -*-
from __future__ import (unicode_literals, division, absolute_import, print_function)
__license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import urllib2
from contextlib import closing
from lxml import html
from PyQt4.Qt import QUrl
from calibre import browser
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 EBookShoppeUKStore(BasicStoreConfig, StorePlugin):
def open(self, parent=None, detail_item=None, external=False):
url_details = 'http://www.awin1.com/cread.php?awinmid=1414&awinaffid=120917&clickref=&p={0}'
url = 'http://www.awin1.com/awclick.php?mid=2666&id=120917'
if external or self.config.get('open_external', False):
if detail_item:
url = url_details.format(detail_item)
open_url(QUrl(url))
else:
detail_url = None
if detail_item:
detail_url = url_details.format(detail_item)
d = WebStoreDialog(self.gui, url, parent, detail_url)
d.setWindowTitle(self.name)
d.set_tags(self.config.get('tags', ''))
d.exec_()
def search(self, query, max_results=10, timeout=60):
url = 'http://www.ebookshoppe.com/search.php?search_query=' + urllib2.quote(query)
br = browser()
counter = max_results
with closing(br.open(url, timeout=timeout)) as f:
doc = html.fromstring(f.read())
for data in doc.xpath('//ul[@class="ProductList"]/li'):
if counter <= 0:
break
id = ''.join(data.xpath('./div[@class="ProductDetails"]/'
'strong/a/@href')).strip()
if not id:
continue
cover_url = ''.join(data.xpath('./div[@class="ProductImage"]/a/img/@src'))
title = ''.join(data.xpath('./div[@class="ProductDetails"]/strong/a/text()'))
price = ''.join(data.xpath('./div[@class="ProductPriceRating"]/em/text()'))
counter -= 1
s = SearchResult()
s.cover_url = cover_url
s.title = title.strip()
s.price = price
s.drm = SearchResult.DRM_UNLOCKED
s.detail_item = id
self.get_author_and_formats(s, timeout)
if not s.author:
continue
yield s
def get_author_and_formats(self, search_result, timeout):
br = browser()
with closing(br.open(search_result.detail_item, timeout=timeout)) as nf:
idata = html.fromstring(nf.read())
author = ''.join(idata.xpath('//div[@id="ProductOtherDetails"]/dl/dd[1]/text()'))
if author:
search_result.author = author
formats = idata.xpath('//dl[@class="ProductAddToCart"]/dd/'
'ul[@class="ProductOptionList"]/li/label/text()')
if formats:
search_result.formats = ', '.join(formats)
search_result.drm = SearchResult.DRM_UNKNOWN
return True

View File

@ -23,12 +23,13 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog
class FoylesUKStore(BasicStoreConfig, StorePlugin):
def open(self, parent=None, detail_item=None, external=False):
url = 'http://www.awin1.com/cread.php?awinmid=1414&awinaffid=120917&clickref=&p='
url = 'http://www.awin1.com/awclick.php?mid=1414&id=120917'
detail_url = 'http://www.awin1.com/cread.php?awinmid=1414&awinaffid=120917&clickref=&p='
url_redirect = 'http://www.foyles.co.uk'
if external or self.config.get('open_external', False):
if detail_item:
url = url + url_redirect + detail_item
url = detail_url + url_redirect + detail_item
open_url(QUrl(url_slash_cleaner(url)))
else:
detail_url = None
@ -54,6 +55,10 @@ class FoylesUKStore(BasicStoreConfig, StorePlugin):
if not id:
continue
# filter out the audio books
if not data.xpath('boolean(.//div[@class="Relative"]/ul/li[contains(text(), "ePub")])'):
continue
cover_url = ''.join(data.xpath('.//a[@class="Jacket"]/img/@src'))
if cover_url:
cover_url = 'http://www.foyles.co.uk' + cover_url

View File

@ -78,7 +78,8 @@ class ManyBooksStore(BasicStoreConfig, StorePlugin):
cover_name = mo.group()
cover_name = cover_name.replace('etext', '')
cover_id = id.split('.')[0]
cover_url = 'http://manybooks_images.s3.amazonaws.com/original_covers/' + id[0] + '/' + cover_name + '/' + cover_id + '-thumb.jpg'
cover_url = 'http://www.manybooks.net/images/' + id[0] + '/' + cover_name + '/' + cover_id + '-thumb.jpg'
print(cover_url)
counter -= 1

View File

@ -0,0 +1,119 @@
# -*- coding: utf-8 -*-
from __future__ import (unicode_literals, division, absolute_import, print_function)
__license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import re
from PyQt4.Qt import (QDialog, QDialogButtonBox)
from calibre.gui2.store.mobileread.adv_search_builder_ui import Ui_Dialog
from calibre.library.caches import CONTAINS_MATCH, EQUALS_MATCH
class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
def __init__(self, parent):
QDialog.__init__(self, parent)
self.setupUi(self)
self.buttonBox.accepted.connect(self.advanced_search_button_pushed)
self.tab_2_button_box.accepted.connect(self.accept)
self.tab_2_button_box.rejected.connect(self.reject)
self.clear_button.clicked.connect(self.clear_button_pushed)
self.adv_search_used = False
self.mc = ''
self.tabWidget.setCurrentIndex(0)
self.tabWidget.currentChanged[int].connect(self.tab_changed)
self.tab_changed(0)
def tab_changed(self, idx):
if idx == 1:
self.tab_2_button_box.button(QDialogButtonBox.Ok).setDefault(True)
else:
self.buttonBox.button(QDialogButtonBox.Ok).setDefault(True)
def advanced_search_button_pushed(self):
self.adv_search_used = True
self.accept()
def clear_button_pushed(self):
self.title_box.setText('')
self.author_box.setText('')
self.format_box.setText('')
def tokens(self, raw):
phrases = re.findall(r'\s*".*?"\s*', raw)
for f in phrases:
raw = raw.replace(f, ' ')
phrases = [t.strip('" ') for t in phrases]
return ['"' + self.mc + t + '"' for t in phrases + [r.strip() for r in raw.split()]]
def search_string(self):
if self.adv_search_used:
return self.adv_search_string()
else:
return self.box_search_string()
def adv_search_string(self):
mk = self.matchkind.currentIndex()
if mk == CONTAINS_MATCH:
self.mc = ''
elif mk == EQUALS_MATCH:
self.mc = '='
else:
self.mc = '~'
all, any, phrase, none = map(lambda x: unicode(x.text()),
(self.all, self.any, self.phrase, self.none))
all, any, none = map(self.tokens, (all, any, none))
phrase = phrase.strip()
all = ' and '.join(all)
any = ' or '.join(any)
none = ' and not '.join(none)
ans = ''
if phrase:
ans += '"%s"'%phrase
if all:
ans += (' and ' if ans else '') + all
if none:
ans += (' and not ' if ans else 'not ') + none
if any:
ans += (' or ' if ans else '') + any
return ans
def token(self):
txt = unicode(self.text.text()).strip()
if txt:
if self.negate.isChecked():
txt = '!'+txt
tok = self.FIELDS[unicode(self.field.currentText())]+txt
if re.search(r'\s', tok):
tok = '"%s"'%tok
return tok
def box_search_string(self):
mk = self.matchkind.currentIndex()
if mk == CONTAINS_MATCH:
self.mc = ''
elif mk == EQUALS_MATCH:
self.mc = '='
else:
self.mc = '~'
ans = []
self.box_last_values = {}
title = unicode(self.title_box.text()).strip()
if title:
ans.append('title:"' + self.mc + title + '"')
author = unicode(self.author_box.text()).strip()
if author:
ans.append('author:"' + self.mc + author + '"')
format = unicode(self.format_box.text()).strip()
if format:
ans.append('format:"' + self.mc + format + '"')
if ans:
return ' and '.join(ans)
return ''

View File

@ -0,0 +1,350 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>752</width>
<height>472</height>
</rect>
</property>
<property name="windowTitle">
<string>Advanced Search</string>
</property>
<property name="windowIcon">
<iconset>
<normaloff>:/images/search.png</normaloff>:/images/search.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>&amp;What kind of match to use:</string>
</property>
<property name="buddy">
<cstring>matchkind</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="matchkind">
<item>
<property name="text">
<string>Contains: the word or phrase matches anywhere in the metadata field</string>
</property>
</item>
<item>
<property name="text">
<string>Equals: the word or phrase must match the entire metadata field</string>
</property>
</item>
<item>
<property name="text">
<string>Regular expression: the expression must match anywhere in the metadata field</string>
</property>
</item>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>A&amp;dvanced Search</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Find entries that have...</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>&amp;All these words:</string>
</property>
<property name="buddy">
<cstring>all</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="all"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>This exact &amp;phrase:</string>
</property>
<property name="buddy">
<cstring>all</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="phrase"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>&amp;One or more of these words:</string>
</property>
<property name="buddy">
<cstring>all</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="any"/>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>But dont show entries that have...</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Any of these &amp;unwanted words:</string>
</property>
<property name="buddy">
<cstring>all</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="none"/>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>See the &lt;a href=&quot;http://calibre-ebook.com/user_manual/gui.html#the-search-interface&quot;&gt;User Manual&lt;/a&gt; for more help</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Titl&amp;e/Author/Price ...</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>&amp;Title:</string>
</property>
<property name="buddy">
<cstring>title_box</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="EnLineEdit" name="title_box">
<property name="toolTip">
<string>Enter the title.</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>&amp;Author:</string>
</property>
<property name="buddy">
<cstring>author_box</cstring>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="clear_button">
<property name="text">
<string>&amp;Clear</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="tab_2_button_box">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Search only in specific fields:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="EnLineEdit" name="author_box"/>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="format_box"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>&amp;Format:</string>
</property>
<property name="buddy">
<cstring>format_box</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="1" column="1">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>EnLineEdit</class>
<extends>QLineEdit</extends>
<header>widgets.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>all</tabstop>
<tabstop>phrase</tabstop>
<tabstop>any</tabstop>
<tabstop>none</tabstop>
<tabstop>buttonBox</tabstop>
<tabstop>title_box</tabstop>
<tabstop>author_box</tabstop>
<tabstop>format_box</tabstop>
<tabstop>clear_button</tabstop>
<tabstop>tab_2_button_box</tabstop>
<tabstop>tabWidget</tabstop>
<tabstop>matchkind</tabstop>
</tabstops>
<resources>
<include location="../../../../resources/images.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -18,7 +18,7 @@ from calibre.gui2.store.web_store_dialog import WebStoreDialog
from calibre.gui2.store.mobileread.models import SearchFilter
from calibre.gui2.store.mobileread.cache_progress_dialog import CacheProgressDialog
from calibre.gui2.store.mobileread.cache_update_thread import CacheUpdateThread
from calibre.gui2.store.mobileread.store_dialog import MobeReadStoreDialog
from calibre.gui2.store.mobileread.store_dialog import MobileReadStoreDialog
class MobileReadStore(BasicStoreConfig, StorePlugin):
@ -38,7 +38,7 @@ class MobileReadStore(BasicStoreConfig, StorePlugin):
d.exec_()
else:
self.update_cache(parent, 30)
d = MobeReadStoreDialog(self, parent)
d = MobileReadStoreDialog(self, parent)
d.setWindowTitle(self.name)
d.exec_()

View File

@ -9,11 +9,11 @@ __docformat__ = 'restructuredtext en'
from PyQt4.Qt import (Qt, QDialog, QIcon)
from calibre.gui2.store.search.adv_search_builder import AdvSearchBuilderDialog
from calibre.gui2.store.mobileread.adv_search_builder import AdvSearchBuilderDialog
from calibre.gui2.store.mobileread.models import BooksModel
from calibre.gui2.store.mobileread.store_dialog_ui import Ui_Dialog
class MobeReadStoreDialog(QDialog, Ui_Dialog):
class MobileReadStoreDialog(QDialog, Ui_Dialog):
def __init__(self, plugin, *args):
QDialog.__init__(self, *args)
@ -49,8 +49,6 @@ class MobeReadStoreDialog(QDialog, Ui_Dialog):
def build_adv_search(self):
adv = AdvSearchBuilderDialog(self)
adv.price_label.hide()
adv.price_box.hide()
if adv.exec_() == QDialog.Accepted:
self.search_query.setText(adv.search_string())

View File

@ -45,6 +45,7 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
self.author_box.setText('')
self.price_box.setText('')
self.format_box.setText('')
self.affiliate_combo.setCurrentIndex(0)
def tokens(self, raw):
phrases = re.findall(r'\s*".*?"\s*', raw)
@ -118,6 +119,9 @@ class AdvSearchBuilderDialog(QDialog, Ui_Dialog):
format = unicode(self.format_box.text()).strip()
if format:
ans.append('format:"' + self.mc + format + '"')
affiliate = unicode(self.affiliate_combo.currentText()).strip()
if affiliate:
ans.append('affiliate:' + affiliate)
if ans:
return ' and '.join(ans)
return ''

View File

@ -149,7 +149,7 @@
</size>
</property>
<property name="text">
<string>See the &lt;a href=&quot;http://calibre-ebook.com/user_manual/gui.html#the-search-interface&quot;&gt;User Manual&lt;/a&gt; for more help</string>
<string>See the &lt;a href=&quot;http://manual.calibre-ebook.com/gui.html#the-search-interface&quot;&gt;User Manual&lt;/a&gt; for more help</string>
</property>
<property name="openExternalLinks">
<bool>true</bool>
@ -226,7 +226,7 @@
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="7" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="clear_button">
@ -244,7 +244,7 @@
</item>
</layout>
</item>
<item row="5" column="1">
<item row="6" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -283,6 +283,32 @@
<item row="3" column="1">
<widget class="EnLineEdit" name="price_box"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Affiliate:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QComboBox" name="affiliate_combo">
<item>
<property name="text">
<string/>
</property>
</item>
<item>
<property name="text">
<string>true</string>
</property>
</item>
<item>
<property name="text">
<string>false</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</widget>

View File

@ -120,6 +120,8 @@ class SearchThread(Thread):
if not self._run:
return
res.store_name = store_name
res.affiliate = store_plugin.base_plugin.affiliate
res.plugin_author = store_plugin.base_plugin.author
self.results.put((res, store_plugin))
self.tasks.task_done()
except:

View File

@ -12,7 +12,7 @@ from operator import attrgetter
from PyQt4.Qt import (Qt, QAbstractItemModel, QVariant, QPixmap, QModelIndex, QSize,
pyqtSignal)
from calibre.gui2 import NONE
from calibre.gui2 import NONE, FunctionDispatcher
from calibre.gui2.store.search_result import SearchResult
from calibre.gui2.store.search.download_thread import DetailsThreadPool, \
CoverThreadPool
@ -33,7 +33,7 @@ class Matches(QAbstractItemModel):
total_changed = pyqtSignal(int)
HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store')]
HEADERS = [_('Cover'), _('Title'), _('Price'), _('DRM'), _('Store'), _('')]
HTML_COLS = (1, 4)
def __init__(self, cover_thread_count=2, detail_thread_count=4):
@ -45,6 +45,8 @@ class Matches(QAbstractItemModel):
Qt.SmoothTransformation)
self.DRM_UNKNOWN_ICON = QPixmap(I('dialog_question.png')).scaledToHeight(64,
Qt.SmoothTransformation)
self.DONATE_ICON = QPixmap(I('donate.png')).scaledToHeight(16,
Qt.SmoothTransformation)
# All matches. Used to determine the order to display
# self.matches because the SearchFilter returns
@ -57,6 +59,9 @@ class Matches(QAbstractItemModel):
self.cover_pool = CoverThreadPool(cover_thread_count)
self.details_pool = DetailsThreadPool(detail_thread_count)
self.filter_results_dispatcher = FunctionDispatcher(self.filter_results)
self.got_result_details_dispatcher = FunctionDispatcher(self.got_result_details)
self.sort_col = 2
self.sort_order = Qt.AscendingOrder
@ -82,10 +87,10 @@ class Matches(QAbstractItemModel):
self.search_filter.add_search_result(result)
if result.cover_url:
result.cover_queued = True
self.cover_pool.add_task(result, self.filter_results)
self.cover_pool.add_task(result, self.filter_results_dispatcher)
else:
result.cover_queued = False
self.details_pool.add_task(result, store_plugin, self.got_result_details)
self.details_pool.add_task(result, store_plugin, self.got_result_details_dispatcher)
self.filter_results()
self.layoutChanged.emit()
@ -112,7 +117,7 @@ class Matches(QAbstractItemModel):
def got_result_details(self, result):
if not result.cover_queued and result.cover_url:
result.cover_queued = True
self.cover_pool.add_task(result, self.filter_results)
self.cover_pool.add_task(result, self.filter_results_dispatcher)
if result in self.matches:
row = self.matches.index(result)
self.dataChanged.emit(self.index(row, 0), self.index(row, self.columnCount() - 1))
@ -150,6 +155,8 @@ class Matches(QAbstractItemModel):
def data(self, index, role):
row, col = index.row(), index.column()
if row >= len(self.matches):
return NONE
result = self.matches[row]
if role == Qt.DisplayRole:
if col == 1:
@ -173,6 +180,10 @@ class Matches(QAbstractItemModel):
return QVariant(self.DRM_UNLOCKED_ICON)
elif result.drm == SearchResult.DRM_UNKNOWN:
return QVariant(self.DRM_UNKNOWN_ICON)
if col == 5:
if result.affiliate:
return QVariant(self.DONATE_ICON)
return NONE
elif role == Qt.ToolTipRole:
if col == 1:
return QVariant('<p>%s</p>' % result.title)
@ -187,6 +198,9 @@ class Matches(QAbstractItemModel):
return QVariant('<p>' + _('The DRM status of this book could not be determined. There is a very high likelihood that this book is actually DRM restricted.') + '</p>')
elif col == 4:
return QVariant('<p>%s</p>' % result.formats)
elif col == 5:
if result.affiliate:
return QVariant('<p>' + _('Buying from this store supports the calibre developer: %s.') % result.plugin_author + '</p>')
elif role == Qt.SizeHintRole:
return QSize(64, 64)
return NONE
@ -206,6 +220,11 @@ class Matches(QAbstractItemModel):
text = 'c'
elif col == 4:
text = result.store_name
elif col == 5:
if result.affiliate:
text = 'a'
else:
text = 'b'
return text
def sort(self, col, order, reset=True):
@ -234,6 +253,7 @@ class SearchFilter(SearchQueryParser):
USABLE_LOCATIONS = [
'all',
'affiliate',
'author',
'authors',
'cover',
@ -284,6 +304,7 @@ class SearchFilter(SearchQueryParser):
all_locs = set(self.USABLE_LOCATIONS) - set(['all'])
locations = all_locs if location == 'all' else [location]
q = {
'affiliate': attrgetter('affiliate'),
'author': lambda x: x.author.lower(),
'cover': attrgetter('cover_url'),
'drm': attrgetter('drm'),
@ -298,23 +319,35 @@ class SearchFilter(SearchQueryParser):
for locvalue in locations:
accessor = q[locvalue]
if query == 'true':
if locvalue == 'drm':
# True/False.
if locvalue == 'affiliate':
if accessor(sr):
matches.add(sr)
# Special that are treated as True/False.
elif locvalue == 'drm':
if accessor(sr) == SearchResult.DRM_LOCKED:
matches.add(sr)
# Testing for something or nothing.
else:
if accessor(sr) is not None:
matches.add(sr)
continue
if query == 'false':
if locvalue == 'drm':
# True/False.
if locvalue == 'affiliate':
if not accessor(sr):
matches.add(sr)
# Special that are treated as True/False.
elif locvalue == 'drm':
if accessor(sr) == SearchResult.DRM_UNLOCKED:
matches.add(sr)
# Testing for something or nothing.
else:
if accessor(sr) is None:
matches.add(sr)
continue
# this is bool, so can't match below
if locvalue == 'drm':
# this is bool or treated as bool, so can't match below.
if locvalue in ('affiliate', 'drm'):
continue
try:
### Can't separate authors because comma is used for name sep and author sep

View File

@ -9,8 +9,8 @@ __docformat__ = 'restructuredtext en'
import re
from random import shuffle
from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox,
QVBoxLayout, QIcon, QWidget, QTabWidget)
from PyQt4.Qt import (Qt, QDialog, QDialogButtonBox, QTimer, QCheckBox, QLabel,
QVBoxLayout, QIcon, QWidget, QTabWidget, QGridLayout)
from calibre.gui2 import JSONConfig, info_dialog
from calibre.gui2.progress_indicator import ProgressIndicator
@ -92,14 +92,21 @@ class SearchDialog(QDialog, Ui_Dialog):
self.store_checks = {}
stores_check_widget = QWidget()
store_list_layout = QVBoxLayout()
store_list_layout = QGridLayout()
stores_check_widget.setLayout(store_list_layout)
for x in sorted(self.gui.istores.keys(), key=lambda x: x.lower()):
icon = QIcon(I('donate.png'))
for i, x in enumerate(sorted(self.gui.istores.keys(), key=lambda x: x.lower())):
cbox = QCheckBox(x)
cbox.setChecked(existing.get(x, False))
store_list_layout.addWidget(cbox)
store_list_layout.addWidget(cbox, i, 0, 1, 1)
if self.gui.istores[x].base_plugin.affiliate:
iw = QLabel(self)
iw.setToolTip('<p>' + _('Buying from this store supports the calibre developer: %s</p>') % self.gui.istores[x].base_plugin.author + '</p>')
iw.setPixmap(icon.pixmap(16, 16))
store_list_layout.addWidget(iw, i, 1, 1, 1)
self.store_checks[x] = cbox
store_list_layout.addStretch()
store_list_layout.setRowStretch(store_list_layout.rowCount(), 10)
self.store_list.setWidget(stores_check_widget)
def build_adv_search(self):
@ -244,6 +251,8 @@ class SearchDialog(QDialog, Ui_Dialog):
# search widget.
self.config['open_external'] = self.open_external.isChecked()
# Create the config dialog. It's going to put two config widgets
# into a QTabWidget for displaying all of the settings.
d = QDialog(self)
button_box = QDialogButtonBox(QDialogButtonBox.Close)
v = QVBoxLayout(d)
@ -261,7 +270,22 @@ class SearchDialog(QDialog, Ui_Dialog):
tab_widget.addTab(chooser_config_widget, _('Choose stores'))
tab_widget.addTab(search_config_widget, _('Configure search'))
# Restore dialog state.
geometry = self.config.get('config_dialog_geometry', None)
if geometry:
d.restoreGeometry(geometry)
else:
d.resize(800, 600)
tab_index = self.config.get('config_dialog_tab_index', 0)
tab_index = min(tab_index, tab_widget.count() - 1)
tab_widget.setCurrentIndex(tab_index)
d.exec_()
# Save dialog state.
self.config['config_dialog_geometry'] = bytearray(d.saveGeometry())
self.config['config_dialog_tab_index'] = tab_widget.currentIndex()
search_config_widget.save_settings()
self.config_changed()
self.gui.load_store_plugins()

View File

@ -22,6 +22,8 @@ class SearchResult(object):
self.detail_item = ''
self.drm = None
self.formats = ''
self.affiliate = False
self.plugin_author = ''
def __eq__(self, other):
return self.title == other.title and self.author == other.author and self.store_name == other.store_name

View File

@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
from __future__ import (unicode_literals, division, absolute_import, print_function)
__license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import urllib2
from contextlib import closing
from lxml import html
from PyQt4.Qt import QUrl
from calibre import browser
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 WHSmithUKStore(BasicStoreConfig, StorePlugin):
def open(self, parent=None, detail_item=None, external=False):
url = 'http://www.whsmith.co.uk/'
url_details = ''
if external or self.config.get('open_external', False):
if detail_item:
url = url_details + detail_item
open_url(QUrl(url))
else:
detail_url = None
if detail_item:
detail_url = url_details + detail_item
d = WebStoreDialog(self.gui, url, parent, detail_url)
d.setWindowTitle(self.name)
d.set_tags(self.config.get('tags', ''))
d.exec_()
def search(self, query, max_results=10, timeout=60):
url = ('http://www.whsmith.co.uk/CatalogAndSearch/SearchWithinCategory.aspx'
'?cat=\Books\eb_eBooks&gq=' + urllib2.quote(query))
br = browser()
counter = max_results
with closing(br.open(url, timeout=timeout)) as f:
doc = html.fromstring(f.read())
for data in doc.xpath('//div[@class="product-search"]/'
'div[contains(@id, "whsSearchResultItem")]'):
if counter <= 0:
break
id = ''.join(data.xpath('.//a[contains(@id, "labelProductTitle")]/@href'))
if not id:
continue
cover_url = ''.join(data.xpath('.//a[contains(@id, "hlinkProductImage")]/img/@src'))
title = ''.join(data.xpath('.//a[contains(@id, "labelProductTitle")]/text()'))
author = ', '.join(data.xpath('.//div[@class="author"]/h3/span/text()'))
price = ''.join(data.xpath('.//span[contains(@id, "labelProductPrice")]/text()'))
pdf = data.xpath('boolean(.//span[contains(@id, "labelFormatText") and '
'contains(., "PDF")])')
epub = data.xpath('boolean(.//span[contains(@id, "labelFormatText") and '
'contains(., "ePub")])')
counter -= 1
s = SearchResult()
s.cover_url = cover_url
s.title = title.strip()
s.author = author.strip()
s.price = price
s.drm = SearchResult.DRM_LOCKED
s.detail_item = id
formats = []
if epub:
formats.append('ePub')
if pdf:
formats.append('PDF')
s.formats = ', '.join(formats)
yield s

View File

@ -49,10 +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('<p>'+
self.label = QLabel(('<p>'+
_('%s has been updated to version <b>%s</b>. '
'See the <a href="http://calibre-ebook.com/whats-new'
'">new features</a>.')%(__appname__, version))
'">new features</a>.') + '<p>'+_('Update <b>only</b> 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!'))

View File

@ -62,7 +62,7 @@
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>&lt;h2&gt;User Manual&lt;/h2&gt;A User Manual is also available &lt;a href=&quot;http://calibre-ebook.com/user_manual&quot;&gt;online&lt;/a&gt;.</string>
<string>&lt;h2&gt;User Manual&lt;/h2&gt;A User Manual is also available &lt;a href=&quot;http://manual.calibre-ebook.com&quot;&gt;online&lt;/a&gt;.</string>
</property>
<property name="wordWrap">
<bool>true</bool>

View File

@ -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): # {{{
@ -918,6 +923,7 @@ class ResultCache(SearchQueryParser): # {{{
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')

View File

@ -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:

View File

@ -134,6 +134,8 @@ class SafeFormat(TemplateFormatter):
'''
def get_value(self, key, args, kwargs):
if key == '':
return ''
try:
key = key.lower()
try:

View File

@ -43,7 +43,7 @@ language = 'en'
# General substitutions.
project = __appname__
copyright = '2008, Kovid Goyal'
copyright = 'Kovid Goyal'
# The default replacements for |version| and |release|, also used in various
# other places throughout the built documents.
@ -86,11 +86,19 @@ pygments_style = 'sphinx'
# given in html_static_path.
html_theme = 'default'
html_theme_options = {'stickysidebar':'true', 'relbarbgcolor':'black'}
# Put the quick search box on top
html_sidebars = {
'**' : ['searchbox.html', 'localtoc.html', 'relations.html',
'sourcelink.html'],
}
# The favicon
html_favicon = 'favicon.ico'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['resources']
html_static_path = ['resources', '../../../icons/favicon.ico']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
@ -108,7 +116,7 @@ html_logo = 'resources/logo.png'
epub_author = 'Kovid Goyal'
epub_cover = 'epub_cover.jpg'
epub_publisher = 'Kovid Goyal'
epub_identifier = 'http://calibre-ebook.com/user_manual'
epub_identifier = 'http://manual.calibre-ebook.com'
epub_scheme = 'url'
epub_uid = 'S54a88f8e9d42455e9c6db000e989225f'
epub_tocdepth = 4
@ -131,7 +139,7 @@ html_copy_source = True
# Output file base name for HTML help builder.
htmlhelp_basename = 'calibredoc'
html_use_opensearch = 'http://calibre-ebook.com/user_manual'
html_use_opensearch = 'http://manual.calibre-ebook.com'
html_show_sphinx = False

View File

@ -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 <http://bugs.calibre-ebook.com/newticket>`_.
simply attach that to a ticket on the |app| `bug tracker <http://calibre-ebook.com/bugs>`_.
If you plan to do a lot of development on |app|, then the best method is to create a
`Launchpad <http://launchpad.net>`_ account. Once you have the account, you can use it to register

View File

@ -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 <http://calibre-ebook.com/get-involved>`_.
2. `Open a ticket <http://bugs.calibre-ebook.com/newticket>`_ (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 <http://calibre-ebook.com/bugs>`_ (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?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -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::

View File

@ -114,13 +114,15 @@ 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 <template_mode>` and :ref:`general program mode <general_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.
* ``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`.
@ -130,6 +132,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":
@ -255,6 +258,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.
@ -264,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``,
* List manipulation: ``count``, ``merge_lists``, ``sublist``, ``subitems``
* Recursion: ``eval``, ``template``
* Relational: ``cmp`` , ``strcmp`` for strings
* String case changes: ``lowercase``, ``uppercase``, ``titlecase``, ``capitalize``
* String manipulation: ``re``, ``shorten``, ``substr``
* Other: ``assign``, ``booksize``, ``print``, ``format_date``,
.. _general_mode:
@ -422,19 +420,8 @@ You might find the following tips useful.
* 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
----------------------------
.. toctree::
:hidden:
.. 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-
template_ref

View File

@ -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-

File diff suppressed because it is too large Load Diff

View File

@ -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
@ -339,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)

View File

@ -8,7 +8,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__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
@ -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):
@ -94,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.')
@ -109,12 +102,12 @@ 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):
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:
@ -124,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):
@ -137,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)
@ -147,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)
@ -157,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)
@ -167,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)
@ -177,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 '
@ -192,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.')
@ -205,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):
@ -215,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.')
@ -226,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)
@ -234,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):
@ -243,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 '
@ -256,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,14 +269,14 @@ 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
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):
@ -295,14 +288,14 @@ 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`')
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
@ -310,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,14 +316,14 @@ 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
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 '
@ -338,26 +331,47 @@ 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):
return fv
if l:
for v in l:
if re.search(pat, v, flags=re.I):
return fv
return nfv
class BuiltinStrInList(BuiltinFormatterFunction):
name = 'str_in_list'
arg_count = 5
__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 '
'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()]
if l:
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
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')
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'
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):
@ -369,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 '
@ -394,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(&)}')
@ -405,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, '
@ -425,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.'
)
@ -442,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 '
@ -452,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:
@ -471,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 '
@ -508,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) '
@ -536,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()
@ -544,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()
@ -552,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)
@ -560,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)
@ -568,7 +583,7 @@ class BuiltinCapitalize(BuiltinFormatterFunction):
class BuiltinBooksize(BuiltinFormatterFunction):
name = 'booksize'
arg_count = 0
doc = _('booksize() -- return value of the field capitalized')
__doc__ = doc = _('booksize() -- return value of the size field')
def evaluate(self, formatter, kwargs, mi, locals):
if mi.book_size is not None:
@ -578,10 +593,21 @@ class BuiltinBooksize(BuiltinFormatterFunction):
pass
return ''
class BuiltinOndevice(BuiltinFormatterFunction):
name = 'ondevice'
arg_count = 0
__doc__ = doc = _('ondevice() -- return Yes if ondevice is set, otherwise return '
'the empty string')
def evaluate(self, formatter, kwargs, mi, locals):
if mi.ondevice_col:
return _('Yes')
return ''
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.')
@ -597,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.')
@ -613,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.')
@ -629,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.')
@ -645,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. '
@ -687,6 +713,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()
@ -695,6 +722,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()

View File

@ -52,7 +52,7 @@ def create_man_page(prog, parser):
lines += ['.SH SEE ALSO',
'The User Manual is available at '
'http://calibre-ebook.com/user_manual',
'http://manual.calibre-ebook.com',
'.PP', '.B Created by '+__author__]
lines = [x if isinstance(x, unicode) else unicode(x, 'utf-8', 'replace') for

View File

@ -29,8 +29,11 @@ def get_lang():
lang = os.environ.get('CALIBRE_OVERRIDE_LANG', lang)
if lang is not None:
return lang
lang = locale.getdefaultlocale(['LANGUAGE', 'LC_ALL', 'LC_CTYPE',
try:
lang = locale.getdefaultlocale(['LANGUAGE', 'LC_ALL', 'LC_CTYPE',
'LC_MESSAGES', 'LANG'])[0]
except:
pass # This happens on Ubuntu apparently
if lang is None and os.environ.has_key('LANG'): # Needed for OS X
try:
lang = os.environ['LANG']

View File

@ -1123,6 +1123,13 @@ class ZipFile:
targetpath = os.sep.join(components)
with open(targetpath, 'wb') as target:
shutil.copyfileobj(source, target)
# Kovid: Try to preserve the timestamps in the ZIP file
try:
mtime = time.localtime()
mtime = time.mktime(member.date_time + (0, 0) + (mtime.tm_isdst,))
os.utime(targetpath, (mtime, mtime))
except:
pass
self.extract_mapping[member.filename] = targetpath
return targetpath