Variable from 3rd party console script
#16
Yes, this works for me with no issue at all.

In the relevant skin xml file, I have this in the label:
Code:
<label>$INFO[Skin.String(teststring)]</label>

In the python script, I do this:
Code:
import xbmc
xbmc.executebuiltin("Skin.SetString(teststring, New Text Goes Here)")
I reload the skin (once) to make sure that label is showing. Then I run the script and the text appears instantly.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#17
(2015-08-28, 19:39)el_Paraguayo Wrote: Yes, this works for me with no issue at all.

In the relevant skin xml file, I have this in the label:
Code:
<label>$INFO[Skin.String(teststring)]</label>

In the python script, I do this:
Code:
import xbmc
xbmc.executebuiltin("Skin.SetString(teststring, New Text Goes Here)")
I reload the skin (once) to make sure that label is showing. Then I run the script and the text appears instantly.
el_Paraguayo,

thanks again for your time.

Perhaps you've misunderstood the issue here (or I have not explain it well, I do apologize for my English).
I know is working in that way, but if you try to use as a string value (New Text Goes Here) a number of a variable it doesn't pick the value but will write the name of the variable. Setstring seems not capable to use a variable as a parameter.
Just for explain it well I need something like

xbmc.executebuiltin("Skin.SetString(teststring, $VAR[testvalue])")

where "testvalue" is a variable that python need to read from my txt.
For now the unique solution I found is to overwrite the value on my xml and reload the skin with python. Didn't find any other elegant solution to do that.
Reply
#18
If you can read the value in your script, then can't you just do this:
Code:
xbmc.executebuiltin("Skin.SetString(teststring, {0})".format(your_variable_name))

EDIT: $VAR is not for using variables from scripts, it's for named variables in the skin file http://kodi.wiki/view/Skinning_Manual#Variables
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#19
Nope. Doesn't works. By the way where did you find that syntax?

Just for a quick recap this is what I tried for now:
-On my xml:

<label>$INFO[skin.String(tempo)]</label>

Works if I use setstring on py.

<label>$INFO[skin.SetString(tempo,31)]</label>

Works if I force a skin reload on py when I change the value using sed.

- On my py:

tempo2 = '31'

with or without quotes, it's the same. It's just a local variable before using the true one on my txt generated by python after looking on my database.

xbmc.executebuiltin("Skin.SetString(tempo,tempo2)")

doesn't update even forcing a skin reload and use the value in cache (if present).

xbmc.executebuiltin("Skin.SetString(tempo, {0}".format(tempo2))

doesn't update even forcing a skin reload and use the value in cache (if present).

xbmc.executebuiltin("ReloadSkin()")
xbmc.executebuiltin("Skin.SetString(tempo,31)")


works.
Reply
#20
(2015-08-28, 20:36)effe Wrote: <label>$INFO[skin.SetString(tempo,31)]</label>
This should not be in your skin file. You use Skin.String as the infolabel to show the data and Skin.SetString from your script to change the value.

Quote:xbmc.executebuiltin("Skin.SetString(tempo,tempo2)")

doesn't update even forcing a skin reload and use the value in cache (if present).
This should just show the word "tempo2". If it doesn't even do that then it feels like your infolabel is wrong and the problem isn't your script.

Quote:xbmc.executebuiltin("Skin.SetString(tempo, {0}".format(tempo2))
Again, this works for me. The "format" command is just python string formatting, nothing special.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#21
(2015-08-28, 20:55)el_Paraguayo Wrote:
(2015-08-28, 20:36)effe Wrote: <label>$INFO[skin.SetString(tempo,31)]</label>
This should not be in your skin file. You use Skin.String as the infolabel to show the data and Skin.SetString from your script to change the value.
Understood, was just one of the tests.
Quote:
Quote:xbmc.executebuiltin("Skin.SetString(tempo,tempo2)")

