mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Migrate show similar books action
This commit is contained in:
parent
bfb8cad41a
commit
4635ae37d7
@ -641,9 +641,13 @@ class ActionPreferences(InterfaceActionBase):
|
||||
name = 'Preferences'
|
||||
actual_plugin = 'calibre.gui2.actions.preferences:PreferencesAction'
|
||||
|
||||
class ActionSimilarBooks(InterfaceActionBase):
|
||||
name = 'Similar Books'
|
||||
actual_plugin = 'calibre.gui2.actions.similar_books:SimilarBooksAction'
|
||||
|
||||
|
||||
plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog,
|
||||
ActionConvert, ActionDelete, ActionEditMetadata, ActionView,
|
||||
ActionFetchNews, ActionSaveToDisk, ActionShowBookDetails,
|
||||
ActionRestart, ActionOpenFolder, ActionConnectShare,
|
||||
ActionSendToDevice, ActionHelp, ActionPreferences]
|
||||
ActionSendToDevice, ActionHelp, ActionPreferences, ActionSimilarBooks]
|
||||
|
@ -51,6 +51,7 @@ class InterfaceAction(QObject):
|
||||
if shortcut:
|
||||
action.setShortcut(shortcut)
|
||||
setattr(self, attr, action)
|
||||
return action
|
||||
|
||||
def genesis(self):
|
||||
pass
|
||||
|
60
src/calibre/gui2/actions/similar_books.py
Normal file
60
src/calibre/gui2/actions/similar_books.py
Normal file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python
|
||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
from functools import partial
|
||||
|
||||
from PyQt4.Qt import QMenu
|
||||
|
||||
from calibre.gui2.actions import InterfaceAction
|
||||
|
||||
class SimilarBooksAction(InterfaceAction):
|
||||
|
||||
name = 'Similar Books'
|
||||
action_spec = (_('Similar books...'), None, None, None)
|
||||
|
||||
def genesis(self):
|
||||
m = QMenu(self.gui)
|
||||
for text, icon, target, shortcut in [
|
||||
(_('Books by same author'), 'user_profile.svg', 'authors', _('Alt+A')),
|
||||
(_('Books in this series'), 'books_in_series.svg', 'series', _('Alt+S')),
|
||||
(_('Books by this publisher'), 'publisher.png', 'publisher', _('Alt+P'))
|
||||
(_('Books with the same tags'), 'tags.svg', 'tag', _('Alt+T'))]:
|
||||
ac = self.create_action(spec=(text, icon, None, shortcut),
|
||||
attr=target)
|
||||
m.addAction(ac)
|
||||
m.triggered.connect(partial(self.show_similar_books, target))
|
||||
self.qaction.setMenu(m)
|
||||
self.similar_menu = m
|
||||
|
||||
def show_similar_books(self, type, *args):
|
||||
search, join = [], ' '
|
||||
idx = self.gui.library_view.currentIndex()
|
||||
if not idx.isValid():
|
||||
return
|
||||
row = idx.row()
|
||||
if type == 'series':
|
||||
series = idx.model().db.series(row)
|
||||
if series:
|
||||
search = ['series:"'+series+'"']
|
||||
elif type == 'publisher':
|
||||
publisher = idx.model().db.publisher(row)
|
||||
if publisher:
|
||||
search = ['publisher:"'+publisher+'"']
|
||||
elif type == 'tag':
|
||||
tags = idx.model().db.tags(row)
|
||||
if tags:
|
||||
search = ['tag:"='+t+'"' for t in tags.split(',')]
|
||||
elif type in ('author', 'authors'):
|
||||
authors = idx.model().db.authors(row)
|
||||
if authors:
|
||||
search = ['author:"='+a.strip().replace('|', ',')+'"' \
|
||||
for a in authors.split(',')]
|
||||
join = ' or '
|
||||
if search:
|
||||
self.gui.search.set_search_string(join.join(search))
|
||||
|
||||
|
@ -7,7 +7,7 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import functools, sys, os
|
||||
|
||||
from PyQt4.Qt import QMenu, Qt, QStackedWidget, \
|
||||
from PyQt4.Qt import Qt, QStackedWidget, \
|
||||
QSize, QSizePolicy, QStatusBar, QLabel, QFont
|
||||
|
||||
from calibre.utils.config import prefs
|
||||
@ -30,28 +30,6 @@ def partial(*args, **kwargs):
|
||||
class LibraryViewMixin(object): # {{{
|
||||
|
||||
def __init__(self, db):
|
||||
similar_menu = QMenu(_('Similar books...'))
|
||||
similar_menu.addAction(self.action_books_by_same_author)
|
||||
similar_menu.addAction(self.action_books_in_this_series)
|
||||
similar_menu.addAction(self.action_books_with_the_same_tags)
|
||||
similar_menu.addAction(self.action_books_by_this_publisher)
|
||||
self.action_books_by_same_author.setShortcut(Qt.ALT + Qt.Key_A)
|
||||
self.action_books_in_this_series.setShortcut(Qt.ALT + Qt.Key_S)
|
||||
self.action_books_by_this_publisher.setShortcut(Qt.ALT + Qt.Key_P)
|
||||
self.action_books_with_the_same_tags.setShortcut(Qt.ALT+Qt.Key_T)
|
||||
self.addAction(self.action_books_by_same_author)
|
||||
self.addAction(self.action_books_by_this_publisher)
|
||||
self.addAction(self.action_books_in_this_series)
|
||||
self.addAction(self.action_books_with_the_same_tags)
|
||||
self.similar_menu = similar_menu
|
||||
self.action_books_by_same_author.triggered.connect(
|
||||
partial(self.show_similar_books, 'authors'))
|
||||
self.action_books_in_this_series.triggered.connect(
|
||||
partial(self.show_similar_books, 'series'))
|
||||
self.action_books_with_the_same_tags.triggered.connect(
|
||||
partial(self.show_similar_books, 'tag'))
|
||||
self.action_books_by_this_publisher.triggered.connect(
|
||||
partial(self.show_similar_books, 'publisher'))
|
||||
|
||||
self.library_view.set_context_menu(self.action_edit, self.action_sync,
|
||||
self.action_convert, self.action_view,
|
||||
@ -122,33 +100,6 @@ class LibraryViewMixin(object): # {{{
|
||||
|
||||
|
||||
|
||||
def show_similar_books(self, type, *args):
|
||||
search, join = [], ' '
|
||||
idx = self.library_view.currentIndex()
|
||||
if not idx.isValid():
|
||||
return
|
||||
row = idx.row()
|
||||
if type == 'series':
|
||||
series = idx.model().db.series(row)
|
||||
if series:
|
||||
search = ['series:"'+series+'"']
|
||||
elif type == 'publisher':
|
||||
publisher = idx.model().db.publisher(row)
|
||||
if publisher:
|
||||
search = ['publisher:"'+publisher+'"']
|
||||
elif type == 'tag':
|
||||
tags = idx.model().db.tags(row)
|
||||
if tags:
|
||||
search = ['tag:"='+t+'"' for t in tags.split(',')]
|
||||
elif type in ('author', 'authors'):
|
||||
authors = idx.model().db.authors(row)
|
||||
if authors:
|
||||
search = ['author:"='+a.strip().replace('|', ',')+'"' \
|
||||
for a in authors.split(',')]
|
||||
join = ' or '
|
||||
if search:
|
||||
self.search.set_search_string(join.join(search))
|
||||
|
||||
def search_done(self, view, ok):
|
||||
if view is self.current_view():
|
||||
self.search.search_done(ok)
|
||||
|
@ -373,15 +373,6 @@ class MainWindowMixin(object):
|
||||
ac(5, 5, 3, 'choose_library', _('%d books')%0, 'lt.png',
|
||||
tooltip=_('Choose calibre library to work with'))
|
||||
|
||||
ac(-1, -1, 0, 'books_by_same_author', _('Books by same author'),
|
||||
'user_profile.svg')
|
||||
ac(-1, -1, 0, 'books_in_this_series', _('Books in this series'),
|
||||
'books_in_series.svg')
|
||||
ac(-1, -1, 0, 'books_by_this_publisher', _('Books by this publisher'),
|
||||
'publisher.png')
|
||||
ac(-1, -1, 0, 'books_with_the_same_tags', _('Books with the same tags'),
|
||||
'tags.svg')
|
||||
|
||||
|
||||
|
||||
return all_actions
|
||||
|
Loading…
x
Reference in New Issue
Block a user