menulib3.py

Created by fime

Created on December 13, 2023

1.32 KB


from kandinsky import draw_string as text
from ion import keydown as key
from time import sleep

def menuInter(ox,oy,name,*inpwids,s=0,bg=(255,255,255),fg=(0,0,0),sl=(255,0,0)):
  wids=[wid.split(',') for wid in inpwids]
  n_wids,p=len(wids),1
  text(name,ox,oy,fg,bg)
  def drawWid(i,s):
    wid=wids[i]+[0]*20
    txt=["{} →","- {} -","{} : %s"%(wid[wid[2]+3]),"{} : %d"%(wid[2])][("btn","lbl","lst","sld").index(wid[0])].format(wid[1])
    col=(fg,sl,bg)[s]
    text(txt,ox,oy+(i+1)*25,col,bg)
  for i,wid in enumerate(wids):
    if wid[0] in "lstsld":wids[i][2]=int(wid[2])
    drawWid(i,i==s)
  while 1:
    drawWid(s,1)
    scan=[k for k in range(5) if key(k)]
    if scan==[]:
      p=0
      continue
    elif p:continue
    v,h,p=0,0,1
    if (4 or 3) in scan and wids[s][0]=="btn":return s
    if 1 in scan:v=-1
    if 2 in scan:v=+1
    if v!=0 :
      drawWid(s,0)
      s=(s+v)%n_wids
      while wids[s][0]=="lbl":s=(s+v)%n_wids
    if wids[s][0]=="btn":continue
    drawWid(s,2)
    if 0 in scan:h=-1
    if 3 in scan:h=+1
    if wids[s][0]=="lst":
      wids[s][2]=(wids[s][2]+h)%len(wids[s][3:])
    else:
      m,M=int(wids[s][3]),int(wids[s][4])
      wids[s][2]=(wids[s][2]+h-m)%(M-m+1)+m

widgets=(
"lbl,Category 1",
"btn,Validate",
"lst,Mode,0,Solo,Vs Bot",
"sld,Diff,5,2,7")

menuInter(25,25,"MENU",*widgets)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.