2006-02-07, 07:26
i need help from a guru. the code is almost complete.
the goal is to create a class that anyone can use to create a set of controlbuttons from either a text file or using file names from a directory.
i will make everything adjustable: number of buttons per column, button sizes, column start x & y positions, etc.
this will make dynamic button creation much easier for people wanting to make scripts and require much less manual coding for everyone!
i have everything in-place an working just need help with debugging the navigation. if you can help, i'd appreciate it!
here's the code that creates the buttons from inputs...
the goal is to create a class that anyone can use to create a set of controlbuttons from either a text file or using file names from a directory.
i will make everything adjustable: number of buttons per column, button sizes, column start x & y positions, etc.
this will make dynamic button creation much easier for people wanting to make scripts and require much less manual coding for everyone!
i have everything in-place an working just need help with debugging the navigation. if you can help, i'd appreciate it!
here's the code that creates the buttons from inputs...
Quote: def buildbuttons(self,dict,buttonset,blposx,blposy,blposxdist,blposydist):
self.btnevent = []
totalnum = len(self.dictbuttons)
c = 0 # column counter
for n in range(totalnum): # loop to create buttons
item = dict[n]
bname = item['name']
bfile = item['file']
cp = (n %buttonspercolumn)+(buttonspercolumn-1)/buttonspercolumn # normalize position of buttons in column
self.posy = blposy + (blposydist * cp) # set vertical position
self.posx = blposx + (blposxdist * c)
btn = xbmcgui.controlbutton(int(self.posx * self.scalex),int(self.posy * self.scaley),int(140 * self.scalex),int(27 * self.scaley),bname,textxoffset=24)
self.addcontrol(btn)
self.btnevent.append(btn)
c = (n-(n %buttonspercolumn)+(buttonspercolumn-1))/buttonspercolumn # normalize to multiple of buttons per column
for n in range(totalnum): # loop to create button navigation
self.btnevent[(n+1)%totalnum].controlup(self.btnevent[n])
self.btnevent[n].controldown(self.btnevent[(n+1)%totalnum]) # (n+1)%totalnum --- wraps navigation
self.btnevent[(n+buttonspercolumn)%buttonspercolumn].controlleft(self.btnevent[n])
self.btnevent[n].controlright(self.btnevent[(n+buttonspercolumn)%buttonspercolumn])