From 60b290caed4f9041402da9d8aad2bf6f7ed5c251 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 4 Jan 2010 19:28:12 -0700 Subject: [PATCH 1/4] Fix bug when trying to set keyboard shortcuts for the viewer with a translated calibre interface. Also possible workarounf for cover flow related crash on OS X --- src/calibre/gui2/cover_flow.py | 8 +++++++- src/calibre/gui2/shortcuts.py | 6 +++--- src/calibre/gui2/ui.py | 3 --- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/cover_flow.py b/src/calibre/gui2/cover_flow.py index 0e326ba239..81d67ff7dd 100644 --- a/src/calibre/gui2/cover_flow.py +++ b/src/calibre/gui2/cover_flow.py @@ -57,7 +57,13 @@ if pictureflow is not None: return self.model.count() def caption(self, index): - return self.model.title(index) + try: + ans = self.model.title(index) + if not ans: + ans = '' + except: + ans = '' + return ans def reset(self): self.emit(SIGNAL('dataChanged()')) diff --git a/src/calibre/gui2/shortcuts.py b/src/calibre/gui2/shortcuts.py index a617b6897f..5c4ebcc2fe 100644 --- a/src/calibre/gui2/shortcuts.py +++ b/src/calibre/gui2/shortcuts.py @@ -152,9 +152,9 @@ class Delegate(QStyledItemDelegate): class Shortcuts(QAbstractListModel): - TEMPLATE = ''' + TEMPLATE = u'''

{0}
- Keys: {1}

+ {2}: {1}

