diff --git a/resources/images/news/eluniversal_ve.png b/resources/images/news/eluniversal_ve.png new file mode 100644 index 0000000000..9211ee2739 Binary files /dev/null and b/resources/images/news/eluniversal_ve.png differ diff --git a/resources/recipes/eluniversal_ve.recipe b/resources/recipes/eluniversal_ve.recipe new file mode 100644 index 0000000000..af5d75e3e7 --- /dev/null +++ b/resources/recipes/eluniversal_ve.recipe @@ -0,0 +1,52 @@ +__license__ = 'GPL v3' +__copyright__ = '2010, Darko Miletic ' +''' +www.eluniversal.com +''' + +from calibre import strftime +from calibre.web.feeds.recipes import BasicNewsRecipe + +class ElUniversal(BasicNewsRecipe): + title = 'El Universal' + __author__ = 'Darko Miletic' + description = 'Noticias de Venezuela' + oldest_article = 2 + max_articles_per_feed = 100 + no_stylesheets = True + use_embedded_content = False + encoding = 'cp1252' + publisher = 'El Universal' + category = 'news, Caracas, Venezuela, world' + language = 'es' + cover_url = strftime('http://static.eluniversal.com/%Y/%m/%d/portada.jpg') + + conversion_options = { + 'comments' : description + ,'tags' : category + ,'language' : language + ,'publisher' : publisher + } + + keep_only_tags = [dict(name='div', attrs={'class':'Nota'})] + remove_tags = [ + dict(name=['object','link','script','iframe']) + ,dict(name='div',attrs={'class':'Herramientas'}) + ] + + feeds = [ + (u'Ultimas Noticias', u'http://www.eluniversal.com/rss/avances.xml' ) + ,(u'Economia' , u'http://www.eluniversal.com/rss/eco_avances.xml') + ,(u'Internacionales' , u'http://www.eluniversal.com/rss/int_avances.xml') + ,(u'Deportes' , u'http://www.eluniversal.com/rss/dep_avances.xml') + ,(u'Cultura' , u'http://www.eluniversal.com/rss/cul_avances.xml') + ,(u'Nacional y politica' , u'http://www.eluniversal.com/rss/pol_avances.xml') + ,(u'Ciencia y tecnologia', u'http://www.eluniversal.com/rss/cyt_avances.xml') + ,(u'Universo empresarial', u'http://www.eluniversal.com/rss/uni_avances.xml') + ,(u'Caracas' , u'http://www.eluniversal.com/rss/ccs_avances.xml') + ] + + def print_version(self, url): + rp,sep,rest = url.rpartition('/') + return rp + sep + 'imp_' + rest + diff --git a/resources/recipes/nejm.recipe b/resources/recipes/nejm.recipe index e6fa32cf95..d41fa5a3e2 100644 --- a/resources/recipes/nejm.recipe +++ b/resources/recipes/nejm.recipe @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from calibre.web.feeds.recipes import BasicNewsRecipe class NYTimes(BasicNewsRecipe): @@ -9,21 +10,17 @@ class NYTimes(BasicNewsRecipe): needs_subscription = True no_stylesheets = True - #remove_tags_before = dict(name='h1', attrs={'class':'heading'}) - #remove_tags_after = dict(name='td', attrs={'class':'newptool1'}) + remove_tags_before = dict(name='div', attrs={'align':'center'}) + remove_tags_after = dict(name='ol', attrs={'compact':'COMPACT'}) remove_tags = [ dict(name='iframe'), #dict(name='div', attrs={'class':'related-articles'}), - #dict(name='div', attrs={'id':['qrformdiv', 'inSection', 'alpha-inner']}), - dict(name='form', attrs={'onsubmit':"return verifySearch(this.w,'Keyword, citation, or author')"}), - dict(name='table', attrs={'cellspacing':'0'}), + dict(name='div', attrs={'id':['sidebar']}), + #dict(name='form', attrs={'onsubmit':"return verifySearch(this.w,'Keyword, citation, or author')"}), + dict(name='table', attrs={'align':'RIGHT'}), ] - def preprocess_html(self, soup): - table = soup.find('table') - if table is not None: - table.extract() - return soup + #TO LOGIN def get_browser(self): @@ -44,9 +41,9 @@ class NYTimes(BasicNewsRecipe): # To parse artice toc def parse_index(self): - soup = self.nejm_get_index() + parse_soup = self.nejm_get_index() - div = soup.find(id='centerTOC') + div = parse_soup.find(id='centerTOC') current_section = None current_articles = [] @@ -81,3 +78,20 @@ class NYTimes(BasicNewsRecipe): return feeds + def preprocess_html(self, soup): + for a in soup.findAll(text=lambda x: x and '[in this window]' in x): + a = a.findParent('a') + url = a.get('href', None) + if not url: + continue + if url.startswith('/'): + url = 'http://content.nejm.org'+url + isoup = self.index_to_soup(url) + img = isoup.find('img', src=lambda x: x and + x.startswith('/content/')) + if img is not None: + img.extract() + table = a.findParent('table') + table.replaceWith(img) + return soup + diff --git a/src/calibre/customize/ui.py b/src/calibre/customize/ui.py index 65a574c3e4..c544419b06 100644 --- a/src/calibre/customize/ui.py +++ b/src/calibre/customize/ui.py @@ -354,21 +354,19 @@ def catalog_plugins(): for plugin in _initialized_plugins: if isinstance(plugin, CatalogPlugin): yield plugin - + def available_catalog_formats(): formats = set([]) for plugin in catalog_plugins(): if not is_disabled(plugin): for format in plugin.file_types: formats.add(format) - return formats + return formats def plugin_for_catalog_format(fmt): for plugin in catalog_plugins(): if fmt.lower() in plugin.file_types: return plugin - else: - return None def device_plugins(): for plugin in _initialized_plugins: diff --git a/src/calibre/gui2/dialogs/book_info.py b/src/calibre/gui2/dialogs/book_info.py index 72b305fd78..8e7d8ee178 100644 --- a/src/calibre/gui2/dialogs/book_info.py +++ b/src/calibre/gui2/dialogs/book_info.py @@ -7,34 +7,47 @@ __docformat__ = 'restructuredtext en' ''' import textwrap, os -from PyQt4.QtCore import QCoreApplication, SIGNAL, QModelIndex, QUrl +from PyQt4.QtCore import QCoreApplication, SIGNAL, QModelIndex, QUrl, QTimer, Qt from PyQt4.QtGui import QDialog, QPixmap, QGraphicsScene, QIcon, QDesktopServices from calibre.gui2.dialogs.book_info_ui import Ui_BookInfo +from calibre.gui2 import dynamic +from calibre import fit_image class BookInfo(QDialog, Ui_BookInfo): - + def __init__(self, parent, view, row): QDialog.__init__(self, parent) Ui_BookInfo.__init__(self) self.setupUi(self) + self.cover_pixmap = None desktop = QCoreApplication.instance().desktop() screen_height = desktop.availableGeometry().height() - 100 self.resize(self.size().width(), screen_height) - - + + self.view = view self.current_row = None + self.fit_cover.setChecked(dynamic.get('book_info_dialog_fit_cover', + False)) self.refresh(row) self.connect(self.view.selectionModel(), SIGNAL('currentChanged(QModelIndex,QModelIndex)'), self.slave) self.connect(self.next_button, SIGNAL('clicked()'), self.next) self.connect(self.previous_button, SIGNAL('clicked()'), self.previous) self.connect(self.text, SIGNAL('linkActivated(QString)'), self.open_book_path) - + self.fit_cover.stateChanged.connect(self.toggle_cover_fit) + self.cover.resizeEvent = self.cover_view_resized + + def toggle_cover_fit(self, state): + dynamic.set('book_info_dialog_fit_cover', self.fit_cover.isChecked()) + self.resize_cover() + + def cover_view_resized(self, event): + QTimer.singleShot(1, self.resize_cover) def slave(self, current, previous): row = current.row() self.refresh(row) - + def open_book_path(self, path): if os.sep in unicode(path): QDesktopServices.openUrl(QUrl('file:'+path)) @@ -43,41 +56,53 @@ class BookInfo(QDialog, Ui_BookInfo): path = self.view.model().db.format_abspath(self.current_row, format) if path is not None: QDesktopServices.openUrl(QUrl('file:'+path)) - - + + def next(self): row = self.view.currentIndex().row() ni = self.view.model().index(row+1, 0) if ni.isValid(): self.view.setCurrentIndex(ni) - + def previous(self): row = self.view.currentIndex().row() ni = self.view.model().index(row-1, 0) if ni.isValid(): self.view.setCurrentIndex(ni) - + + def resize_cover(self): + if self.cover_pixmap is None: + return + self.setWindowIcon(QIcon(self.cover_pixmap)) + self.scene = QGraphicsScene() + pixmap = self.cover_pixmap + if self.fit_cover.isChecked(): + scaled, new_width, new_height = fit_image(pixmap.width(), + pixmap.height(), self.cover.size().width()-10, + self.cover.size().height()-10) + if scaled: + pixmap = pixmap.scaled(new_width, new_height, + Qt.KeepAspectRatio, Qt.SmoothTransformation) + self.scene.addPixmap(pixmap) + self.cover.setScene(self.scene) + def refresh(self, row): if isinstance(row, QModelIndex): row = row.row() if row == self.current_row: return self.previous_button.setEnabled(False if row == 0 else True) - self.next_button.setEnabled(False if row == self.view.model().rowCount(QModelIndex())-1 else True) + self.next_button.setEnabled(False if row == self.view.model().rowCount(QModelIndex())-1 else True) self.current_row = row info = self.view.model().get_book_info(row) self.setWindowTitle(info[_('Title')]) self.title.setText(''+info.pop(_('Title'))) self.comments.setText(info.pop(_('Comments'), '')) - + cdata = info.pop('cover', '') - pixmap = QPixmap.fromImage(cdata) - self.setWindowIcon(QIcon(pixmap)) - - self.scene = QGraphicsScene() - self.scene.addPixmap(pixmap) - self.cover.setScene(self.scene) - + self.cover_pixmap = QPixmap.fromImage(cdata) + self.resize_cover() + rows = u'' self.text.setText('') self.data = info @@ -94,4 +119,4 @@ class BookInfo(QDialog, Ui_BookInfo): txt = info[key] txt = u'
\n'.join(textwrap.wrap(txt, 120)) rows += u'%s:%s'%(key, txt) - self.text.setText(u''+rows+'
') \ No newline at end of file + self.text.setText(u''+rows+'
') diff --git a/src/calibre/gui2/dialogs/book_info.ui b/src/calibre/gui2/dialogs/book_info.ui index 27e15f96a1..02dae12281 100644 --- a/src/calibre/gui2/dialogs/book_info.ui +++ b/src/calibre/gui2/dialogs/book_info.ui @@ -1,7 +1,8 @@ - + + BookInfo - - + + 0 0 @@ -9,70 +10,77 @@ 783 - + Dialog - - - - + + + + TextLabel - + Qt::AlignCenter - - + + - - + + - - + + TextLabel - + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - + true - - + + Comments - - - + + + - + + + Fit &cover to view + + + + + - - + + &Previous - - + + :/images/previous.svg:/images/previous.svg - - + + &Next - - + + :/images/next.svg:/images/next.svg @@ -84,7 +92,7 @@ - + diff --git a/src/calibre/library/cli.py b/src/calibre/library/cli.py index 2ccc686c99..991c2aef7d 100644 --- a/src/calibre/library/cli.py +++ b/src/calibre/library/cli.py @@ -691,7 +691,8 @@ def command_catalog(args, dbpath): return 1 if opts.verbose: log("library.cli:command_catalog dispatching to plugin %s" % plugin.name) - plugin.run(args[1], opts, get_db(dbpath, opts)) + with plugin: + plugin.run(args[1], opts, get_db(dbpath, opts)) return 0 # end of GR additions