From 4da2c050b9f2b7f9f9d684ee37520debf6c906a7 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Mon, 10 Dec 2018 18:47:01 -0500 Subject: [PATCH 1/2] EasyPrint no longer uses global variables... made debug window reopen if EasyPrint called after close --- PySimpleGUIQt/PySimpleGUIQt.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/PySimpleGUIQt/PySimpleGUIQt.py b/PySimpleGUIQt/PySimpleGUIQt.py index f7ad3451..0ffca9fa 100644 --- a/PySimpleGUIQt/PySimpleGUIQt.py +++ b/PySimpleGUIQt/PySimpleGUIQt.py @@ -5806,6 +5806,8 @@ _easy_print_data = None # global variable... I'm cheating class DebugWin(): + debug_window = None + def __init__(self, size=(None, None), location=(None, None), font=None, no_titlebar=False, no_button=False, grab_anywhere=False, keep_on_top=False): # Show a form that's a running counter @@ -5830,9 +5832,9 @@ class DebugWin(): endchar = end if end is not None else '\n' if self.window is None: # if window was destroyed already, just print + self.__init__() print(*args, sep=sepchar, end=endchar) return - Window.active_popups[self.window] = 'debug window' event, values = self.window.Read(timeout=0) if event == 'Quit' or event is None: self.Close() @@ -5856,12 +5858,12 @@ def PrintClose(): def EasyPrint(*args, size=(None, None), end=None, sep=None, location=(None, None), font=None, no_titlebar=False, no_button=False, grab_anywhere=False, keep_on_top=False): - global _easy_print_data - if _easy_print_data is None: - _easy_print_data = DebugWin(size=size, location=location, font=font, no_titlebar=no_titlebar, + + if DebugWin.debug_window is None: + DebugWin.debug_window = DebugWin(size=size, location=location, font=font, no_titlebar=no_titlebar, no_button=no_button, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top) - _easy_print_data.Print(*args, end=end, sep=sep) + DebugWin.debug_window.Print(*args, end=end, sep=sep) Print = EasyPrint @@ -5869,10 +5871,9 @@ eprint = EasyPrint def EasyPrintClose(): - global _easy_print_data - if _easy_print_data is not None: - _easy_print_data.Close() - _easy_print_data = None + if DebugWin.debug_window is not None: + DebugWin.debug_window.Close() + DebugWin.debug_window = None # ======================== Scrolled Text Box =====# @@ -7045,7 +7046,7 @@ def PopupGetText(message, title=None, default_text='', password_char='', size=(N def main(): ChangeLookAndFeel('GreenTan') - SetOptions(progress_meter_color=(COLOR_SYSTEM_DEFAULT)) + # SetOptions(progress_meter_color=(COLOR_SYSTEM_DEFAULT)) # SetOptions(element_padding=(0,0)) # ------ Menu Definition ------ # menu_def = [['&File', ['!&Open::KeyOpen', '&Save::KeySave', '---', '&Properties::KeyProp', 'E&xit']], From 9e10666af124b02c6763d1f1d799d810c440425e Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Mon, 10 Dec 2018 18:50:42 -0500 Subject: [PATCH 2/2] Use classmethod instead of static method for Window, EasyPrint no longer uses global variable, EasyPrint re-open window if closed --- PySimpleGUI.py | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index e0eb6be8..042563c3 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -103,6 +103,7 @@ DEFAULT_ELEMENT_TEXT_COLOR = COLOR_SYSTEM_DEFAULT DEFAULT_TEXT_ELEMENT_BACKGROUND_COLOR = None DEFAULT_TEXT_COLOR = COLOR_SYSTEM_DEFAULT DEFAULT_INPUT_ELEMENTS_COLOR = COLOR_SYSTEM_DEFAULT +DEFAULT_INPUT_ELEMENTS_COLOR = COLOR_SYSTEM_DEFAULT DEFAULT_INPUT_TEXT_COLOR = COLOR_SYSTEM_DEFAULT DEFAULT_SCROLLBAR_COLOR = None # DEFAULT_BUTTON_COLOR = (YELLOWS[0], PURPLES[0]) # (Text, Background) or (Color "on", Color) as a way to remember @@ -3092,14 +3093,14 @@ class Window: self.XFound = False self.ElementPadding = element_padding or DEFAULT_ELEMENT_PADDING - @staticmethod - def IncrementOpenCount(): - Window.NumOpenWindows += 1 + @classmethod + def IncrementOpenCount(self): + self.NumOpenWindows += 1 # print('+++++ INCREMENTING Num Open Windows = {} ---'.format(Window.NumOpenWindows)) - @staticmethod - def DecrementOpenCount(): - Window.NumOpenWindows -= 1 * (Window.NumOpenWindows != 0) # decrement if not 0 + @classmethod + def DecrementOpenCount(self): + self.NumOpenWindows -= 1 * (self.NumOpenWindows != 0) # decrement if not 0 # print('----- DECREMENTING Num Open Windows = {} ---'.format(Window.NumOpenWindows)) # ------------------------- Add ONE Row to Form ------------------------- # @@ -3583,6 +3584,7 @@ class Window: return False def __del__(self): + # print('DELETING WINDOW') for row in self.Rows: for element in row: element.__del__() @@ -5642,6 +5644,8 @@ _easy_print_data = None # global variable... I'm cheating class DebugWin(): + debug_window = None + def __init__(self, size=(None, None), location=(None, None), font=None, no_titlebar=False, no_button=False, grab_anywhere=False, keep_on_top=False): # Show a form that's a running counter win_size = size if size != (None, None) else DEFAULT_DEBUG_WINDOW_SIZE @@ -5663,6 +5667,7 @@ class DebugWin(): endchar = end if end is not None else '\n' if self.window is None: # if window was destroyed already, just print + self.__init__() print(*args, sep=sepchar, end=endchar) return @@ -5671,10 +5676,10 @@ class DebugWin(): self.Close() print(*args, sep=sepchar, end=endchar) # Add extra check to see if the window was closed... if closed by X sometimes am not told - try: - state = self.window.TKroot.state() - except: - self.Close() + # try: + # state = self.window.TKroot.state() + # except: + # self.Close() def Close(self): if self.window is None: @@ -5687,23 +5692,22 @@ def PrintClose(): EasyPrintClose() -def EasyPrint(*args, size=(None, None), end=None, sep=None, location=(None, None), font=None, no_titlebar=False, no_button=False, grab_anywhere=False, keep_on_top=False): - global _easy_print_data +def EasyPrint(*args, size=(None, None), end=None, sep=None, location=(None, None), font=None, no_titlebar=False, no_button=False, grab_anywhere=False, keep_on_top=False): + + + if DebugWin.debug_window is None: + DebugWin.debug_window = DebugWin(size=size, location=location, font=font, no_titlebar=no_titlebar, no_button=no_button, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top) + DebugWin.debug_window.Print(*args, end=end, sep=sep) - if _easy_print_data is None: - _easy_print_data = DebugWin(size=size, location=location, font=font, no_titlebar=no_titlebar, no_button=no_button, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top) - _easy_print_data.Print(*args, end=end, sep=sep) Print = EasyPrint eprint = EasyPrint def EasyPrintClose(): - global _easy_print_data - if _easy_print_data is not None: - _easy_print_data.Close() - _easy_print_data = None - + if DebugWin.debug_window is not None: + DebugWin.debug_window.Close() + DebugWin.debug_window = None # ======================== Scrolled Text Box =====# # ===================================================#