Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 04-29-2023, 10:07 AM   #1096
ownedbycats
Custom User Title
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: 10,981
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That fixed it.

I must've accidentally deleted it while removing the reverted column-name tweak. (That explains why updating to 6.17 seemed to break it.)

Last edited by ownedbycats; 04-29-2023 at 01:02 PM.
ownedbycats is offline   Reply With Quote
Old 05-09-2023, 12:15 PM   #1097
ownedbycats
Custom User Title
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: 10,981
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Would it be possible to make a module that replicates the behaviour of the 'paste' button in the identifiers field?
ownedbycats is offline   Reply With Quote
Old 05-10-2023, 05:18 AM   #1098
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
Would it be possible to make a module that replicates the behaviour of the 'paste' button in the identifiers field?
I don't understand. What is special about identifiers paste that would make you want to create a module?
capink is offline   Reply With Quote
Old 05-10-2023, 07:05 AM   #1099
ownedbycats
Custom User Title
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: 10,981
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
The 'paste' button will convert the URL to an id if there's a rule for it. (The tooltip only mentions isbn and url but that's a mistake.) This would let me copy the link of a goodreads or fantasticfiction page from browser and then paste it without opening the MDE.

Last edited by ownedbycats; 05-10-2023 at 07:33 AM.
ownedbycats is offline   Reply With Quote
Old 05-11-2023, 07:47 AM   #1100
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
That is not something I would be interested in.
capink is offline   Reply With Quote
Old 05-11-2023, 08:15 AM   #1101
chaley
Grand Sorcerer
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: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
The 'paste' button will convert the URL to an id if there's a rule for it. (The tooltip only mentions isbn and url but that's a mistake.) This would let me copy the link of a goodreads or fantasticfiction page from browser and then paste it without opening the MDE.
Here is a python template that contains a copy of the base calibre code the the MDE uses. It returns the ID:VAL pair for a URL in the clipboard, if possible. You should be able to use it in a Copy to Clipboard action.
Code:
python:


def parse_clipboard_for_identifier():
    from calibre.ebooks.metadata.sources.prefs import msprefs
    from calibre.utils.formatter import EvalFormatter
	from qt.core import QApplication
	import re
    text = str(QApplication.clipboard().text()).strip()
    if not text:
        return None

    rules = msprefs['id_link_rules']
    if rules:
        formatter = EvalFormatter()
        vals = {'id' : '__ID_REGEX_PLACEHOLDER__'}
        for key in rules.keys():
            rule = rules[key]
            for name, template in rule:
                try:
                    url_pattern = formatter.safe_format(template, vals, '', vals)
                    url_pattern = re.escape(url_pattern).replace('__ID_REGEX_PLACEHOLDER__', '(?P<new_id>.+)')
                    if url_pattern.startswith('http:') or url_pattern.startswith('https:'):
                        url_pattern = '(?:http|https):' + url_pattern.partition(':')[2]
                    new_id = re.compile(url_pattern)
                    new_id = new_id.search(text).group('new_id')
                    if new_id:
                        vals = {}
                        vals[key] = new_id
                        return vals
                except Exception:
                    import traceback
                    traceback.print_exc()
                    continue

    from calibre.customize.ui import all_metadata_plugins

    for plugin in all_metadata_plugins():
        try:
            identifier = plugin.id_from_url(text)
            if identifier:
                vals = {}
                vals[identifier[0]] = identifier[1]
                return vals
        except Exception:
            pass

    return None

def evaluate(book, context):
	x = parse_clipboard_for_identifier()
	if x:
		return ', '.join(k + ':' + v for k,v in x.items())
	return ''
chaley is offline   Reply With Quote
Old 05-11-2023, 10:51 AM   #1102
ownedbycats
Custom User Title
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: 10,981
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Thanks. Copies to clipboard works

Is there a way to pass the clipboard contents to a SFE? I was thinking maybe a chain variable. Or maybe I can just add the template itself to the variable.

