home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 January / maximum-cd-2011-01.iso / DiscContents / calibre-0.7.26.msi / file_1173 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-10-31  |  2.8 KB  |  68 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
  6. __docformat__ = 'restructuredtext en'
  7. from functools import partial
  8. from PyQt4.Qt import QMenu, QToolButton
  9. from calibre.gui2.actions import InterfaceAction
  10.  
  11. class SimilarBooksAction(InterfaceAction):
  12.     name = 'Similar Books'
  13.     action_spec = (_('Similar books...'), None, None, None)
  14.     popup_type = QToolButton.InstantPopup
  15.     action_type = 'current'
  16.     
  17.     def genesis(self):
  18.         m = QMenu(self.gui)
  19.         for text, icon, target, shortcut in [
  20.             (_('Books by same author'), 'user_profile.png', 'authors', _('Alt+A')),
  21.             (_('Books in this series'), 'books_in_series.png', 'series', _('Alt+Shift+S')),
  22.             (_('Books by this publisher'), 'publisher.png', 'publisher', _('Alt+P')),
  23.             (_('Books with the same tags'), 'tags.png', 'tag', _('Alt+T'))]:
  24.             ac = self.create_action(spec = (text, icon, None, shortcut), attr = target)
  25.             m.addAction(ac)
  26.             ac.triggered.connect(partial(self.show_similar_books, target))
  27.         
  28.         self.qaction.setMenu(m)
  29.         self.similar_menu = m
  30.  
  31.     
  32.     def show_similar_books(self, type, *args):
  33.         search = []
  34.         join = ' '
  35.         idx = self.gui.library_view.currentIndex()
  36.         if not idx.isValid():
  37.             return None
  38.         row = idx.row()
  39.         if type == 'series':
  40.             series = idx.model().db.series(row)
  41.             if series:
  42.                 search = [
  43.                     'series:"' + series + '"']
  44.             
  45.         elif type == 'publisher':
  46.             publisher = idx.model().db.publisher(row)
  47.             if publisher:
  48.                 search = [
  49.                     'publisher:"' + publisher + '"']
  50.             
  51.         elif type == 'tag':
  52.             tags = idx.model().db.tags(row)
  53.             if tags:
  54.                 search = [ 'tag:"=' + t + '"' for t in tags.split(',') ]
  55.             
  56.         elif type in ('author', 'authors'):
  57.             authors = idx.model().db.authors(row)
  58.             if authors:
  59.                 search = [ 'author:"=' + a.strip().replace('|', ',') + '"' for a in authors.split(',') ]
  60.                 join = ' or '
  61.             
  62.         
  63.         if search:
  64.             self.gui.search.set_search_string(join.join(search))
  65.         
  66.  
  67.  
  68.