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 04-11-2021, 07:54 AM   #511
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.
 
chaley's Avatar
 
Posts: 9,836
Karma: 3190480
Join Date: Jan 2010
Location: UK
Device: Reader
@capink: what do you think about a template function
Code:
is_book_var_defined('var_name')
that returns '1' or ''.

The function would get around the ambiguity between a defined book_var that contains '' and an undefined book_var. Something like this:
Code:
	if is_book_var_defined('foo') then
		result = book_vars('foo')
	else
		result = field('whatever')
	fi;
	result
chaley is offline   Reply With Quote
Old 04-11-2021, 08:08 AM   #512
capink
Evangelist
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: 499
Karma: 47410
Join Date: Aug 2015
Device: Kindle
Yes, I can see the use for this. Will add to the next release.
capink is online now   Reply With Quote
Advert
Old 04-11-2021, 08:25 AM   #513
capink
Evangelist
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: 499
Karma: 47410
Join Date: Aug 2015
Device: Kindle
On a second thought, wouldn't a defined_book_vars() that returns a list of defined vars for book cover more ground? We can test for the above using:

Code:
str_in_list(defined_book_vars(), ',', 'var_name', 1, '')
capink is online now   Reply With Quote
Old 04-11-2021, 08:45 AM   #514
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.
 
chaley's Avatar
 
Posts: 9,836
Karma: 3190480
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by capink View Post
On a second thought, wouldn't a defined_book_vars() that returns a list of defined vars for book cover more ground? We can test for the above using:

Code:
str_in_list(defined_book_vars(), ',', 'var_name', 1, '')
Not sure.

On the plus side: in addition to checking for individual book vars, your suggestion has the advantage of being able to ask about more than one variable at once, as in
Code:
list_contains(defined_book_vars(), ',', '^(var_name1|var_name2)$', 1, '')
or check for prefixes
Code:
list_contains(defined_book_vars(), ',', '^var_name.*$', 1, '')
However, it is a bit more complicated to use in the simple case.

I think I lean in the same direction you do: the generality is better. And anyway, if someone really wants to use the original suggestion then they can do it with a stored template.
Code:
program:
	arguments(var_name);
	if str_in_list(defined_book_vars(), ',', 'var_name', 1, '') then
		'1'
	else
		''
	fi
PS: I am thinking about adding "return" to the template language, which would allow the above template to be written
Code:
program:
	arguments(var_name);
	if str_in_list(defined_book_vars(), ',', 'var_name', 1, '') then
		return('1')
	else
		return('')
	fi
chaley is offline   Reply With Quote
Old 04-11-2021, 08:50 AM   #515
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.
 
chaley's Avatar
 
Posts: 9,836
Karma: 3190480
Join Date: Jan 2010
Location: UK
Device: Reader
Another topic: while playing with actions today I noticed that some of the template dialogs, for example the Template Scope one, have extra fields related to stored templates, specifically the template name and the documentation. I am changing TemplateDialog to permit you to hide them.

With the changed TemplateDialog I tested this in Action Chains.templates.py and it works. Starting at line 404:
Code:
        TemplateDialog.__init__(self,
                                parent,
                                text,
                                mi=mi,
                                text_is_placeholder=text_is_placeholder,
                                all_functions=self.all_functions,
                                builtin_functions=builtin_functions,
                                global_vars=global_vars)
        self.setup_saved_template_editor(show_buttonbox=not dialog_is_st_editor,
                                         show_doc_and_name=False)
I will let you know when the changes are in calibre source.
chaley is offline   Reply With Quote
Advert
Old 04-11-2021, 09:14 AM   #516
capink
Evangelist
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: 499
Karma: 47410
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
PS: I am thinking about adding "return" to the template language, which would allow the above template to be written
That would be useful addition.

Quote:
Originally Posted by chaley View Post
On the plus side: in addition to checking for individual book vars, your suggestion has the advantage of being able to ask about more than one variable at once, as in
This is what I had in mind when thinking about this. The prefix thing is another good use for this.

Quote:
Originally Posted by chaley View Post
Another topic: while playing with actions today I noticed that some of the template dialogs, for example the Template Scope one, have extra fields related to stored templates, specifically the template name and the documentation. I am changing TemplateDialog to permit you to hide them.

