Work in Progress - XBMCstubs re-worked (code auto-completion and quick help for Python IDEs)

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Roman_V_M Offline
Fan
Posts: 548
Joined: Jun 2011
Reputation: 14
Location: Kyiv, Ukraine
Post: #1
Started to learn how to create XBMC Python addons, I came across xbmcstubs project and started using it. Then I've decided to update it with the most recent information from the latest XBMC Python docs and my personal experience.

What is this and why do you need it?

XBMC stubs are literally Python module stubs which mimic XBMC Python API modules. They contain most (hopefully, all) classes, methods, functions and constants declarations with docstrings, and minimal code not to raise syntax errors.
If you using some Python IDE (Eclipse+Pydev, Python Tools for Visual Studio, PyScripter etc.), you can add those modules to Python import paths of your current XBMC addon project, and you will get code auto-completion and quick help that greatly facilitates writing addon code and reduces the number of errors.

Where to add these stub modules in my IDE?

Eclipse+PyDev: right-click on an XBMC addon project, then "Properties" > "PYTHONPATH" > "External Libraries" > "Add source folder".
Python Tools for Visual Studio: you need to add the folder with stub .py files to "Search Paths" of your PTVS project.
PyCharm (thanks to jerimiah797 for the info and a screenshot): Open the project folder in PyCharm. Select Settings, then click 'Project Structure' under Project Settings. Then click '+ Add Content Root', browse to where you have put the folder containing the stub files, and select the folder. Then click 'Apply', and then 'Okay'.

Below are the example screenshots from popular Python IDEs:

Eclipse + PyDev:

[Image: qoy1.th.jpg]

Python Tools for Visual Studio 2012:

[Image: 70pf.th.jpg]

PyCharm:

[Image: hksg.jpg]

I'm also proud to note that those stub modules include the most up-to-date info about XBMC Python modules with some details taken directly from C++ source code, because original docstrings include incorrect info in some cases.

You can find the latest XBMC Python stub modules in my Github repo.
The documentation for XBMC Python API auto-generated from xbmcstubs docstrings: http://romanvm.github.io/xbmcstubs/docs

However, there is some work to do, so any comments, corrections, and pull requests are welcomed.

Warning: those stub modules do not include any useful code so don't try to run/debug your addon directly from IDE, unless you add some debug code to them. They are meant only to help writing addon code.

AMD A4-3300 + AsRock A75M-ITX
XBMC-DSplayer 13.1 (custom build) on Windows 7
(This post was last modified: 2014-02-20 12:29 by Roman_V_M.)
find quote
Roman_V_M Offline
Fan
Posts: 548
Joined: Jun 2011
Reputation: 14
Location: Kyiv, Ukraine
Post: #2
I've also added documentation for XBMC Python modules auto-generated from XBMCstubs docstrings: http://romanvm.github.io/xbmcstubs/docs
This is the most up to date XBMC Python documentation, because, frankly speaking, official documentation pages are far from perfect (and Gotham docs are really messy at some places).
Any comments or corrections are welcomed Smile

AMD A4-3300 + AsRock A75M-ITX
XBMC-DSplayer 13.1 (custom build) on Windows 7
(This post was last modified: 2013-09-27 08:57 by Roman_V_M.)
find quote
jerimiah797 Offline
Member
Posts: 61
Joined: Mar 2011
Reputation: 2
Post: #3
This looks awesome! I can't wait to try it out. Do you know if there's anything similar for the domain-specific xml that xbmc uses?
find quote
Roman_V_M Offline
Fan
Posts: 548
Joined: Jun 2011
Reputation: 14
Location: Kyiv, Ukraine
Post: #4
(2013-09-25 03:08)jerimiah797 Wrote:  Do you know if there's anything similar for the domain-specific xml that xbmc uses?

You mean auto-completion for XBMC skin files? I doubt such thing exists. With Python it's relatively simple due to full code introspection.

AMD A4-3300 + AsRock A75M-ITX
XBMC-DSplayer 13.1 (custom build) on Windows 7
find quote
jerimiah797 Offline
Member
Posts: 61
Joined: Mar 2011
Reputation: 2
Post: #5
Yeah, I've only worked with xml in the context of xbmc files so i dont know that much about it. I'm wondering if there's an editor that supports some kind of xml dictionary so it can autocomplete only the tags that xbmc recognizes and flag tags that aren't in the 'dictionary'.
find quote
Dhorse Offline
Junior Member
Posts: 30
Joined: Nov 2012
Reputation: 0
Post: #6
Could you tell me how i would add this to VS2012? I am still pretty new to this.
find quote
Roman_V_M Offline
Fan
Posts: 548
Joined: Jun 2011
Reputation: 14
Location: Kyiv, Ukraine
Post: #7
(2013-09-27 17:21)Dhorse Wrote:  Could you tell me how i would add this to VS2012? I am still pretty new to this.

