コード例 #1
0
def set_dots_button():
    global loop_no
    global first_set_app
    global app
    global board_frame, msg_main_frame, msg_frame, sqs
    global width, height, min_xlen, nx, ny
    global n_rearrange_cycles, rearrange_cycle
    global players, sp
    global move_no_label
    global snapshot1, snapshot2         # tracemalloc instances
    global board_change
    global run_game
    
    loop_no += 1 
    SlTrace.lg("\nLoop %d" % loop_no)
    SlTrace.lg("Memory Used: %.0f MB, Change: %.2f MB"
                % (SlTrace.getMemory()/1.e6, SlTrace.getMemoryChange()/1.e6))
    SlTrace.lg("Dots Set Button", "button")

    if SlTrace.trace("pgm_stack"):
        stack = traceback.extract_stack()
        SlTrace.lg("pgm_stack depth=%d" % len(stack))
        if SlTrace.trace("pgm_stack_list"):
            list_len = 14
            print_list = traceback.format_list(stack)
            for line in print_list[-list_len:]:
                SlTrace.lg("  " + line)
    app = setup_app()
    
    app.update_form()
        
        
        
    min_xlen = app.get_component_val("figure_size", "min", min_xlen)
    min_xlen = float(min_xlen)
    min_xlen = str(min_xlen)
    min_ylen = min_xlen
    
    ###rects.append(rect1)
    ###rects.append(rect2)
    xmin = .1*float(width)
    xmax = .9*float(width)
    xlen = (xmax-xmin)/float(nx)
    min_xlen = float(min_xlen)
    if xlen < min_xlen:
        SlTrace.lg("nx=%d xlen(%.0f) set to %.0f" % (nx, xlen, min_xlen))
        xlen = min_xlen
    ymin = .1*float(height)
    ymax = .9*float(height)
    ylen = (ymax-ymin)/float(ny)
    min_ylen = float(min_ylen)
    if ylen < min_ylen:
        SlTrace.lg("ny=%d ylen(%.0f) set to %.0f" % (ny, ylen, min_ylen))
        ylen = min_ylen

    if board_change:
        if board_frame is not None:    
            board_frame.destroy()
            board_frame = None
        if msg_main_frame is not None:    
            msg_main_frame.destroy()
            msg_main_frame = None
        if sqs is not None:
            sqs.destroy()
            sqs = None
        if sp is not None:
            sp.destroy()
            sp = None
        board_frame = Frame(mw, width=width, height=height, bg="", colormap="new")
        board_frame.pack(side="top", fill=NONE, expand=NO)
        msg_main_frame = Frame(mw)
        msg_main_frame.pack(side="bottom", expand=NO, fill=BOTH)
        msg_frame = Frame(msg_main_frame)
        msg_frame.pack(side="bottom", expand=YES, fill=BOTH)
        board_change = False
    if sqs is None:
        sqs = SelectDots(board_frame, mw=mw,
                        image_hash=image_hash,
                        display_game=display_game,
                        nrows=ny, ncols=nx,
                        width=width, height=height,
                        check_mod=check_mod)
        sqs.display()
            
    if sp is None:
        if command_stream is not None:
            command_stream.reset()      # Reset stream
        sp = SelectPlay(board=sqs, msg_frame=msg_frame,
                        display_game=display_game,
                        results_file=rF,
                        mw=mw, start_run=False,
                        numgame=numgame,
                        game_control=game_control,
                        cmd_stream=command_stream,
                        player_control=player_control,
                        profile_running=profile_running,
                        on_exit=pgm_exit,
                        on_end=end_game,
                        move_first=1, before_move=before_move,
                        after_move=after_move,
                        show_ties=show_ties,
                        undo_micro_move=undo_micro_move,
                        undo_len=undo_len)
        ###if command_stream is not None:
        ###    command_stream.set_play_control(sp)
        ###    command_stream.set_cmd_stream_proc(sp.cmd_stream_proc)
        if player_control is not None:
            player_control.set_play_control(sp)
            score_window.set_play_control(sp)
    sp.set_stroke_move(stroke_move)
    if first_set_app:
        if run_resets:
            sp.reset_score()
    if show_players:
        show_players_window(display=show_players)
    player_control.set_all_scores(0)
    ###if show_score:
    ###    show_score_window()
    first_set_app = False    
    if SlTrace.trace("memory"):
        ###obj_list = objgraph.show_most_common_types(limit=20)
        ###SlTrace.lg("objgraph=%s" % obj_list)    
        global memory_trace
        if not memory_trace:
            tracemalloc.Filter(True, "select*")
            tracemalloc.start()
            tracemalloc.Filter(True, "select*")
            memory_trace = True
        snapshot = tracemalloc.take_snapshot()
        top_stats = snapshot.statistics('lineno', True)
        SlTrace.lg("[ Top 25 ]")
        for stat in top_stats[:25]:
            SlTrace.lg(str(stat))

        nc = gc.collect()
        SlTrace.lg("gc.collect=%d" % nc)
        nc = gc.collect()
        SlTrace.lg("gc.collect=%d" % nc)
        
        ###obj_list = objgraph.show_most_common_types(limit=20)
        ###SlTrace.lg("objgraph=%s" % obj_list)    
        objgraph.show_growth(limit=20, file=SlTrace.getLogFile())
        objgraph.show_growth(limit=20)
        objgraph.get_new_ids(file=SlTrace.getLogFile())
        objgraph.get_new_ids()
        ###obj = objgraph.by_type('SelectPlayer')
        ###objgraph.show_backrefs([obj], max_depth=10)
        SlTrace.lg("gc.garbage:%s" % gc.garbage)
        if snapshot1 is None and snapshot2 is None:
            snapshot1 = tracemalloc.take_snapshot()
        elif snapshot2 is None:
            snapshot2 = tracemalloc.take_snapshot()
        else:
            snapshot1 = snapshot2
            snapshot2 = tracemalloc.take_snapshot()
            
        if snapshot2 is not None:        
            top_stats = snapshot2.compare_to(snapshot1, 'lineno', True)
            SlTrace.lg("[ Top 25 differences]")
            for stat in top_stats[:25]:
                SlTrace.lg(str(stat))
            snapshot1 = snapshot2
            snapshot2 = None
        """
        Setup for next game
        """
    sp.reset()
    if run_game:
        run_game = False            # Clear after running
        mw.after(0, sp.running_loop)
