![]() |
#466 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
Also, Count Pages supports being called directly from plugins with support for choosing which statistics to calculate and a callback function for the results. I don't remember if there is an option to suppress the prompt. It's been a while since I needed to look at it. I added this at the request of another developer for a private plugin they had. |
|
![]() |
![]() |
![]() |
#467 | |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,995
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Quote:
Last edited by ownedbycats; 03-30-2021 at 09:42 PM. |
|
![]() |
![]() |
Advert | |
|
![]() |
#468 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
|
|
![]() |
![]() |
![]() |
#469 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,995
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
When Count Pages runs from FanFicFare, it seems to follow the prompt in the settings.
|
![]() |
![]() |
![]() |
#470 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
@chaley: Attached to this post is a beta that adds scope management to the plugin. I will leave it for few days for testing before releasing it. I'd like to hear your feedback on this. Here is how this works:
Under the hood this is how scopes work:
The whole thing seems to be working well. The only thing that I have doubts about the is user interface for this. Finally, Here is an example of a custom scope manager that uses a template defined by the user to return the list of book_ids (copy/paste into the module editor): Code:
from __future__ import (unicode_literals, division, absolute_import, print_function) # python 3 compatibility from six import text_type as unicode from PyQt5.Qt import (QApplication, Qt, QVBoxLayout, QGroupBox, QCheckBox, QRadioButton) from calibre import prints from calibre.constants import DEBUG from calibre.utils.search_query_parser import ParseException from calibre_plugins.action_chains.scopes.base import ActionScope from calibre_plugins.action_chains.templates import TemplateBox, check_template, get_metadata_object class TemplateScopeConfigWidget(TemplateBox): def __init__(self, plugin_action): self.plugin_action = plugin_action self.gui = plugin_action.gui self.db = self.gui.current_db placeholder_text = _('The template entered here should return a comma separated list ' 'of book_ids') TemplateBox.__init__( self, self.gui, plugin_action, template_text='', placeholder_text=placeholder_text, dialog_is_st_editor=True ) vl_chk = self.vl_chk = QCheckBox(_('Exclude books not in current virtual libarary')) vl_chk.setChecked(False) self.user_layout_1.addWidget(vl_chk) options_groupbox = QGroupBox(_('Options')) self.user_layout_2.addWidget(options_groupbox) options_groupbox_layout = QVBoxLayout() options_groupbox.setLayout(options_groupbox_layout) ids_opt = self.ids_opt = QRadioButton(_('Template output is a list of book ids')) options_groupbox_layout.addWidget(ids_opt) ids_opt.setChecked(True) search_opt = self.search_opt = QRadioButton(_('Template output is a calibre search')) options_groupbox_layout.addWidget(search_opt) def load_settings(self, settings): if settings: template = settings['template'] self.textbox.insertPlainText(template) self.vl_chk.setChecked(settings.get('vl')) if settings.get('opt') == 'search': self.search_opt.setChecked(True) def save_settings(self): settings = {} settings['template'] = unicode(self.textbox.toPlainText()).rstrip() settings['vl'] = self.vl_chk.isChecked() if self.ids_opt.isChecked(): settings['opt'] = 'ids' elif self.search_opt.isChecked(): settings['opt'] = 'search' return settings class TemplateScope(ActionScope): name = 'Template Scopes' def get_book_ids(self, gui, settings, chain): db = gui.current_db template = settings.get('template', '') template_output = chain.evaluate_template(template, book_id=None) if settings.get('opt') == 'ids': try: book_ids = [int(x.strip()) for x in template_output.split(',')] except: book_ids = [] elif settings.get('opt') == 'search': try: book_ids = db.data.search_getting_ids(template_output, '', use_virtual_library=False) except ParseException: book_ids = [] if settings.get('vl'): vl_ids = self.get_current_restriction_book_ids() book_ids = list(set(vl_ids).intersection(set(book_ids))) return book_ids def validate(self, settings): gui = self.plugin_action.gui db = gui.current_db if not settings: return (_('Scope errors'), _('You must configure this scope before running it')) mi = get_metadata_object(gui) is_template_valid = check_template(settings['template'], self.plugin_action, print_error=False) if is_template_valid is not True: return is_template_valid return True def config_widget(self): return TemplateScopeConfigWidget
Edit2: The custom single field edit action posted previously will no longer work with this new version. Edit3: Also the third option in Basic Scopes: "Act on books in that have values in Book Vars" is not at all user friendly and not descriptive enough. If anyone have better alternative? Last edited by capink; 04-03-2021 at 06:17 AM. Reason: remove attached zip. version released. |
|
![]() |
![]() |
Advert | |
|
![]() |
#471 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,636
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
|
![]() |
![]() |
![]() |
#472 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
But, I did look. For the confirmation, it will do whatever you have configured. But, I'm surprised that I didn't have an option for that. The other option missing is to calculate the various statistics, return them but not update the columns. It wasn't something requested at the time, but, I could see a use for this. |
|
![]() |
![]() |
![]() |
#473 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,012
Karma: 500000
Join Date: Jun 2015
Device: Rocketbook, kobo aura h2o, kobo forma, kobo libra color
|
I run multiple count pages on small batches of books all the time. Very occasionally I get race condition where the count pages initial dialog box gets lost and won't go away, but that's the only issue I've seen. This problem might be worse if you run a separate count pages for each book, all in parallel.
I'd be tempted to select all the uncounted books and run a single count pages job, except that occasionally some large book gets stuck and never finishes, and then all the counts in that job before it are lost. |
![]() |
![]() |
![]() |
#474 | |||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
I would then for action conditions:
The scoping stuff works as I expect. I changed my sample "Average Ratings" chain to use the scope "Act on all books", deleting the selection modifiers. It worked, was fast, and didn't mess with the selection in the library view. I couldn't test some things because of the chain_vars exception. Regarding: Quote:
![]() Regarding Quote:
|
|||
![]() |
![]() |
![]() |
#475 | |||||||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
Quote:
Quote:
Quote:
The button dialog was added not for the buttons, but for setting global options for the plugin. I had one in a transitional version that I removed, but I decided to keep the dialog for future use. If this is confusing, I can hide it until I need it. Quote:
I like your idea of clikcing on icons triggering the appropriate dialogs, but there are two problems with this:
Quote:
Quote:
![]() |
|||||||
![]() |
![]() |
![]() |
#476 | ||
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
Code:
TemplateDialog.accept(self) Code:
QDialog.accept(self) |
||
![]() |
![]() |
![]() |
#477 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
IIRC TemplateDialog.reject(self) was problematic because it also closes the parent dialog (which is the chains dialog when the template dialog is a conditions dialog). That is why I implemented reject in the first place. I will call self.save_geometry() from both, unless I shouldn't for some reason.
|
![]() |
![]() |
![]() |
#478 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
|
|
![]() |
![]() |
![]() |
#479 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Ok, will call TemplateDialog.accept() only.
|
![]() |
![]() |
![]() |
#480 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
I had it happen again. It seems to happen only when a chain is being defined. Once the chain is defined and saved it stops. I also restarted calibre in the middle of that but I don't think that changed the behavior.
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[Editor Plugin] Editor Chains | capink | Plugins | 106 | 06-17-2025 05:36 PM |
Action Chains Resources | capink | Plugins | 77 | 06-16-2025 12:45 PM |
[GUI Plugin] Noosfere_util, a companion plugin to noosfere DB | lrpirlet | Plugins | 2 | 08-18-2022 03:15 PM |
[GUI Plugin] Save Virtual Libraries To Column (GUI) | chaley | Plugins | 14 | 04-04-2021 05:25 AM |