View Single Post
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: 183
Karma: 3587000
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