doesn't update even forcing a skin reload and use the value in cache (if present).
This should just show the word "tempo2". If it doesn't even do that then it feels like your infolabel is wrong and the problem isn't your script.
Ops! I wrote the same sentence twice, my mistake. Yes, will shows the word "tempo2".
Quote:
Quote:xbmc.executebuiltin("Skin.SetString(tempo, {0}".format(tempo2))
Again, this works for me. The "format" command is just python string formatting, nothing special.
For me isn't working (Xubuntu 15.04 64bit - python 2.7.9 - Kodi 15.1). It doesn't update and it use the last value registered. No errors in log.
How curious, we can use str formatting as a value but not the name of a variable?
Again here is my simple py:
Code:
import xbmc, imp

tempo2 = '31'

def main():
    monitor = xbmc.Monitor()
    if monitor.waitForAbort(10):
        return

    while True:
        xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
        if monitor.waitForAbort(10):
            break
        xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        if monitor.waitForAbort(10):
            break
#    xbmc.executebuiltin("ReloadSkin()") <------- Doesn't make any difference. #
    xbmc.executebuiltin("Skin.SetString(tempo, {0}".format(tempo2))
    xbmc.executebuiltin('XBMC.ActivateWindow(1180)')
        if monitor.waitForAbort(10):
            break
        xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        if monitor.waitForAbort(300):
            break

if __name__ == '__main__':
    main()

Thanks again for your time, but I think I'll give up.
Reply
#22
Looks like you're missing a bracket after the }. Take a look at my example again. But if this was wrong, you should be getting a script error...
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#23
I'm sorry you can't see my face now. This happens when you can't use pycharm to check the code but just a text editor.
Yes, is working now picking the value directly from my txt. Oddly enough, Kodi didn't report a script error, tested right now. It reports an error if, for example, I pull out a 'x' from xbmc. That's curious.

For the sake of knowledge if someone is looking for a similar thing, here's the complete revised script:
Code:
import xbmc, imp

def main():
    monitor = xbmc.Monitor()
    if monitor.waitForAbort(10):
        return

    while True:
        xbmc.executebuiltin('XBMC.ActivateWindow(weather)')
        if monitor.waitForAbort(10):
            break
        xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        if monitor.waitForAbort(10):
            break
    def getVarFromFile(filename):
        f = open(filename)
        global data
        data = imp.load_source('data', '', f)
        f.close()
    getVarFromFile('/home/effe/var.txt')
    xbmc.executebuiltin("Skin.SetString(tempo, {0})".format(data.wait_time))
    xbmc.executebuiltin('XBMC.ActivateWindow(1180)')
        if monitor.waitForAbort(10):
            break
        xbmc.executebuiltin('XBMC.ActivateWindow(home)')
        if monitor.waitForAbort(300):
            break

if __name__ == '__main__':
    main()

Now that I understood how to use my data I'm ready to create a more complex setup. Thanks!
Reply
#24
Actually, thinking about it, it wouldn't report an error because you're sending a command as a string. Your previous code was still a string, so no code error, it's just that Kodi didn't know how to handle it.

Glad it's working now!
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#25
(2015-08-28, 23:17)el_Paraguayo Wrote: Actually, thinking about it, it wouldn't report an error because you're sending a command as a string. Your previous code was still a string, so no code error, it's just that Kodi didn't know how to handle it.

Glad it's working now!
Man, did you ever try to populate a string with psycopg2 from a DB? Works on a normal python script under pycharm but doesn't on kodi. And no errors in log... Any clue?
Reply
#26
Never used psycopg2. No idea why you are getting mixed results. Try putting some debugging in your code and see what the string value is.
BBC Live Football Scores: Football scores notifications service.
script.squeezeinfo: shows what's playing on your Logitech Media Server
Reply
#27
Solved. The issue were on my skin, created for kodi 15.1, based on Arctic Zephyr and hugely customized. Since AZ is not compatible with kodi 16 I've installed kodi 15.2 from Ubuntu repos and after a little tweaking time now is working fine with Psycopg2. Wink
Reply

Logout Mark Read Team Forum Stats Members Help
Variable from 3rd party console script0