diff --git a/imgsrc/random.svg b/imgsrc/random.svg new file mode 100644 index 0000000000..8dec21307e --- /dev/null +++ b/imgsrc/random.svg @@ -0,0 +1,758 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + diff --git a/resources/images/random.png b/resources/images/random.png new file mode 100644 index 0000000000..d8dfc3629e Binary files /dev/null and b/resources/images/random.png differ diff --git a/src/calibre/customize/builtins.py b/src/calibre/customize/builtins.py index 620254b1f5..ecf92195d5 100644 --- a/src/calibre/customize/builtins.py +++ b/src/calibre/customize/builtins.py @@ -843,6 +843,12 @@ class ActionNextMatch(InterfaceActionBase): description = _('Find the next or previous match when searching in ' 'your calibre library in highlight mode') +class ActionPickRandom(InterfaceActionBase): + name = 'Pick Random Book' + actual_plugin = 'calibre.gui2.actions.random:PickRandomAction' + description = _('Choose a random book from your calibre library') + + class ActionStore(InterfaceActionBase): name = 'Store' author = 'John Schember' @@ -873,7 +879,7 @@ plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog, ActionSendToDevice, ActionHelp, ActionPreferences, ActionSimilarBooks, ActionAddToLibrary, ActionEditCollections, ActionChooseLibrary, ActionCopyToLibrary, ActionTweakEpub, ActionNextMatch, ActionStore, - ActionPluginUpdater] + ActionPluginUpdater, ActionPickRandom] # }}} diff --git a/src/calibre/gui2/actions/choose_library.py b/src/calibre/gui2/actions/choose_library.py index b233575fa2..726fee7910 100644 --- a/src/calibre/gui2/actions/choose_library.py +++ b/src/calibre/gui2/actions/choose_library.py @@ -152,10 +152,7 @@ class ChooseLibraryAction(InterfaceAction): self.choose_menu.addMenu(self.maintenance_menu) def pick_random(self, *args): - import random - pick = random.randint(0, self.gui.library_view.model().rowCount(None)) - self.gui.library_view.set_current_row(pick) - self.gui.library_view.scroll_to_row(pick) + self.gui.iactions['Pick Random Book'].pick_random() def library_name(self): db = self.gui.library_view.model().db diff --git a/src/calibre/gui2/actions/random.py b/src/calibre/gui2/actions/random.py new file mode 100644 index 0000000000..6c722d16ae --- /dev/null +++ b/src/calibre/gui2/actions/random.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import (unicode_literals, division, absolute_import, + print_function) + +__license__ = 'GPL v3' +__copyright__ = '2011, Kovid Goyal ' +__docformat__ = 'restructuredtext en' + +import random + +from calibre.gui2.actions import InterfaceAction + +class PickRandomAction(InterfaceAction): + + name = 'Pick Random Book' + action_spec = (_('Pick a random book'), 'random.png', 'Catalog builder', None) + dont_add_to = frozenset(['menubar-device', 'toolbar-device', 'context-menu-device']) + + def genesis(self): + self.qaction.triggered.connect(self.pick_random) + + def pick_random(self): + pick = random.randint(0, self.gui.library_view.model().rowCount(None)) + self.gui.library_view.set_current_row(pick) + self.gui.library_view.scroll_to_row(pick) + + diff --git a/src/calibre/gui2/actions/view.py b/src/calibre/gui2/actions/view.py index a877a8f75f..f67b0767d6 100644 --- a/src/calibre/gui2/actions/view.py +++ b/src/calibre/gui2/actions/view.py @@ -207,7 +207,7 @@ class ViewAction(InterfaceAction): self._view_books([index]) def view_random(self, *args): - self.gui.iactions['Choose Library'].pick_random() + self.gui.iactions['Pick Random Book'].pick_random() self._view_books([self.gui.library_view.currentIndex()]) def _view_calibre_books(self, ids):