Since upgrading to Panda 1.7, a certain TKinter window hangs itself and the main Panda window whenever it loses focus to another application.
a) I run a Panda app
b) I open a TKinter window, running in a separate Python thread
c) I can move the TK window around as much as I like
d) I click on another window such as the command prompt or even the main Panda window. Clicking on the textarea also causes the same behaviour.
e) I can’t switch back to the TK window because it is all frozen, and requires a forced quit using the Task Manager
The code for the TK window is here:
class TkCodeEditor(threading.Thread):
def __init__(self, aMaster, aCodeBlockID, resultObj):
# build frame
self.Master = aMaster
self.Master.title('Editing "' + get_block_name(aCodeBlockID) + '"')
self.CodeBlockID = aCodeBlockID
self.resultObj = resultObj
self.startHash = hashlib.md5()
self.startHash.update(get_code(self.CodeBlockID))
EditFrame = Frame(self.Master)
EditFrame.pack(side=LEFT, fill=BOTH, expand=True)
# build code text
TextFrame = Frame(EditFrame)
self.CodeText = Text(TextFrame)
scroll = Scrollbar(TextFrame)
scroll['command'] = self.CodeText.yview # allows scroll bar to move text
self.CodeText.configure(yscrollcommand=scroll.set) # allows text to move scrollbar
self.CodeText.insert(END, get_code(self.CodeBlockID))
self.CodeText.config(undo=1) # this is after the .insert() so user doesn't accidentally erase everything
self.CodeText.pack(anchor=NW, side=LEFT, fill=BOTH, expand=True)
scroll.pack(anchor=NE, side=RIGHT, fill=Y, expand=True)
TextFrame.pack(side=TOP, fill=BOTH, expand=True)
ButtonFrame = Frame(EditFrame)
ButtonFrame.pack(anchor=SE, side=BOTTOM, fill=X, expand=True)
self.CancelButton = Button(ButtonFrame, text='Cancel', fg='black', command=self._cancel)
self.CancelButton.pack(side=RIGHT)
self.SaveNewButton = Button(ButtonFrame, text='Save New', command=self._save_new)
self.SaveNewButton.pack(side=RIGHT)
self.SaveButton = Button(ButtonFrame, text='Save', command=self._save)
if get_code_id(aCodeBlockID) == 1:
self.SaveButton.config(state=DISABLED)
self.SaveButton.pack(side=RIGHT)
self.CodeText.focus_force()
self.Master.bind('<Escape>', self._escape)
threading.Thread.__init__(self)
def run(self):
self.Master.mainloop()
def _get_text(self):
nowText = self.CodeText.get(1.0, END)
nowText = nowText[:len(nowText) - 1]
return nowText
def _save(self):
set_code(self.CodeBlockID, self._get_text())
compile_code(self.CodeBlockID)
self.resultObj.pleaseRedraw = True
self._cancel()
def _save_new(self):
# irrelevant detail
self._cancel()
def _has_changed(self):
self.nowHash = hashlib.md5()
self.nowHash.update(self._get_text())
return self.nowHash.digest() != self.startHash.digest() # i.e. user has changed something
def _escape(self, event=None):
if not self._has_changed():
self._cancel()
def _cancel(self):
self.Master.destroy()
It is called with these lines:
TKRoot = Tk()
editor = TkCodeEditor(TKRoot, CodeBlockID, self)
editor.start()