How to use pressMenu method in fMBT

Best Python code snippet using fMBT_python

menu.py

Source:menu.py Github

copy

Full Screen

...497 menudraw(scr, y+i, x+1+w-maxbinding, ' ' + mainbinding, bindattr)498 menudraw(scr, y+i, x+2+w, titlenote, attr)499 menudraw(scr, y+i, x+3+w, ls, colors.color_menu)500 vd.onMouse(scr, y+i, x, 1, w+3,501 BUTTON1_PRESSED=lambda y,x,key,p=sheet.activeMenuItems[:level]+[j]: sheet.pressMenu(*p),502 BUTTON2_PRESSED=vd.nop,503 BUTTON3_PRESSED=vd.nop,504 BUTTON1_RELEASED=vd.nop,505 BUTTON2_RELEASED=vd.nop,506 BUTTON3_RELEASED=vd.nop)507 i += 1508@VisiData.api509def nop(vd, *args, **kwargs):510 return False511@BaseSheet.property512@drawcache513def menus(sheet):514 'List of hierarchical menu items for commands available on this sheet.'515 def _menus(sheet, item):516 if item.longname:517 cmd = sheet.getCommand(item.longname)518 if cmd:519 item.cmd = cmd520 if vd.commands[item.longname].get('TableSheet', None):521 item.obj = 'TableSheet'522 elif vd.commands[item.longname].get('BaseSheet', None):523 item.obj = 'BaseSheet'524 else:525 item.obj = ''526 return item527 elif item.menus:528 menus = _menu_list(sheet, item.menus)529 if menus:530 title = getattr(item, 'title', '')531 return AttrDict(title=title, menus=menus, longname='')532 else:533 return item534 def _menu_list(sheet, menus):535 ret = []536 for i in menus:537 m = _menus(sheet, i)538 if m:539 ret.append(m)540 return ret541 return _menu_list(sheet, vd.menus)542@VisiData.api543def drawMenu(vd, scr, sheet):544 h, w = scr.getmaxyx()545 scr.addstr(0, 0, ' '*(w-1), colors.color_menu)546 disp_menu_boxchars = sheet.options.disp_menu_boxchars547 x = 1548 ymax = 4549 toplevel = sheet.menus550 for i, item in enumerate(toplevel):551 if sheet.activeMenuItems and i == sheet.activeMenuItems[0]:552 attr = colors.color_menu_active553 vd.drawSubmenu(scr, sheet, 1, x, item.menus, 1, disp_menu_boxchars)554 else:555 attr = colors.color_menu556 menudraw(scr, 0, x, ' ', attr)557 for j, ch in enumerate(item.title):558 menudraw(scr, 0, x+j+1, ch, attr | (curses.A_UNDERLINE if ch.isupper() else 0))559 menudraw(scr, 0, x+j+2, ' ', attr)560 vd.onMouse(scr, 0, x, 1, len(item.title)+2,561 BUTTON1_PRESSED=lambda y,x,key,i=i,sheet=sheet: sheet.pressMenu(i),562 BUTTON2_PRESSED=vd.nop,563 BUTTON3_PRESSED=vd.nop,564 BUTTON1_RELEASED=vd.nop,565 BUTTON2_RELEASED=vd.nop,566 BUTTON3_RELEASED=vd.nop)567 x += len(item.title)+2568 rightdisp = sheet.options.disp_menu_fmt.format(sheet=sheet, vd=vd)569 menudraw(scr, 0, x+4, rightdisp, colors.color_menu)570 if not sheet.activeMenuItems:571 return572 currentItem = getMenuItem(sheet)573 cmd = currentItem.cmd574 if not cmd:575 return576 # helpbox577 sidelines = []578 if 'push(' in cmd.execstr:579 sidelines += [vd.options.disp_menu_push + ' pushes sheet']580 if 'input' in cmd.execstr:581 sidelines += [vd.options.disp_menu_input + ' needs input']582 helpattr = colors.color_menu_help583 helpx = 30584 helpw = min(w-helpx-4, 76)585 ls,rs,ts,bs,tl,tr,bl,br,lsr,rsl = disp_menu_boxchars586 helplines = textwrap.wrap(cmd.helpstr or '(no help available)', width=helpw-4)587 # place helpbox just below deepest menu588 menuh = 2+sum(sheet.activeMenuItems[1:-1])589 menuh += len(getMenuItem(sheet, sheet.activeMenuItems[:-1]).menus)590 menuy = 16 # min(menuh, h-len(helplines)-3)591 y = menuy592 menudraw(scr, y, helpx, tl+ts*(helpw-2)+tr, helpattr) # top line593 y += 1594 # cmd.helpstr text595 for i, line in enumerate(helplines):596 menudraw(scr, y+i, helpx, ls+' '+line+' '*(helpw-len(line)-3)+rs, helpattr)597 y += len(helplines)598 if sidelines:599 menudraw(scr, y, helpx, ls+' '*(helpw-2)+rs, helpattr)600 for i, line in enumerate(sidelines):601 menudraw(scr, y+i+1, helpx, ls+' '+line+' '*(helpw-len(line)-6)+rs, helpattr)602 y += len(sidelines)+1603 menudraw(scr, y, helpx, bl+bs*(helpw-2)+br, helpattr)604 mainbinding = sheet.revbinds.get(cmd.longname, [None])[0]605 if mainbinding:606 menudraw(scr, menuy, helpx+2, rsl, helpattr)607 ks = vd.prettykeys(mainbinding or '(unbound)')608 menudraw(scr, menuy, helpx+3, ' '+ks+' ', colors.color_menu_active)609 menudraw(scr, menuy, helpx+2+len(ks)+3, lsr, helpattr)610 menudraw(scr, menuy, helpx+19, ' '+cmd.longname+' ', helpattr)611@BaseSheet.api612def pressMenu(sheet, *args):613 '''Navigate to given menupath in *args* and activate menu if not already activated. Return True if pressing current item.614 Example: sheet.pressMenu("Help", "Version")615 '''616 ret = False617 p = _intMenuPath(sheet, args)618 if p == sheet.activeMenuItems: # clicking on current menu item619 if getMenuItem(sheet, p).longname:620 ret = True621 else:622 p += [0]623 sheet.activeMenuItems = p624 if not vd.menuRunning:625 vd.runMenu()626 return ret627@BaseSheet.api628def checkMenu(sheet):629 sheet.activeMenuItems[0] %= len(sheet.menus)630@VisiData.api631def runMenu(vd):632 'Activate menu, with sheet.activeMenuItems containing the navigated menu path. Does not return until menu is deactivated.'633 old_disp_menu = vd.options.disp_menu634 vd.options.disp_menu=True635 vd.menuRunning = True636 sheet = vd.activeSheet637 vd.setWindows(vd.scrFull)638 try:639 while True:640 if len(sheet.activeMenuItems) < 2:641 sheet.activeMenuItems.append(0)642 vd.draw_all()643 k = vd.getkeystroke(vd.scrMenu, sheet)644 currentItem = getMenuItem(sheet)645 if k in ['^C', '^Q', '^[', 'q']:646 return647 elif k in ['KEY_MOUSE']:648 keystroke, y, x, winname, winscr = vd.parseMouse(menu=vd.scrMenu, top=vd.winTop, bot=vd.winBottom)649 if winname != 'menu': # clicking off the menu is an escape650 return651 f = vd.getMouse(winscr, x, y, keystroke)652 if f:653 if f(y, x, keystroke):654 break655 else:656 return657 elif k in ['KEY_RIGHT', 'l']:658 if currentItem.menus and sheet.activeMenuItems[1] != 0: # not first item659 sheet.activeMenuItems.append(0)660 else:661 sheet.activeMenuItems = [sheet.activeMenuItems[0]+1, 0]662 elif k in ['KEY_LEFT', 'h']:663 if len(sheet.activeMenuItems) > 2:664 sheet.activeMenuItems.pop(-1)665 else:666 sheet.activeMenuItems = [sheet.activeMenuItems[0]-1, 0]667 elif k in ['KEY_DOWN', 'j']:668 sheet.activeMenuItems[-1] += 1669 elif k in ['KEY_UP', 'k']:670 sheet.activeMenuItems[-1] -= 1671 elif k in [ENTER, ' ', '^J', '^M']:672 if currentItem.menus:673 sheet.activeMenuItems.append(0)674 else:675 break676 sheet.checkMenu()677 finally:678 vd.menuRunning = False679 sheet.activeMenuItems = []680 vd.options.disp_menu=old_disp_menu681 vd.draw_all()682 sheet.execCommand(currentItem.longname)683BaseSheet.addCommand('^[f', 'menu-file', 'pressMenu("File")', '')684BaseSheet.addCommand('^[e', 'menu-edit', 'pressMenu("Edit")', '')685BaseSheet.addCommand('^[v', 'menu-view', 'pressMenu("View")', '')686BaseSheet.addCommand('^[c', 'menu-column', 'pressMenu("Column")', '')687BaseSheet.addCommand('^[r', 'menu-row', 'pressMenu("Row")', '')688BaseSheet.addCommand('^[d', 'menu-data', 'pressMenu("Data")', '')689BaseSheet.addCommand('^[p', 'menu-plot', 'pressMenu("Plot")', '')690BaseSheet.addCommand('^[s', 'menu-system', 'pressMenu("System")', '')691BaseSheet.addCommand('^[h', 'menu-help', 'pressMenu("Help")', '')692BaseSheet.bindkey('^H', 'menu-help')693BaseSheet.bindkey('KEY_BACKSPACE', 'menu-help')...