I guess by "VS2012" you really mean Python Tools for Visual Studio. You need to download a ZIP from Gighub, unpack it to a folder of your convenience and add the folder with stub .py files to "Search Paths" of your PTVS project.
See the example below:

[Image: 70pf.th.jpg]

AMD A4-3300 + AsRock A75M-ITX
XBMC-DSplayer 13.1 (custom build) on Windows 7
find quote
Martijn Offline
Team Kodi
Posts: 11,209
Joined: Jul 2011
Reputation: 162
Location: Dawn of time
Post: #8
can i ask if you found docstrings that needed fixing in xbmc source code?
because you stated:
Quote:because original docstrings include incorrect info in some cases.

if yes can we perhaps expect a PR to fix these?

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
(This post was last modified: 2013-09-27 20:27 by Martijn.)
find quote
Roman_V_M Offline
Fan
Posts: 548
Joined: Jun 2011
Reputation: 14
Location: Kyiv, Ukraine
Post: #9
(2013-09-27 20:25)Martijn Wrote:  can i ask if you found docstrings that needed fixing in xbmc source code?
because you stated:
Quote:because original docstrings include incorrect info in some cases.

if yes can we perhaps expect a PR to fix these?

I'm afraid, PR is not possible because the C++ files in question are not present on Github and are auto-generated during compilation. Those are:
\xbmc\interfaces\python\generated\
AddonModuleXbmc.cpp
AddonModuleXbmcaddon.cpp
AddonModuleXbmcgui.cpp
AddonModuleXbmcplugin.cpp
AddonModuleXbmcvfs.cpp

Also I need to note that to say that my C++ knowledge is very basic will be a great exaggeration.Smile

AMD A4-3300 + AsRock A75M-ITX
XBMC-DSplayer 13.1 (custom build) on Windows 7
find quote
Martijn Offline
Team Kodi
Posts: 11,209
Joined: Jul 2011
Reputation: 162
Location: Dawn of time
Post: #10
They are generated from the files located here:
https://github.com/xbmc/xbmc/blob/master...es/legacy/

example:
https://github.com/xbmc/xbmc/blob/master...rol.h#L417
https://github.com/xbmc/xbmc/blob/master...Xbmc.h#L41

If you grep through those files finding the "wrong" text you will end up on the file containing that text.

Edit:
already started on some a while ago. need to finish it
https://github.com/xbmc/xbmc/pull/3187

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
(This post was last modified: 2013-09-27 21:14 by Martijn.)
find quote
Roman_V_M Offline
Fan
Posts: 548
Joined: Jun 2011
Reputation: 14
Location: Kyiv, Ukraine
Post: #11
2 Martijn

Thanks for the explanation, I'll see what I can do.

P. S. Added some screenshots to the OP.

AMD A4-3300 + AsRock A75M-ITX
XBMC-DSplayer 13.1 (custom build) on Windows 7
find quote
Martijn Offline
Team Kodi
Posts: 11,209
Joined: Jul 2011
Reputation: 162
Location: Dawn of time
Post: #12
(2013-09-28 15:24)Roman_V_M Wrote:  2 Martijn

Thanks for the explanation, I'll see what I can do.

P. S. Added some screenshots to the OP.

Thanks. Will appreciate it Smile

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
find quote
jerimiah797 Offline
Member
Posts: 61
Joined: Mar 2011
Reputation: 2
Post: #13
I've tried out the stubs and they work in PyCharm, too. Here's how to install (per project, not globally)

Open the project folder in PyCharm. Select Settings, then click 'Project Structure' under Project Settings. Then click '+ Add Content Root', browse to where you have put the folder containing the stub files, and select the folder. The stubs folder can be anywhere on your machine, it doesn't have to be in your project (skin, addon, script, whatever) folder. Then click 'Apply', and then 'Okay'.

Thanks so much for this, Roman!!!! It's really saves a lot of time pouring over the pydocs and figuring out which methods can be used in a given context.

-Jerimiah

PS I'm working on the XML helper code and have made some progress defining the default xml namespace and associated tags and rules for an xbmc compliant window file. There are currently several methods to do this and I'm experimenting to find out the best way that doesn't confuse xbmc when it loads the xml files. So far, some methods don't work. I'll keep you posted.
find quote
Roman_V_M Offline
Fan
Posts: 548
Joined: Jun 2011
Reputation: 14
Location: Kyiv, Ukraine
Post: #14
2 jerimiah797

Thanks for the info. Could you also provide an example screenshot like the ones in the OP? I will update the OP with your info.

BTW, I've changed docstrings structure in xbmcgui module to provide better tooltips.

AMD A4-3300 + AsRock A75M-ITX
XBMC-DSplayer 13.1 (custom build) on Windows 7
find quote
jerimiah797 Offline
Member
Posts: 61
Joined: Mar 2011
Reputation: 2
Post: #15
Here you go!

-Jerimiah

[Image: t1gdr7v.png]
find quote
Post Reply