return elements from list to window ->must be unicode or str
#1
Hi,

I want to output all elements in a list into a window.

Here an example code:
PHP Code:
#!/usr/bin/env python
import xbmcxbmcgui
import sys 
import data

ACTION_PREVIOUS_MENU 
10

array = ["2""54""045""45""5435"]

class 
MyClass(xbmcgui.Window):
  
def __init__(self):
    
self.strAction xbmcgui.ControlLabel(400250200200'''font30',)
    
self.addControl(self.strAction)
    
self.strAction.setLabel(computeInput())

def computeInput():
  for 
i in array:
    print(
str(i))

mydisplay MyClass()
mydisplay .doModal()
del mydisplay 

I thought that converting i to a string would suffice, however with this example i also get:
"Error Contents: argument "label" for method "setLabel" must be unicode or str"

I think i have to use "return" in the function to achive my goal, any hints on how to do that with lists
and not receiving the "must be unicode or str" error?

Thanks in advance,
Reply
#2
Yes, the problem is that the computeInput() function doesn't actually return any information - so setLabel() has no input to use (it's probably set to None). Using print, will simply print to the xbmc.log, t doesn't send data back into the ControlLabel.

What you do next depends on what you want to see.

You can simply return the list as a list (assuming all are str)

Code:
def computeInput():
    return ', '.join(array)

OR you can return as multiline and explicitly covert to str

Code:
def computeInput():
    return '\n'.join(map(str, array))

However, I've never used the[/code] Winodw class - so I've no idea is a ControlLabel can display these values. I would have thought a ControlTextBox would have been better - but it depends on what you are doing.
Add-on:PleXBMC (wiki) - Play Plex media through XBMC
PleXBMC Helper - Integrate Official/Unoffical Plex remote control apps into PleXBMC
PleXBMC Repository - install and manage all PleXBMC addons
Quartz3 PleXBMC - Integrate PleXBMC into home menus
Reply
#3
Yes, you got the error because computeInput() returns implicit None which can't be set as caption to a label.

Not really critical but can result in unexpected behavior: You should avoid naming (especially global) variables like python datatypes/modules.

Also you created a list, maybe a name like "my_list" or "labels" would fit better and avoids confusing.

I created a small demo script a year ago where I set a windowxml's label's caption.
My GitHub. My Add-ons:
Image
Reply

Logout Mark Read Team Forum Stats Members Help
return elements from list to window ->must be unicode or str0