![]() |
#361 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
Code:
program: all_authors = category_items('authors'); res = ''; for a in '&' all_authors: ratings = from_search('rating', strcat('rating:true and author"=', a, '"')); if ratings then avg = divide(mean(ratings), 2); res = list_union(res, strcat(a, ':', avg), ',') fi rof; res Last edited by capink; 02-23-2021 at 04:24 AM. |
|
![]() |
![]() |
![]() |
#362 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
for a in authors separator '&': Code:
for a in authors separator if something then '&' else ',' fi: |
|
![]() |
![]() |
![]() |
#363 | ||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
Code:
program: book_ids = from_selection('id'); all_authors = category_items('authors',book_ids); res = ''; for a in all_authors separator '&': ratings = from_search('rating', strcat('rating:true and author:"=', a, '"')); if ratings then avg = divide(mean(ratings), 2); res = list_union(res, strcat(a, ':', avg), ',') fi rof; res Quote:
![]() |
||
![]() |
![]() |
![]() |
#364 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Also turns out subitems() automatically removes duplicates anyway. So this works fine to get the top level genres:
Code:
program: genres = category_items('#genre'); subitems(genres, 0, 1) |
![]() |
![]() |
![]() |
#365 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,974
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Question: In View Manager, I have a view called "On Device." I use a one-action chain and Event Manager to switch to it when the device plug in.
Is it possible to make a condition to make it not run if the view is already set to On Device? Thank you! Last edited by ownedbycats; 02-23-2021 at 05:07 PM. |
![]() |
![]() |
![]() |
#366 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
You will need a custom template function to check for that. Taking a quick look at the view manager code, this can be easily done using this template:
Code:
from calibre_plugins.action_chains.templates import TemplateFunction class ViewManagerLastVIew(TemplateFunction): name = 'view_manager_last_view' arg_count = 0 def evaluate(self, formatter, kwargs, mi, locals): import calibre_plugins.view_manager.config as cfg gui = self.plugin_action.gui library_config = cfg.get_library_config(gui.current_db) return library_config.get(cfg.KEY_LAST_VIEW, '') Code:
Template : program: view_manager_last_view() Datatype : text Comparison : != Condition Value : On Device In the mean time, you can test the above to see whether it works. |
![]() |
![]() |
![]() |
#367 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,974
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
A while ago I did some experimenting and found that adding the condition to the actions rather than the chain itself doesn't result in error. This is clumsy though, and doesn't work if you want to use other conditions for the specific actions.
But it works well enough for a single-action chain, and the code above worked. ![]() Last edited by ownedbycats; 02-24-2021 at 03:25 AM. |
![]() |
![]() |
![]() |
#368 |
Member
![]() Posts: 13
Karma: 10
Join Date: Apr 2013
Device: lots of, frequently changing
|
Edit metadata in bulk with preset
Hello, what a great plugin, I have lots of very convenient chains.
Is it possible to call the calibre action "Edit metadata in bulk" with preset to "Change cover: Set from e-book files" and directly execute this? I think this should work with a module, but I have no idea how to start here. Any hints are highly appreciated, thanks. |
![]() |
![]() |
![]() |
#369 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
You can try the following code (copy/past into the module editor):
Code:
from calibre.ebooks.metadata.meta import metadata_from_formats from calibre_plugins.action_chains.actions.base import ChainAction class CoverFromBook(ChainAction): name = 'Cover from book' support_scopes = True def run(self, gui, settings, chain): db = gui.current_db.new_api book_ids = chain.scope().get_book_ids() for book_id in book_ids: fmts = db.formats(book_id, verify_formats=False) paths = list(filter(None, [db.format_abspath(book_id, fmt) for fmt in fmts])) mi = metadata_from_formats(paths) if mi.cover_data: cdata = mi.cover_data[-1] if cdata is not None: db.set_cover({book_id: cdata}) Last edited by capink; 07-16-2021 at 03:41 AM. |
![]() |
![]() |
![]() |
#370 |
Member
![]() Posts: 13
Karma: 10
Join Date: Apr 2013
Device: lots of, frequently changing
|
![]() |
![]() |
![]() |
![]() |
#371 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,974
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Did program: connected_device_name('main') get changed? This condition always shows up as true even with nothing plugged in:
EDIT: I just noticed the addition of the new option. ![]() |
![]() |
![]() |
![]() |
#372 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Some conditions slowed down the menu loading (e.g selection_count() when thousands of books are selected), so I made disabling menu entries based on conditions optional in version 0.6.5.
|
![]() |
![]() |
![]() |
#373 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,012
Karma: 500000
Join Date: Jun 2015
Device: Rocketbook, kobo aura h2o, kobo forma, kobo libra color
|
Would it be faster / possible to have a function that returned selection count as 0, 1, or many? That might be a better fit for determining if a menu entry should be enabled or not.
|
![]() |
![]() |
![]() |
#374 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
You can already do that by using the selection_count() function which returns the exact number of selected books, and combine that with the comparison operators (= | != | > |<) in the condition evaluator dialog. (see attached screenshot)
Having a function that returns the selection count as 0, 1, or many will not improve performance as it still needs to make the same call that takes time when a lot of books are selected: Code:
len(gui.current_view().selectionModel().selectedRows()) |
![]() |
![]() |
![]() |
#375 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,974
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I have this code:
Code:
{ "active": true, "chain_settings": { "chain_links": [ { "action_name": "Single Field Edit", "action_settings": { "col_name": "#kobocoll", "template": "program:\n\tg = field('#genres');\n\tk = field('#kobocoll');\n\tif list_contains(g, ',', '^Fanfiction$', '1', '') then\n\t\tk = list_union(k, 'Fanfiction', ',')\n\tfi;\n\tif list_contains(g, ',', '^Cozy Mystery$', '1', '') then\n\t\tk = list_union(k, 'Cozy Mysteries', ',')\n\tfi;\n\tif list_contains(g, ',', '^Horses$', '1', '') then\n\t\tk = list_union(k, 'Horses', ',')\n\tfi;\n\tif list_contains(g, ',', '^(Fantasy|Science Fiction)$', '1', '') then\n\t\tk = list_union(k, 'Fantasy & Sci-Fi', ',')\n\tfi;\n\tk", "value_type": "template" }, "comment": "Update #kobocoll column" }, { "action_name": "Calibre Actions", "action_settings": { "disable_busy_cursor": false, "selection": [ { "display": "Send to device", "path": [ "Send To Device" ] } ] }, "comment": "Send to device if device is connected", "condition_settings": { "cmp_type": "=", "datatype": "text", "template": "program: connected_device_name('main')", "value": "Kobo Aura HD" } }, { "action_name": "Calibre Actions", "action_settings": { "disable_busy_cursor": false, "selection": [ { "display": "Add to list: Send to Device", "path": [ "Reading List", "Add to list", "Add to list: Send to Device" ], "paths_text": "Add to list|Add to list: Send to Device" } ] }, "comment": "Add to \"Send to Device\" list if device is not connected", "condition_settings": { "cmp_type": "=", "datatype": "text", "template": "program: connected_device_name('main')", "value": "" } }, { "action_name": "Single Field Edit", "action_settings": { "col_name": "#onkobo", "template": "program:\n\tif and(\tcheck_yes_no('#onkobo', '', '', 1),) then \t'False' \n\telse 'True'\n\tfi", "value_type": "template" }, "comment": "Set #onkobo column" } ], "refresh_gui": true }, "image": "sync.png", "menuText": "Send to Device", "subMenu": "" }, Any idea why? Last edited by ownedbycats; 03-13-2021 at 06:59 PM. |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |