PDA

View Full Version : A little help on addControl for loops


ocwasere
2007-04-12, 16:31
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

##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

Nuka1195
2007-04-12, 16:48
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,3 0,30, RootDir + str(test[id][2:][i][0])+".png"))
self.addControl(self.testpicture[-1])

ocwasere
2007-04-13, 01:40
been trying for days to do that thanks
had to add self. does self mean the class

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

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

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 (http://www.ocsweb.co.uk/guitar/xbmc/)

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

anyway thank again Nuka1195 for your help