2013-03-13, 03:25
I've built a custom Raspberry Pi distro (PiBox) and cross compiled XBMC (XBMCbox) to install as an opkg. Works okay but keyboard and mouse are not working yet. That's a Q for another forum.
What I'd like to do is write an addon that will allow me to configure the network directly from XBMC's interface. Raspbmc has one, but it works with NetworkManager which my distro won't be using (and the code is rather messy, hard to follow - a comment or two would have been nice). I may try connman later, but for now I just want a simple manual configuration using wpa_supplicant or wired ethernet.
I've read through the following material:
* http://wiki.xbmc.org/index.php?title=Add-on_development
* http://wiki.xbmc.org/index.php?title=HOW..._for_XBMC
* http://wiki.xbmc.org/index.php?title=HOW...n_Scripts
* http://wiki.xbmc.org/index.php?title=Python_development
* http://wiki.xbmc.org/index.php?title=Addon_Settings
* http://code.google.com/p/xbmc-gpodder-in...oads/list
* http://xbmcswift2.readthedocs.org/en/latest/index.html
I've written a simple app based on the tutorial in HOW-TO_write_Python_Scripts_for_XBMC and was able to draw a few items on the screen. But when I try to add a text box it doesn't show up. In fact I get errors that the script failed. I'll add the code at the end of this post.
Looking at lots of example addons it looks like most don't try to do what I'm doing, which is create a form for user input. One option is to create buttons that open the virtual keyboard for text entry and then place the results in the button. I can do this, but its not as nice as, say, the Weather Underground settings window. It looks to me like the use of the programmatic interface is not as popular as the settings.xml?
My question is: what's the recommended way to add a configuration dialog to XBMC (preferrably one I can drop under the System options although Programs would be okay too) to accept user keyboard input? Use the programmatic interface to define UI components or use an xml definition? If the latter, is there a "Hello World" version out there somewhere using xml? If it would help, I'd be happy to write this with lots of comments and provide it as a reference for future addon authors trying to do something similar.
I'm a C and Java developer by trade (with lots of XML background), and have done Perl and PHP among other languages. Python is new to me but its not really the syntax that's tripping me up. It's the API. I can't quite get my head around it yet.
Any tips would be appreciated. Here is my current addon.py:
What I'd like to do is write an addon that will allow me to configure the network directly from XBMC's interface. Raspbmc has one, but it works with NetworkManager which my distro won't be using (and the code is rather messy, hard to follow - a comment or two would have been nice). I may try connman later, but for now I just want a simple manual configuration using wpa_supplicant or wired ethernet.
I've read through the following material:
* http://wiki.xbmc.org/index.php?title=Add-on_development
* http://wiki.xbmc.org/index.php?title=HOW..._for_XBMC
* http://wiki.xbmc.org/index.php?title=HOW...n_Scripts
* http://wiki.xbmc.org/index.php?title=Python_development
* http://wiki.xbmc.org/index.php?title=Addon_Settings
* http://code.google.com/p/xbmc-gpodder-in...oads/list
* http://xbmcswift2.readthedocs.org/en/latest/index.html
I've written a simple app based on the tutorial in HOW-TO_write_Python_Scripts_for_XBMC and was able to draw a few items on the screen. But when I try to add a text box it doesn't show up. In fact I get errors that the script failed. I'll add the code at the end of this post.
Looking at lots of example addons it looks like most don't try to do what I'm doing, which is create a form for user input. One option is to create buttons that open the virtual keyboard for text entry and then place the results in the button. I can do this, but its not as nice as, say, the Weather Underground settings window. It looks to me like the use of the programmatic interface is not as popular as the settings.xml?
My question is: what's the recommended way to add a configuration dialog to XBMC (preferrably one I can drop under the System options although Programs would be okay too) to accept user keyboard input? Use the programmatic interface to define UI components or use an xml definition? If the latter, is there a "Hello World" version out there somewhere using xml? If it would help, I'd be happy to write this with lots of comments and provide it as a reference for future addon authors trying to do something similar.
I'm a C and Java developer by trade (with lots of XML background), and have done Perl and PHP among other languages. Python is new to me but its not really the syntax that's tripping me up. It's the API. I can't quite get my head around it yet.
Any tips would be appreciated. Here is my current addon.py:
Code:
import xbmc
import xbmcgui
import xbmcaddon
#get actioncodes from https://github.com/xbmc/xbmc/blob/master/xbmc/guilib/Key.h
ACTION_PREVIOUS_MENU = 10
ACTION_SELECT_ITEM = 7
#
# ----------------------------------------------------------------------------------------
# UI gets called when XBMC starts this script and sets __name__ to "main"
# UI provides the user interface for this addon
# ----------------------------------------------------------------------------------------
#
class UI(xbmcgui.Window):
def __init__(self):
# SSID
self.ssidText = xbmcgui.ControlTextBox(100, 160, 600, 200)
self.addControl(self.ssidText)
self.ssidLabel = xbmcgui.ControlLabel(100, 120, 600, 200, 'SSID')
self.addControl(self.ssidLabel)
# What to do when something happens to our plugin, like the user wants to exit.
def onAction(self, action):
if action == ACTION_PREVIOUS_MENU:
self.message("Goodbye")
self.close()
if action == ACTION_SELECT_ITEM:
self.message("You selected something (with ENTER)")
# What to do when something happens to a UI component
def onControl(self, control):
if control == self.ssidText:
keyboard = xbmc.Keyboard('local')
keyboard.doModal()
if (keyboard.isConfirmed()):
self.ssidText.setLabel(keyboard.getText())
# A generic dialog box, called based on actions or control events.
def message(self, message):
dialog = xbmcgui.Dialog()
dialog.ok(" My message title", message)
# ----------------------------------------------------------------------------------------
# This is run automatically when the script starts.
# ----------------------------------------------------------------------------------------
if ( __name__ == "__main__" ):
myUI = UI()
myUI .doModal()
del myUI