def play_thru(self, autoplay=False): goban = Goban(int(self.header_dict['SZ'])) #, skinfile=self.skin) color = 'black' for _, turn in enumerate(self.moves): goban.place_stone(turn[0], int(turn[1:]), color) if autoplay: func = lambda: time.sleep(.25) else: func = Cli.wait Cli.make_page(self.label, str(goban), func) if color == 'white': color = 'black' elif color == 'black': color = 'white'
def main(): """Launch an interface, i.e., main loop.""" if SHELL.interface == 'Tk': SHELL.main_window.mainloop() else: while True: f = lambda: SHELL.list_menu(MENU_OPTS) action = Cli.make_page(func=f) if action == 1: scriptname = choose_file(SCRIPT_LIST) MENU_OPTS.items[0] = scriptname elif action == 2: shell_name = select_shell(SHELL_LIST) MENU_OPTS.items[1] = shell_name elif action == 3: pass elif action == 4: try: run_script(scriptname, shell_name) except KeyboardInterrupt: continue elif action == 5: open_in_editor(scriptname) elif action == 6: sys.exit(0)
def work_with_p_files(cartesian): """ Writes instance to pickle file or loads instance from pickle file. """ #global file_list, pickle_list if ARGS and ARGS.infile: infile = ARGS.infile else: infile = 'save.p' current_dir = os.getcwd() file_list = os.listdir(current_dir) filemenu_list = ['..', 'save as pickle', 'open a pickle file'] if infile in file_list: filemenu_list.append("reopen '" + infile + "'") menu1 = PlainList(filemenu_list) #pickle_list = [] sel1 = Cli.make_page('pickle', cartesian, lambda: SHELL.list_menu(menu1)) if sel1 == 2: cartesian.save_p_file(BASENAME) elif sel1 != 1: cartesian = Cli.open_p_file() return cartesian
def access_gnugo_functs(self, basename): """ Scoring/estimating tools from gnugo; this should take filename instead. """ Cli.make_page( 'WRITE FILE: {}.sgf'.format(basename), self, lambda: self.write_sgf( basename)) menu1 = ListPrompt(['..', 'fast', 'medium', 'slow']) sel1 = Cli.make_page('MENU: GNUGO Scoring Tools', self, menu1.input) gnugo_dict = {'fast':'estimate', 'medium':'finish', 'slow':'aftermath'} print('') #pylint: disable=C0325 if sel1 != 1: os.system('gnugo --score ' + gnugo_dict[menu1.items[sel1 - 1]] +\ ' --quiet -l {}.sgf'.format(basename)) Cli.wait()
def main(): """ Lets user browse and preview skins for the Goban class. """ goban = Goban(sh_obj=SHELL, size=9) if __name__ == '__main__': while True: choice = Cli.make_page(func=lambda: SHELL.list_menu(LIST_OBJ)) skinfile = LIST_OBJ[choice - 1] try: if SHELL.py_version == 2: goban.skin_dict = json.load(open('skins/' + skinfile, 'rb')) elif SHELL.py_version == 3: file_ptr = open('skins/{}'.format(skinfile), 'rb') text_buffer = file_ptr.read().decode('utf-8') goban.skin_dict = json.loads(text_buffer) except IOError: Cli.text_splash(Cli.box("File Error with '{}'".format( skinfile)), duration=0) SHELL.wait() continue goban.cursor = [0, 0] Cli.text_splash("== Now give '{}' a try! ==".format( skinfile), duration=1, flashes=4) goban.view_edit()
def main(): """ Feed fortunes to the selected ASCII character. """ parse_help_flag() Cli() cow = '' message1 = define_text() cow_num = Cli.make_page('UP NEXT: {}'.format(message1), '', MENU_FUNC) while True: message2 = message1 message1 = define_text() cow = LIST_OBJ[cow_num - 1] ascii_cow = subprocess.check_output( 'echo "{}"|cowsay -f {}'.format(message2, cow), shell=True) ascii_cow = "\n\n{}\n\n".format(ascii_cow) Cli.make_page('UP NEXT: {}'.format(message1), ascii_cow, Cli.wait) cow_num = Cli.make_page('UP NEXT: {}'.format(message1), '', MENU_FUNC)
def select_shell(shell_list_): """ Select shell to use. """ if SHELL.interface == 'bash': listobj = AbstractList(shell_list_) shell_menu = lambda: SHELL.list_menu(listobj) number = Cli.make_page(func=shell_menu) shell_name_ = shell_list_[number - 1] elif SHELL.interface == 'Tk': shell_name_ = shellvar.get().strip() return shell_name_
def graph_operations(cartesian): """ Functions relating to the board: edit it, trash it, view it with an external viewer. """ plane_response = Cli.make_page( 'MENU: Plane', cartesian, lambda: SHELL.list_menu(PLANE_OPTS)) if plane_response == 2: cartesian.view_edit() elif plane_response == 3: try: color = cartesian.color_chooser() cartesian.fill(color) except KeyboardInterrupt: pass elif plane_response == 4: if ARGS and ARGS.external: Cli.make_page( 'FILE: {}.sgf'.format(BASENAME), cartesian, lambda: cartesian.write_sgf(BASENAME)) # View board (with external app). If gnugo is specified, append the #appropriate flags. if ARGS and ARGS.external == 'gnugo': proc = subprocess.Popen( 'gnugo --mode ascii --quiet -l {}.sgf'.format(BASENAME), shell=True) else: proc = subprocess.Popen( '{} {}.sgf'.format(ARGS.external, BASENAME), shell=True) proc.wait() # Trash board and create a new one the same size else: cartesian = _make_graph() elif plane_response == 5: cartesian = _make_graph() return cartesian
def choose_file(script_list_): """ Choose file to run. """ if SHELL.interface == 'Tk': val = menu1.curselection() scriptname_ = script_list_[val[0]] elif SHELL.interface == 'bash': listobj = AbstractList(script_list_) script_menu = lambda: SHELL.list_menu(listobj) number = Cli.make_page(func=script_menu) scriptname_ = script_list_[number - 1] return scriptname_
def file_actions(cartesian): """ work with files: open or save """ sel1 = Cli.make_page( 'MENU: File Actions', cartesian, lambda: SHELL.list_menu(FILE_OPTS)) if sel1 == 2: cartesian.write_txt(BASENAME) elif sel1 == 3: cartesian.write_sgf(BASENAME) elif sel1 == 4: cartesian.save_p_file(BASENAME) elif sel1 == 5: cartesian = Cli.open_p_file() # A = A.__class__.open_p_file() elif sel1 == 6: cartesian = work_with_p_files(cartesian) return cartesian
def main(): """ Gets the user's choice and gives them a preview. """ _first_pass = True art = '' if __name__ == '__main__': while True: if SHELL.interface in ['dialog'] and not _first_pass: Cli.wait() else: _first_pass = False #selection = Cli.make_page(obj='\n' + art, func=menu_func) selection = Cli.make_page( obj='\n' + art, func=lambda: SHELL.list_menu(LIST_OBJ)) if selection == -1: break figlet_font = FONT_OPTIONS[selection - 1] art = subprocess.check_output('toilet --gay -f {} "{}"'.format( figlet_font, PHRASE), shell=True)
def main(): """ user can create a collection of Thing objects """ things = [] label_pile = [str(thing) for thing in things] enum = Enumeration(label_pile, 'Inventory') # Start Screen SHELL.welcome( 'Things', 'This is a test/demonstration of my cjh.shell module and Thing class.') print('') # pylint: disable=C0325 selection = SHELL.list_menu(MAIN_MENU) while True: if selection == 1: name = form( enum, selection, lambda: SHELL.input('\nName of thing: ')) something = Thing() something.label = name things.append(something) elif selection == 2: form(enum, selection, Cli.wait) elif selection == 3: discard_menu = ListPrompt(label_pile) if len(things) > 0: print('Choose a <Thing> to Discard.') # pylint: disable=C0325 discard = form( enum, selection, lambda: discard_menu.input(hidden=True)) things.remove(things[discard - 1]) elif selection == 4: print('\n') # pylint: disable=C0325 sys.exit('Good bye.') label_pile = [str(thing) for thing in things] enum = Enumeration(label_pile, 'Inventory') selection = Cli.make_page( header='Main Menu', obj=str(enum) + Cli.hrule( width=.333, string=True), func=lambda: SHELL.list_menu(MAIN_MENU))
def main(): """ the main function """ #fx_list = [] if ARGS is not None and ARGS.quiet is False: SHELL.welcome( script_name='== simple graph calc ==', description='A simple text-based graphing calculator.') graph = _make_graph() # if there is an --infile, open graph in editor if ARGS is not None and ARGS.infile is True: graph.view_edit() # Main Loop while True: if SHELL.interface in ['bash']: Cli.clear() # Will this work on SL4A? main_response = Cli.make_page( 'MENU: Main', graph, lambda: SHELL.list_menu(MAIN_OPTS)) print(main_response) #use try keyboard interrupt if main_response == 1: graph = graph_operations(graph) elif main_response == 2: graph = functions_menu(graph) elif main_response == 3: graph.access_gnugo_functs(BASENAME) elif main_response == 4: graph = file_actions(graph) else: break
def form(enum, selection, function): """ print appropriate header and page content, then run function f """ return Cli.make_page( header=MENU_OPTIONS[selection - 1], obj=str(enum), func=function)
def functions_menu(cartesian): """ Add/View Functions """ while True: funct_response = Cli.make_page( 'MENU: Functions', cartesian, lambda: SHELL.list_menu(FUNCT_OPTS)) if funct_response == 1: break elif funct_response == 2: # List attached functions--currently Polynoms only Cli.make_page('view functions', cartesian, cartesian.list_functs) elif funct_response == 3: # Auto-Shapes menu2 = PlainList(['..', 'ellipse', 'sine wave']) while True: sel2 = Cli.make_page( 'auto-shapes', cartesian, lambda: SHELL.list_menu(menu2)) if sel2 == 1: break if sel2 == 2: # Ellipses/Circles menu3 = PlainList(['..', 'circle', 'ellipse']) # Perhaps the interface should not be like this and it # should return all the way up to the 'Functions' menu? # But maybe it's good as it is. while True: sel3 = Cli.make_page( 'plot an ellipse', cartesian, lambda: SHELL.list_menu(menu3)) if sel3 == 1: break if sel3 == 2: try: color = cartesian.color_chooser() Cli.make_page( 'circles', cartesian, lambda: cartesian.prompt_circle(color)) except KeyboardInterrupt: pass elif sel3 == 3: try: color = cartesian.color_chooser() Cli.make_page( 'ellipse', cartesian, lambda: cartesian.prompt_ellipse(color)) except KeyboardInterrupt: pass elif sel2 == 3: # Sine Waves try: color = cartesian.color_chooser() main_text = refresh_main_table(cartesian) Cli.make_page( 'plot a sine wave', main_text, lambda: cartesian.prompt_wave(color)) except KeyboardInterrupt: pass elif funct_response == 4: cartesian.add_polynomial() elif funct_response == 5: try: color = cartesian.color_chooser() main_text = refresh_main_table(cartesian) Cli.make_page( 'plot a point', main_text, lambda: cartesian.prompt_point( color)) except KeyboardInterrupt: pass return cartesian