how to create xbmcgui.ControlButton sequence?
#1
i'm trying to create a set of buttons using a while statement. i want to create them in numerical sequence starting at 1. 'n' is my counter

desired result example :

self.btnevent1 = xbmcgui.controlbutton(<data here>)
self.btnevent2 = xbmcgui.controlbutton(<data here>)
self.btnevent3 = xbmcgui.controlbutton(<data here>)
...

i've tried a few things that work in jscript & vbscript... but python does not like it.

any help is appreciated.

thanks
I'm not an expert but I play one at work.
Reply
#2
can't you use an array?

Quote:self.btnevent = []
self.btnevent.append(xbmcgui.controlbutton(<data here>))



For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#3
the problem comes into play when i try to create the navigation. i'm trying to create the button at the same time as the navigation, in a single loop. is there any better way to do this? i'm thinking i'm going to have to create two loops, one to initialize the button and then one to create the navigation. imo, not too cool and definitely not efficient.

here's the function code i'd like to work, single loop...

Quote: def buildhsbtnevents(self,dict,hs_buttonset,hs_evblposx,hs_evblposy,hs_evblposxdist,hs_evblposydist,hs_evbln
avleft,hs_evblnavup,hs_evblnavright,hs_evblnavdown):
print 'buildhsbtnevents(hs_buttonset)', str(hs_buttonset)
if hs_buttonset == 1: n = 1 # new set starting numbering over
print 'buildhsbtnevents(n)', str(n)
self.posy = hs_evblposy + hs_evblposydist # set vertical position
self.posx = hs_evblposx

end = len(self.dicthsbtnevents)
print 'dicthsbtnevents(size)', str(end)

self.btnevent = []
while n <= end:
item = dict[n]
btnstatus = 0 #item['status'] # ! to be used later !
btnname = item['name']
print 'dicthsbtnevents(while): btnname= '+btnname+', n= '+ str(n)
prev = n - 1
next = n + 1
if n == end: next = 1
if n == 1: prev = end
print 'dicthsbtnevents(after n logic): prev= '+str(prev)+', next= '+ str(next)
if btnstatus == 0: img = "off" # button is off (0)
elif btnstatus == 1: img = "on" # button is on (1)
else: img = "off" # button is other, default to off

self.btnevent.append(xbmcgui.controlbutton(int(self.posx * self.scalex),int(self.posy * self.scaley),int(140 * self.scalex),int(30 * self.scaley),btnname,2,2,'left','font13','0xffffffff','0xffffffff'))
# x, y, width, height, label, focustexture, nofocustexture, textxoffset, textyoffset, alignment, font, textcolor, disabledcolor)

self.navup = self.btnevent[prev]
self.navdown = self.btnevent[next]
self.navleft = hs_evblnavleft
self.navright = hs_evblnavright

self.btnevent[n].controlleft(self.navleft)
self.btnevent[n].controlup(self.navup)
self.btnevent[n].controlright(self.navright)
self.btnevent[n].controldown(self.navdown)

self.addcontrol(self.btnevent[n]) # display the completed button

n = n + 1 # increment counter

i get this error...
Quote: file "homecontrol_v2.py", line 315, in buildhsbtnevents
self.hs_evblnavup = self.btnevent[prev]
indexerror: list index out of range
I'm not an expert but I play one at work.
Reply
#4
you can't do the first button inside the loop (or at least can't do the navigation of the first button inside the loop in the way you are doing it) as self.btnevent[prev] (and self.btnevent[next]) is not defined yet (array out of bounds error).

you can set the actual navigation to the button controls without using the btnevent array easily enough (you seem to have the actual button controls as the navup, navdown etc. members?)

anyway, the fault at hand is the references into the btnevent array that haven't been defined yet (next and prev)

cheers,
jonathan
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
#5
you can only set navigation after the control is added to a window (that really should be mentioned somewhere prominently).

you also have a problem in that you are trying to index the next object in the array before you even put a next object in the array!

the way you should do this is in two loops:
Quote:self.buttons = []
for i in range(0,10):
self.buttons.append(xbmcgui.controlbutton(10+i*30,20,....))
self.addcontrol(self.buttons[-1]) #last button in array

for i in range (0,10):
self.buttons[i].controlup(self.buttons[(i+1)%10]) #i+1%10 will wrap the navigation)
self.buttons[(i+1)%10].controldown(self.buttons[i])

also
Quote: if btnstatus == 0: img = "off" # button is off (0)
elif btnstatus == 1: img = "on" # button is on (1)
else: img = "off"
is the same as
Quote: if btnstatus == 1: img = "on" # button is on (1)
else: img = "off"
the cnn script has a makebuttons() method that is a good example

edit jon you type too quickly!!



Reply
#6
asteron,
thanks so much, the code and the cnn script really helped!

i have one more question about this. currently i have controlright & controlleft begin defined using globals
hs_evblnavright= 'self.statlist'
hs_evblnavleft = 'self.statlist'

then in the class i have...
self.btnevent[n].controlleft(hs_evblnavleft)
self.btnevent[n].controlright(hs_evblnavright)

on my pc everything works fine, but on the xbox i get this error...

Quote:17-01-2006 20:04:30 info self.btnevent[n].controlleft(hs_evblnavleft)
17-01-2006 20:04:30 info typeerror
17-01-2006 20:04:30 info :
17-01-2006 20:04:30 info object should be of type control

here's the current py in case you need to see it...

homecontrol.zip
I'm not an expert but I play one at work.
Reply
#7
hs_evblnavright = 'self.statlist'

this makes hs_evblnavright a string (since the right hand side is a string) and so since it is not a control it cannot be passed to conrolright.

you should try just passing the list by

self.btnevent[n].controlright(self.statlist)
Reply
#8
i'm trying to make it dynamic so to pass in the controls that will be neighbors to the buttons. this is so as i add more controls on the screen, and if they need to be moved around, it will be as simple as passing in a variable. in the future of this script it will be important. i found the same problem when trying to create navigation from my listcontrol to a 'to be' defined set of generated buttons. the button control does not yet exist when i want to define the navigation for the controlleft on the listcontrol.

this code will be adapted to more complex functions as i get better at python... like image arrays.

if we had a cursor defined navigation would be unnecessary but the complexity of the screen demands more flexibility in the code if it is to be easily customizable (via a simple config file) for the end user.

the goal is to create a set of generic button generators to share with the community for future scripts.

i want to help others that want to write python scripts not need to go through the hours of 'pain' i did trying to create and learn at the same time. i have spent literally about 10x more time on this one script and trying to learn python then i did for the same outcome with jscript/asp/vbscript. very frustrating.

i do appreciate the help you, bbb, jm, and nuka have given!

below is the goal for my end result for this script... it was create using asp and very generic functions. no end-user code manipulation of functions is necessary to fully customize it. most sections of the screen are created with a sinle line input from the main asp page.
every single image is a button; the green/yellow dim bars are independant buttons.

Image



I'm not an expert but I play one at work.
Reply
#9
ok

in the main window code, after you create/add the statlist, you should assign the global the control.

Quote: self.addcontrol(self.statlist)
#if you need to *modify* a global val outside the function you have
#or make a local variable global you need to declare it with 'global'
global hs_evblnavright, hs_evblnavleft
hs_evblnavright = self.statlist
hs_evblnavleft = self.statlist

you may also need delete them from the top of the file or you might be type errors (i forget how strongly typed python is in this regard). i don't think you use them before you make statlist.

-ast
Reply

Logout Mark Read Team Forum Stats Members Help
how to create xbmcgui.ControlButton sequence?0