![]() |
#271 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
It is not a problem for template actions because it does not result in errors if the column is missing, as you indicated.
But the validation is done by calling the validate method of each action, which will return false if custom column is not present. e.g. single field edit, search and replace ... etc validate methods check whether the column(s) is present. Anyway, changing the check_chain() to only validate if the conditions are true is not a big deal. |
![]() |
![]() |
![]() |
#272 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Assuming I understand you, in this case you will need to use capink's proposed solution. Reason: the Single Field Edit action specifies the destination field. If that destination doesn't exist then the action will fail regardless of what the template does or doesn't do. The action condition must check for the existence of the destination to prevent the action from running.
|
![]() |
![]() |
Advert | |
|
![]() |
#273 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
Code:
template: program: if field_exists('#somefield') then 'true' fi datatype: text comparison: = Condition value = true |
|
![]() |
![]() |
![]() |
#274 |
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
|
Thank you very much! I'll wait for your changes in the plugin and chaley's in calibre.
|
![]() |
![]() |
![]() |
#275 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
You can test the version in the second post using the current_library_name condition until the changes made by chaley are released.
|
![]() |
![]() |
Advert | |
|
![]() |
#276 | |
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
|
Quote:
![]() |
|
![]() |
![]() |
![]() |
#277 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
new version released
Version 0.6.3
Version 0.6.4
The latest version has a change that is not compatible with previous versions. If you have chain/action conditions that check the selection count using the globals(selection_count) function, you have to change that to use the newly introduced selection_count() template function. This new template function only works with the action chains plugin. I will correct all previous posts the reference globals(selection_count) to reflect the new change. The problem is with the old approach is that it used to pre-calculate the selection count before running every chain and every action, in case there is a template asking for the selection count. The process of calculating the selection count can be expensive if you have a lot of rows selected, which slows down things, often unnecessarily when there are no templates asking for the selection count. With the new template function, the selection count is only calculated on demand. Also caching is used whenever possible. e.g. checking all chain conditions happens before showing the menu; to disable items with conditions that evaluate to false. Since selections are not going to change when the menu is being shown, the first time the function is called, it caches the value to be re-used when checking subsequent chains, an flushes the cache after the menu is shown. Likewise, globals(containing_folder) is replaced by containing_folder(). The globals() function is reserved for variables set by the user using the Chain Variables action, or set programmatically (by custom actions) using chain_tools.set_chain_vars() and chain_tools.set_book_vars(). Last edited by capink; 01-19-2021 at 10:49 AM. |
![]() |
![]() |
![]() |
#278 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,000
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Would the pre-calculation be why there was sometimes a little lag when I clicked on the AC menu?
|
![]() |
![]() |
![]() |
#279 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
If you have conditions (for chains) actually testing for selection count, you are not going to see much of difference as far as lag, because the old approach also made sure to calculate once when pressing the menu.
The new approach will make difference for people who do not use chain conditions with selection_count. It will also shorten the time between actions because the pre-calculation had to be repeated ahead of each action, regardless of action conditions. Edit: Also you will notice the lag is proportionate to how many rows are selected when you press the menu. Edit2: The lag comes from testing chain conditions before showing menu items. It is usually less than a second. Having a huge number of rows selected can make it longer, for people who have conditions using the selection_count(). Last edited by capink; 01-19-2021 at 01:58 PM. |
![]() |
![]() |
![]() |
#280 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,000
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I have two chains checking the connected device and one using selection count. The lag usually occurs the first time I click after launching Calibre, lasts one or two seconds depending on how many rows are selected. Maybe it's checking the device status too?
|
![]() |
![]() |
![]() |
#281 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Could be. Never used device checking before. The best way to know is to test with and without the condition and see the difference.
Maybe the solution to this is to make disabling menu items based on chains conditions optional? and if conditions are not met when the user opted not to grey out menu item and presses it, pop up an error message? |
![]() |
![]() |
![]() |
#282 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 11,000
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
It's not that big a problem to begin with, really. I think it is related to the device check though as I notice the momentary lag returns after I plug in my Kobo.
|
![]() |
![]() |
![]() |
#283 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
@capink: looking through your code where you use the template dialog I note that in one case case you reimplement the part that calls the formatter, and in another case you more-or-less reimplement the dialog.
Case 1 is templates.py/TemplateBox. It seems that you were forced to reimplement textbox_changed so you could call safe_format with your new functions. To avoid that I could add two parameters to init Code:
all_functions=None, builtin_functions=None Case 2 is ConditionsEval, which reimplements the entire dialog. I think you were forced to this for the same reason as case 1, and because you wanted to add the widgets for datatype, comparison, condition value, icon, and tooltip. To get around adding the widgets I could add several empty label/QBoxLayout pairs to the base TemplateDialog that are normally invisible, named user_label_N and user_layout_N where N is 1-6. You would use these to add your own fields to TemplateDialog. This would both get rid of a lot of the semi-duplicated code and add the template reference. If this interests you then I could give you a copy of the necessary files. If it works out for you then I would submit my changes to Kovid. |
![]() |
![]() |
![]() |
#284 | ||
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
First of all, thank you so much for continuous help, it is really appreciated.
![]() Quote:
Quote:
Code:
self.user_layout = QGridLayout() self.gridLayout.addLayout(self.user_layout, row, col, 2, 1) I can already do something similar by adding to self.verticalLayout as in the attached screen. But it is at the bottom of dialog. Would be better If I have access right above the font row. Edit: After thinking about it more, I think would should stick the the first point for now, which would make the template dialog re-usable for both cases. Something does not feel right about altering the template dialog that much to accommodate the plugin. I will only be re-implementing the textbox and the template_value in the ConditionsEval. The rest I can inherit if you make the first change. Last edited by capink; 01-20-2021 at 12:18 PM. |
||
![]() |
![]() |
![]() |
#285 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
I added 6 invisible rows above the font size line. Each row is a named label and a QBoxLayout. You can add widgets to that layout (default layout direction is vertical), or you can add a nested layout to do something more complicated. I did it this way so that the labels will line up with the existing ones. Why more than 1? So you can have multiple labels. Why 6? Felt like a nice number. Here is an example, gui2.actions.show_template_tester.py. I used two of the 6 lines. The first is a label with a single QComboBox widget. The second is a label with an embedded grid layout. Spoiler:
Last edited by chaley; 01-20-2021 at 12:40 PM. Reason: Corrected name of QBoxWidget -> QBoxLayout |
|
![]() |
![]() |
![]() |
|
![]() |
||||
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 |