from ion import keydown from kandinsky import fill_rect as drawRect, draw_string as drawTxt def menu(x,y,elements,col=(0,0,0),bg_col=(255,255,255)): def kd(x): if keydown(x): while keydown(x):pass return True return False kd(4) el_size,select,txt_size,draw=25,0,[0 for i in range(len(elements))],1 while True: if kd(1): draw=1 select=max(0,select-1) if kd(2): draw=1 select=min(len(elements)-1,select+1) if kd(0): draw=1 type=elements[select][0] if type=="sld":elements[select][-1]=max(elements[select][-1]-1,elements[select][2][0]) if type=="lst":elements[select][-1]=max(elements[select][-1]-1,0) if kd(3): draw=1 type=elements[select][0] if type=="sld":elements[select][-1]=min(elements[select][-1]+1,elements[select][2][1]) if type=="lst":elements[select][-1]=min(elements[select][-1]+1,len(elements[select][2])-1) if kd(4) and elements[select][0]=="btn": break if draw: for nb,el in enumerate(elements): drawRect(x,y+el_size*nb,10*txt_size[nb],el_size,bg_col) slcted=1 if nb==select else 0 type=el[0] name=el[1] val=el[-1] if type=="btn":disp_txt=name elif type=="sld":disp_txt=name+" : {}".format(val) elif type=="lst":disp_txt=name+" : {}".format(el[2][val]) else : disp_txt="error" if slcted: disp_txt="> "+disp_txt txt_size[nb]=len(disp_txt) drawTxt(disp_txt,x,y+nb*el_size,col,bg_col) draw=0 return elements[select][1],{x[1]:x[-1] for x in elements if x[0]!="btn"}