Kodi Community Forum

Full Version: Python returning a string?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys
How do I get the content of a string back to a window?

I can see the string through the script, but I want the output to appear in a lavel.

Something like:
<label2>$INFO[Skin.String(STRING)]</label2>

Kind regards
cyber7
how can we help you with so few informations?

what's the code?
what are you trying to do?
where do you want to show ?
what have you done so far?

...
Sorry if the info is missing,
What I do is: Run a script uising:
python script.py
It displays the result, ie:
Your answer is: AUBREY

The code is at work, so I can't give the exact details, but as far as I can remember, it looks like:

STRING = (and the function)

What I would like to do is not display the string in the program, but return it into XBMC's windows with, as I said in my previous post:

<label2>$INFO[Skin.String(STRING)]</label2>

so that the contents of STRING is displayed in <label2>

Hope this is more clear
cheers
cyber7
ps - I see from the link in the previous post that:

Methods defined here:

getLabel(...)
getLabel() -- Returns the text value for this label.

example:
- label = self.label.getLabel()
setLabel(...)
setLabel(label) -- Set's text for this label.

label : string or unicode - text string.

example:
- self.label.setLabel('Status')


Does this mean that I can (after STRING has been assigned) do the following in python:

self.label.setLabel('STRING')

and then in my window code do:

<label2>$INFO[Skin.String(STRING)]</label2>

which means that label2 will display AUBREY?
Quote:self.label.setLabel('STRING')

and then in my window code do:

<label2>$INFO[Skin.String(STRING)]</label2>

which means that label2 will display AUBREY?

no, you're fillin label and want to display label2
I do understand that, but I can not find a:

self.strActionInfo.setString(STRING)

option to set the string in the python script to return to the window...

or am I sitting the pot miss?
bump <burp>
Smile
sorry, guys, I realy would like to get some answer on this... I have fine-read the xbmc and xb,cgui libs, but can not see anything that would return the sting I am looking for into some kind of SETSTRING function?
You should post some relevant code from your skin file and your python script. It looks like you misunderstand the concept here
OK, Here goes:

PYTHON.py
import xbmc, xbmcgui

#get actioncodes from keymap.xml
ACTION_PREVIOUS_MENU = 10
class MyClass(xbmcgui.Window):
def __init__(self):
IPADD = xbmc.getIPAddress()
self.strActionInfo = xbmcgui.ControlLabel(250, 80, 2000, 2000, '', 'font14', '0xFFBBBBFF')
self.addControl(self.strActionInfo)
self.strActionInfo.setLabel(IPADD)
self.list = xbmcgui.ControlList(200, 150, 300, 400)
self.addControl(self.list)
self.list.addItem(IPADD)
self.setFocus(self.list)
def onAction(self, action):
if action == ACTION_PREVIOUS_MENU:
self.close()
mydisplay = MyClass()
mydisplay.doModal()
del mydisplay


This will display in a NEW WINDOW my IP ADDRESS, but seeing that I use multiple routes and connections, I would like to pass the "IPADD" value into a string.

I have read that you can do a:
xbmc.executebuiltin('Skin.SetString(StringName,StringValue)')
but trying to add this into the code gives me an invalid syntax error...Oo

I know I am new with python, but is an advanced scrypt writer in UNIX (All falvours of linux). I just dont know how to get the output of my script (if it was a .sh script) back into the SetString of XBMC:confused2:

Cheers and I hope this clears it up a bit more
cyber7 (aka AubreyX)
could you post your xml too ?

and your class code?
Basically the XML looks like this:
<item id="1">
<label>test</label>
<onclick>RunScript(special://skin/scripts/ipsetting.py)</onclick>)
<label2>CURRENT IP ADDRESS: $INFO[Skin.String(IPADD)]</label2>
</item>

It is the CURRENT IP ADDRESS: information that I would like to keep updated...

Kind regards
cyber7
Don't worry, guys, I found the answer:
xbmc.executebuiltin('Skin.SetString(IPADD,%s)' % IPADD)

now, when calling the Skin.String(IPADD) I get the correct info Smile

(Took me long enough)<sigh>(If only I can get to grips with python faster between my daily work!)