The issue with GUI is who can do the GUI message loop, wait for user to click something. Anyone can, I have two message loops here, one running in the main loop below, and one running in the trace call back. They work together, no problem. This code handles a simple stop and wait for click in the trace call. I will fix it to check for breakpoint match, and insert this into the debuger, adding another ten lines of code. Hence, we can break anywhere, and do go into all we want.
import tkinter,sys,inspect
#Break Point class
class BreakPoints :
master = None
bpoints = []
bpnum =0
def __init__(self,root) :
self.master = root
self.bpoints.append(1)
def append(self,linenum):
if self.bpoints.count(linenum) == 0 :
self.bpoints.append(linenum)
self.bpnum=self.bpnum+1
def delete (self,linenum) :
if self.count(linenum) > 0 :
self.bpoints.remove(linenum)
self.bpnum=self.bpnum-1
def isin(self,linenum) : return(self.bpoints.count(linenum))
def format(self) : print("Points: ",self.bpoints)
def checkfun(frame,event,arg) :
global Breaks
global root
caller = inspect.getframeinfo(inspect.stack()[0][0])
print ("%s:%d - %s" % (caller.filename, caller.lineno, event))
was = Breaks.bpnum
while True:
if not was == Breaks.bpnum : break
root.update_idletasks()
root.update()
return(None)
def NewBreak(event) :
global Breaks
Breaks.append(Breaks.bpnum+4)
Breaks.format()
########### Main start
root = tkinter.Tk()
global Breaks
Breaks = BreakPoints(root)
NewBreak(root)
NewBreak(root)
print(" Test ", Breaks.isin(1),Breaks.isin(2),Breaks.isin(4))
cc = tkinter.StringVar()
w = tkinter.Button(root,text="Click")
w.pack(side='left')
w.bind("<Button-1>", NewBreak)
w = tkinter.Label(root, textvariable=cc)
w.pack()
cc.set("Tester!")
print('hello')
while True:
root.update_idletasks()
sys.setprofile(checkfun)
sys.settrace(checkfun)
root.update()
No comments:
Post a Comment