2005-12-30, 04:42
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
here is the data file that is being read in...
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
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