def reverse_next(dbg, n=1): """Perform n 'reverse-next' commands.""" while n > 0: n -= 1 dbg.update_state() orig_state = dbg.state().copy() debug_loop_counter = 0 while True: debug_loop_counter += 1 fredutil.fred_debug("RN: LOOP ITERATION %d" % debug_loop_counter) if dbg.state().level() > orig_state.level(): fredutil.fred_debug("RN: DEEPER") dbg.do_next() elif dbg.state().level() < orig_state.level(): fredutil.fred_debug("RN: SHALLOWER") dbg.do_step() else: fredutil.fred_debug("RN: SAME") if dbg.state() == orig_state: fredutil.fred_debug("RN: AT ORIG STATE") if dbg.current_checkpoint().last_command_non_ignore().is_next() or \ dbg.current_checkpoint().last_command_non_ignore().is_step(): fredutil.fred_debug("RN: AFTER NEXT OR STEP") # Gene - n_lvl is apparently never used. n_lvl = dbg.state().level() undo.undo(dbg) break else: fredutil.fred_debug("RN: NOT AFTER NEXT OR STEP") undo.undo(dbg) else: fredutil.fred_debug("RN: NOT AT ORIG STATE") dbg.do_next() dbg.update_state() fredutil.fred_debug("Reverse next finished.")
def testUndo(): contestParticipants = [] backupParticipants = [] add(contestParticipants, constructorScore(1, 2, 3)) x = equals(contestParticipants) backupParticipants.append(x) add(contestParticipants, constructorScore(1, 1, 1)) x = equals(contestParticipants) backupParticipants.append(x) undo(contestParticipants, backupParticipants) print(backupParticipants) #assert contestParticipants == [{'p1': 1, 'p2': 2, 'p3': 3}]
def menuButtonHandler(name): if name == 'Draw': drawingMenuFunctions.drawingMenu(GAMESPACE, MAPS, MAINMENU, DRAWINGMENU, UNDOLIST) elif name == 'Distance': distanceTool.distanceMeasure(GAMESPACE, MAINMENU) elif name == 'Save': saveLoad.saveGame(GAMESPACE, MAPS, MAINMENU, SAVEMENU) elif name == 'Load': saveLoad.loadGame(GAMESPACE, MAPS, MAINMENU, LOADMENU) elif name == 'Undo': undo.undo(GAMESPACE, MAPS, MAINMENU, UNDOLIST) elif name == 'CharacterCreator': characterMenuFunctions.characterCreator(GAMESPACE, MAPS, MAINMENU, CHARACTERCREATORSUPER, UNDOLIST) elif name == 'About': message.message(GAMESPACE, MAINMENU, ABOUT, 'About')
def menu(): # main menu function while True: try: option0 = str(input("Use a new list or predefined? ")) assert option0 == "New" or option0 == "Predefined" break except: print("Invalid input") if option0 == "New": cit.citire() while (True): while True: try: option = input( "Give the number corresponding to the requirement: ") assert str( option) == "Undo" or int(option) >= 0 and int(option) < 6 break except: print("Invalid input") if str(option) == "Undo": undo.undo() elif int(option) == 1: ui.requirement1() elif int(option) == 2: ui.requirement2() elif int(option) == 3: ui.requirement3() elif int(option) == 4: ui.requirement4() elif int(option) == 5: ui.requirement5() elif int(option) == 0: break
def drawingMenuSubFunction(event, gamespace, maps, mainMenu, drawingMenu, undolist): shapeMenu, colorMenu = drawingMenu global width if shapeMenu.getButtonCollision(event.pos): shape = shapeMenu.buttonList[shapeMenu.getButtonCollision( event.pos)].name shapeMenu.buttonClicked(shape) if shape == 'Undo': undo.undo(gamespace, maps, shapeMenu, undolist) elif shape == 'Polygon': sketchPolygon(gamespace, drawingMenu, maps, undolist) elif shape in ('Rect', 'Circle', 'Line', 'Ellipse'): sketchOnMap(shape, gamespace, drawingMenu, maps, undolist, width[shape]) else: suffix = shape[-12:] shape = shape[:-12] if suffix == 'SizeDecrease' and width[shape] > WIDTH_LOWER_LIMIT[ shape]: width[shape] -= 1 shapeMenu.imageList[shape + "Size"].update(width[shape], True) elif suffix == 'SizeIncrease' and width[shape] < WIDTH_UPPER_LIMIT[ shape]: width[shape] += 1 shapeMenu.imageList[shape + "Size"].update(width[shape], True) shapeMenu.buttonUnclicked(shape) elif colorMenu.getButtonCollision(event.pos): gamespace.drawingColor = colorMenu.buttonList[ colorMenu.getButtonCollision(event.pos)].color shapeMenu.imageList['ColorImage'].update(gamespace.drawingColor, True)
def reverse_step(dbg, n=1): """Perform n 'reverse-step' commands.""" while n > 0: n -= 1 dbg.update_state() orig_state = dbg.state().copy() debug_loop_counter = 0 while True: debug_loop_counter += 1 fredutil.fred_debug("RS: LOOP ITERATION %d" % debug_loop_counter) if dbg.state().level() > orig_state.level(): fredutil.fred_debug("RS: DEEPER") dbg.do_next() if dbg.state() == orig_state: undo.undo(dbg) break elif dbg.state().level() < orig_state.level(): fredutil.fred_debug("RS: SHALLOWER") dbg.do_step() else: fredutil.fred_debug("RS: SAME") if dbg.state() == orig_state: fredutil.fred_debug("RS: AT ORIG STATE") if dbg.current_checkpoint().last_command_non_ignore().is_step(): fredutil.fred_debug("RS: AFTER STEP") undo.undo(dbg) break else: fredutil.fred_debug("RS: NOT AFTER STEP") undo.undo(dbg) dbg.do_step() else: fredutil.fred_debug("RS: NOT AT ORIG STATE") # TODO: This is a very inefficient implementation. dbg.do_step() if dbg.state() == orig_state: continue undo.undo(dbg) dbg.do_next() dbg.update_state() fredutil.fred_debug("Reverse step finished.")
def ui_undo_command(listOfParticipants, parts, backupParticipants): if parts[0] == 'undo' and len(parts) == 1: undo(listOfParticipants, backupParticipants)
def undo(self): undo.undo() self.notifyModification(undo.canUndo()) for listener in self.__listeners: listener.listenUndoRedo()
def command_run(text, irc, commands): if text.IRCcmd == "JOIN" and irc.joinmsg() and irc.isAwake(): if text.nick != irc.nick(): irc.msg("Welcome to the sexy plane %s. " "Enter !commands to view the bot functions." % text.nick) if text.nick in irc.modlist: if text.command in ("!wake\r\n", "!wake"): irc.wake() irc.resumeTimers() irc.msg("BellamyBot is online.") elif text.command in ("!sleep\r\n", "!sleep"): irc.sleep() irc.pauseTimers() irc.msg("Sleep mode activated") elif text.command == "!joinmsg": if text.argument in ("on\r\n", "on"): irc.activateJoinMsg() print("Join messages ON") elif text.argument in ("off\r\n", "off"): irc.deactivateJoinMsg() print("Join messages OFF") elif text.command == "!timers": if text.argument in ("on\r\n", "on"): irc.resumeTimers() elif text.argument in ("off\r\n", "off"): irc.pauseTimers() elif text.command == "!gamemode": if text.argument in ("on\r\n", "on"): irc.activateGames() print("Game mode ON") elif text.argument in ("off\r\n", "off"): irc.deactivateGames() print("Game mode OFF") elif text.command == "!setgig": try: filehandle.clear_file('text/gig') filehandle.list_append('text/gig', text.argument) except IOError as e: print(e) elif text.command == "!settour": try: filehandle.clear_file('text/tour') filehandle.list_append('text/tour', text.argument) except IOError as e: print(e) # Setlist controls elif text.command == "!add": txtfunctions.add_song(text.argument) undo.add() elif text.command == "!exp": original = filehandle.remove_nr(text.argument) check = txtfunctions.acronym_replace(text.argument) if check == original: irc.msg("There is no expansion for " + original) else: irc.msg(original + " expands to " + check) elif text.command in ("!clearset\r\n", "!clearset"): try: filehandle.clear_file('text/setlist') undo.refresh() except IOError as e: print(e) irc.msg("Current setlist has been cleared.") elif text.command in ("!pop\r\n", "!pop"): try: txtfunctions.song_pop() except IOError as e: print(e) return except IndexError as i: print(i) return undo.add() irc.msg("The last song has been erased") elif text.command == "!insert": try: response = txtfunctions.insert_song(text.argument) except IOError as e: print(e) return if response.find('ERROR') == -1: undo.add() irc.msg(response) elif text.command == "!replace": try: response = txtfunctions.replace_song(text.argument) except IOError as e: print(e) if response.find('ERROR') == -1: undo.add() irc.msg(response) elif text.command == "!delete": try: response = txtfunctions.delete_song(text.argument) except IOError as e: print(e) if response != 'Could not delete any songs.': undo.add() irc.msg(response) elif text.command in ("!setprevious\r\n", "!setprevious"): try: response = txtfunctions.set_previous() except IOError as e: print(e) except RuntimeError as r: print(r) irc.msg(response) elif text.command in ("!undo\r\n", "!undo"): if undo.undo(): irc.msg("Undid last change to setlist.") elif text.command in ("!redo\r\n", "!redo"): if undo.redo(): irc.msg("Redid last change to setlist.") elif text.command == "!cmd": cmd.function(irc, commands, text.argument) # All user commands if text.command in ("!bot\r\n", "!bot"): statePhrase = ("BellamyBot version %s created by Kueller917. Status: " % irc.version()) if irc.isAwake(): statePhrase = statePhrase + "ONLINE" else: statePhrase = statePhrase + "OFFLINE" irc.msg(statePhrase) elif text.command in ("!gig\r\n", "!gig"): try: gig = filehandle.get_list('text/gig') except IOError as e: print(e) irc.msg(gig[0]) elif text.command in ("!previous\r\n", "!previous"): gigarchive.print_recent_setlist(irc) elif text.command == "!message": try: filehandle.list_append('text/ircmsg', "%s: %s" % (text.nick, filehandle.remove_nr(text.argument))) except IOError as e: print(e) if len(irc.owners) > 0: irc.memo(irc.owners[0], "You have a message from %s" % text.nick) elif text.command in ("!source\r\n", "!source"): sourceMsg = ("Get your own copy of BellamyBot today! %s" % irc.source()) irc.msg(sourceMsg) # State dependent commands if irc.isAwake(): # General commands if text.command in ("!setlist\r\n", "!setlist"): setmsg = "CURRENT SETLIST: " try: currentset = txtfunctions.print_set('text/setlist') except IOError as e: print(e) if currentset == '': currentset = "...is empty" setmsg = setmsg + currentset irc.msg(setmsg) elif text.command == "!count": gigarchive.song_count(irc, text.argument) elif text.command == "!lastplayed": song = txtfunctions.acronym_replace(text.argument) gigarchive.last_played(irc, song) elif text.command == "!findset": gigarchive.find_setlist(irc, text.argument.strip()) elif text.command == "!loadset": date = text.argument.strip() setlist = gigarchive.print_set_by_date(irc, date) elif text.command == "!info": try: infolist = filehandle.get_list('text/info') except IOError: print('Error opening file info') return command = text.argument.strip() for line in infolist: if line.split(':')[0] == command: irc.msg(line.split(':')[1]) elif text.command == "!eval": ev = boteval.BotEval() ev.eval(irc, text.argument) elif text.command in ("!commands\r\n", "!commands"): irc.msg("Set commands: !gig, !setlist, !previous, !findset, " "!loadset, !count, !lastplayed.") irc.msg("Other: !bot, !source, !closer, !opener, !realfan, " "!roulette, !setfm, !ru-roulette, !setgen. Use !info " "for a description of any command.") elif text.command.strip() in commands: cmd.execute(irc, commands, text) if irc.gamesActive(): # Games if text.command in ("!closer\r\n", "!closer"): try: closer = musegames.random_game('text/gigcloser') except IOError as e: print(e) irc.msg("%s\'s gig has closed with %s!" % (text.nick, closer)) elif text.command in ("!opener\r\n", "!opener"): try: opener = musegames.random_game('text/opener') except IOError as e: print(e) irc.msg("%s\'s gig has opened with %s!" % (text.nick, opener)) elif text.command in ("!realfan\r\n", "!realfan"): if randint(0,1): irc.msg("%s is a REAL FAN. Good for you." % text.nick) else: irc.msg("%s is not a REAL FAN. Go away." % text.nick) elif text.command in ("!roulette\r\n", "!roulette"): output = musegames.T2L_roulette() if output != -1: irc.msg(output) else: irc.greenOn() irc.greenNick(text.nick) irc.msg("You landed on GREEN! Type !green to get your song") elif text.command in ("!green\r\n", "!green"): if irc.greenActive(): if irc.checkGreen(text.nick): irc.greenOff() irc.greenNick(None) irc.msg(musegames.roulette_green(text.nick)) else: irc.msg("You did not land on green.") elif text.command in ("!setfm\r\n", "!setfm"): setlist = setlistfm.get_setlist(irc.mbid()) for messagePart in setlist: irc.msg(messagePart) elif text.command in ("!manson\r\n", "!manson"): try: mansons = musegames.manson_game(text.nick) except IOError as e: print(e) except IndexError as i: print(i) irc.msg(mansons) elif text.command in ("!ru-roulette\r\n", "!ru-roulette"): timercommands.russian_roulette(irc, text.nick) elif text.command in ("!setgen\r\n", "!setgen"): setlistgenerator.generate(irc)