Full Screen

Full Screen

V3.py

Source:V3.py Github

copy

Full Screen

1import pygame, pickle, sys, time, random, math, logging2from _thread import *3stop_threads=True#The global variable that tells the threads to stop4pygame.display.init()5pygame.font.init()6redAmber=pygame.image.load("./Assets/TL A R.png")7red=pygame.image.load("./Assets/TL R.png")8amber=pygame.image.load("./Assets/TL A.png")9green=pygame.image.load("./Assets/TL G.png")10road=pygame.image.load("./Assets/road.png")11binny=pygame.image.load("./Assets/bin.png")12tJunct=pygame.image.load("./Assets/Junction T.png")13fourJunct=pygame.image.load("./Assets/Junction +.png")14splitJunct=pygame.image.load("./Assets/Junction Split.png")15rotateImg=pygame.image.load("./Assets/Rotate.png")16edit=pygame.image.load("./Assets/Edit Tool.png")17timey=pygame.image.load("./Assets/Time.png")18WIDTH=120019HEIGHT=80020BACKGROUND=pygame.Color("#EAEAEA")21BLUE=pygame.Color("#00A896") 22OFFBLUE=pygame.Color("#88CCCC")23ORANGE=pygame.Color("#89043D")24LB=pygame.Color("#2FE6DE")25BLACK=pygame.Color("#000000")26win = pygame.display.set_mode((WIDTH, HEIGHT))27class Object(object):28 def __init__(self, x, y, width, height, typ):29 self.typ=typ30 self.x=x31 self.y=y32 self.width=int(width)33 self.height=int(height)34 self.conn=[]35 self.rotation=36036 if self.typ==redAmber:37 self.i="TL"38 elif self.typ==road:39 self.i="RD"40 elif self.typ==tJunct:41 self.i="TJ"42 elif self.typ==fourJunct:43 self.i="4J"44 elif self.typ==splitJunct:45 self.i="SJ"46 elif self.typ==timey:47 self.i="TM"48 elif self.typ==rotateImg:49 self.i="RO"50 elif self.typ==edit:51 self.i="ET"52 def move(self, xMid, yMid, win):53 self.x=xMid-(self.width/2)54 self.y=yMid-(self.height/2)55 self.conn=[]56 def checkWithin(self, x, y):57 if self.x<x and (self.x+self.width)>x:58 if self.y<y and (self.y+self.height)>y:59 return True60 return False61 def checkInside(self, x1, y1, x2, y2):62 tempX=self.x+(self.width/2)63 tempY=self.y+(self.height/2)64 if tempX>x1 and tempX<x2:65 if tempY>y1 and tempY<y2:66 return True67 return False68 69 def getXY(self):70 listy=(self.x, self.y, self.width, self.height, self.typ)71 return listy72 def draw(self, win):73 win.blit(self.typ, (int(self.x), int(self.y)))74 def addConnection(self, conn):75 self.conn.append(conn)76 77 def popConnections(self):78 temp=self.conn79 self.conn=[]80 return temp81 def pygameSux(self):82 listy=(self.x, self.y, self.i, self.conn, self.rotation)83 return listy84 85class TrafficLight(Object):86 def __init__(self, x, y, timeOn, timeOff, connections):87 Object.__init__(self, x, y, "20", "20", redAmber)88 self.x=x89 self.y=y90 self.timeOn=timeOn91 self.timeOff=timeOff92 self.connections=connections93 def setTimes(self, timeOne, timeTwo):94 self.timeOn=timeOne95 self.timeOff=timeTwo96class Road(Object):#REMINDER TO ADD ORIENTATION TO STUFF97 def __init__(self, x, y, length, con1, con2):98 Object.__init__(self, x, y, "60", "20", road)99 self.x=x100 self.y=y101 self.length=length102 self.con1=con1103 self.con2=con2104class FourJunction(Object):105 def __init__(self, x, y, conn1, conn2, conn3, conn4):106 Object.__init__(self, x, y, "60", "60", fourJunct)107 self.x=x108 self.y=y109 self.conn1=conn1110 self.conn2=conn2111 self.conn3=conn3112 self.conn4=conn4113class TJunction(Object):114 def __init__(self, x, y, conn1, conn2, conn3):115 Object.__init__(self, x, y, "60", "60", tJunct)116 self.x=x117 self.y=y118 self.conn1=conn1119 self.conn2=conn2120 self.conn3=conn3121class Split(Object):122 def __init__(self, x, y, rd1, split1, split2):123 Object.__init__(self, x, y, "60", "60", splitJunct)124 self.x=x125 self.y=y126 self.rd1=rd1127 self.split1=split1128 self.split2=split2129class Edit(Object):130 def __init__(self, x, y):131 Object.__init__(self, x, y, "20", "20", edit)132 self.x=x133 self.y=y134class Time(Object):135 def __init__(self, x, y):136 Object.__init__(self, x, y, "20", "20", timey)137 self.x=x138 self.y=y139 def move(self, x, y, win):140 pass141class Rotate(Object):142 def __init__(self, x, y):143 Object.__init__(self, x, y, "20", "20", rotateImg)144 self.x=x145 self.y=y146def assemble(bigList):147 print(bigList)148 149def timeMenu():150 print("TimeMenu")151def saveBoard(win, l, num):152 listy=[]153 length=len(l)154 for x in range (length, 0, -1):155 o=l[x-1]156 if o.checkInside(0, 600, 200, 800):157 l.remove(o)158 for i in l:159 temp=i.pygameSux()160 listy.append(temp)161 if num==0:162 with open('saveOne.pickle', 'wb') as handle:163 pickle.dump(listy, handle, protocol=pickle.HIGHEST_PROTOCOL)164 else:165 with open('saveTwo.pickle', 'wb') as handle:166 pickle.dump(listy, handle, protocol=pickle.HIGHEST_PROTOCOL)167 168def loadBoard(win, num):169 if num==0:170 with open('saveOne.pickle', 'rb') as handle:171 temp = pickle.load(handle)172 else:173 with open('saveTwo.pickle', 'rb') as handle:174 temp = pickle.load(handle)175 print(temp)176 listy=[]177 listy=assemble(temp)178 return listy179def MRS(win):180 print("MRS Running")181 win.fill(BACKGROUND)182 drawText(win, "Design Saved To File 1", 600, 300, 60, BLUE)183 pygame.display.flip()184 for x in range(4):185 for event in pygame.event.get():186 if event.type==pygame.QUIT:#Quit187 stop_threads=False188 print("Goodbye!")189 pygame.quit()190 sys.exit()191 time.sleep(0.5)192 193 win.fill(BACKGROUND)194 195 drawText(win, "Return To Menu", 60, 20, 20, BLUE)196 pygame.draw.rect(win,BLUE, (0, 10, 120, 20), 2)197 198 pygame.display.flip()199 200 while True:201 for event in pygame.event.get():202 if event.type==pygame.QUIT:#Quit203 stop_threads=False204 print("Goodbye!")205 pygame.quit()206 sys.exit()207 208 if event.type==pygame.MOUSEBUTTONDOWN:209 pos=pygame.mouse.get_pos()210 print(pos)211 if pos[0]>0 and pos[0]<160:#Return To Menu212 if pos[1]>10 and pos[1]<30:213 print("Returning To Main Menu")214 mainMenu(win)215 break216 217def GUI(win):218 print("GUI Running")219 win.fill(BACKGROUND)220 drawText(win, "Design Saved To File 1", 600, 300, 60, BLUE)221 pygame.display.flip()222 for x in range(4):223 for event in pygame.event.get():224 if event.type==pygame.QUIT:#Quit225 stop_threads=False226 print("Goodbye!")227 pygame.quit()228 sys.exit()229 time.sleep(0.5)230 231 win.fill(BACKGROUND)232 233 drawText(win, "Return To Menu", 60, 20, 20, BLUE)234 pygame.draw.rect(win,BLUE, (0, 10, 120, 20), 2)235 236 pygame.display.flip()237 238 while True:239 for event in pygame.event.get():240 if event.type==pygame.QUIT:#Quit241 stop_threads=False242 print("Goodbye!")243 pygame.quit()244 sys.exit()245 246 if event.type==pygame.MOUSEBUTTONDOWN:247 pos=pygame.mouse.get_pos()248 print(pos)249 if pos[0]>0 and pos[0]<160:#Return To Menu250 if pos[1]>10 and pos[1]<30:251 print("Returning To Main Menu")252 mainMenu(win)253 break254 255def drawText(win, text, x, y, size, colour):256 try:257 font = pygame.font.SysFont("Comic Sans", size)258 toBlit = font.render(text, 1, colour, False)259 win.blit(toBlit, ( int( x-(toBlit.get_width()/2) ) , int( y-(toBlit.get_height()/2)) ))260 except:261 logging.warning('Font Error, Saw It Coming Ngl')262def normalMenu(win, l):263 pygame.draw.rect(win,BLUE, (0, 600, 100, 100), 2)264 drawText(win, "Lights", 50, 620, 30, BLUE)265 pygame.draw.rect(win,BLUE, (100, 600, 100, 100), 2)266 drawText(win, "Roads", 150, 620, 30, BLUE)267 pygame.draw.rect(win,BLUE, (100, 700, 100, 100), 2)268 drawText(win, "Junctions", 50, 720, 30, BLUE)269 pygame.draw.rect(win,BLUE, (0, 700, 100, 100), 2)270 drawText(win, "Other", 150, 720, 30, BLUE)271 firstQuart=0272 secondQuart=0273 274 for i in l:275 c=i.getXY()276 if c[4]==redAmber:277 if c[0]>0 and c[0]<100:278 if c[1]>600 and c[1]<700:279 firstQuart=1280 elif c[4]==road:281 if c[0]>100 and c[0]<200:282 if c[1]>600 and c[1]<700:283 secondQuart=1284 if firstQuart==0:285 l.append(TrafficLight(40, 645, None, None, 0))286 elif secondQuart==0:287 l.append(Road(120, 645, None, None, None))288 return l289def junctionMenu(win, l):290 pygame.draw.rect(win,BLUE, (0, 600, 100, 100), 2)291 drawText(win, "New Junction", 50, 620, 21, BLUE)292 pygame.draw.rect(win,BLUE, (100, 600, 100, 100), 2)293 drawText(win, "4-Way", 150, 620, 30, BLUE)294 pygame.draw.rect(win,BLUE, (100, 700, 100, 100), 2)295 drawText(win, "Lane Split", 50, 720, 26, BLUE)296 pygame.draw.rect(win,BLUE, (0, 700, 100, 100), 2)297 drawText(win, "Back", 150, 720, 30, BLUE)298 firstQuart=0299 secondQuart=0300 thirdQuart=0301 for i in l:302 c=i.getXY()303 if c[4]==tJunct:304 if c[0]>0 and c[0]<100:305 if c[1]>600 and c[1]<700:306 firstQuart=1307 elif c[4]==fourJunct:308 if c[0]>100 and c[0]<200:309 if c[1]>600 and c[1]<700:310 secondQuart=1311 elif c[4]==splitJunct:312 if c[0]>0 and c[0]<100:313 if c[1]>700 and c[1]<800:314 thirdQuart=1315 if firstQuart==0:316 l.append(TJunction(20, 635, None, None, None))317 elif secondQuart==0:318 l.append(FourJunction(120, 635, None, None, None, None))319 elif thirdQuart==0:320 l.append(Split(20, 735, None, None, None))321 return l322def otherMenu(win, l):323 pygame.draw.rect(win,BLUE, (0, 600, 100, 100), 2)324 drawText(win, "Edit", 50, 620, 30, BLUE)325 pygame.draw.rect(win,BLUE, (100, 600, 100, 100), 2)326 drawText(win, "Time", 150, 620, 30, BLUE)327 pygame.draw.rect(win,BLUE, (100, 700, 100, 100), 2)328 drawText(win, "Rotate", 50, 720, 20, BLUE)329 pygame.draw.rect(win,BLUE, (0, 700, 100, 100), 2)330 drawText(win, "Back", 150, 720, 30, BLUE)331 firstQuart=0332 secondQuart=0333 thirdQuart=0334 for i in l:335 c=i.getXY()336 if c[4]==edit:337 if c[0]>0 and c[0]<100:338 if c[1]>600 and c[1]<700:339 firstQuart=1340 elif c[4]==timey:341 if c[0]>100 and c[0]<200:342 if c[1]>600 and c[1]<700:343 secondQuart=1344 elif c[4]==rotateImg:345 if c[0]>0 and c[0]<100:346 if c[1]>700 and c[1]<800:347 thirdQuart=1348 if firstQuart==0:349 l.append(Edit(40, 645))350 elif secondQuart==0:351 l.append(Time(140, 645))352 elif thirdQuart==0:353 l.append(Rotate(40, 745))354 return l355 356def drawAll(win, listy, m):357 win.fill(BACKGROUND)358 win.blit(binny, (200, 740))359 if m==0:360 listy=normalMenu(win, listy)361 if m==1:362 listy=junctionMenu(win, listy)363 if m==2:364 listy=otherMenu(win, listy)365 try:366 for i in listy:367 i.draw(win)368 except:369 pass370 return listy371def rotate(win, obj, deg):372 temp=obj.popConnections()373 typ=obj.getXY()374 obj.typ=pygame.transform.rotate(typ[4], deg)375 obj.conn=temp376 obj.width, obj.height=obj.height, obj.width377 obj.rotation+=deg378 if obj.rotation==450:379 obj.rotation=90380 381def main(win):382 print("Design Phase Started")383 pygame.display.set_caption('Design Phase')384 clock=pygame.time.Clock()385 386 itemList=[]387 l=TrafficLight(40, 645, None, None, 0)388 itemList.append(Road(120, 645, None, None, None))389 #itemList.append(Road(120, 645, None, None, None))390 itemList.append(l)391 clock.tick(540)392 menu=0393 last=False394 lastMenu=False395 saveImport=0396 #rotate(win, itemList[0], 90)397 #rotate(win, itemList[1], 90)398 while True:399 press=False400 pressMenu=False401 saveCheck=False402 itemList=drawAll(win, itemList, menu)403 x, y = pygame.mouse.get_pos()404 if x>0 and x<120:405 if y>10 and y<30:406 pygame.draw.rect(win, OFFBLUE, (0, 10, 120, 20))407 if x>1050 and x<1190:408 if y>680 and y<715:409 pygame.draw.rect(win, OFFBLUE, (1050, 680, 140, 35))410 elif y>740 and y<775:411 pygame.draw.rect(win, OFFBLUE, (1050, 740, 140, 35))412 if y>0 and y<30:413 if x>1000 and x<1100:414 pygame.draw.rect(win,OFFBLUE, (1000, 0, 100, 30))415 if x>1100 and x<1200:416 pygame.draw.rect(win,OFFBLUE, (1100, 0, 100, 30))417 drawText(win, "Return To Menu", 60, 20, 20, BLUE)418 pygame.draw.rect(win,BLUE, (0, 10, 120, 20), 2)419 drawText(win, "Run MRS", 1120, 760, 40, BLUE)420 pygame.draw.rect(win,BLUE, (1050, 740, 140, 35), 2)421 drawText(win, "Run GUI", 1120, 700, 40, BLUE)422 pygame.draw.rect(win,BLUE, (1050, 680, 140, 35), 2)423 if saveImport==0:424 pygame.draw.rect(win,BLUE, (1000, 0, 100, 30), 2)425 drawText(win, "Save", 1050, 15, 30, BLUE)426 pygame.draw.rect(win,BLUE, (1100, 0, 100, 30), 2)427 drawText(win, "Import", 1150, 15, 30, BLUE)428 elif saveImport==1:429 pygame.draw.rect(win,BLUE, (1000, 0, 100, 30), 2)430 drawText(win, "File 1", 1050, 15, 30, BLUE)431 pygame.draw.rect(win,BLUE, (1100, 0, 100, 30), 2)432 drawText(win, "File 2", 1150, 15, 30, BLUE)433 elif saveImport==2:434 pygame.draw.rect(win,BLUE, (1000, 0, 100, 30), 2)435 drawText(win, "File 1", 1050, 15, 30, BLUE)436 pygame.draw.rect(win,BLUE, (1100, 0, 100, 30), 2)437 drawText(win, "File 2", 1150, 15, 30, BLUE)438 if pygame.mouse.get_pressed()[0]:439 try:440 posX, posY=event.pos441 442 if last:443 l.move(posX, posY, win)444 press=True445 446 else:447 if posX>0 and posX<160:#Return To Menu448 if posY>10 and posY<30:449 print("Returning To Main Menu")450 mainMenu(win)451 break452 453 elif posX>1050 and posX<1190:#Run GUI or MRS454 if posY>740 and posY<770:455 MRS(win)456 break457 458 elif posY>680 and posY<710:459 GUI(win)460 break461 462 if posX>130 and posX<150:463 if posY>635 and posY<655:464 for i in itemList:465 temp=i.pygameSux()466 spareList.append(temp)467 print(spareList)468 with open('spareSave.pickle', 'wb') as handle:469 pickle.dump(spareList, handle, protocol=pickle.HIGHEST_PROTOCOL)470 timeMenu()471 if posY>0 and posY<30:472 if posX>1000 and posX<1100:473 if not lastSave:474 if saveImport==1:475 saveBoard(win, itemList, 0)476 saveImport=0477 elif saveImport==2:478 itemList=loadBoard(win, 0)479 saveImport=0480 elif saveImport==0:481 saveImport=1482 saveCheck=True483 elif posX>1100 and posX<1200:484 if not lastSave:485 if saveImport==0:486 saveImport=2487 elif saveImport==1:488 saveBoard(win, itemList, 1)489 saveImport=0490 elif saveImport==2:491 itemList=loadBoard(win, 1)492 saveImport=0493 saveCheck=True494 for i in itemList:495 if i.checkWithin(posX, posY):496 i.move(posX, posY, win)497 l=i498 press=True499 break500 501 if not press:502 if menu==0:503 if posY>700 and posY<800:504 if posX>0 and posX<100:505 if not lastMenu:506 menu=1507 press=True508 length=len(itemList)509 for x in range (length, 0, -1):510 o=itemList[x-1]511 if o.checkInside(0, 600, 200, 800):512 itemList.remove(o)513 514 pressMenu=True515 516 elif posX>100 and posX<200:517 if not lastMenu:518 menu=2519 length=len(itemList)520 for x in range (length, 0, -1):521 o=itemList[x-1]522 if o.checkInside(0, 600, 200, 800):523 itemList.remove(o)524 pressMenu=True525 526 elif menu==1:527 if posX>100 and posX<200:528 if posY>700 and posY<800:529 if not lastMenu:530 menu=0531 length=len(itemList)532 for x in range (length, 0, -1):533 o=itemList[x-1]534 if o.checkInside(0, 600, 200, 800):535 itemList.remove(o)536 pressMenu=True537 538 elif menu==2:539 if posX>100 and posX<200:540 if posY>700 and posY<800:541 if not lastMenu:542 menu=0543 length=len(itemList)544 for x in range (length, 0, -1):545 o=itemList[x-1]546 if o.checkInside(0, 600, 200, 800):547 itemList.remove(o)548 pressMenu=True549 550 except:551 logging.warning("Event.pos Error, SAW IT COMING NGL")552 if last==True and press==False:553 for i in itemList:554 one=l.getXY()555 two=i.getXY()556 if i.checkInside(200, 740, 240, 800):557 itemList.remove(i)558 elif two[4]==edit:559 for x in itemList:560 if not x==i:561 if x.checkWithin(two[0]-(two[2]/2), two[1]-(two[3]/2)):562 print("!")563 itemList.remove(i)564 elif two[4]==rotateImg:565 itemList.remove(i)566 elif l!=i:567 if i.rotation%180==0 and l.rotation%180==0:568 temp=one[0]+one[2]569 y1=one[1]+(one[3]/2)570 y2=two[1]+(two[3]/2)571 if (temp+10)>two[0] and (temp-10)<two[0]:572 if (y1+10)>y2 and (y1-10)<y2:573 l.move(two[0]-(one[2]/2), y2, win)574 575 temp=two[0]+two[2]576 if (temp+10)>one[0] and (temp-10)<one[0]:577 if (y1+10)>y2 and (y1-10)<y2:578 l.move(two[0]+two[2]+(one[2]/2), y2, win)579 if not i.rotation%180==0 and not l.rotation%180==0:580 temp=one[1]+one[3]581 x1=one[0]+(one[2]/2)582 x2=two[0]+(two[2]/2)583 if (temp+10)>two[1] and (temp-10)<two[1]:584 if (x1+10)>x2 and (x1-10)<x2:585 l.move(x2, two[1]-(one[3]/2), win)586 587 temp=two[1]+two[3]588 if (temp+10)>one[1] and (temp-10)<one[1]:589 if (x1+10)>x2 and (x1-10)<x2:590 l.move(x2, two[1]+two[3]+(one[3]/2), win)591 592 593 for event in pygame.event.get():594 if event.type==pygame.QUIT:#Quit595 stop_threads=False596 logging.critical("Goodbye!")597 pygame.quit()598 sys.exit() 599 600 if press:601 last=True602 else:603 last=False604 if pressMenu:605 lastMenu=True606 else:607 lastMenu=False608 if saveCheck:609 lastSave=True610 else:611 lastSave=False612 613 pygame.display.flip()614 615 mainMenu(win)616def threaded_title(win, WIDTH, HEIGHT):617 global stop_threads618 while stop_threads:619 if stop_threads:620 win.fill(BACKGROUND) 621 drawText(win, "Traffic Light Optimiser", int(WIDTH/2), int(-200+HEIGHT/2), 60, BLUE)622 drawText(win, "Click To Start", int(WIDTH/2), int(-100+HEIGHT/2), 50, BLUE)623 pygame.display.flip() 624 else:625 break626 time.sleep(0.5)627 if stop_threads:628 win.fill(BACKGROUND) 629 drawText(win, "Traffic Light Optimiser", int(WIDTH/2), int(-200+HEIGHT/2), 60, BLUE) 630 pygame.display.flip()631 else:632 break633 time.sleep(0.5)634 print("Thread Ended")635 return636def mainMenu(win):637 global stop_threads 638 print("Running Main Menu")639 pygame.display.set_caption("Reinforcement Learning Traffic Lights") 640 stop_threads=True 641 run = True 642 clock = pygame.time.Clock() 643 start_new_thread(threaded_title, (win, WIDTH, HEIGHT))644 print("Thread Started") 645 while run:646 clock.tick(30) 647 for event in pygame.event.get():648 if event.type==pygame.QUIT:#Quit649 stop_threads=False650 logging.critical("Goodbye!")651 pygame.quit()652 sys.exit()653 if event.type==pygame.MOUSEBUTTONDOWN:654 run = False655 stop_threads=False656 main(win)657while True:658 mainMenu(win)...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

