![]() |
#166 | |
null operator (he/him)
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 21,725
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Quote:
OBC could use the AHK or PTFB utility to send Shift/F2 when he/she presses some other key sequence. BR |
|
![]() |
![]() |
![]() |
#167 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,974
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
I've been looking into AHK/Pulover's Macro Creator to automate some non-Calibre tasks anyways. I might be able to do something with that.
|
![]() |
![]() |
![]() |
#168 |
Hedge Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 802
Karma: 19999999
Join Date: May 2011
Location: UK/Philippines
Device: Kobo Touch, Nook Simple
|
Good luck. I played with that program some time ago. I even managed to produce some working macros. I found it was not the easiest of programs to master.
|
![]() |
![]() |
![]() |
#169 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
|
|
![]() |
![]() |
![]() |
#170 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Thanks. Should be useful.
|
![]() |
![]() |
![]() |
#171 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Help on the chain variables action
The Chain Variables action enables the user to set variables to the chain, to be utilized in multiple ways like marking books or using them in conditional execution of actions. The user can set constant variables, or can set dynamic variables using Calibre's template. When setting dynamic variables using templates, only General Program Mode is supported. i.e templates starting with program.
In addition to user variables, the plugin offers some predefined variables that can be used by the user when setting dynamic variables. These Variables include:
The location values are: library, main, card and cardb. The value depends in which library/device view you are currently in. The selection count is the number of books currently selected in books view. The _chain_iteration can be used in conjunction with _chain_name, to prevent clashes with variables set by previous runs of the same chain. The chain variables action, like other actions, can be used multiple times during the lifetime of the chain to either set new variables, or re-set previously set variable to new values. All the variables, can be accessed in templates, by using the globals function like the example below Code:
program: n = globals(_chain_name); i = globals(_chain_iteration); strcat(n, '_', i)
Last edited by capink; 01-14-2022 at 12:59 PM. |
![]() |
![]() |
![]() |
#172 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Help on the Conditions Dialog
The Conditions Dialog can be used to set conditions on chains or actions. If these conditions are not met, the action/chain will not run. Conditions are made possible by leveraging the powerful yet simple calibre template language. For more on templates, visit this link.
The best way to understand conditions is through examples. Let's say you want your chain to run only if a certain device is connected to calibre. To do this, use the condition dialog to define the following: Code:
template = program: connected_device_name('main') datatype = text comparison = "=" condition value = your device name In addition to the usual template functions that can be used to test a variety of conditions (e.g. current_library_name, connected_device_name .... etc), the action chains plugin define some extra template functions that can be used as well. For example, Action Chains defines a function selection_count(), which returns the number of books currently selected in books view. So if the user wants a chain to be enabled only when one books is selected the, he can do it like this: Code:
template = program: selection_count() datatype = number comparison = "=" condition value = 1 The condition dialog available for both chains/actions, can be applied simultaneously to multiple chains/actions. N.B Variables defined by the user through Chain vars action, can be accessed by using the globals() template function. These also can be used in testing conditions. For more on this see this post. Notes:
Last edited by capink; 03-23-2025 at 10:36 PM. |
![]() |
![]() |
![]() |
#173 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
EDIT: A modified version of this action is available as a builtin action in the action chains plugin starting from version 1.4.0. The builtin action is called "Search Using Templates".
This is a custom action that allows constructing a calibre search using calibre template editor. The search can be a simple text search or a search constructed from a template. Code:
# python3 compatibility from six import text_type as unicode from calibre import prints from calibre.constants import DEBUG from calibre.gui2 import error_dialog from calibre.ebooks.metadata.book.formatter import SafeFormat from calibre_plugins.action_chains.actions.base import ChainAction from calibre_plugins.action_chains.database import is_search_valid from calibre_plugins.action_chains.templates import check_template, get_metadata_object from calibre_plugins.action_chains.templates.dialogs import TemplateBox try: load_translations() except NameError: prints("ActionsChain::action/search.py - exception when loading translations") class TemplateSearchWidget(TemplateBox): def __init__(self, parent, plugin_action, action, name, title): self.plugin_action = plugin_action self.action = action self.gui = plugin_action.gui self.db = self.gui.current_db mi = get_metadata_object(self.gui) TemplateBox.__init__( self, parent, plugin_action, template_text='', placeholder_text=_('Enter a search expression here. It can be either ' 'an ordinary text string or a template.'), mi=mi ) self.setWindowTitle(title) def textbox_changed(self): TemplateBox.textbox_changed(self) template = self.template_value.text() text = SafeFormat().safe_format(template, self.mi, 'Exception: ', self.mi, template_functions=self.plugin_action.template_functions) if text: ok = is_search_valid(self.db, text) and not text.lower().startswith('exception:') ss = 'QLineEdit { border: 2px solid %s; border-radius: 3px }' % ( '#50c878' if ok else '#FF2400') self.template_value.setStyleSheet(ss) else: self.template_value.setStyleSheet('') def load_settings(self, settings): if settings: template = settings['template'] self.textbox.insertPlainText(template) def save_settings(self): settings = {} settings['template'] = unicode(self.textbox.toPlainText()).rstrip() return settings def accept(self): self.settings = self.save_settings() # validate settings is_valid = self.action.validate(self.settings) if is_valid is not True: msg, details = is_valid error_dialog( self, msg, details, show=True ) return TemplateBox.accept(self) class TemplateSearchAction(ChainAction): name = 'Template Search' def run(self, gui, settings, chain): template = settings['template'] template_output = chain.evaluate_template(template, book_id=None) gui.search.clear() gui.search.set_search_string(template_output) def validate(self, settings): gui = self.plugin_action.gui db = gui.current_db if not settings: return (_('Settings Error'), _('You must configure this action 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 search_text = SafeFormat().safe_format(settings['template'], mi, 'Exception: ', mi, template_functions=self.plugin_action.template_functions) if not is_search_valid(db, search_text): return (_('Settings Error'), _('Search ({}) is not valid'.format(search_text))) return True def config_widget(self): return TemplateSearchWidget Last edited by capink; 04-25-2021 at 06:18 AM. |
![]() |
![]() |
![]() |
#174 |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Version 0.3.99
This version only works with the latest calibre version as it makes use of the new "globals" template function. The main change in this version is that it enables setting conditions that determines whether a chain, or an action inside a chain, is going to run. The conditions are set using calibre's template language. Simple examples are illustrated below on how to do this. This version does change the config file of the plugin to accommodate a change made to Calibre Actions, so you are advised to backup the "Actions Chains.json" file in your plugin folder, just in case. Also the order and width of columns in the add actions dialog will be reset. Special thanks for @chaley, as most of these features where ideas of his. He was also generous enough to add a new template function that made these new features possible. ![]() @ownedbycats: This version addresses some problems you were having with the plugin.
@compurandom: See the examples above for conditional execution of chains. The exact dialog is available for single actions as well. Also, a new chains variables action is available, where you can set chain variables, either as constant values, or values calculated by templates. You have some predefined variables that you can access from a template using the new globals function. For example if you want to mark books after each action, you can use this template: Code:
program: c = globals(_chain_name); i = globals(_chain_iteration); a = globals(_action_name); i2 = globals(_action_index); strcat(c, '_', i, '_', a, '_', i2) At the end of your chain, you can show all books marked by this chain, by using a custom action that constructs a search from templates. In the settings of this custom action, use this template to show all books marked by the chain: Code:
program: c = globals(_chain_name); i = globals(_chain_iteration); strcat('marked:"', c, '_', i, '"') You can define your own values using the Chains Variables actions, or if you writing custom action and want to define your own variables, you can use this in your code: Code:
chain.set_chain_vars({'myvar': 'myval'}) Also, there is the ability to support book specific variables (see the example above about containing_folder). To to this, you add this to your custom action: Code:
chain.set_book_vars(book_id, {'bookvar': 'bookval'}) Code:
template_result = chain.evaluate_template('your template code', book_id) Last edited by capink; 05-05-2021 at 09:30 AM. |
![]() |
![]() |
![]() |
#175 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,974
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Thank you, and happy holidays!
Another use for the new conditions: I added the same "is device connected?" template to add a new action to my send-to-device chain. If the device is connected, it'll send the book directly there. Though it'll still appear on the list until I figure out the "if device is not connected" template. EDIT: I kinda worked around this by setting up a "sync lists if device is connected" action. Clumsy but it works. Last edited by ownedbycats; 12-24-2020 at 03:16 PM. |
![]() |
![]() |
![]() |
#176 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,631
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
Quote:
Pdta: I see that you're adding it to the list (so manual sync). The sync with reading list is automatic. Sorry for the misunderstanding. |
|
![]() |
![]() |
![]() |
#177 | |
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
|
Quote:
I don't use devices in calibre, so my knowledge is not very deep. But, the plugin does define a variable called location, I believe the following template can be used as a condition that makes sure no device is attached: Code:
template = program: globals(location) datatype = text comparison = "=" condition value = library Edit: Also the icon I chose for conditions does not work well the dark mode, will look for a better one. Last edited by capink; 12-24-2020 at 04:59 PM. |
|
![]() |
![]() |
![]() |
#178 | |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,974
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
globals(location) = library didn't work (I think this actually determines whether you're in 'library' or 'device' view) but setting the device to an arbitrary non-valid value did work.
![]() Quote:
Last edited by ownedbycats; 12-24-2020 at 05:12 PM. |
|
![]() |
![]() |
![]() |
#179 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,631
Karma: 12595249
Join Date: Jun 2009
Location: Madrid, Spain
Device: Kobo Clara/Aura One/Forma,XiaoMI 5, iPad, Huawei MediaPad, YotaPhone 2
|
|
![]() |
![]() |
![]() |
#180 |
Custom User Title
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 10,974
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
|
Another thing to report: The "condition" icon has very low contrast on the dark background. On #2 and #4, it's difficult to see, and #3 and #5 I actually can't see at all unless the line's selected. If it's possible to change UI elements for dark mode, inverting it to white ought to do the trick.
|
![]() |
![]() |
![]() |
|
![]() |
||||
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 |