A little help on addControl for loops
#1
can somone tell me the right way to add ControlImage in a for loop
this is what i have trying for days

it seems to add the ControlImage ok, but i get an error if i try and remove them

thanks

Code:
##Add Control

##        range(len(test[id][2:])): = [0, 1, 2]

        for i in range(len(test[id][2:])):

            testpicture='testpicture'+str(i)

            x = 300 - 30/2 + 6*30 - int(test[id][2:][i][1])*30
            y = 200 - 30/2 - 50/2 + int(test[id][2:][i][2])*50

            self.testpicture =xbmcgui.ControlImage(x,y,30,30, RootDir + str(test[id][2:][i][0])+".png")
            self.addControl(self.testpicture)

##Add Control Debug Output

##print self.testpicture =  <xbmcgui.ControlImage instance at 0x033CEA30>
##print testpicture =  testpicture0
##print self.testpicture =  <xbmcgui.ControlImage instance at 0x033CEB48>
##print testpicture =  testpicture1
##print self.testpicture =  <xbmcgui.ControlImage instance at 0x033CEC38>
##print testpicture =  testpicture2

##Finish Add Control

##Remove Control

        self.removeControl(self.testpicture0)
        self.removeControl(self.testpicture1)
        self.removeControl(self.testpicture2)

##Finish Remove Control Debug Output

AttributeError: MyClass instance has no attribute 'testpicture0'

##Finish Remove Control
Reply
#2
Code:
testpicture=[]
        for i in range(len(test[id][2:])):
            x = 300 - 30/2 + 6*30 - int(test[id][2:][i][1])*30
            y = 200 - 30/2 - 50/2 + int(test[id][2:][i][2])*50
            self.testpicture.append(xbmcgui.ControlImage(x,y,30,30, RootDir + str(test[id][2:][i][0])+".png"))
            self.addControl(self.testpicture[-1])
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#3
been trying for days to do that thanks
had to add self. does self mean the class

Code:
self.fingeringpicture=[]
        for i in range(len(chords[id][2:])):
            x = 300 - 30/2 + 6*30 - int(chords[id][2:][i][1])*30
            y = 200 - 30/2 - 50/2 + int(chords[id][2:][i][2])*50
            self.fingeringpicture.append(xbmcgui.ControlImage(x,y,30,30, RootDir + str(chords[id][2:][i][0])+".png"))
            self.addControl(self.fingeringpicture[-1])

            fingering = range(len(chords[id][2:]))

and does [-1] = add the last in the list in self.addControl(self.fingeringpicture[-1])

added fingering = range(len(chords[id][2:])) so i know last id

Code:
def onControl(self, control):
        if control == self.list:
            self.delfingering(fingering)

Code:
def delfingering(self,id):
        for i in id:
            self.removeControl(self.fingeringpicture[i])

any way with all the fingering going on i better explain what i'm trying to do

XBMC Guitar Chords

i have done it in php using ImageCreate
but finding python a bit of a struggle (only been a week i'll keep tryingSmile )

anyway thank again Nuka1195 for your help
Reply

Logout Mark Read Team Forum Stats Members Help
A little help on addControl for loops0