コード例 #1
0
 def set_colors(self, runner_):
     for i, m in enumerate(runner_.memory):
         self.memory_nums[i]["readonlybackground"] = dbgcodeeditor.darken(dbgcodeeditor.COLOR_MAP[m.state])
         self.memorys[i]["bg"] = dbgcodeeditor.COLOR_MAP[m.state]
         if (runner_.breakpoints_active
            and m.state == runner.ValueState.normal
            and m.breakpoint != runner.BreakpointState.off):
             self.memory_nums[i]["readonlybackground"] = dbgcodeeditor.darken(codeeditor.BREAKPOINT_BG_COLOR)
             self.memorys[i]["bg"] = codeeditor.BREAKPOINT_BG_COLOR
コード例 #2
0
    def __init__(self, master):
        super().__init__(master)

        self.getting_inp = False
        self.run_to_halt = False
        self.show_debug = 0
        self.all_output = []
        self.runner = runner.Runner(self.give_output)

        # Top row of buttons

        self.button_frame = tkinter.Frame(self)
        self.button_frame.grid(row=0, column=0, columnspan=2,
                               sticky=tkinter.E + tkinter.W + tkinter.N)

        self.run_to_hlt_btn = tkinter.Button(self.button_frame,
                                             text="Run",
                                             command=self.run_to_hlt)
        self.run_to_hlt_btn.grid(row=0, column=0, sticky=tkinter.E + tkinter.W,
                                 padx=2, pady=2)

        self.run_step_btn = tkinter.Button(self.button_frame,
                                           text="Step",
                                           command=self.next_step)
        self.run_step_btn.grid(row=0, column=1, sticky=tkinter.E + tkinter.W,
                               padx=2, pady=2)

        self.reset_btn = tkinter.Button(self.button_frame, text="Reset",
                                        command=self.reset)
        self.reset_btn.grid(row=0, column=2, sticky=tkinter.E + tkinter.W,
                            padx=2, pady=2)

        self.debug_var = tkinter.BooleanVar(value=False)
        self.debug_btn = tkinter.Button(self.button_frame,
                                        command=self.toggle_debug, text="Debug")
        self.debug_btn.grid(row=0, column=3, sticky=tkinter.E + tkinter.W,
                            padx=2, pady=2)

        switch_cmd = getattr(self.master, "codemode", lambda: None)
        self.exit_btn = tkinter.Button(self.button_frame, text="Back to code",
                                       command=switch_cmd)
        self.exit_btn.grid(row=0, column=4, sticky=tkinter.E + tkinter.W,
                           padx=2, pady=2)

        for col in range(5):
            self.button_frame.columnconfigure(col, weight=1)
        self.button_frame.rowconfigure(0, weight=1)

        # Left row of inputs

        self.control_frame = tkinter.Frame(self)
        self.control_frame.grid(row=1, column=0,
                                sticky=tkinter.NE + tkinter.SW,
                                padx=5, pady=5)

        tkinter.Label(self.control_frame,
                      text="Accumulator:").grid(row=0, column=0,
                                                sticky=tkinter.W)

        self.accumulator_var = tkinter.StringVar(value="000")
        vcmd = self.register(self.accumulator_changed), "%P", "%V"
        self.accumulator = mn = tkinter.Entry(self.control_frame, width=5,
                                              bg="white", borderwidth=0,
                                              textvar=self.accumulator_var,
                                              vcmd=vcmd, validate="all")
        self.accumulator.grid(row=0, column=1, sticky=tkinter.W,
                              padx=10, pady=5)

        tkinter.Label(self.control_frame,
                      text="Counter:").grid(row=1, column=0, sticky=tkinter.W)

        self.counter_var = tkinter.StringVar(value="000")
        vcmd = self.register(self.counter_changed), "%P", "%V"
        self.counter = tkinter.Entry(self.control_frame, width=5,
                                     bg="white", borderwidth=0,
                                     textvar=self.counter_var,
                                     vcmd=vcmd, validate="all")
        self.counter.grid(row=1, column=1, sticky=tkinter.W, padx=10, pady=5)

        tkinter.Label(self.control_frame,
                      text="Input:").grid(row=2, column=0, sticky=tkinter.W)

        self.input_frame = tkinter.Frame(self.control_frame)
        self.input_var = tkinter.StringVar()
        vcmd = self.register(self.check_input), "%P"
        self.input = tkinter.Entry(self.input_frame, width=5,
                                   textvariable=self.input_var,
                                   state="disabled",
                                   validate="key", vcmd=vcmd)
        self.input.grid(row=0, column=0, padx=10, pady=5)
        self.input.bind("<Return>", self.got_input)

        self.input_btn = tkinter.Button(self.input_frame, text="Submit",
                                        command=self.got_input,
                                        state="disabled")
        self.input_btn.grid(row=0, column=1, padx=10, pady=5)
        self.input_frame.grid(row=2, column=1, sticky=tkinter.W)

        tkinter.Label(self.control_frame,
                      text="Output:").grid(row=3, column=0, sticky=tkinter.W)

        self.output = stext.ScrolledText(self.control_frame, height=10,
                                         width=20, state="disabled",
                                         bg="white")
        self.output.grid(row=3, column=1, sticky=tkinter.NW + tkinter.SE,
                         padx=10, pady=5)

        # Output formatting
        normal_font = self.output.cget("font")

        bold_font = tkfont.Font(self.output, normal_font)
        bold_font["weight"] = "bold"

        italic_font = tkfont.Font(self.output, normal_font)
        italic_font["slant"] = "italic"

        self.output.tag_configure("output", font=normal_font)
        self.output.tag_configure("input", font=normal_font)
        self.output.tag_configure("error", font=bold_font, foreground="red")
        self.output.tag_configure("done", font=normal_font)

        self.output.tag_configure("debug_write", font=italic_font,
                                  foreground=dbgcodeeditor.darken(dbgcodeeditor.WRITTEN_COLOR))
        self.output.tag_configure("debug_read", font=italic_font,
                                  foreground=dbgcodeeditor.darken(dbgcodeeditor.READ_COLOR))
        self.output.tag_configure("debug_jump", font=italic_font,
                                  foreground=dbgcodeeditor.darken(dbgcodeeditor.NEXT_EXEC_COLOR))
        self.output.tag_configure("debug_other", font=italic_font,
                                  foreground=dbgcodeeditor.darken(dbgcodeeditor.EXECUTED_COLOR))

        self.output.tag_configure("debug_output", font=bold_font)
        self.output.tag_configure("debug_input", font=bold_font)
        self.output.tag_configure("debug_error", font=bold_font,
                                  foreground="red")
        self.output.tag_configure("debug_breakpoint", font=bold_font,
                                  foreground="red")
        self.output.tag_configure("debug_done", font=bold_font)

        tkinter.Label(self.control_frame, text="Speed:").grid(row=4,
                                                              column=0,
                                                              sticky=tkinter.W)

        self.speed_scale = tkinter.Scale(self.control_frame,
                                         orient="horizontal",
                                         length=150,
                                         to=2.5, resolution=0.01)
        self.speed_scale["from"] = 0.01
        self.speed_scale.set(0.01)
        self.speed_scale.grid(row=4, column=1,
                              sticky=tkinter.E + tkinter.W, padx=10)

        self.control_frame.columnconfigure(1, weight=1)
        self.control_frame.rowconfigure(3, weight=1)

        # Tabber for switching between memory and code

        self.tabber = ttk.Notebook(self)
        self.tabber.grid(row=1, column=1, sticky=STICKY_NESW, padx=5, pady=5)
        self.tabber.bind("<<NotebookTabChanged>>", self.unfocus_tabber_widget)

        # Memory display in the tabber

        self.memory_frame = MemoryDisplay(self.tabber, self.setmem,
                                          self.update_memory)
        self.tabber.add(self.memory_frame, text="Memory", sticky=STICKY_NESW)

        # Code display in the tabber

        self.code_editor = dbgcodeeditor.DebugCodeEditor(self.tabber)
        self.tabber.add(self.code_editor, text="Code", sticky=STICKY_NESW)

        # Make resizeable

        self.columnconfigure(1, weight=3)
        self.columnconfigure(0, weight=2)
        self.rowconfigure(1, weight=1)

        self.after(1, self.run_halt_check)  # Kick off

        self.menus = []
        self.run_menu = tkinter.Menu(self.master.menu, tearoff=False)
        self.run_menu.add_command(label="Run", command=self.run_to_halt)
        self.run_menu.add_command(label="Step", command=self.next_step)
        self.run_menu.add_command(label="Reset", command=self.reset)
        self.menus.append(dict(label="Run", menu=self.run_menu))

        self.debug_trace_var = tkinter.BooleanVar()
        self.breakpoints_active_var = tkinter.BooleanVar()

        self.debug_menu = tkinter.Menu(self.master.menu, tearoff=False)
        self.debug_menu.add_checkbutton(label="Debug trace", variable=self.debug_trace_var,
                                        command=self.update_debug_from_vars)
        self.debug_menu.add_checkbutton(label="Breapoints", variable=self.breakpoints_active_var,
                                        command=self.update_debug_from_vars)
        self.menus.append(dict(label="Debug", menu=self.debug_menu))

        self.breakpoints_active = False