From 02a53f90648398c09669ba4b98e1e712ff706dca Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 31 Aug 2009 08:02:04 -0600 Subject: [PATCH 1/4] Fix #3363 (Edit metadata in bulk window doesn't resize horizontally properly) --- src/calibre/gui2/dialogs/metadata_bulk.ui | 439 +++++++++++----------- 1 file changed, 216 insertions(+), 223 deletions(-) diff --git a/src/calibre/gui2/dialogs/metadata_bulk.ui b/src/calibre/gui2/dialogs/metadata_bulk.ui index f3cf8ab251..59fdc5d27a 100644 --- a/src/calibre/gui2/dialogs/metadata_bulk.ui +++ b/src/calibre/gui2/dialogs/metadata_bulk.ui @@ -17,232 +17,225 @@ :/images/edit_input.svg:/images/edit_input.svg - - - - - Qt::Horizontal + + + + + 6 - - - - 6 + + 0 + + + + + Meta information - - 0 - - - - - Meta information - - - - - - &Author(s): - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - authors - - - - - - - Author s&ort: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - author_sort - - - - - - - Specify how the author(s) of this book should be sorted. For example Charles Dickens should be sorted as Dickens, Charles. - - - - - - - &Rating: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - rating - - - - - - - Rating of this book. 0-5 stars - - - Rating of this book. 0-5 stars - - - QAbstractSpinBox::PlusMinus - - - stars - - - 5 - - - - - - - &Publisher: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - publisher - - - - - - - Add ta&gs: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - tags - - - - - - - Tags categorize the book. This is particularly useful while searching. <br><br>They can be any words or phrases, separated by commas. - - - - - - - Open Tag Editor - - - Open Tag Editor - - - - :/images/chapters.svg:/images/chapters.svg - - - - - - - &Remove tags: - - - remove_tags - - - - - - - Comma separated list of tags to remove from the books. - - - - - - - &Series: - - - Qt::PlainText - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - series - - - - - - - List of known series. You can add new series. - - - List of known series. You can add new series. - - - true - - - QComboBox::InsertAlphabetically - - - QComboBox::AdjustToContents - - - - - - - - - - Remove &format: - - - remove_format - - - - - - - A&utomatically set author sort - - - - - - - true - - - - - - - true - - - - - - - - - + + + + + &Author(s): + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + authors + + + + + + + A&utomatically set author sort + + + + + + + Author s&ort: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + author_sort + + + + + + + Specify how the author(s) of this book should be sorted. For example Charles Dickens should be sorted as Dickens, Charles. + + + + + + + &Rating: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + rating + + + + + + + Rating of this book. 0-5 stars + + + Rating of this book. 0-5 stars + + + QAbstractSpinBox::PlusMinus + + + stars + + + 5 + + + + + + + &Publisher: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + publisher + + + + + + + true + + + + + + + Add ta&gs: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + tags + + + + + + + Tags categorize the book. This is particularly useful while searching. <br><br>They can be any words or phrases, separated by commas. + + + + + + + Open Tag Editor + + + Open Tag Editor + + + + :/images/chapters.svg:/images/chapters.svg + + + + + + + &Remove tags: + + + remove_tags + + + + + + + Comma separated list of tags to remove from the books. + + + + + + + &Series: + + + Qt::PlainText + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + series + + + + + + + List of known series. You can add new series. + + + List of known series. You can add new series. + + + true + + + QComboBox::InsertAlphabetically + + + QComboBox::AdjustToContents + + + + + + + Remove &format: + + + remove_format + + + + + + + + + + true + + + + + + + - + Qt::Horizontal From c1eceec7e782540dadac5ad5c62470cc506d382f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 31 Aug 2009 08:16:01 -0600 Subject: [PATCH 2/4] Fix #3367 ('QMouseEvent' object has no attribute 'key') --- src/calibre/gui2/search_box.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/search_box.py b/src/calibre/gui2/search_box.py index 1263ff003e..6ecd3ad239 100644 --- a/src/calibre/gui2/search_box.py +++ b/src/calibre/gui2/search_box.py @@ -41,7 +41,7 @@ class SearchBox2(QComboBox): self.connect(self.line_edit, SIGNAL('key_pressed(PyQt_PyObject)'), self.key_pressed, Qt.DirectConnection) self.connect(self.line_edit, SIGNAL('mouse_released(PyQt_PyObject)'), - self.key_pressed, Qt.DirectConnection) + self.mouse_released, Qt.DirectConnection) self.setEditable(True) self.help_state = True self.as_you_type = True From 330779fa13700f2e2d7b4745e348a94fbc64b703 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 31 Aug 2009 13:05:13 -0600 Subject: [PATCH 3/4] Improved recipe for CNN --- src/calibre/web/feeds/recipes/recipe_cnn.py | 58 +++++++++++++++------ 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/src/calibre/web/feeds/recipes/recipe_cnn.py b/src/calibre/web/feeds/recipes/recipe_cnn.py index 369aff2e99..f9aef380f9 100644 --- a/src/calibre/web/feeds/recipes/recipe_cnn.py +++ b/src/calibre/web/feeds/recipes/recipe_cnn.py @@ -3,7 +3,6 @@ __copyright__ = '2008, Kovid Goyal ' ''' Profile to download CNN ''' -import re from calibre.web.feeds.news import BasicNewsRecipe class CNN(BasicNewsRecipe): @@ -11,28 +10,53 @@ class CNN(BasicNewsRecipe): title = 'CNN' description = 'Global news' timefmt = ' [%d %b %Y]' - __author__ = 'Kovid Goyal' + __author__ = 'Kovid Goyal and Sujata Raman' language = _('English') no_stylesheets = True use_embedded_content = False oldest_article = 15 - preprocess_regexps = [(re.compile(i[0], re.IGNORECASE | re.DOTALL), i[1]) for i in [ - (r'.*?.*?', lambda match : ''), - (r'', lambda match : ''), - (r'<\!\-\-Article End\-\->.*?', lambda match : ''), - (r'()
    .*?
