Migrate help and prefs actions

This commit is contained in:
Kovid Goyal 2010-08-12 23:18:31 -06:00
parent 0ffaa50f6d
commit bfb8cad41a
5 changed files with 98 additions and 53 deletions

View File

@ -633,9 +633,17 @@ class ActionConnectShare(InterfaceActionBase):
name = 'Connect Share' name = 'Connect Share'
actual_plugin = 'calibre.gui2.actions.device:ConnectShareAction' actual_plugin = 'calibre.gui2.actions.device:ConnectShareAction'
class ActionHelp(InterfaceActionBase):
name = 'Help'
actual_plugin = 'calibre.gui2.actions.help:HelpAction'
class ActionPreferences(InterfaceActionBase):
name = 'Preferences'
actual_plugin = 'calibre.gui2.actions.preferences:PreferencesAction'
plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog, plugins += [ActionAdd, ActionFetchAnnotations, ActionGenerateCatalog,
ActionConvert, ActionDelete, ActionEditMetadata, ActionView, ActionConvert, ActionDelete, ActionEditMetadata, ActionView,
ActionFetchNews, ActionSaveToDisk, ActionShowBookDetails, ActionFetchNews, ActionSaveToDisk, ActionShowBookDetails,
ActionRestart, ActionOpenFolder, ActionConnectShare, ActionRestart, ActionOpenFolder, ActionConnectShare,
ActionSendToDevice, ] ActionSendToDevice, ActionHelp, ActionPreferences]

View File

@ -0,0 +1,25 @@
#!/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 PyQt4.Qt import QUrl
from calibre.gui2 import open_url
from calibre.gui2.actions import InterfaceAction
class HelpAction(InterfaceAction):
name = 'Help'
action_spec = (_('Help'), 'help.svg', _('Browse the calibre User Manual'), _('F1'),)
def genesis(self):
self.qaction.triggered.connect(self.show_help)
def show_help(self, *args):
open_url(QUrl('http://calibre-ebook.com/user_manual'))

View File

@ -0,0 +1,62 @@
#!/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 PyQt4.Qt import QIcon, QMenu
from calibre.gui2.actions import InterfaceAction
from calibre.gui2.dialogs.config import ConfigDialog
from calibre.gui2 import error_dialog, config
class PreferencesAction(InterfaceAction):
name = 'Preferences'
action_spec = (_('Preferences'), 'config.svg', None, _('Ctrl+P'))
def genesis(self):
pm = QMenu()
pm.addAction(QIcon(I('config.svg')), _('Preferences'), self.do_config)
pm.addAction(QIcon(I('wizard.svg')), _('Run welcome wizard'),
self.gui.run_wizard)
self.qaction.setMenu(pm)
self.preferences_menu = pm
for x in (self.gui.preferences_action, self.qaction):
x.triggered.connect(self.do_config)
def do_config(self, checked=False, initial_category='general'):
if self.gui.job_manager.has_jobs():
d = error_dialog(self.gui, _('Cannot configure'),
_('Cannot configure while there are running jobs.'))
d.exec_()
return
if self.gui.must_restart_before_config:
d = error_dialog(self.gui, _('Cannot configure'),
_('Cannot configure before calibre is restarted.'))
d.exec_()
return
d = ConfigDialog(self.gui, self.gui.library_view,
server=self.gui.content_server, initial_category=initial_category)
d.exec_()
self.gui.content_server = d.server
if self.gui.content_server is not None:
self.gui.content_server.state_callback = \
self.Dispatcher(self.gui.iactions['Connect Share'].content_server_state_changed)
self.gui.content_server.state_callback(self.gui.content_server.is_running)
if d.result() == d.Accepted:
self.gui.read_toolbar_settings()
self.gui.search.search_as_you_type(config['search_as_you_type'])
self.gui.tags_view.set_new_model() # in case columns changed
self.gui.iactions['Save To Disk'].reread_prefs()
self.gui.tags_view.recount()
self.gui.create_device_menu()
self.gui.set_device_menu_items_state(bool(self.gui.device_connected))
self.gui.tool_bar.apply_settings()

View File

