Kodi Community Forum

Full Version: Beginner's GUI Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, new to forums but long time XBMC user. My Python is ok but I am struggling to get my head around the xbmcgui API. Trawling google has lead me to write the following (very simple) test script:

Code:
import xbmcaddon, xbmc, xbmcgui

def addMenuItem(caption, link, icon=None, thumbnail=None, folder=False):
    listItem = xbmcgui.ListItem(unicode(caption), iconImage=icon, thumbnailImage=thumbnail)
    listItem.setInfo(type="Video", infoLabels={ "Title": caption })
    return xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=link, listitem=listItem, isFolder=folder)

def endListing():
    xbmcplugin.endOfDirectory(int(sys.argv[1]))

addMenuItem('TestCaption','/')
endListing()

I was hoping this would bring up a menu screen with one option 'TestCaption' (obviously going nowhere at this stage) .

When I select my addon, I get a script failure - any help appreciated.[/code]
the xbmc.log file will tell you exactly what's wrong:
- TypeError: argument "iconImage" for method "XBMCAddon::xbmcgui::ListItem" must be unicode or str
- TypeError: argument "thumbnailImage" for method "XBMCAddon::xbmcgui::ListItem" must be unicode or str
- NameError: global name 'xbmcplugin' is not defined
xbmc.log... of course there is! that is all kinds of useful - thankyou very much!

just to make sure I'm on the right track, picking up instructions from the command lines (.arg[whatever]) and then referring to 'mode' as I've seen elsewhere, feels a little hacky. Is that the recommended way? I'm working my way through the API docs but like examples and many seem to go down this route....
If you don't want to go the ugly way, have a look to xbmcswift.
Have a look to any of my add-ons (see my github account) and the xbmcswift website: www.xbmcswift.com
Ha, yeah I'd rather avoid the ugly! xbmcswift looks cool - thanks for the link, I'll have a play around.