From 45e336b61e5c5d525b433a5f8d136a09951d1a60 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Fri, 22 Nov 2019 21:41:29 -0600 Subject: [PATCH] Add plugin option for toolbar button to pop menu. --- calibre-plugin/config.py | 19 ++++++++++++++++--- calibre-plugin/fff_plugin.py | 19 ++++++++++++++++--- calibre-plugin/prefs.py | 1 + 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/calibre-plugin/config.py b/calibre-plugin/config.py index e38b8d7b..aac53fff 100644 --- a/calibre-plugin/config.py +++ b/calibre-plugin/config.py @@ -283,6 +283,7 @@ class ConfigWidget(QWidget): prefs['autoconvert'] = self.basic_tab.autoconvert.isChecked() prefs['show_est_time'] = self.basic_tab.show_est_time.isChecked() prefs['urlsfromclip'] = self.basic_tab.urlsfromclip.isChecked() + prefs['button_instantpopup'] = self.basic_tab.button_instantpopup.isChecked() prefs['updatedefault'] = self.basic_tab.updatedefault.isChecked() prefs['deleteotherforms'] = self.basic_tab.deleteotherforms.isChecked() prefs['adddialogstaysontop'] = self.basic_tab.adddialogstaysontop.isChecked() @@ -406,8 +407,8 @@ class ConfigWidget(QWidget): prefs['auto_reject_from_email'] = self.imap_tab.auto_reject_from_email.isChecked() prefs['update_existing_only_from_email'] = self.imap_tab.update_existing_only_from_email.isChecked() prefs['download_from_email_immediately'] = self.imap_tab.download_from_email_immediately.isChecked() - prefs.save_to_db() + self.plugin_action.set_popup_mode() def edit_shortcuts(self): self.save_settings() @@ -508,6 +509,8 @@ class BasicTab(QWidget): self.auto_reject_seriesurlid = QCheckBox(_("Reject Without Confirmation?"),self) self.auto_reject_seriesurlid.setToolTip(_("Automatically reject storys with existing Series Anthology books.\nOnly works if 'Check for existing Series Anthology books' is on.\nDoesn't work when Collect Metadata in Background is selected.")) self.auto_reject_seriesurlid.setChecked(prefs['auto_reject_seriesurlid']) + self.auto_reject_seriesurlid.setEnabled(self.checkforseriesurlid.isChecked()) + self.checkforseriesurlid.stateChanged.connect(lambda x : self.auto_reject_seriesurlid.setEnabled(self.checkforseriesurlid.isChecked())) horz = QHBoxLayout() horz.addItem(QtGui.QSpacerItem(20, 1)) horz.addWidget(self.auto_reject_seriesurlid) @@ -574,10 +577,20 @@ class BasicTab(QWidget): self.urlsfromclip.setChecked(prefs['urlsfromclip']) self.l.addWidget(self.urlsfromclip) + self.button_instantpopup = QCheckBox(_('FanFicFare button opens menu?'),self) + self.button_instantpopup.setToolTip(_('The FanFicFare toolbar button will bring up the plugin menu. If unchecked, it will Download from URLs or optionally Update, see below.')) + self.button_instantpopup.setChecked(prefs['button_instantpopup']) + self.l.addWidget(self.button_instantpopup) + self.updatedefault = QCheckBox(_('Default to Update when books selected?'),self) - self.updatedefault.setToolTip(_('The top FanFicFare plugin button will start Update if\nbooks are selected. If unchecked, it will always bring up \'Add New\'.')) + self.updatedefault.setToolTip(_('The FanFicFare toolbar button will Update if books are selected. If unchecked, it will always Download from URLs.')) self.updatedefault.setChecked(prefs['updatedefault']) - self.l.addWidget(self.updatedefault) + self.updatedefault.setEnabled(not self.button_instantpopup.isChecked()) + self.button_instantpopup.stateChanged.connect(lambda x : self.updatedefault.setEnabled(not self.button_instantpopup.isChecked())) + horz = QHBoxLayout() + horz.addItem(QtGui.QSpacerItem(20, 1)) + horz.addWidget(self.updatedefault) + self.l.addLayout(horz) self.adddialogstaysontop = QCheckBox(_("Keep 'Add New from URL(s)' dialog on top?"),self) self.adddialogstaysontop.setToolTip(_("Instructs the OS and Window Manager to keep the 'Add New from URL(s)'\ndialog on top of all other windows. Useful for dragging URLs onto it.")) diff --git a/calibre-plugin/fff_plugin.py b/calibre-plugin/fff_plugin.py index 049b9763..a7139031 100644 --- a/calibre-plugin/fff_plugin.py +++ b/calibre-plugin/fff_plugin.py @@ -36,10 +36,10 @@ import email import traceback try: - from PyQt5.Qt import (QApplication, QMenu, QTimer, Qt) + from PyQt5.Qt import (QApplication, QMenu, QTimer, Qt, QToolButton) from PyQt5.QtCore import QBuffer except ImportError as e: - from PyQt4.Qt import (QApplication, QMenu, QTimer, Qt) + from PyQt4.Qt import (QApplication, QMenu, QTimer, Qt, QToolButton) from PyQt4.QtCore import QBuffer from calibre.constants import numeric_version as calibre_version @@ -189,7 +189,7 @@ class FanFicFarePlugin(InterfaceAction): # otherwise configured hot keys won't work until the menu's # been displayed once. self.rebuild_menus() - + self.set_popup_mode() self.add_new_dialog = AddNewDialog(self.gui, prefs, self.qaction.icon()) @@ -280,6 +280,7 @@ class FanFicFarePlugin(InterfaceAction): def library_changed(self, db): # We need to reset our menus after switching libraries self.rebuild_menus() + self.set_popup_mode() rejecturllist.clear_cache() self.imap_pass = None @@ -429,6 +430,18 @@ class FanFicFarePlugin(InterfaceAction): else: self.add_dialog() + def set_popup_mode(self): + if prefs['button_instantpopup']: + self.popup_type = QToolButton.InstantPopup + else: + self.popup_type = QToolButton.MenuButtonPopup + for bar in self.gui.bars_manager.bars: + w = bar.widgetForAction(self.qaction) + if w is not None: + w.setPopupMode(self.popup_type) + w.update() + return + def get_epubmerge_plugin(self): if 'EpubMerge' in self.gui.iactions and self.gui.iactions['EpubMerge'].interface_action_base_plugin.version >= (1,3,1): return self.gui.iactions['EpubMerge'] diff --git a/calibre-plugin/prefs.py b/calibre-plugin/prefs.py index 2973f616..4f0d1d6e 100644 --- a/calibre-plugin/prefs.py +++ b/calibre-plugin/prefs.py @@ -128,6 +128,7 @@ default_prefs['mark'] = False default_prefs['showmarked'] = False default_prefs['autoconvert'] = False default_prefs['urlsfromclip'] = True +default_prefs['button_instantpopup'] = False default_prefs['updatedefault'] = True default_prefs['fileform'] = 'epub' default_prefs['collision'] = SAVE_UPDATE