ControlList to string
#1
Hi everyone! I'm trying to write a script and I got stuck. I have filled a ControlList (self.list) with items, each item is a string from a file, I give the user the possibility to modify the list throgh virtual keyboard and then I would like to save the changes back to the file, but this seem not to work (bugs out when I try to get the size of the ControlList):

Code:
if dialog.yesno("Save", "do you want to save the file?"):
i = range(self.list.size())
while(i):
    config = "\n".join(self.list.getListItem(i).getLabel())
fname = xbmc.translatePath('special://home/addons/myscript/myfile')
w = open(fname, 'w')
w.write(config)
w.close()
self.close()

What am I doing wrong? Is there a better way insted of going through ControlList?
Cheers!
Reply
#2
Changed the code to below, works if there is 1 item in list, returns blank if there are more, any thoughts? any one?


Code:
dialog = xbmcgui.Dialog()
        if dialog.yesno("Save", "Do you want to save the file?"):
            indexes = range(self.list.size())
            config = ""
            for i in indexes:
                config = "\n".join(self.list.getListItem(i).getLabel())
            fname = xbmc.translatePath('special://home/addons/myscript/myfile')
            w = open(fname, 'r+')
            w.write(config)
            w.close()
            self.close()
        else:
            self.close()
Reply
#3
The for loop is not appending to config - it's setting it.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#4
Can't believe i missed that! 8-o
Cheers!
Reply

Logout Mark Read Team Forum Stats Members Help
ControlList to string0