@ -11,12 +11,12 @@ from functools import partial
from PyQt4.Qt import QIcon, Qt, QWidget, QAction, QToolBar, QSize, \ from PyQt4.Qt import QIcon, Qt, QWidget, QAction, QToolBar, QSize, \
pyqtSignal, QToolButton, \ pyqtSignal, QToolButton, \
QObject, QVBoxLayout, QSizePolicy, QLabel, QHBoxLayout, QActionGroup, \ QObject, QVBoxLayout, QSizePolicy, QLabel, QHBoxLayout, QActionGroup, \
QMenu, QUrl QMenu
from calibre.constants import __appname__ from calibre.constants import __appname__
from calibre.gui2.search_box import SearchBox2, SavedSearchBox from calibre.gui2.search_box import SearchBox2, SavedSearchBox
from calibre.gui2.throbber import ThrobbingButton from calibre.gui2.throbber import ThrobbingButton
from calibre.gui2 import config, open_url, gprefs from calibre.gui2 import config, gprefs
from calibre.gui2.widgets import ComboBoxWithHelp from calibre.gui2.widgets import ComboBoxWithHelp
from calibre import human_readable from calibre import human_readable
from calibre.gui2.dialogs.scheduler import Scheduler from calibre.gui2.dialogs.scheduler import Scheduler
@ -372,8 +372,6 @@ class MainWindowMixin(object):
ac(5, 5, 3, 'choose_library', _('%d books')%0, 'lt.png', ac(5, 5, 3, 'choose_library', _('%d books')%0, 'lt.png',
tooltip=_('Choose calibre library to work with')) tooltip=_('Choose calibre library to work with'))
ac(10, 10, 3, 'help', _('Help'), 'help.svg', _('F1'), _("Browse the calibre User Manual"))
ac(11, 11, 0, 'preferences', _('Preferences'), 'config.svg', _('Ctrl+P'))
ac(-1, -1, 0, 'books_by_same_author', _('Books by same author'), ac(-1, -1, 0, 'books_by_same_author', _('Books by same author'),
'user_profile.svg') 'user_profile.svg')
@ -385,26 +383,9 @@ class MainWindowMixin(object):
'tags.svg') 'tags.svg')
self.action_help.triggered.connect(self.show_help)
pm = QMenu()
pm.addAction(QIcon(I('config.svg')), _('Preferences'), self.do_config)
pm.addAction(QIcon(I('wizard.svg')), _('Run welcome wizard'),
self.run_wizard)
self.action_preferences.setMenu(pm)
self.preferences_menu = pm
for x in (self.preferences_action, self.action_preferences):
x.triggered.connect(self.do_config)
return all_actions return all_actions
# }}} # }}}
def show_help(self, *args):
open_url(QUrl('http://calibre-ebook.com/user_manual'))

View File

@ -34,7 +34,6 @@ from calibre.gui2.main_window import MainWindow
from calibre.gui2.layout import MainWindowMixin from calibre.gui2.layout import MainWindowMixin
from calibre.gui2.device import DeviceMixin from calibre.gui2.device import DeviceMixin
from calibre.gui2.jobs import JobManager, JobsDialog, JobsButton from calibre.gui2.jobs import JobManager, JobsDialog, JobsButton
from calibre.gui2.dialogs.config import ConfigDialog
from calibre.gui2.init import LibraryViewMixin, LayoutMixin from calibre.gui2.init import LibraryViewMixin, LayoutMixin
from calibre.gui2.search_box import SearchBoxMixin, SavedSearchBoxMixin from calibre.gui2.search_box import SearchBoxMixin, SavedSearchBoxMixin
from calibre.gui2.search_restriction_mixin import SearchRestrictionMixin from calibre.gui2.search_restriction_mixin import SearchRestrictionMixin
@ -354,36 +353,6 @@ class Main(MainWindow, MainWindowMixin, DeviceMixin, # {{{
return self.memory_view.model().db, self.card_a_view.model().db, self.card_b_view.model().db return self.memory_view.model().db, self.card_a_view.model().db, self.card_b_view.model().db
def do_config(self, checked=False, initial_category='general'):
if self.job_manager.has_jobs():
d = error_dialog(self, _('Cannot configure'),
_('Cannot configure while there are running jobs.'))
d.exec_()
return
if self.must_restart_before_config:
d = error_dialog(self, _('Cannot configure'),
_('Cannot configure before calibre is restarted.'))
d.exec_()
return
d = ConfigDialog(self, self.library_view,
server=self.content_server, initial_category=initial_category)
d.exec_()
self.content_server = d.server
if self.content_server is not None:
self.content_server.state_callback = \
Dispatcher(self.iactions['Connect Share'].content_server_state_changed)
self.content_server.state_callback(self.content_server.is_running)
if d.result() == d.Accepted:
self.read_toolbar_settings()
self.search.search_as_you_type(config['search_as_you_type'])
self.tags_view.set_new_model() # in case columns changed
self.iactions['Save To Disk'].reread_prefs()
self.tags_view.recount()
self.create_device_menu()
self.set_device_menu_items_state(bool(self.device_connected))
self.tool_bar.apply_settings()
def library_moved(self, newloc): def library_moved(self, newloc):
if newloc is None: return if newloc is None: return