hi folks,
first time posting here in scripts, but have a keen interest in getting xbmc to control my x-10 devices as well.
i am currently running homeseer 1.7 on a windows xp computer. much thanks to tartag and affini for answering a couple of questions and getting me started on the right path. however, as soon as i started down the path, i think i took a hard left!
i have decided that with my homeseer setup it would be easiest to do as nickle and affini have suggested previously.... which is... create some .asp pages on my winxp machine since homeseer has a built in webserver and have those .asp pages run by calling them from a python script in xbmc.
well, i was able to get the very basic concept working in xbmc with a simple script:
i.e. the 2 line script below runs a simple .asp page on my winxp computer and turns on the x-10 device (a lamp in this case) assigned to code b2.
import urllib
urllib.urlopen("[url]http://192.168.0.150:80/scott/b02on.asp"[/url])
my problem comes when i tried to create a more complex script for xbmc that has different .asp pages run when various buttons are pressed in xbmc.
the script is shown below and the page looks good when i run the script in xbmc. the buttons show up, i can highlight and move up and down, etc...., however, when i select a button, nothing happens (although xbmc makes a clicking sound like the button was pressed).
i would expect the
urllib.urlopen("[url]http://192.168.0.150:80/scott/dosomething.asp"[/url]) "command" to be executed just like it did in the simple script, but my ignorance of python has gotten the best of me.
this is my first python proggy ever, so can someone please show me, why i get no action on a button press in my if / elif statements? any help would be greatly appreciated!
p.s. i know this script has alot of extras in it and can be made much more efficient.... just trying to get the basic concept working first before messing with it too much.
Quote:##***************script starts here ************
import xml.dom.minidom, urllib, xbmc, xbmcgui
import urllib2, urlparse, string, textwrap, os, image
import htmllib, formatter, stringio, re
import socket, time, sys, threading
from string import split, replace, find
from xbmcgui import dialogprogress as 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
try: emulating = xbmcgui.emulating
except: emulating = false
action_move_left = 1
action_move_right = 2
action_move_up = 3
action_move_down = 4
action_page_up = 5 #left trigger
action_page_down = 6 #right trigger
action_select_item = 7 #a button
action_highlight_item = 8
action_parent_dir = 9 #b button
action_previous_menu = 10 #back button
action_show_info = 11
action_pause = 12
action_stop = 13
action_next_item = 14
action_prev_item = 15
action_xbutton = 18 #y button
action_whitebutton = 117
## change to true to show debug information on the script console (white button when you are in the scripts window in xbmc)
debug = true
######### the below expression calls the .asp page and turns housecode b01 on like it is supposed to ##########
########### why won't the same expression work when a button press is executed (see further down in script)
urllib.urlopen("[url]http://192.168.0.150:80/scott/b01on.asp"[/url])
root = "f:\\xbmc\\media\\"
class rhouse_main(xbmcgui.window):
def (self):
if emulating: xbmcgui.window.(self)
self.scalex = ( float(self.getwidth()) / float(720) )
self.scaley = ( float(self.getheight()) / float(480) )
self.currentstate = none
self.selecteddistributor = -1
self.addcontrol(xbmcgui.controlimage(0,0,1280,720, root + "background-x10.png"))
self.addcontrol(xbmcgui.controlimage(int(100 * self.scalex),int(65 * self.scaley),int(670 * self.scalex),int(68 * self.scaley), root + "x10-topbar.gif"))
self.lbltitle = xbmcgui.controlfadelabel(int(75 * self.scalex),int(53 * self.scaley), int(500 * self.scalex), int(90 * self.scaley), "font13", "0xffffffff")
self.addcontrol(self.lbltitle)
self.lbltitle.addlabel("xbmc home control")
# add buttons
self.btnchristmason = xbmcguicontrolbutton(int(60*self.scalex), int(100*self.scaley), int(140*self.scalex), int(30*self.scaley), "christmas on")
self.btnchristmasoff = xbmcguicontrolbutton(int(60*self.scalex), int(132*self.scaley), int(140*self.scalex), int(30*self.scaley), "christmas off")
self.btnstudyon = xbmcguicontrolbutton(int(60*self.scalex), int(164*self.scaley), int(140*self.scalex), int(30*self.scaley), "study on")
self.btnstudyoff = xbmcguicontrolbutton(int(60*self.scalex), int(196*self.scaley), int(140*self.scalex), int(30*self.scaley), "study off")
self.btnporchon = xbmcguicontrolbutton(int(60*self.scalex), int(228*self.scaley), int(140*self.scalex), int(30*self.scaley), "porch on")
self.btnporchoff = xbmcguicontrolbutton(int(60*self.scalex), int(260*self.scaley), int(140*self.scalex), int(30*self.scaley), "porch off")
self.btnfoyeron = xbmcguicontrolbutton(int(60*self.scalex), int(324*self.scaley), int(140*self.scalex), int(30*self.scaley), "foyer on")
self.btnfoyeroff = xbmcguicontrolbutton(int(60*self.scalex), int(356*self.scaley), int(140*self.scalex), int(30*self.scaley), "foyer off")
self.btnlivingroomon = xbmcguicontrolbutton(int(60*self.scalex), int(388*self.scaley), int(140*self.scalex), int(30*self.scaley), "living room on")
self.btnlivingroomoff = xbmcguicontrolbutton(int(60*self.scalex), int(388*self.scaley), int(140*self.scalex), int(30*self.scaley), "living room off")
self.checkdownload = xbmcguicontrolcheckmark(int(71*self.scalex), int(439*self.scaley), int(120*self.scalex), int(20*self.scaley), "toggle test1", checkwidth=20, checkheight=20, alignment=0)
self.checksave = xbmcguicontrolcheckmark(int(191*self.scalex), int(439*self.scaley), int(100*self.scalex), int(20*self.scaley), "toggle test2", checkwidth=20, checkheight=20, alignment=0 )
self.labelstatus = xbmcguicontrollabel(int(300*self.scalex), int(439*self.scaley), int(150*self.scalex), int(20*self.scaley), "saving data files..." )
self.addcontrol(self.btnchristmason)
self.addcontrol(self.btnchristmasoff)
self.addcontrol(self.btnstudyon)
self.addcontrol(self.btnstudyoff)
self.addcontrol(self.btnporchon)
self.addcontrol(self.btnporchoff)
self.addcontrol(self.btnfoyeron)
self.addcontrol(self.btnfoyeroff)
self.addcontrol(self.btnlivingroomon)
self.addcontrol(self.btnlivingroomoff)
self.addcontrol(self.checkdownload)
self.addcontrol(self.checksave)
self.btnchristmason.controlup(self.checkdownload)
self.btnchristmason.controldown(self.btnchristmasoff)
self.btnchristmasoff.controlup(self.btnchristmason)
self.btnchristmasoff.controldown(self.btnstudyon)
self.btnstudyon.controlup(self.btnchristmasoff)
self.btnstudyon.controldown(self.btnstudyoff)
self.btnstudyoff.controlup(self.btnstudyon)
self.btnstudyoff.controldown(self.btnporchon)
self.btnporchon.controlup(self.btnstudyoff)
self.btnporchon.controldown(self.btnporchoff)
self.btnporchoff.controlup(self.btnporchon)
self.btnporchoff.controldown(self.btnfoyeron)
self.btnfoyeron.controlup(self.btnporchoff)
self.btnfoyeron.controldown(self.btnfoyeroff)
self.btnfoyeroff.controlup(self.btnfoyeron)
self.btnfoyeroff.controldown(self.btnlivingroomon)
self.btnlivingroomon.controlup(self.btnfoyeroff)
self.btnlivingroomon.controldown(self.checkdownload)
self.checkdownload.controlup(self.btnlivingroomon)
self.checkdownload.controldown(self.btnchristmason)
self.checkdownload.controlright(self.checksave)
self.checksave.controlup(self.btnlivingroomon)
self.checksave.controldown(self.btnchristmason)
self.checksave.controlleft(self.checkdownload)
self.setfocus(self.btnchristmason)
def onaction(self, action):
if action == action_previous_menu:
self.result = -1
self.close()
def oncontrol(self, control):
if control == self.btnchristmason:
printdebug('christmas on button pressed.')
urllib.urlopen("[url]http://192.168.0.150:80/scott/b01on.asp"[/url])
elif control == self.btnchristmasoff:
printdebug('chrismtas off button pressed.')
urllib.urlopen("[url]http://192.168.0.150:80/scott/b01off.asp"[/url])
elif control == self.btnstudyon:
printdebug('study on button pressed.')
urllib.urlopen("[url]http://192.168.0.150:80/scott/b02on.asp"[/url])
elif control == self.btnstudyoff:
printdebug('study off button pressed.')
urllib.urlopen("[url]http://192.168.0.150:80/scott/b02off.asp"[/url])
elif control == self.btnporchon:
printdebug('porch on button pressed.')
urllib.urlopen("[url]http://192.168.0.150:80/scott/b03on.asp"[/url])
elif control == self.btnporchoff:
printdebug('porch off button pressed.')
urllib.urlopen("[url]http://192.168.0.150:80/scott/b03off.asp"[/url])
elif control == self.btnfoyeron:
printdebug('foyer on button pressed.')
urllib.urlopen("[url]http://192.168.0.150:80/scott/b04on.asp"[/url])
elif control == self.btnfoyeroff:
printdebug('foyer off button pressed.')
urllib.urlopen("[url]http://192.168.0.150:80/scott/b04off.asp"[/url])
elif control == self.btnlivingroomon:
printdebug('living room on button pressed.')
urllib.urlopen("[url]http://192.168.0.150:80/scott/b05on.asp"[/url])
elif control == self.btnlivingroomoff:
printdebug('living room off button pressed.')
urllib.urlopen("[url]http://192.168.0.150:80/scott/b05off.asp"[/url])
elif control == self.checksave:
printdebug('save checkbox pressed.')
if self.checksave.getselected():
self.checksave.setselected(true)
urllib.urlopen("[url]http://192.168.0.150:80/scott/b01on.asp"[/url])
elif control == self.checkdownload:
printdebug('download checkbox pressed.')
if self.checkdownload.getselected():
self.checkdownload.setselected(true)
urllib.urlopen("[url]http://192.168.0.150:80/scott/b02on.asp"[/url])
# tried open socket with page url, but this did not work
# rh_sock = urllib.urlopen("[url]http://192.168.0.150:80/scott/b01on.asp"[/url])
# rh_html = rh_sock.read()
# rh_sock.close()
display_main = rhouse_main()
display_main.domodal()
del display_main
##*****************end of script***********
edit: i put the script code that did not work in quotes to make it easier to read. see notes in later post(s) - a similar but different script is now working, but not sure why .... more to come....