I need help please
#1
hello i just recently got into python because i want to make scripts /programs for xbox. thank god for python i was stuck thinking c++ was only answer.

anyway i've been reading the tutorial and it just doesn't seem to work correctly:

Quote:import xbmc, xbmcgui
#get actioncodes from keymap.xml
action_previous_menu = 10
action_select_item = 7

class myclass(xbmcgui.window):
def onaction(self, action):
if action == action_previous_menu:
self.close()
if action == action_select_item:
self.straction = xbmcgui.controllabel(300, 200, 200, 200, "", "font14", "0xff00ff00")
self.addcontrol(self.straction)
self.straction.setlabel("hello nicky!")
mydisplay = myclass()
mydisplay.domodal()
del mydisplay

this doesn't do anything when i run it on my xbox.. when i run it in cmd.exe it says:

file "f:\python24\display.py", line 9, in ?
if action == action_select_item:
nameerror: name 'action' is not defined

please help me!
Reply
#2
python uses indentation to mark code blocks instead of braces, which is why everyone's scripts look so neat Smile
action doesn't exist on line 9 because you're outside "onaction"
Reply
#3
edit: fixed it thank you!
Reply
#4
another problem.. kind of simple.. how do i make a variable public so it can be used after data receives data..

Quote:import xbmc, xbmcgui
from socket import *
host = '192.168.1.100' # the remote host
port = 777 # the same port as used by the server
s = socket(af_inet, sock_stream)
s.connect((host, port))
s.send('notice|')
while 1:
data = s.recv(1024)
if not data: break
s.close()
#get actioncodes from keymap.xml
action_previous_menu = 10
action_select_item = 7

class myclass(xbmcgui.window):
def onaction(self, action):
if action == action_previous_menu:
self.close()
if action == action_select_item:
self.straction = xbmcgui.controllabel(300, 200, 200, 200, "", "font14", "0xff00ff00")
self.addcontrol(self.straction)
self.straction.setlabel(`data`)
mydisplay = myclass()
mydisplay.domodal()
del mydisplay

i'm trying to display the data in the label but its empty. please help.
Reply
#5
this should do it: self.straction.setlabel(data)
Reply
#6
that didn't fix it.. it still doesn't display anything because data is empty.. before it displayed ``
Reply
#7
you have to declare you want the variable from the global namespace.


in onaction():
type

global data

as the first line of the function (with proper indent)

you might also need to add this line before where you set data but i dont think so.

also this is a development question and belongs in the other python forum.
Reply
#8
same problem.. Sad heres my updated code:

Quote:import xbmc, xbmcgui
from socket import *
host = '192.168.1.100' # the remote host
port = 777 # the same port as used by the server
s = socket(af_inet, sock_stream)
s.connect((host, port))
s.send('notice|')
while 1:
data = s.recv(1024)
if not data: break
s.close()
#get actioncodes from keymap.xml
action_previous_menu = 10
action_select_item = 7

class myclass(xbmcgui.window):
def onaction(self, action):
global data
if action == action_previous_menu:
self.close()
if action == action_select_item:
self.straction = xbmcgui.controllabel(300, 200, 200, 200, "", "font14", "0xff00ff

00")
self.addcontrol(self.straction)
self.straction.setlabel(`data`)
mydisplay = myclass()
mydisplay.domodal()
del mydisplay

also tried puting the global up top because its written to up above.. same thing.
Reply
#9
is data some sort of binary data and not a string?
also are those backticks around 'data'?

if data is a string you can do
self.straction.setlabel(data)

im not sure how easy it is to format binary data into a string but i suspect its not bad.

also you might want to have a fullscreen controlimage in the background so you can see something...
Reply
#10
to format data into a string do: str(data)

might give unwanted results if the data isn't prepared for this. like printing a zip file in the command window in windows give some funny results on your pc speaker Wink

looking at your code i see another problem however. you break the loop if data is empty. that means that your code will only continue if data is empty. now think about that for a while. (unless i am entirely wrong here, just had a quick look).

you don't need the global tag by the way. it would work anyways as long as it's set before the function which uses it.
try setting data = "test" somewhere after the loop and try again with the code you had in the beginning (3rd post?).
xbmcscripts.com administrator
Reply
#11
this is so weird nothing works.. by the way i know vb is sending the data as i have checks.

heres the code i removed the `` and added str() still not working


Quote:import xbmc, xbmcgui
from socket import *
global data
host = '192.168.1.100' # the remote host
port = 777 # the same port as used by the server
s = socket(af_inet, sock_stream)
s.connect((host, port))
s.send('notice|')
while 1:
data = s.recv(1024)
if not data: break
s.close()
#get actioncodes from keymap.xml
action_previous_menu = 10
action_select_item = 7

class myclass(xbmcgui.window):
def onaction(self, action):
if action == action_previous_menu:
self.close()
if action == action_select_item:
self.straction = xbmcgui.controllabel(300, 200, 200, 200, "", "font14", "0xff00ff00")
self.addcontrol(self.straction)
self.straction.setlabel(str(data))
mydisplay = myclass()
mydisplay.domodal()
del mydisplay

why isnt this working? lol Sad
Reply
#12
i updated my last post just in case you didn't notice as you posted right after my edit.

try

temp = s.recv(1024)
if not temp: break
data = data + temp


that is only from guessing what s.recv does, i haven't looked it up. i am guessing it gets data in blocks of 1024 bytes, but if not my code isn't right. i don't have time to look further at it now. remember to create data before the while loop (do a data = "")
xbmcscripts.com administrator
Reply
#13
ok its obvious.. its s.recv isn't getting any data .. lol once i did data = "test me" after loop it displayed test me.. but i just tried your code and it displays nothing.

so any ideas?
Reply
#14
well, whatever you're connecting to isn't sending data a way socket accepts or you're connecting the wrong way. i suggest you just copy the non-xbmc part into a new document then get it working on your pc first. do a print data after the loop to display it's contents.

and never mind that loop while testing the first times. do print s.recv(1024) or somthing.
xbmcscripts.com administrator
Reply
#15
thanks for all your help i fixed it.. i had a winsock1.close in my vb server after i sent the data and i guess it effected it some how.

:p
Reply

Logout Mark Read Team Forum Stats Members Help
I need help please0