WIP Newbie: addon to manually configure network
#1
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:

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
Reply
#2
ControlTextBox doesn't have a "setLabel"-method but "setText" - maybe this is the reason for the error you get?
I quickly executed your code and didn't saw any error.
My GitHub. My Add-ons:
Image
Reply
#3
I get different results on different platforms. On my 64-bit Fedora 16, I get script errors. On my 32-bit Fedora 16 I can enter and exit my addon a few times but eventually XBMC crashes. Removing the text control prevents the crashes.

I switched out the text box with a button. This has potential but the inactive state of the button (focus not applied) makes the button invisible: black button on black background. I'm guessing I'll need to add some kind of background texture in order to see the button outline when not in focus.

Another thing: retrieving the window width/height with self.getWidth() and self.getHeight() kind of works, but if I try to use these values to compute the sizes and positions of the window widgets I get script errors or crashes. Currently I'm guessing this is due to my misunderstanding of how python variables can be manipulated (I'm assuming python is type-less). Sadly window fonts are not as easily scaled. This is how I use these methods:

Code:
# Compute window sections and sizes
    width = self.getWidth();
    height = self.getHeight();
    strw = "Width: " + str(width);
    strh = "Height: " + str(height);
    self.width = xbmcgui.ControlLabel(100, 160, 100, 50, strw)
    self.addControl(self.width)
    self.height = xbmcgui.ControlLabel(100, 200, 100, 50, strh)
    self.addControl(self.height)

    lcolx = (width/2 - (width/2*.4)) / 2
    rcolx = width/2 + lcolx
    str1x = "lcolx: " + str(lcolx);
    str2x = "rcolx: " + str(rcolx);
    self.lcolx = xbmcgui.ControlLabel(100, 240, 100, 50, str1x)
    self.addControl(self.lcolx)
    self.rcolx = xbmcgui.ControlLabel(100, 300, 100, 50, str2x)
    self.addControl(self.rcolx)
Reply
#4
i would use a window.xml and the edit control. my example wouldn't work as is with current xbmc, but if you want to look at it i can pass you a copy.

this would work better only if your controls don't need to be dynamically added or you have a finite amount of controls.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#5
That's actually what I'll have: static window widgets and only a few of them. At least for now. Complex network configurations may be added later, but initially it will be fairly simple. The typical use case is a home user utilizing a wifi router or a wired connection.

So, yes, I'd love to see your example even if its not working. It might provide some insight on what to research to make it work.

Thanks!
Reply
#6
http://xbmc-addons.googlecode.com/svn/pa...editor.zip

there are two files in the zip. the xml file would go in a resources/skins/skinname/720p folder or your skins 720p folder. but it should give you an idea.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#7
Thanks for the sample code. It's a bit bigger than a hello world, but it's well structured and commented which helps a lot.

I'll be digging through it over the next week to see what I can come up with.

Thanks again.
Reply

Logout Mark Read Team Forum Stats Members Help
Newbie: addon to manually configure network0