SetLabel Command for ListItem in ControlList
#1
hi folks,

have tried and tried to get 3 lines (or so) to work within the script, but am having no luck....

please look at the 3 lines near the end of the script below that have "################ problem is here" commented out.

this script works with x-10 devices to control lights in my house by reading in a text file and displaying a list of the lights in the house with a lightbulb icon by the ones that are on (along with the word "on" or "off") out to the right.

i am able to cut lights on or off (and update my data which is stored in lists) by clicking an item in the list (as long as the aforementioned 3 lines are commented out).

my problem is that i want to change the "on" or "off" status (stored in label2 of the listitem) in the list when it is selected and don't know how to "update" an item in the list.  i will also update the lightbulb icon later if somebody can just help me with changing the on/off text in label2 of the listitem in the controllist.

i can post pictures of the gui and supporting files if it would help, but my problem is basically in the 3 lines mentioned earlier (these 3 lines are where i took a stab at it and failed miserably).


thanks,

buzzster



Quote:import os, xbmc, xbmcgui, string
import urllib

xbmcguidialogprogress, window as xbmcguiwindow, lock as xbmcguilock, controlimage as xbmcguicontrolimage, controllabel as xbmcguicontrollabel, controlbutton as xbmcguicontrolbutton, controlcheckmark as xbmcguicontrolcheckmark, unlock as xbmcguiunlock, controlimage as xbmcguicontrolimage, controllist as xbmcguicontrollist, dialog as xbmcguidialog

#get actioncodes from keymap.xml
action_previous_menu = 10
action_select_item = 7

root = "f:\\xbmc\\scripts\\x10\\"
websvr = "[url]http://192.168.0.150:80/xbmc";[/url]   # will eventually use this variable instead of explicit definitions below

class myclass(xbmcgui.window):
  def (self):
   
      ##   0 - 1080i      (1920x1080)
      ##   1 - 720p       (1280x720)
      ##   2 - 480p 4:3   (720x480)
      ##   3 - 480p 16:9  (720x480)
      ##   4 - ntsc 4:3   (720x480)
      ##   5 - ntsc 16:9  (720x480
      self.setcoordinateresolution(2)
 
      self.addcontrol(xbmcgui.controlimage(0,0,720,480, root + "background-x10.png"))
      self.lbltitle = xbmcgui.controlfadelabel(75, 53, 500, 90, "font13", "0xffffffff")
      self.addcontrol(self.lbltitle)
      self.lbltitle.addlabel("xbmc home control")
             
      ### make the list
      self.statlist = xbmcgui.controllist(210, 100, 335, 360, imagewidth=12, imageheight=15, itemheight=18, space=0)
      self.addcontrol(self.statlist)
      global status
      global devicename
      global code
      global lastchange
     
      f = open(root + "currentstatus.txt")
      s = f.read()
      f.close()
      ls = s.split("\n") # this means each new line will be loaded into it's own array.
      status = []
      devicename = []
      code = []
      lastchange = []
      for l in ls:
         if l != "":
             item = l.split("|")
             if (item[0] == 'on'):
               self.statlist.additem(xbmcgui.listitem(label = item[1], label2 = item[0], thumbnailimage= root+"on.png"))
             else:
               self.statlist.additem(xbmcgui.listitem(label = item[1], label2 = item[0]))
             self.setfocus(self.statlist)
             status.append(item[0])
             devicename.append(item[1])
             code.append(item[2])
             lastchange.append(item[3])
         
  def onaction(self, action):
      if action == action_previous_menu:
          self.close()

  def oncontrol(self, control):
      if control == self.statlist:
          titem = self.statlist.getselecteditem()
          itempos = self.statlist.getselectedposition()
          curstatus=status[itempos]
          curdevicename=devicename[itempos]
          curcode=code[itempos]
          curlastchange=lastchange[itempos]
##       myitem = xbmcgui.listitem() ################ problem is here
          if (curstatus == 'off'):
            urllib.urlopen("[url]http://192.168.0.150:80/xbmc/"+curcode+"on.asp"[/url])
            status[itempos] = "on"
##        self.titem.myitem.setlabel2('on') ################ problem is here
          else:
            urllib.urlopen("[url]http://192.168.0.150:80/xbmc/"+curcode+"off.asp"[/url])
            status[itempos] = "off"
##        self.titem.myitem.setlabel2('off') ################ problem is here

##    def message(self, message):
##       dialog = xbmcgui.dialog()
##       dialog.ok("command testing dialog", message)

mydisplay = myclass()
mydisplay.domodal()
del mydisplay


here is the data file that is being read in...

Quote:off|living room table lamp|b5|12/25/2005 3:47:20 pm|
on|master bedroom scott's table lamp|b9|5/10/2005 11:27:41 pm|
off|foyer table lamp|b4|12/26/2005 11:26:47 am|
off|front porch exterior lights|b3|12/27/2005 11:16:07 pm|
off|master bedroom shea's table lamp|b16|12/26/2005 10:06:41 pm|
on|great room sony stereo|c1|12/22/2005 3:05:14 pm|
off|front guest room ceiling fan light|g10|12/22/2005 3:05:55 pm|
off|front guest room table lamp|g11|12/22/2005 3:06:03 pm|
on|rear guest bedroom table lamp|g15|5/14/2005 9:05:33 am|
off|kitchen sink light|b6|5/11/2005 2:13:45 pm|
on|great room table lamp|b7|12/28/2005 7:34:00 pm|
off|emily's bedroom overhead light|b13|12/20/2005 12:04:57 pm|
off|sarah's bedroom overhead light|g14|5/14/2005 9:05:50 am|
off|emily's bedroom table lamp|b14|5/15/2005 1:00:00 am|
off|universal christmas lights|b1|12/28/2005 8:43:51 pm|
on|study floor lamp|b2|12/28/2005 8:43:48 pm|

