Embed plugin inside script - Printable Version
+- XBMC Community Forum (http://forum.xbmc.org)
+-- Forum: Development (/forumdisplay.php?fid=32)
+--- Forum: Python Add-on Development (/forumdisplay.php?fid=26)
+--- Thread: Embed plugin inside script (/showthread.php?tid=130978)
Pages: 1 2
Embed plugin inside script - bossanova808 - 2012-05-08 05:22
With my Add-on:XSqueeze, I have a need to embed a plugin.
Well, put better, I want to embed a plugin (for choosing music for playback inside XSqueeze), so that I can use the simple XBMC plugin structure and thus get views, lists etc. 'for free' without implementing all this stuff in a WindowXML which seems like a lot more work...
Is it possible to put a plugin inside a script at all? I.e. instantiate one directly in the script...such that one has access to the script AND plugin code at once, if you see what I mean.
Obviously one can call the plugin like any other, but then I have no access to the script's scope/classes, and would like if possible to reduce code duplication as I have a need for a lot of the stuff in the main addon when I call the script.
Hopefully this is clear enough & makes sense...basically, I need an easy way of building lists (of names with pictures) and getting the selections, which then trigger actions on an external server program...this seems pretty easy to do in a plugin as the list stuff is all taken care of...or is there a really easy way to do such a list with WindowXML I am missing - my early experiements have not been successful, I can get items to show, but only the focussed item at any one time, and one doesn't get the standard views etc.
Advice very much appreciated!!
RE: Embed plugin inside script - Bstrdsmkr - 2012-05-08 05:44
I think it's pretty much assumed that if you're creating your own window that you want full control. With using the plugin methods, you're giving up 99% of the control of the look and feel to the skin.
You can only pass strings between instances of scripts or plugins. If you can't do it any other way, you can pickle the object in one instance, pass the resulting string to the next instance and unpickle it there.
That being said, if you could clarify exactly what you need to do that you can't do from an addon, maybe we can find a way around it
RE: Embed plugin inside script - bossanova808 - 2012-05-08 05:49
Well, it's not so much not being able to do what I want, just that it's much more bang for buck for this particular purpose using a plugin. This is a separate bit to the main addon that simply supplies lists (e.g). New Music, Albums, Artists, etc, then as you go into the list actual album names or whatever) - the user chooses something and a messages is sent to the external to XBMC server to start playback...
So basically the easy-listing with all the skin views you get for free via a plugin is what I need, but I ideally want to hang on to my server connection class, player class, etc., to reduce code duplication.
Is there an easy way in an addon to get that plugin like structure going on, is the question, really? I have tried manually creating a list but this involves a WindowXML, skin file etc. etc, which seems more work than just doing it in a plugin structure.
If I pickle the objects and pass them from the addon to the plugin, then they are in full scope at the plugin side?? I guess that would work, but I presume pickling is the sort of thing that is a bit platform specific and may create issues (like, e.g. POpen())
RE: Embed plugin inside script - Bstrdsmkr - 2012-05-08 06:44
pickle is cross platform and generally pretty gremlin free. Obviously the object that comes out the other side isn't the same so setting it to a new value won't affect the original, but it'll give you a pretty decent approximation. The only thing is you have to make sure any name spaces used by the original are already imported before you unpickle on the other side.
I admit I'm still no clear about what exactly you're doing (don't have a squeezebox) so this may or may not apply, but hopefully it'll give you an idea at least. An addon can include a service that runs without the actual addon having been launched. I use this for a "subscription" service that periodically creates new .strm files when new content is posted to a website. Here's the addon.xml for a combined service and traditional addon: https://github.com/bstrdsmkr/1Channel/blob/master/1Channel/addon.xml
If that's not what you're after, and you want to preserve a bunch of framework code, you can include it in a script module and require that from both addons.
RE: Embed plugin inside script - bossanova808 - 2012-05-08 06:53
I've read up a bit on pickle and it doesn't seem like passing a network connection in a pickled object will work (the connection to squeezeserver is basically via telnet of all things!!) - certainly in Python3+ they seem to be against it even if it might currently work.
>> If that's not what you're after, and you want to preserve a bunch of framework code, you can include it in a script module and require that from both addons.
Yeah that seems like the more sensible option really. It's not a lot of code and it's probably best to do it that way.
(I don't think a service helps me here but thanks for tha idea too!)
RE: Embed plugin inside script - bossanova808 - 2012-05-08 07:32
Yeah after some thinking that should work, I just need to ifgure out how to get the settings of the script from within the plugin so they don't have to configure twice...
RE: Embed plugin inside script - spiff - 2012-05-08 08:19
You can instance xbmc.Addon for any id...
RE: Embed plugin inside script - Bstrdsmkr - 2012-05-08 09:02
...and then call get_settings() from that instance =)
RE: Embed plugin inside script - bossanova808 - 2012-05-08 12:48
Yeah for future searchers this is what you do:
(and thanks for the help!!)
RE: Embed plugin inside script - bossanova808 - 2012-05-09 04:34
Ok - another question - I am trying to pass arguments to the plugin called from my addon. This is to force it always to start in 'mode 0' at the root menu.
To do this I am using this code:
..however, this breaks the 'magic' bit where I get the int handle to the plugin...
thisPlugin = int(sys.argv)
...makes sens because the arguments have changed I guess, but I can no longer find a way to get this magic handle in the plugin (and there seems to be no other way to force the plugin to always start at the root node)