With the changed TemplateDialog I tested this in Action Chains.templates.py and it works. Starting at line 404:
Code:
        TemplateDialog.__init__(self,
                                parent,
                                text,
                                mi=mi,
                                text_is_placeholder=text_is_placeholder,
                                all_functions=self.all_functions,
                                builtin_functions=builtin_functions,
                                global_vars=global_vars)
        self.setup_saved_template_editor(show_buttonbox=not dialog_is_st_editor,
                                         show_doc_and_name=False)
I will let you know when the changes are in calibre source.
Yes, would make it a lot better and less confusing. Will be waiting for the changes.
capink is online now   Reply With Quote
Old 04-11-2021, 12:11 PM   #517
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.
 
chaley's Avatar
 
Posts: 9,836
Karma: 3190480
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by capink View Post
Yes, would make it a lot better and less confusing. Will be waiting for the changes.
The changes are in calibre source.

I also changed the dialog layout a lot. Let me know if you see anything wrong/strange.
chaley is offline   Reply With Quote
Old 04-11-2021, 01:14 PM   #518
capink
Evangelist
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: 499
Karma: 47410
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
The changes are in calibre source.

I also changed the dialog layout a lot. Let me know if you see anything wrong/strange.
It is working great.
Attached Thumbnails
Click image for larger version

Name:	1.png
Views:	35
Size:	92.5 KB
ID:	186544  
capink is online now   Reply With Quote
Old 04-11-2021, 03:21 PM   #519
Terisa de morgan
Grand Sorcerer
Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.Terisa de morgan ought to be getting tired of karma fortunes by now.
 
Terisa de morgan's Avatar
 
Posts: 5,663
Karma: 5860861
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
Thank you both of you, I'll try to make it work tomorrow, and I'll be back with my misadventures for sure
Terisa de morgan is offline   Reply With Quote
Old 04-11-2021, 08:07 PM   #520
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.
 
ownedbycats's Avatar
 
Posts: 2,635
Karma: 11430576
Join Date: Oct 2018
Device: Kobo Aura HD
I found a tyop!
Attached Thumbnails
Click image for larger version

Name:	2021-04-11 20_59_28-Scope settings.png
Views:	31
Size:	16.4 KB
ID:	186552  
ownedbycats is offline   Reply With Quote
Old 04-13-2021, 11:59 AM   #521
capink
Evangelist
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: 499
Karma: 47410
Join Date: Aug 2015
Device: Kindle
Version 1.7.0
  • Update: Add persistent storage for templates. Can be accessed using these new template functions: persistent_vars(), set_persistent_vars(), list_persistent_vars(), delete_persistent_vars(), list_persistent_namespaces(), delete_persistent_namespaces()
  • Update: Copy To Clipboard: Add option to write to a file.
  • Update: Chain Variables: Add option to ask for variables at runtime.
  • Update: Library View Double Clicked: tweak to allow single click edit (action_chains_single_click_edit).
  • Update: Add a tweak to allow disabling submenu inheriting first action icon (action_chains_default_sub_menu_icon).
  • Update: Update the way table state is saved to avoid messing it up every-time a new column is added.
  • Update: Add options to customize scope icon and tooltip.
  • Update: Add new template function: list_book_vars()

The new persistent storage allows template functions to save data permanently. Here is how you can save a variable to persistent storage:

Code:
set_persistent_vars('name', 'value')
It also supports namespace hierarchies as well for more flexible structure. For example if you want to save the same variable name but with a different value for each library, use the third argument as the namespace:

Code:
set_persistent_vars('name', 'value', current_library_name())
If you want to store permanent book vars (the same variable with different value per book per library), use a hierarchical namespace (in the form of library_name.book_id):

Code:
ns = strcat(current_library_name(), '.', field(id));
set_persistent_vars('name', 'value', ns)
You retrieve the value in the same way

Code:
ns = strcat(current_library_name(), '.', field(id));
persistent_vars('name', ns)
@ownedbycats: The new file option in the Copy To Clipboard action might solve your problems with command line limit if the program you are using supports reading filenames from a file. You can output you data to a file using Copy To Clipboard, and feed the file to the Open With action using the template option.