EDIT: To add directly, I put the template in a variable called copied_id and then used this:

Code:
program:

newid = globals(copied_id);

list_union(newid, $identifiers, ',')

Last edited by ownedbycats; 05-11-2023 at 10:58 AM.
ownedbycats is offline   Reply With Quote
Old 05-11-2023, 10:55 AM   #1103
chaley
Grand Sorcerer
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: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Is there a way to pass the clipboard contents to a SFE? I was thinking maybe a chain variable. Or maybe I can just add the template itself to the variable.
The template produces a string. You can do whatever you want with it.

EDIT: or are you asking if you can get the actual clipboard contents? Yes. This line in the template does that.
Code:
text = str(QApplication.clipboard().text()).strip()
You could store this template to use in other templates:
Code:
python:
def evaluate(book, context):
	from qt.core import QApplication
	return str(QApplication.clipboard().text()).strip()

Last edited by chaley; 05-11-2023 at 11:02 AM.
chaley is offline   Reply With Quote
Old 05-24-2023, 10:07 AM   #1104
dragoworld235
Enthusiast
dragoworld235 began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Oct 2012
Device: kobo libra 2
Hi, is there a way to use a chain as an action in another chain?
I’m trying to use composition instead of having to rewrite every actions when creating specific chains.

An example.
I’m using custom column for the #type of ebook (book, manga… it can take more than one value, and an imported file is set to none), its #origin (bought, given), its #source (what store…), if I’ve #done cleaning it.
I’ve got a chain "1" for setting the #type to "book" (removing "none" and adding "book").
A chain "2" to set to a specific bookstore: set #origin to "bought" and #source to "7switch".
A chain "3" to set #done to true.
When working on a batch of books (for example re-importing all my bought books from the 7switch store), I would like to create a chain "4" that is just a composition of "1", then "2", then "3".

Is there already a way to do that that I’ve missed?
Thanks a lot for all the work.
dragoworld235 is offline   Reply With Quote
Old 05-24-2023, 11:34 AM   #1105
ownedbycats
Custom User Title
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: 10,981
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Calibre Preferences > Tweaks > Plugin Tweaks. Add action_chains_experimental = True

This will enable a 'Chain Caller' action which lets you run another chain.

Click image for larger version

Name:	2023-05-24 12_36_19-Window.png
Views:	918
Size:	40.3 KB
ID:	201665

It's a little slow as there's checks for recursion to prevent it getting stuck in an endless loop.

Note: While doesn't seem to be the case here, this may be useful later on: if the reason for using chain-caller is to avoid duplication of templates used for Single-Field Edits, you can use a stored template (Calibre Preferences > Template Functions > Stored Template tab).

As it skips the recursion check, using a stored template in the SFE is faster than using chain-caller on a single-action chain used to hold the template:

Click image for larger version

Name:	2023-05-24 13_45_12-calibre - Preferences - Template functions.png
Views:	911
Size:	48.8 KB
ID:	201667

Click image for larger version

Name:	2023-05-24 13_44_18-Window.png
Views:	933
Size:	29.4 KB
ID:	201668

Last edited by ownedbycats; 05-24-2023 at 02:20 PM. Reason: Add info on stored templates
ownedbycats is offline   Reply With Quote
Old 05-26-2023, 03:54 AM   #1106
dragoworld235
Enthusiast
dragoworld235 began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Oct 2012
Device: kobo libra 2
Thanks, that’s exactly what I was looking for.
The slowness of the recursion checking is not a problem for me, but it’s nice to know there is a workaround if needed.

While doing some tests, I’ve noticed the chains are identified by there title, so changing it is removing its shorcut association, or breaking the Chain caller action. Not a problem for me because I won’t be renaming chains now.