edit:
if anyone is interested here is a link to a screenshot of the view that is automatically generated. 
http://home.carolina.rr.com/scottandshea...hot001.jpg

also, here are links to supporting files needed if anyone wants to run the script - just put these in the same directory of the script and change the root variable at the start of the script - you may need to comment out the url calls at the end, but it should display just like in the screenshot above.

http://home.carolina.rr.com/scottandshea...nd-x10.png
http://home.carolina.rr.com/scottandshea/files/on.png
http://home.carolina.rr.com/scottandshea...status.txt

credit once again goes to tartag for supplying the .png images!

buzzster



Reply
#2
the controllist doesn't support a way to change individual list items. you'll have to reset and readd them if that is the way you want to do it.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#3
maybe checkbox controls would be more appropriate since you can toggle them.
Reply
#4
thanks!  so, based on your input i changed the code of the last "def" area (see below) and it works like a charm.  i was afraid that reseting the list and recreating it would cause a noticeable blip, but it is smooth as silk.

the only challenge i still have is that if i click on a certain item in the list (say the 5th item), the focus is moved from that 5th item back to the first item when the controllist is reset and re-created.  i did not see it in the commands, but when you setfocus on the controllist, is there a way to also specify the position or nth item in the list as having control? (in the above case, i would want to set control back to the 5th item).

Quote:   def oncontrol(self, control):
      if control == self.statlist:
          itempos = self.statlist.getselectedposition()
          curstatus=status[itempos]
          curdevicename=devicename[itempos]
          curcode=code[itempos]
          curlastchange=lastchange[itempos]
          if (curstatus == 'off'):
            urllib.urlopen(websvr+curcode+"on.asp")
            status[itempos] = "on"
          else:
            urllib.urlopen(websvr+curcode+"off.asp")
            status[itempos] = "off"
          self.statlist.reset()
          i=0
          for k in status:
             if (status[i] == 'on'):
               self.statlist.additem(xbmcgui.listitem(label = devicename [i], label2 = status[i], thumbnailimage= root+"on.png"))
             else:
               self.statlist.additem(xbmcgui.listitem(label = devicename [i], label2 = status[i]))
             i=i+1    
          self.setfocus(self.statlist)    

mydisplay = myclass()
mydisplay.domodal()
del mydisplay

this brings up question #2:
is there something like an "onfocus" command where you can perform an action when an item in a controllist is highlighted.  to give a specific example, when you look at the screenshot here:
http://home.carolina.rr.com/scottandshea...hot001.jpg
for whatever item is highlighted in the list, i would like to display more details about that item in the black area to the left (such as the date and time that the status of the currently highlighted item last changed).
is there such an "onfocus" like command?

asteron:  great thought about using checkboxes - i originally started out using checkboxes, but decided to go with a controllist to make the script more universal for others who may have x-10 home automation stuff.  i also plan on adding more devices for control and i thought it may get tiring manually changing the gui to add/remove checkbox items.  who knows, i still may have to go that route in the end...

thanks,
buzzster
Reply
#5
selectitem(...)
selectitem(item) -- select an item by index

item is the index on the item to select.

i don't know if this changes focus or not.

#2, there is getfocus, but that's on a control basis, not an individual list. you would have to use a different way of doing things.

i would suggest you look at asteron's stocks script it looks  and acts like a list, but would allow different colors for on/off status. really good script.

this would also solve #1.


looks like your script is gonna be nice. there might be a way to post commands, if you're still interested, i downloaded hs v2,0 and understand a little better what needs to be done. i could play with it some.



For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#6
wow - all i had to do was add the following line at the end of my last "def" section and it keeps/returns the focus to the last item selected in the list.  i had downloaded an older xbmcgui.htm documentation file that did not have that command in it. thanks!!!!

self.statlist.selectitem(itempos)

as for some type of "onfocus" functionality, is that something that would be a good candidate for addition to the xbmcgui in the future?  i could see applications for that for many things (i.e. ability to provide summary information about a highlighted object).  this would be the same type functionality that is used on the main xbmc screen (as you highlight my programs, my pictures, my videos, the pictures to the right change (using pmiii)).

i looked at asteron's code in xstocks and i was impressed and a bit overwhelmed.  i think i understand why he suggested using checkboxes now - i would have sworn xstocks used controllist(s).

also on the homeseer front - i am using 1.7 as 2.0 is a bit buggy from accounts i have seen (plus it costs more $$$Wink.  there is a good online manual for 1.7, and i plan to dive back into potential ways to do an html "post" to the homeseer server.  i just got stuck and frustrated before and decided to focus more on stuff that was easier to do.

thanks again!
Reply

Logout Mark Read Team Forum Stats Members Help
SetLabel Command for ListItem in ControlList0