Finally, the action_chains_single_click_edit tweak makes it possible still edit by single clicking, which you lose when you set the tweak (in case you want to connect the double click event to a chain):

Code:
doubleclick_on_library_view = 'do_nothing'
Unfortunately, there is bug there where it also open the field editor when double clicking as well. I don't know the cause for this, so if anyone can help with this.
capink is online now   Reply With Quote
Old 04-13-2021, 02:20 PM   #522
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.
 
chaley's Avatar
 
Posts: 9,836
Karma: 3190480
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by capink View Post
Finally, the action_chains_single_click_edit tweak makes it possible still edit by single clicking, which you lose when you set the tweak (in case you want to connect the double click event to a chain):

Code:
doubleclick_on_library_view = 'do_nothing'
Unfortunately, there is bug there where it also open the field editor when double clicking as well. I don't know the cause for this, so if anyone can help with this.
I don't see this behavior. I set the calibre tweak
Code:
doubleclick_on_library_view = 'do_nothing'
I then set the plugin tweak
Code:
action_chains_single_click_edit = True
A single click in the library view edits the cell. A double click in the library view runs the action. Isn't this what is supposed to happen?
chaley is offline   Reply With Quote
Old 04-13-2021, 02:25 PM   #523
capink
Evangelist
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: 499
Karma: 47410
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
A single click in the library view edits the cell. A double click in the library view runs the action. Isn't this what is supposed to happen?
Yes, that is what supposed to happen. Have you tried double clicking on an already selected book? It does not happen when you double click on book that is not selected.
capink is online now   Reply With Quote
Old 04-13-2021, 05:32 PM   #524
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.
 
chaley's Avatar
 
Posts: 9,836
Karma: 3190480
Join Date: Jan 2010
Location: UK
Device: Reader
Quote:
Originally Posted by capink View Post
Yes, that is what supposed to happen. Have you tried double clicking on an already selected book? It does not happen when you double click on book that is not selected.
Yes. For example:
  1. Select a book by single-clicking on a cell such as title. The line turns blue. No editor opens. No action runs.
  2. Single-click on a cell on that line, for example authors. The editor opens.
  3. Double-click on a cell, for example authors. The action runs.
Inverting the order of the last two steps doesn't change anything.
chaley is offline   Reply With Quote
Old 04-13-2021, 06:32 PM   #525
capink
Evangelist
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: 499
Karma: 47410
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
Yes. For example:
  1. Select a book by single-clicking on a cell such as title. The line turns blue. No editor opens. No action runs.
  2. Single-click on a cell on that line, for example authors. The editor opens.
  3. Double-click on a cell, for example authors. The action runs.
Inverting the order of the last two steps doesn't change anything.
When I reach number 3, the action runs and the cell opens for editing.

After more testing, it seems to be chain dependent. When I tested with some chains that contain only one action, it behaved normally. The chain I was initially testing with (attached below) has two conditional actions and it always triggers the abnormal behavior.

This might suggest that the problem is somewhere in my code? Not really sure. Will investigate more and see if I get to the bottom of this.

Edit: After testing some more, I think I found the culprit. The chain loop makes this call between actions:

Code:
QApplication.processEvents()
If I comment this out, the problem does not happen anymore. I don't know calling processEvents() leads to this?
Attached Files
File Type: zip on_double_click.zip (594 Bytes, 12 views)

Last edited by capink; 04-13-2021 at 06:44 PM.
capink is online now   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] Save Virtual Libraries To Column (GUI) chaley Plugins 14 04-04-2021 05:25 AM
[GUI Plugin] KindleUnpack - The Plugin DiapDealer Plugins 468 02-07-2021 04:07 PM
[GUI Plugin] Manga plugin mastertea Plugins 0 10-20-2019 02:45 PM
[GUI Plugin] Wordpress frescogamba Plugins 11 04-06-2015 09:09 PM
[GUI Plugin] Plugin Updater **Deprecated** kiwidude Plugins 159 06-19-2011 12:27 PM


All times are GMT -4. The time now is 10:03 AM.


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