''' def __init__(self, shortcuts, config_file_base_name, parent=None): @@ -212,7 +212,7 @@ class Shortcuts(QAbstractListModel): key = self.order[row] if role == Qt.DisplayRole: return QVariant(self.TEMPLATE.format(self.descriptions[key], - _(' or ').join(self.get_shortcuts(key)))) + _(' or ').join(self.get_shortcuts(key)), _('Keys'))) if role == Qt.ToolTipRole: return QVariant(_('Double click to change')) if role == DEFAULTS: diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 49f4476188..4d40dccfcd 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -533,8 +533,6 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): if not config['separate_cover_flow']: self.library.layout().addWidget(self.cover_flow) self.cover_flow.currentChanged.connect(self.sync_listview_to_cf) - #self.connect(self.cover_flow, SIGNAL('itemActivated(int)'), - # self.show_book_info) self.connect(self.status_bar.cover_flow_button, SIGNAL('toggled(bool)'), self.toggle_cover_flow) self.connect(self.cover_flow, SIGNAL('stop()'), @@ -758,7 +756,6 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): sm.select(index, sm.ClearAndSelect|sm.Rows) self.library_view.setCurrentIndex(index) except: - #raise pass From 203d48295c2eab7aeb0731c209d8805845ed2dc2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 4 Jan 2010 20:04:47 -0700 Subject: [PATCH 2/4] Nicer looking tooltips --- src/calibre/gui2/__init__.py | 11 +++++++++++ src/calibre/gui2/convert/__init__.py | 6 ++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 317fe9c94a..5d67e3a1b1 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -529,6 +529,17 @@ class Application(QApplication): self.load_translations() qt_app = self + self.setStyleSheet(''' + QToolTip { + border: 2px solid black; + padding: 5px; + border-radius: 10px; + opacity: 200; + background-color: white; + } + ''') + + def load_translations(self): if self._translator is not None: self.removeTranslator(self._translator) diff --git a/src/calibre/gui2/convert/__init__.py b/src/calibre/gui2/convert/__init__.py index 383fe2d36f..34940f081a 100644 --- a/src/calibre/gui2/convert/__init__.py +++ b/src/calibre/gui2/convert/__init__.py @@ -145,10 +145,8 @@ class Widget(QWidget): help = help_provider(name) if not help: continue g._help = help - g.setToolTip('\n'.join(w.wrap(help.replace('<', '<').replace('>', - '>')))) - g.setWhatsThis('\n'.join(w.wrap(help.replace('<', '<').replace('>', - '>')))) + g.setToolTip('\n'.join(w.wrap(help))) + g.setWhatsThis('\n'.join(w.wrap(help))) g.__class__.enterEvent = lambda obj, event: self.set_help(getattr(obj, '_help', obj.toolTip())) From 25593455d49a85d90a90b82ac784e45413325b9f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 4 Jan 2010 20:10:22 -0700 Subject: [PATCH 3/4] ... --- src/calibre/gui2/dialogs/config/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/calibre/gui2/dialogs/config/__init__.py b/src/calibre/gui2/dialogs/config/__init__.py index 32da148584..156faec7ce 100644 --- a/src/calibre/gui2/dialogs/config/__init__.py +++ b/src/calibre/gui2/dialogs/config/__init__.py @@ -437,6 +437,8 @@ class ConfigDialog(ResizableDialog, Ui_Dialog): self.priority_label.setVisible(iswindows) self._plugin_model = PluginModel() self.plugin_view.setModel(self._plugin_model) + self.plugin_view.setStyleSheet( + "QTreeView::item { padding-bottom: 10px;}") self.connect(self.toggle_plugin, SIGNAL('clicked()'), lambda : self.modify_plugin(op='toggle')) self.connect(self.customize_plugin, SIGNAL('clicked()'), lambda : self.modify_plugin(op='customize')) self.connect(self.remove_plugin, SIGNAL('clicked()'), lambda : self.modify_plugin(op='remove')) From 536e629356f990053e84bcb853820adad1d2dc51 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 4 Jan 2010 22:34:33 -0700 Subject: [PATCH 4/4] Improved recipe for CNN --- resources/recipes/cnn.recipe | 54 +++++++++++++++++------------------- src/calibre/gui2/__init__.py | 19 +++++++------ 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/resources/recipes/cnn.recipe b/resources/recipes/cnn.recipe index 21c4139d6e..8c3cfa6de8 100644 --- a/resources/recipes/cnn.recipe +++ b/resources/recipes/cnn.recipe @@ -4,13 +4,14 @@ __copyright__ = '2008, Kovid Goyal ' Profile to download CNN ''' from calibre.web.feeds.news import BasicNewsRecipe +from calibre.ebooks.BeautifulSoup import BeautifulSoup class CNN(BasicNewsRecipe): title = 'CNN' description = 'Global news' timefmt = ' [%d %b %Y]' - __author__ = 'Kovid Goyal and Sujata Raman' + __author__ = 'Krittika Goyal and Sujata Raman' language = 'en' no_stylesheets = True @@ -18,7 +19,8 @@ class CNN(BasicNewsRecipe): oldest_article = 15 recursions = 1 match_regexps = [r'http://sportsillustrated.cnn.com/.*/[1-9].html'] - + max_articles_per_feed = 25 + extra_css = ''' .cnn_strycntntlft{font-family :Arial,Helvetica,sans-serif;} h2{font-family :Arial,Helvetica,sans-serif; font-size:x-small} @@ -44,7 +46,7 @@ class CNN(BasicNewsRecipe): .cnnInlineT1Caption{font-family :Arial,Helvetica,sans-serif; font-size:x-small;font-weight:bold;} .cnnInlineT1Credit{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#333333;} .col10{color:#5A637E;} - .cnnInlineRailBulletList{color:black;} + .cnnInlineRailBulletList{color:black;} .cnnLine0{font-family :Arial,Helvetica,sans-serif; color:#666666;font-weight:bold;} .cnnTimeStamp{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#333333;} .galleryhedDek{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#575757;} @@ -55,31 +57,22 @@ class CNN(BasicNewsRecipe): .captionname{font-family :Arial,Helvetica,sans-serif; font-size:x-small;color:#575757;} inStoryIE{{font-family :Arial,Helvetica,sans-serif; font-size:x-small;} ''' - keep_only_tags = [ - dict(name='div', attrs={'class':["cnnWCBoxContent","cnnContent","cnnMainBodySecs","cnn_storyarea","cnn_strycntntlft","cnn_strytmstmp"]}), - dict(name='div', attrs={'id':["contentBody","content"]}), - dict(name='td', attrs={'id':["cnnRecapStory"]}), - dict(name='td', attrs={'class':["cnnBigSideLeft"]}), - ] - remove_tags = [ - dict(name='div', attrs={'class':["cnnInlineRailSelectList","cnn_strycntntrgt","cnn_strybtntools","cnn_strylctcntr cnn_strylctcqrelt","cnn_strylceclbtn","cnn_stryftsbttm","cnn_strybtmmorebx","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"]}), - dict(name='div', attrs={'id':["cnn_ftrcntnt"]}) - ] - # def print_version(self, url): - # return 'http://www.printthis.clickability.com/pt/printThis?clickMap=printThis&fb=Y&url=' + url + #remove_tags_before = dict(name='h1', attrs={'class':'heading'}) + #remove_tags_after = dict(name='td', attrs={'class':'newptool1'}) + remove_tags = [ + dict(name='iframe'), + dict(name='div', attrs={'class':['cnnEndOfStory', 'cnnShareThisItem', 'cnn_strylctcntr cnn_strylctcqrelt', 'cnnShareBoxContent', 'cnn_strybtmcntnt', 'cnn_strycntntrgt']}), + dict(name='div', attrs={'id':['IEContainer', 'clickIncludeBox']}), + #dict(name='ul', attrs={'class':'article-tools'}), + #dict(name='ul', attrs={'class':'articleTools'}), + ] feeds = [ ('Top News', 'http://rss.cnn.com/rss/cnn_topstories.rss'), ('World', 'http://rss.cnn.com/rss/cnn_world.rss'), ('U.S.', 'http://rss.cnn.com/rss/cnn_us.rss'), - ('Sports', 'http://rss.cnn.com/rss/si_topstories.rss'), + #('Sports', 'http://rss.cnn.com/rss/si_topstories.rss'), ('Business', 'http://rss.cnn.com/rss/money_latest.rss'), ('Politics', 'http://rss.cnn.com/rss/cnn_allpolitics.rss'), ('Law', 'http://rss.cnn.com/rss/cnn_law.rss'), @@ -91,10 +84,15 @@ class CNN(BasicNewsRecipe): ('Offbeat', 'http://rss.cnn.com/rss/cnn_offbeat.rss'), ('Most Popular', 'http://rss.cnn.com/rss/cnn_mostpopular.rss') ] - def preprocess_html(self, soup): - - for tag in soup.findAll(name=['ul','li']): - tag.name = 'div' - - return soup + story = soup.find(name='div', attrs={'class':'cnnBody_Left'}) + if story is None: + story = soup.find(name='div', attrs={'id':'cnnContentContainer'}) + soup = BeautifulSoup('t') + body = soup.find(name='body') + body.insert(0, story) + else: + soup = BeautifulSoup('t') + body = soup.find(name='body') + body.insert(0, story) + return soup diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 5d67e3a1b1..82f65f8c42 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -529,15 +529,16 @@ class Application(QApplication): self.load_translations() qt_app = self - self.setStyleSheet(''' - QToolTip { - border: 2px solid black; - padding: 5px; - border-radius: 10px; - opacity: 200; - background-color: white; - } - ''') + if islinux: + self.setStyleSheet(''' + QToolTip { + border: 2px solid black; + padding: 5px; + border-radius: 10px; + opacity: 200; + background-color: #e1e1ff; + } + ''') def load_translations(self):