', lambda match : match.group(1)), # drop story highlights - (r'

(.*?)

(.*?)

', lambda match : '

' + match.group(1) + '

' + match.group(2) + '

'), # sports uses h2 for main title and h1 for subtitle (???) switch these around - (r'.*?', lambda match : ''), # drop 'watch more' links - (r'(
).*?(||', lambda match : ''), # drop table formatting - (r'
.*?
', lambda match : ''), # drop extra business links - (r'.*?', lambda match : '') # drop business 'to top' link - ] ] + extra_css = ''' + h1{font-family :Arial,Helvetica,sans-serif; font-size:large} + h2{font-family :Arial,Helvetica,sans-serif; font-size:x-small} + .cnnTxtCmpnt{font-family :Arial,Helvetica,sans-serif; font-size:x-small} + .cnnTMcontent{font-family :Arial,Helvetica,sans-serif; font-size:xx-small;color:#575757} + .storytext{font-family :Arial,Helvetica,sans-serif; font-size:x-small} + .storybyline{font-family :Arial,Helvetica,sans-serif; font-size:xx-small; color:#575757} + .credit{font-family :Arial,Helvetica,sans-serif; font-size:xx-small; color:#575757} + .storyBrandingBanner{font-family :Arial,Helvetica,sans-serif; font-size:xx-small; color:#575757} + .storytimestamp{font-family :Arial,Helvetica,sans-serif; font-size:xx-small; color:#575757} + .timestamp{font-family :Arial,Helvetica,sans-serif; font-size:xx-small; color:#575757} + .subhead p{font-family :Arial,Helvetica,sans-serif; font-size:xx-small;} + .cnnStoryContent{font-family :Arial,Helvetica,sans-serif; font-size:xx-small} + .cnnContentContainer{font-family :Arial,Helvetica,sans-serif; font-size:xx-small} + .col1{font-family :Arial,Helvetica,sans-serif; font-size:x-small; color:#666666;} + .col3{color:#333333; font-family :Arial,Helvetica,sans-serif; font-size:x-small;font-weight:bold;} + .cnnInlineT1Caption{font-family :Arial,Helvetica,sans-serif; font-size:xx-small;font-weight:bold;} + .cnnInlineT1Credit{font-family :Arial,Helvetica,sans-serif; font-size:xx-small;color:#333333;} + .col10{color:#5A637E} + .cnnTimeStamp{font-family :Arial,Helvetica,sans-serif; font-size:xx-small;color:#333333;} + .galleryhedDek{font-family :Arial,Helvetica,sans-serif; font-size:xx-small;color:#575757;} + .galleryWidgetHeader{font-family :Arial,Helvetica,sans-serif; font-size:xx-small;color:#004276;} + .article-content{font-family :Arial,Helvetica,sans-serif; font-size:xx-small} + .cnnRecapStory{font-family :Arial,Helvetica,sans-serif; font-size:xx-small} + ''' + keep_only_tags = [ + dict(name='div', attrs={'class':["cnnWCBoxContent","cnnContent","cnnMainBodySecs"]}), + dict(name='div', attrs={'id':["contentBody","content"]}), + dict(name='td', attrs={'id':["cnnRecapStory"]}),] + remove_tags = [ + dict(name='div', attrs={'class':["storyLink","article-tools clearfix","widget video related-video vList","cnnFooterBox","scrollArrows","boxHeading","cnnInlineMailbag","mainCol_lastBlock","cnn_bookmarks","cnnFooterBox","cnnEndOfStory","cnnInlineSL","cnnStoryHighlights","cnnFooterClick","cnnSnapShotHeader","cnnStoryToolsFooter","cnnWsnr","cnnUGCBox","cnnTopNewsModule","cnnStoryElementBox","cnnStoryPhotoBoxNavigation"]}), + dict(name='span', attrs={'class':["cnnEmbeddedMosLnk"]}), + dict(name='div', attrs={'id':["cnnIncldHlder","articleCommentsContainer","featuredContent","superstarsWidget","shareMenuContainer","rssMenuContainer","storyBrandingBanner","cnnRightCol","siteFeatures","quigo628","rightColumn","clickIncludeBox","cnnHeaderRightCol","cnnSCFontLabel","cnnSnapShotBottomRight","cnnSCFontButtons","rightColumn"]}), + dict(name='p', attrs={'class':["cnnTopics"]}), + dict(name='td', attrs={'class':["cnnRightRail"]}), + dict(name='table', attrs={'class':["cnnTMbox"]}), + dict(name='ul', attrs={'id':["cnnTopNav","cnnBotNav","cnnSBNav"]}), + ] - def print_version(self, url): - return 'http://www.printthis.clickability.com/pt/printThis?clickMap=printThis&fb=Y&url=' + url + # def print_version(self, url): + # return 'http://www.printthis.clickability.com/pt/printThis?clickMap=printThis&fb=Y&url=' + url feeds = [ ('Top News', 'http://rss.cnn.com/rss/cnn_topstories.rss'), From ec16cc89f40505bc4e4086dad8ad26eaf71916d2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 31 Aug 2009 14:09:08 -0600 Subject: [PATCH 4/4] Fix #3368 (TypeError: not enough arguments for format string) --- src/calibre/ebooks/pml/pmlml.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/calibre/ebooks/pml/pmlml.py b/src/calibre/ebooks/pml/pmlml.py index 1777d1290b..2438fd9bef 100644 --- a/src/calibre/ebooks/pml/pmlml.py +++ b/src/calibre/ebooks/pml/pmlml.py @@ -75,13 +75,13 @@ class PMLMLizer(object): self.log = log self.image_hrefs = {} self.link_hrefs = {} - + def extract_content(self, oeb_book, opts): self.log.info('Converting XHTML to PML markup...') self.oeb_book = oeb_book self.opts = opts return self.pmlmlize_spine() - + def pmlmlize_spine(self): self.image_hrefs = {} self.link_hrefs = {} @@ -139,15 +139,15 @@ class PMLMLizer(object): # Remove excess spaces at beginning and end of lines text = re.sub('(?m)^[ ]+', '', text) text = re.sub('(?m)[ ]+$', '', text) - + # Remove excessive newlines text = re.sub('%s{1,1}' % os.linesep, '%s%s' % (os.linesep, os.linesep), text) text = re.sub('%s{3,}' % os.linesep, '%s%s' % (os.linesep, os.linesep), text) text = re.sub('[ ]{2,}', ' ', text) - + # Remove excessive \p tags text = re.sub(r'\\p\s*\\p', '', text) - + # Remove anchors that do not have links anchors = set(re.findall(r'(?<=\\Q=").+?(?=")', text)) links = set(re.findall(r'(?<=\\q="#).+?(?=")', text)) @@ -157,7 +157,7 @@ class PMLMLizer(object): for entity in set(re.findall('&.+?;', text)): mo = re.search('(%s)' % entity[1:-1], text) text = text.replace(entity, entity_to_unicode(mo)) - + return text def dump_text(self, elem, stylizer, page, tag_stack=[]): @@ -167,7 +167,7 @@ class PMLMLizer(object): text = u'' style = stylizer.style(elem) - + if style['display'] in ('none', 'oeb-page-head', 'oeb-page-foot') \ or style['visibility'] == 'hidden': return u'' @@ -180,7 +180,7 @@ class PMLMLizer(object): if 'block' not in tag_stack: tag_count += 1 tag_stack.append('block') - + # Process tags that need special processing and that do not have inner # text. Usually these require an argument if tag in IMAGE_TAGS: @@ -192,15 +192,15 @@ class PMLMLizer(object): text += '\\w' width = elem.get('width') if width: - text += '="%s%"' % width + text += '="%s%%"' % width else: text += '="50%"' - + # Process style information that needs holds a single tag # Commented out because every page in an OEB book starts with this style #if style['page-break-before'] == 'always': # text += '\\p' - + pml_tag = TAG_MAP.get(tag, None) if pml_tag and pml_tag not in tag_stack: tag_count += 1 @@ -240,23 +240,23 @@ class PMLMLizer(object): # Proccess tags that contain text. if hasattr(elem, 'text') and elem.text != None and elem.text.strip() != '': text += self.elem_text(elem, tag_stack) - + for item in elem: text += self.dump_text(item, stylizer, page, tag_stack) - + close_tag_list = [] for i in range(0, tag_count): close_tag_list.insert(0, tag_stack.pop()) text += self.close_tags(close_tag_list) if tag in SEPARATE_TAGS: text += os.linesep + os.linesep - + if 'block' not in tag_stack: text += os.linesep + os.linesep #if style['page-break-after'] == 'always': # text += '\\p' - + if hasattr(elem, 'tail') and elem.tail != None and elem.tail.strip() != '': text += self.elem_tail(elem, tag_stack)