Have a good day everyone.
dragoworld235 is offline   Reply With Quote
Old 05-26-2023, 05:09 AM   #1107
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
The recursion check does not cause any delay at all. It does not even take 0.01 of a second. This is simply a wrong impression.
capink is offline   Reply With Quote
Old 06-03-2023, 04:47 AM   #1108
ownedbycats
Custom User Title
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: 10,981
Karma: 75337983
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
SFE: On taglikes, does 'predefined value' overwrite column contents, or adds it as a new entry?
ownedbycats is offline   Reply With Quote
Old 06-03-2023, 05:04 AM   #1109
Philantrop
Addict
Philantrop does all things with Zen-like beautyPhilantrop does all things with Zen-like beautyPhilantrop does all things with Zen-like beautyPhilantrop does all things with Zen-like beautyPhilantrop does all things with Zen-like beautyPhilantrop does all things with Zen-like beautyPhilantrop does all things with Zen-like beautyPhilantrop does all things with Zen-like beautyPhilantrop does all things with Zen-like beautyPhilantrop does all things with Zen-like beautyPhilantrop does all things with Zen-like beauty
 
Philantrop's Avatar
 
Posts: 296
Karma: 32153
Join Date: Dec 2008
Device: Kindles (e-ink)
AttributeError using 1.18.7 in Calibre 6.19.1, action type "Calibre Actions"

Using version 1.18.7 I get an error when I try to add or modify an action type "Calibre Actions" and try calling its settings:

Code:
calibre, version 6.19.1
ERROR: Unhandled exception: <b>AttributeError</b>:'int' object has no attribute 'replace'

calibre 6.19.1  embedded-python: True
Linux-6.3.3-200.fc38.x86_64-x86_64-with-glibc2.37 Linux ('64bit', 'ELF')
('Linux', '6.3.3-200.fc38.x86_64', '#1 SMP PREEMPT_DYNAMIC Wed May 17 14:31:24 UTC 2023')
Python 3.10.1
Interface language: en_GB
Successfully initialized third party plugins: [...]

Traceback (most recent call last):
  File "calibre_plugins.action_chains.gui.__init__", line 46, in setup_ui
    self.widget = self.widget_cls(self.plugin_action, self.chain_name, self.chains_config)
TypeError: CalibreActionsWidget.__init__() takes 2 positional arguments but 4 were given

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "calibre_plugins.action_chains.gui.views", line 430, in _on_button_clicked
    d = SettingsWidgetDialog(name, self, self.plugin_action, config_widget, action, m.chain_name, m.chains_config, title)
  File "calibre_plugins.action_chains.gui.__init__", line 41, in __init__
    Dialog.__init__(self, title, name, parent)
  File "calibre/gui2/widgets2.py", line 225, in __init__
  File "calibre_plugins.action_chains.gui.__init__", line 51, in setup_ui
    self.widget = self.widget_cls(self.plugin_action)
  File "calibre_plugins.action_chains.actions.calibre_actions", line 162, in __init__
    self._init_controls()
  File "calibre_plugins.action_chains.actions.calibre_actions", line 197, in _init_controls
    self._populate_actions_tree(lookup_menu_map)
  File "calibre_plugins.action_chains.actions.calibre_actions", line 287, in _populate_actions_tree
    self._populate_action_children(QMenu.actions(m), tl,
  File "calibre_plugins.action_chains.actions.calibre_actions", line 307, in _populate_action_children
    text = get_title(ac, plugin_name)
  File "calibre_plugins.action_chains.actions.calibre_actions", line 74, in get_title
    safe_title = get_safe_title(action)
  File "calibre_plugins.action_chains.actions.calibre_actions", line 68, in get_safe_title
    return text.replace('&&', '—').replace('&', '').replace('—', '&')
AttributeError: 'int' object has no attribute 'replace'
Philantrop is offline   Reply With Quote
Old 06-03-2023, 05:54 AM   #1110
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,196
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
SFE: On taglikes, does 'predefined value' overwrite column contents, or adds it as a new entry?
It overwrites. If you want to add, use templates as we already discussed previously. This entry is already in the misc tips section in the first post.
capink is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 10:36 PM.


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