コード例 #2
0
def set_squares_button():
    global loop_no
    global first_set_app
    global app
    global board_frame, msg_frame, sqs, board_canvas
    global width, height, min_xlen, nx, ny
    global n_rearrange_cycles, rearrange_cycle
    global players, sp
    global move_no_label
    global snapshot1, snapshot2         # tracemalloc instances
    loop_no += 1 
    SlTrace.lg("\nLoop %d" % loop_no)
    SlTrace.lg("Memory Used: %.0f MB, Change: %.2f MB"
                % (SlTrace.getMemory()/1.e6, SlTrace.getMemoryChange()/1.e6))
    SlTrace.lg("Squares Set Button", "button")
    if SlTrace.trace("pgm_stack"):
        stack = traceback.extract_stack()
        SlTrace.lg("pgm_stack depth=%d" % len(stack))
        if SlTrace.trace("pgm_stack_list"):
            list_len = 14
            print_list = traceback.format_list(stack)
            for line in print_list[-list_len:]:
                SlTrace.lg("  " + line)
        
    app = setup_app(app)
    if board_canvas is not None:
        SlTrace.lg("delete board_canvas")
        board_canvas.delete()
        board_canvas = None
    if board_frame is not None:    
        board_frame.destroy()
        board_frame = None
    if msg_frame is not None:    
        msg_frame.destroy()
        msg_frame = None
    if sp is not None:
        sp.destroy()
        sp = None
    
    app.update_form()
        
        
        
    rects =  []
    rects_rows = []         # So we can pass row, col
    rects_cols = []
    min_xlen = app.get_component_val("figure_size", "min", min_xlen)
    min_xlen = float(min_xlen)
    min_xlen = str(min_xlen)
    min_ylen = min_xlen
    
    ###rects.append(rect1)
    ###rects.append(rect2)
    xmin = .1*float(width)
    xmax = .9*float(width)
    xlen = (xmax-xmin)/float(nx)
    min_xlen = float(min_xlen)
    if xlen < min_xlen:
        SlTrace.lg("nx=%d xlen(%.0f) set to %.0f" % (nx, xlen, min_xlen))
        xlen = min_xlen
    ymin = .1*float(height)
    ymax = .9*float(height)
    ylen = (ymax-ymin)/float(ny)
    min_ylen = float(min_ylen)
    if ylen < min_ylen:
        SlTrace.lg("ny=%d ylen(%.0f) set to %.0f" % (ny, ylen, min_ylen))
        ylen = min_ylen
    board_frame = Frame(mw, width=width, height=height, bg="", colormap="new")
    board_frame.pack()
    msg_frame = Frame(mw)
    msg_frame.pack(side="bottom")
    
    
    board_canvas = Canvas(board_frame, width=width, height=height)
    board_canvas.pack()
            
    if sp is not None and sp.cur_message is not None:
        sp.cur_message.destroy()
        sp.msg = None
    sqs = SelectSquares(board_canvas, mw=mw, nrows=ny, ncols=nx,
                        width=width, height=height,
                        check_mod=check_mod)
    sqs.display()
    sp = SelectPlay(board=sqs, msg_frame=msg_frame,
                    mw=mw, start_run=False, game_control=game_control,
                    on_exit=pgm_exit,
                    on_end=end_game,
                    move_first=1, before_move=before_move,
                    after_move=after_move,
                    show_ties=show_ties)
    sp.set_stroke_move(stroke_move)
    if first_set_app:
        if run_resets:
            sp.reset_score()
    if show_players:
        show_players_window()
    if show_score:
        show_score_window()
    first_set_app = False    
    if SlTrace.trace("memory"):
        ###obj_list = objgraph.show_most_common_types(limit=20)
        ###SlTrace.lg("objgraph=%s" % obj_list)    
        snapshot = tracemalloc.take_snapshot()
        top_stats = snapshot.statistics('lineno', True)
        SlTrace.lg("[ Top 25 ]")
        for stat in top_stats[:25]:
            SlTrace.lg(str(stat))

        nc = gc.collect()
        SlTrace.lg("gc.collect=%d" % nc)
        nc = gc.collect()
        SlTrace.lg("gc.collect=%d" % nc)
        
        ###obj_list = objgraph.show_most_common_types(limit=20)
        ###SlTrace.lg("objgraph=%s" % obj_list)    
        objgraph.show_growth(limit=20, file=SlTrace.getLogFile())
        objgraph.show_growth(limit=20)
        objgraph.get_new_ids(file=SlTrace.getLogFile())
        objgraph.get_new_ids()
        ###obj = objgraph.by_type('SelectPlayer')
        ###objgraph.show_backrefs([obj], max_depth=10)
        SlTrace.lg("gc.garbage:%s" % gc.garbage)
        if snapshot1 is None and snapshot2 is None:
            snapshot1 = tracemalloc.take_snapshot()
        elif snapshot2 is None:
            snapshot2 = tracemalloc.take_snapshot()
        else:
            snapshot1 = snapshot2
            snapshot2 = tracemalloc.take_snapshot()
            
        if snapshot2 is not None:        
            top_stats = snapshot2.compare_to(snapshot1, 'lineno', True)
            SlTrace.lg("[ Top 25 differences]")
            for stat in top_stats[:25]:
                SlTrace.lg(str(stat))
            snapshot1 = snapshot2
            snapshot2 = None
    if run_game:
        mw.after(0, sp.running_loop)