'How to inherit from PDB module and call step/list commands

I want to make a tkinter GUI wrapper for PDB in Python and make an interactive debugger which will be native to Python environment.

I created a class which inherits from PDB module but i still didn't manage to understand how to invoke 'step' in anyway other then explicitly writing 'step' on the PDB console.

This is my code:

class WinPdb(Pdb):
    def __init__(self):
        super(WinPdb, self).__init__()
        self.initialize_gui()

    def initialize_gui(self):
        """
        TODO: documentation
        :return:
        """
        # Initialize window properties
        self.window = Tk()
        self.window.title("WinPdb - The ultimate python debugger")
        self.window.geometry("500x500")
        self.window.configure(background='black')

        # Initialize text box
        self.text_entry = Text(self.window, height=8, width=40)
        scroll = Scrollbar(self.window)
        self.text_entry.configure(yscrollcommand=scroll.set)
        self.text_entry.config(state=DISABLED)
        self.text_entry.pack(side=LEFT)

        # Initialize button
        button = Button(self.window, text='step', command=self.do_step)
        button.pack()

    def do_list(self, arg):
        first = self.lineno + 1
        last = first + 5
        filename = self.curframe.f_code.co_filename
        print("1: %s" % self.curframe.f_code.co_filename)
        print("2: %s" % self.curframe.f_globals)
        try:
            lines = linecache.getlines(filename, self.curframe.f_globals)
            self.text_entry.config(state=NORMAL)
            self.text_entry.delete('1.0', END)
            self.text_entry.insert(END, self._get_print_line(lines[first-1:last], first, [], self.curframe))
            self.text_entry.config(state=DISABLED)
            self._print_lines(lines[first-1:last], first, [],
                              self.curframe)
            if len(lines) < last:
                self.message('[EOF]')
        except KeyboardInterrupt:
            pass

    def do_step(self, arg: str = '') -> bool | None:
        super(WinPdb, self).do_step(arg)
        self.do_list(arg)

Calling the function "do_step" does not actually do the same as writing "step" on the console, although i am not sure why.

Any ideas as to why will be much appreciated.

Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source