...59 self.label_information.text = self.information_bus60 print(self.information_bus)61 busapp.mapscreen.addBusMarker(bus_taken)6263 def pressMenu(self, *args):64 busapp.screenmanager.current = "Menu principal"6566 def pressMap(self, *args):67 busapp.screenmanager.current = "Menu map"6869 def pressBus(self, *args):70 busapp.screenmanager.current = "Menu bus"717273# Une classe permettant l'affichage d'un écran74# qui affichera la carte avec lequelle des interaction seront possible75class MapScreen(Screen):7677 def __init__(self, **kwargs):78 super(MapScreen, self).__init__(**kwargs)79 self.fl = FloatLayout()80 with self.fl.canvas:81 Color(1, 1, 1, .8, mode='rgba')82 Rectangle(size=Window.size)8384 self.mapview = MapView(zoom=13, lat=48.35, lon=-1.2, pos_hint={"top":0.9}, size_hint=(1, .7))85 self.arret_list = []86 self.bus_onMap = None87 self.arret_onMap = None88 self.button_menu = Button(height=40, width=40, size_hint=(None, None), pos=(20, 0), pos_hint={'top': 0.97})89 self.button_menu.bind(on_press=lambda x: self.get_coo())90 self.button_tr_info = Button(size_hint=(1 / 3, .1), pos=(0, 0), pos_hint={'top': 0.1}, text="Menu")91 self.button_tr_info.bind(on_press=self.pressMenu)92 self.button_tr_map = Button(size_hint=(1 / 3, .1), pos=(Window.size[0] / 3, 0), pos_hint={'top': 0.1}, text="Map")93 self.button_tr_map.bind(on_press=self.pressMap)94 self.button_tr_bus = Button(size_hint=(1 / 3, .1), pos=(Window.size[0] / 1.5, 0), pos_hint={'top': 0.1}, text="Bus")95 self.button_tr_bus.bind(on_press=self.pressBus)96 self.fl.add_widget(self.button_menu)97 self.fl.add_widget(self.button_tr_info)98 self.fl.add_widget(self.button_tr_map)99 self.fl.add_widget(self.button_tr_bus)100101 self.fl.add_widget(self.mapview)102 self.add_widget(self.fl)103104 def pressMenu(self, *args):105 busapp.screenmanager.current = "Menu principal"106107 def pressMap(self, *args):108 busapp.screenmanager.current = "Menu map"109110 def pressBus(self, *args):111 busapp.screenmanager.current = "Menu bus"112113 def addBusMarker(self, bus_taken):114 info = data_bus[bus_taken]115 if self.bus_onMap == True:116 self.mapview.remove_marker(self.bus_marker)117 self.removeArretMarker()118 else:119 self.bus_onMap = True120 self.bus_marker = MapMarkerPopup(lat=info["latitude"], lon=info["longitude"], source="bus_marker2.png", size=(20, 20))121122 self.bus_marker.add_widget(Label(pos=(0,-40), text=bus_taken, color=(0,0,0,1)))123 self.mapview.add_marker(self.bus_marker)124125 self.mapview.get_latlon_at(Window.size[0]/2, Window.size[1]/2, zoom=None)126 self.addArretMarker("Ligne-"+info["ligne"])127128 def addArretMarker(self, ligne):129 for arret in data_stop[ligne]:130 print(arret)131 arret_marker = MapMarkerPopup(lat=data_stop[ligne][arret]["latitude"], lon=data_stop[ligne][arret]["longitude"],132 source="bus_stop.png")133 arret_marker.add_widget(Label(pos=(0, -40), text=data_stop[ligne][arret]["name"], color=(0, 0, 0, 1)))134 self.arret_list.append(arret_marker)135 self.mapview.add_marker(arret_marker)136137 def removeArretMarker(self):138 for arret in self.arret_list:139 self.mapview.remove_marker(arret)140 self.arret_list.clear()141142 def get_coo(self):143 print(self.arret_list)144 print(str(self.mapview.get_latlon_at(Window.size[0] / 2, Window.size[1] / 2, zoom=None)))145146147# Une classe permettant l'affichage d'un écran148# qui permettra à l'utilisateur de selectionné un bus149# pour lequel il veut connaitre les information150class BusScreen(Screen):151 def __init__(self, **kwargs):152 super(BusScreen, self).__init__(**kwargs)153 self.fl = FloatLayout()154 with self.fl.canvas:155 Color(1, 1, 1, .8, mode='rgba')156 Rectangle(size=Window.size)157 self.button_menu = Button(height=40, width=40, size_hint=(None, None), pos=(20, 0), pos_hint={'top': 0.97})158 self.button_tr_info = Button(size_hint=(1 / 3, .1), pos=(0, 0), pos_hint={'top': 0.1}, text="Menu")159 self.button_tr_info.bind(on_press=self.pressMenu)160 self.button_tr_map = Button(size_hint=(1 / 3, .1), pos=(Window.size[0] / 3, 0), pos_hint={'top': 0.1}, text="Map")161 self.button_tr_map.bind(on_press=self.pressMap)162 self.button_tr_bus = Button(size_hint=(1 / 3, .1), pos=(Window.size[0] / 1.5, 0), pos_hint={'top': 0.1}, text="Bus")163 self.button_tr_bus.bind(on_press=self.pressBus)164 self.button_bus1 = Button(size_hint=(.3, .1), pos=(20, 0), pos_hint={'top': 0.85}, text="Bus-1")165 self.button_bus1.bind(on_press=lambda x:busapp.mainscreen.bus_choice("Bus-1"))166 self.button_bus2 = Button(size_hint=(.3, .1), pos=(20, 0), pos_hint={'top': 0.75}, text="Bus-2")167 self.button_bus2.bind(on_press=lambda x:busapp.mainscreen.bus_choice("Bus-2"))168 self.fl.add_widget(self.button_menu)169 self.fl.add_widget(self.button_tr_info)170 self.fl.add_widget(self.button_tr_map)171 self.fl.add_widget(self.button_tr_bus)172 self.fl.add_widget(self.button_bus1)173 self.fl.add_widget(self.button_bus2)174175 self.add_widget(self.fl)176177 def pressMenu(self, *args):178 busapp.screenmanager.current = "Menu principal"179180 def pressMap(self, *args):181 busapp.screenmanager.current = "Menu map"182183 def pressBus(self, *args):184 busapp.screenmanager.current = "Menu bus"185186187# classe principale permettant de lancer l'application et de gerer chaque un des écran188class MyApp(App):189 def build(self):190 self.screenmanager = ScreenManager()191 self.screenmanager.transition = NoTransition() ...

