From 9cce12e8c2457ee46c1b7dcf019ba88e217231b5 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Wed, 19 Jun 2019 08:30:04 -0400 Subject: [PATCH] Added new force parameter to all SetFocus calls. Removed calls to WM_DESTROY due to memory leak --- PySimpleGUI.py | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index fe717511..5ec43573 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -704,10 +704,13 @@ class InputText(Element): text = '' return text - def SetFocus(self): + def SetFocus(self, force=False): """ """ try: - self.TKEntry.focus_set() + if force: + self.TKEntry.focus_force() + else: + self.TKEntry.focus_set() except: pass @@ -1023,10 +1026,13 @@ class Listbox(Element): """ """ return self.Values - def SetFocus(self): + def SetFocus(self, force=False): """ """ try: - self.TKListbox.focus_set() + if force: + self.TKListbox.focus_force() + else: + self.TKListbox.focus_set() except: pass @@ -1405,13 +1411,17 @@ class Multiline(Element): """ """ return self.TKText.get(1.0, tk.END) - def SetFocus(self): + def SetFocus(self, force=False): """ """ try: - self.TKText.focus_set() + if force: + self.TKText.focus_force() + else: + self.TKText.focus_set() except: pass + def __del__(self): """ """ super().__del__() @@ -2082,13 +2092,17 @@ class Button(Element): """ """ return self.ButtonText - def SetFocus(self): + def SetFocus(self, force=False): """ """ try: - self.TKButton.focus_set() + if force: + self.TKButton.focus_force() + else: + self.TKButton.focus_set() except: pass + def Click(self): """Generates a click of the button as if the user clicked the button :return: @@ -2881,10 +2895,16 @@ class Graph(Element): if self.ParentForm.CurrentlyRunningMainloop: self.ParentForm.TKroot.quit() # kick out of loop if read was called - def SetFocus(self): + def SetFocus(self, force=False): """ """ - self._TKCanvas2.focus_set() - # self._TKCanvas2.focus_force() + try: + if force: + self._TKCanvas2.focus_force() + else: + self._TKCanvas2.focus_set() + except: + pass + def __del__(self): """ """ @@ -4852,8 +4872,8 @@ class Window: self.TKAfterID = self.TKroot.after(timeout, self._TimeoutAlarmCallback) self.CurrentlyRunningMainloop = True # print(f'In main {self.Title} {self.TKroot}') - self.TKroot.protocol("WM_DESTROY_WINDOW", self.OnClosingCallback) - self.TKroot.protocol("WM_DELETE_WINDOW", self.OnClosingCallback) + # self.TKroot.protocol("WM_DESTROY_WINDOW", self.OnClosingCallback) + # self.TKroot.protocol("WM_DELETE_WINDOW", self.OnClosingCallback) self.TKroot.mainloop() # print('Out main') self.CurrentlyRunningMainloop = False