Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 02-23-2021, 05:18 AM   #361
capink
Addict
capink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipedia
 
Posts: 352
Karma: 47240
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
@capink: specifying a separator in a for statement and the function list_remove_duplicates(l, sep) are now available in master source.
Thanks for both. I don't seem to know how to use the new for loop. I am trying to modify your previous template to this:

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
Obviously I am doing something wrong (and probably silly) here.

Last edited by capink; 02-23-2021 at 05:24 AM.
capink is offline   Reply With Quote
Old 02-23-2021, 05:27 AM   #362
chaley
Grumpy old git
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 9,566
Karma: 3125998
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by capink View Post
Thanks for both. I don't seem to know how to use the new for loop. I am trying to modify your previous template to this:
The syntax is
Code:
	for a in authors separator '&':
I used the keyword 'separator' to remove some ambiguity in the language parser. Note that the 'thing' following the keyword is an arbitrary expression. You can do something like this, admittedly a bit strange:
Code:
	for a in authors separator if something then '&' else ',' fi:
chaley is offline   Reply With Quote
Old 02-23-2021, 06:33 AM   #363
capink
Addict
capink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipedia
 
Posts: 352
Karma: 47240
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
[/CODE]I used the keyword 'separator' to remove some ambiguity in the language parser.
That makes senese. It is now working for me.

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
Using all authors without restricting them using from_search() or from_selection() on large libraries is not recommended as it is verrrrrrry slow.

Quote:
Originally Posted by chaley View Post
Note that the 'thing' following the keyword is an arbitrary expression.
Wow. I will sure come up with a use for that sometime in the future.
capink is offline   Reply With Quote
Old 02-23-2021, 08:54 AM   #364
capink
Addict
capink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipedia
 
Posts: 352
Karma: 47240
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)
capink is offline   Reply With Quote
Old 02-23-2021, 05:58 PM   #365
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
Posts: 1,909
Karma: 9610948
Join Date: Oct 2018
Device: Kobo 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 06:07 PM.
ownedbycats is offline   Reply With Quote
Old 02-24-2021, 04:16 AM   #366
capink
Addict
capink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipediacapink knows more than wikipedia
 
Posts: 352
Karma: 47240
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, '')
Copy/Paste the above code into the module manager. Now you can use this function in a condition as follows:

Code:
Template        : program: view_manager_last_view()
Datatype        : text
Comparison      : !=
Condition Value : On Device
However, your request uncovers another problem. When the conditions are not met, an error dialog will pop-up. This might not be suitable for events. I can turn this off for events and let it fail silently, or add an option in the conditions dialog to make the error dialog optional. Will think about it to see which of these two options is more suitable, and then add it later.

In the mean time, you can test the above to see whether it works.
capink is offline   Reply With Quote
Old 02-24-2021, 04:21 AM   #367
ownedbycats
Wizard
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
Posts: 1,909
Karma: 9610948
Join Date: Oct 2018
Device: Kobo 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 04:25 AM.
ownedbycats is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[GUI Plugin] KindleUnpack - The Plugin DiapDealer Plugins 468 02-07-2021 05:07 PM
[GUI Plugin] Save Virtual Libraries To Column (GUI) chaley Plugins 12 12-27-2020 02:31 PM
[GUI Plugin] Manga plugin mastertea Plugins 0 10-20-2019 03:45 PM
[GUI Plugin] Wordpress frescogamba Plugins 11 04-06-2015 10:09 PM
[GUI Plugin] Plugin Updater **Deprecated** kiwidude Plugins 159 06-19-2011 01:27 PM


All times are GMT -4. The time now is 02:20 PM.


MobileRead.com is a privately owned, operated and funded community.