Full Screen

Full Screen

drawer.js

Source:drawer.js Github

copy

Full Screen

1// SPDX-FileCopyrightText: 2021-2022 The Manyverse Authors2//3// SPDX-License-Identifier: CC0-1.04const wd = require('wd');5const RECOVERY = require('./utils/recovery');6module.exports = function (driver, t) {7 t.test('Drawer has some menu items', async function (t) {8 await driver.sleep(2000);9 // Open drawer10 const pressMenu = new wd.TouchAction(driver);11 pressMenu.press({x: 80, y: 150});12 pressMenu.release();13 await driver.performTouchAction(pressMenu);14 t.pass('I press the Menu (top left corner)');15 t.ok(16 await driver.elementByAndroidUIAutomator(17 'new UiSelector().descriptionContains("My Profile")',18 ),19 'I see "My profile"',20 );21 t.ok(22 await driver.elementByAndroidUIAutomator(23 'new UiSelector().descriptionContains("Show Raw Database")',24 ),25 'I see "Raw database"',26 );27 t.ok(28 await driver.elementByAndroidUIAutomator(29 'new UiSelector().descriptionContains("Send Bug Report as Email")',30 ),31 'I see "Email bug report"',32 );33 t.ok(34 await driver.elementByAndroidUIAutomator(35 'new UiSelector().descriptionContains("Go To Settings")',36 ),37 'I see "Settings"',38 );39 t.end();40 });41 t.test("Drawer shows user's id", async function (t) {42 const partOfId = RECOVERY.id.substr(0, 10);43 t.ok(44 await driver.waitForElementByAndroidUIAutomator(45 'new UiSelector().textContains("' + partOfId + '")',46 6000,47 ),48 'I see my user id on the drawer',49 );50 t.end();51 });52 t.test('Drawer can be hidden by sliding', async function (t) {53 await driver.sleep(2000);54 // Open drawer55 const pressMenu = new wd.TouchAction(driver);56 pressMenu.press({x: 80, y: 150});57 pressMenu.wait(20);58 pressMenu.release();59 await driver.performTouchAction(pressMenu);60 t.pass('I open the drawer');61 // Slide drawer out of view62 const slideToLeft = new wd.TouchAction(driver);63 slideToLeft.press({x: 300, y: 500});64 slideToLeft.wait(60);65 slideToLeft.moveTo({x: 50, y: 500});66 slideToLeft.release();67 await driver.performTouchAction(slideToLeft);68 t.pass('I slide the drawer out of view');69 await driver.sleep(1000);70 t.ok(71 await driver.waitForElementByAndroidUIAutomator(72 'new UiSelector().text("Public posts")',73 6000,74 ),75 'I see the Central screen and the Public tab',76 );77 t.end();78 });79 t.test('Drawer has a link to the Settings screen', async function (t) {80 await driver.sleep(2000);81 // Open drawer82 const pressMenu = new wd.TouchAction(driver);83 pressMenu.press({x: 80, y: 150});84 pressMenu.release();85 await driver.performTouchAction(pressMenu);86 t.pass('I open the drawer');87 const aboutButton = await driver.elementByAndroidUIAutomator(88 'new UiSelector().descriptionContains("Go To Settings")',89 );90 await aboutButton.click();91 t.pass('I tap the Settings button');92 t.end();93 });...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful