Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 10-07-2022, 11:17 PM   #1
jacobalbano
Junior Member
jacobalbano began at the beginning.
 
jacobalbano's Avatar
 
Posts: 5
Karma: 10
Join Date: May 2022
Device: Kobo Libra H2O
Can I put multiple plugin classes in the same package?

Is it possible to include, for example, a metadada downloader and a filetype plugin in the same package?

I currently have a filetype plugin that's designed specifically to work with one particular site. I'd like to now add a metadata downloader that works with the same site. It makes sense to me that both of these pieces of functionality would live in the same plugin, but I haven't been able to get Calibre to load multiple plugin classes from the same file.

Is there something I'm missing, or is this not possible?

Sorry if this has been answered already, I wasn't able to find anything on the forums.
jacobalbano is offline   Reply With Quote
Old 10-07-2022, 11:42 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,866
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
No, IIRC it's not possible.
kovidgoyal is offline   Reply With Quote
Advert
Old 10-08-2022, 11:32 AM   #3
Leseratte_10
Groupie
Leseratte_10 ought to be getting tired of karma fortunes by now.Leseratte_10 ought to be getting tired of karma fortunes by now.Leseratte_10 ought to be getting tired of karma fortunes by now.Leseratte_10 ought to be getting tired of karma fortunes by now.Leseratte_10 ought to be getting tired of karma fortunes by now.Leseratte_10 ought to be getting tired of karma fortunes by now.Leseratte_10 ought to be getting tired of karma fortunes by now.Leseratte_10 ought to be getting tired of karma fortunes by now.Leseratte_10 ought to be getting tired of karma fortunes by now.Leseratte_10 ought to be getting tired of karma fortunes by now.Leseratte_10 ought to be getting tired of karma fortunes by now.
 
Posts: 181
Karma: 2010542
Join Date: Sep 2021
Device: PB Era, PB InkPad 3 Pro
It's possible, but a bit tricky. I've seen it used in a couple other plugins (don't remember where), and I plan to use it for my ACSM plugin, too.

You basically just put the other plugin's __init__.py file under another file name, and then do something like this in the "main" plugin's initialize() method:

Code:
    def init_embedded_plugins(self):
        from calibre.customize.ui import _initialized_plugins
        from calibre_plugins.mynamespace.my_other_plugin_file import MyOtherPluginClass

        def init_plg(plg_type):
            for plugin in _initialized_plugins:
                if isinstance(plugin, plg_type):
                    return plugin
            
            plugin = plg_type(self.plugin_path)
            _initialized_plugins.append(plugin)
            plugin.initialize()

            return plugin

        init_plg(MyOtherPluginClass)
Basically, you're "hijacking" Calibre and just forcing that second plugin's main class into the global "_initialized_plugins" array and then calling "initialize" yourself.

I don't recommend using this for plugins that aren't closely related to eachother (as the user has no way to manage the plugins seperately then), but it does seem to work, and it's a simple way to add GUI stuff (so, an InterfacePlugin) to a FileTypePlugin or other plugins that can't have a GUI.

Though, I have not really tested this code with other plugin types.

The plugins will then *both* show up in the Calibre plugin list - you need to mess around with its "can_be_disabled", "type" and "installation_type" members to get it to work how you want it. If the user were to remove the "embedded" plugin it'll reappear after a restart (as it gets loaded from the main one again), to prevent confusion I'd make sure to name the embedded plugin something like "Extension for X plugin" to make it clear to the user that these two belong together.
Leseratte_10 is offline   Reply With Quote
Old 10-08-2022, 11:56 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,866
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
That is fragile since the details of how plugins are managed by calibre is internal and subject to arbitrary change.
kovidgoyal is offline   Reply With Quote
Old 10-08-2022, 12:24 PM   #5
jacobalbano
Junior Member
jacobalbano began at the beginning.
 
jacobalbano's Avatar
 
Posts: 5
Karma: 10
Join Date: May 2022
Device: Kobo Libra H2O
Alright, cool. I'll play around with the approach Leseratte_10 mentioned, but if it's not officially supported I might be better off just not worrying about it and just make two packages. Thanks both of you for the replies!
jacobalbano is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using wordpress_xmlrpc package in my plugin wrench100 Development 4 08-17-2018 07:17 PM
Multiple classes compatibility senhal ePub 5 11-23-2015 08:00 PM
Multi-plugin package jgoguen Development 5 05-25-2015 04:21 PM
Applying multiple classes to an element Hatgirl Kindle Formats 11 04-06-2011 02:53 PM
keeping or removing a div with multiple classes JohnsonZA Recipes 1 09-25-2010 10:33 AM


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


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