Release Example minimal plugin
#1
Here's an idea I just had: to jumpstart plugin development, a complete "working" almost minimal plugin, with a single setting to show how that works.

Would it be worthwhile to include something like this in the development wiki? Maybe at least some code comments could be added, and maybe it could really play something - the video file would then need to be hosted reliably somewhere.

https://github.com/viljoviitanen/plugin.minimal.example

code and graphics of the example plugin are in public domain.
Reply
#2
"locale.setlocale(locale.LC_ALL, 'C')" why? That doesnt seem very 'minimal'. Also you don't need to give the id in Addon()
Reply
#3
(2013-09-16, 13:39)takoi Wrote: "locale.setlocale(locale.LC_ALL, 'C')" why? That doesnt seem very 'minimal'. Also you don't need to give the id in Addon()

Setlocale was there because some python routines are dependant on the locale, especially date parsing failed if locale was non-english, and xbmc did in in the past pass on the user locale from environment. So as I used Ubuntu in Finnish, my plugin did not work for me. That seems to be fixed now - even though on the command line my locale is fi_FI.UTF_8, in xbmc python it's empty so that can be safely removed.

Also, I did not realize you can call Addon() without parameters, and it's not mentioned in the api documentation either! http://mirrors.xbmc.org/docs/python-docs...addon.html

Anyway I fixed both issues, thanks.
Reply
#4
id in xbmcaddon.Addon(id='script.recentlyadded') is optional, if omitted its using its own id.

this can be useful if you are trying to get settings for some other addon installed.
Reply
#5
Well I'd sure like to see the automatic class documentation fixed Smile https://github.com/xbmc/xbmc/pull/3281
Reply
#6
I would suggest respecting the official Python Styleguide (PEP8) when doing an example Plugin - or at least any consistent usage of style.

PHP Code:
import xbmcguixbmcpluginxbmcaddon

addon 
xbmcaddon.Addon();

username=addon.getSetting('username')
if 
username=='':
  
username='nobody'

item xbmcgui.ListItem('Hello, '+username

Should be:
PHP Code:
import xbmcgui
import xbmcplugin
import xbmcaddon


addon 
xbmcaddon.Addon()

username addon.getSetting('username')
if 
not username:
    
username 'nobody'

item xbmcgui.ListItem('Hello, ' username

Style Errors:
- no semicolon at line end
- space before and after equal sign (of assignment and comparison)
- don't compare to empty string, use "not" statement
- space before and after plus sign
- use 4 spaces for indentation
- every import in a single line

In total: 7 errors in 6 not empty lines...

And (imo) even better would be even:
PHP Code:
import xbmcgui
import xbmcplugin
import xbmcaddon


addon 
xbmcaddon.Addon()

username addon.getSetting('username') or 'nobody'

item xbmcgui.ListItem('Hello, %s' username

Improvements:
- Use "or" statement
- Don't concat strings (they are immutable)
My GitHub. My Add-ons:
Image
Reply
#7
(2013-09-16, 21:17)viljoviitanen Wrote: Well I'd sure like to see the automatic class documentation fixed Smile https://github.com/xbmc/xbmc/pull/3281

proper fix
https://github.com/xbmc/xbmc/commit/28ea...193c314492
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#8
(2013-09-17, 12:43)sphere Wrote: Improvements:
- Use "or" statement
- Don't concat strings (they are immutable)

Can I put your suggestions in with the public domain/unlicense licensed example plugin?

(Me, I just look at api documentation code hopefully working things, I didn't even know there was an official style guide for python...)
Reply
#9
(2013-09-17, 19:51)viljoviitanen Wrote: Can I put your suggestions in with the public domain/unlicense licensed example plugin?

Of course!
And don't get my comment wrong: I appreciate your idea.
My GitHub. My Add-ons:
Image
Reply
#10
(2013-09-17, 20:38)sphere Wrote: Of course!
And don't get my comment wrong: I appreciate your idea.

I didn't, no problem. I updated the plugin at github, thanks.
Reply
#11
I'll call this a release and changed the thread tag. Hopefully it will be useful to someone.
Reply

Logout Mark Read Team Forum Stats Members Help
Example minimal plugin0