From aa2911b91e9c22df7ea0c28aa83ac5272e2d1b09 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Sun, 30 Sep 2018 19:20:50 -0400 Subject: [PATCH] New Error Element --- PySimpleGUI.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index bf41a8c5..da3771c4 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -204,6 +204,7 @@ ELEM_TYPE_MENUBAR = 600 ELEM_TYPE_PROGRESS_BAR = 200 ELEM_TYPE_BLANK = 100 ELEM_TYPE_TABLE = 700 +ELEM_TYPE_ERROR = 666 # ------------------------- Popup Buttons Types ------------------------- # POPUP_BUTTONS_YES_NO = 1 @@ -1989,7 +1990,7 @@ class TKCalendar(ttk.Frame): # ---------------------------------------------------------------------- # -# Canvas # +# Menu # # ---------------------------------------------------------------------- # class Menu(Element): def __init__(self, menu_definition, background_color=None, size=(None, None), tearoff=True, pad=None, key=None): @@ -2043,6 +2044,35 @@ class Table(Element): +# ---------------------------------------------------------------------- # +# Error Element # +# ---------------------------------------------------------------------- # +class ErrorElement(Element): + def __init__(self, key=None): + + self.Key = key + super().__init__(ELEM_TYPE_ERROR, key=key) + + return + + def Update(self, *args, **kwargs): + Popup('Keyword error', self.Key, 'Hey duffus, you gave me a bad key and now you\'re trying to do an update.', 'You need to stop this madness and check your spelling') + return + + + def MenuItemChosenCallback(self, item_chosen): + # print('IN MENU ITEM CALLBACK', item_chosen) + self.ParentForm.LastButtonClicked = item_chosen + self.ParentForm.FormRemainedOpen = True + self.ParentForm.TKroot.quit() # kick the users out of the mainloop + + def __del__(self): + super().__del__() + + + + + # ------------------------------------------------------------------------- # # Window CLASS # @@ -2188,6 +2218,7 @@ class Window: except: pass + def Read(self): self.NonBlocking = False if self.TKrootDestroyed: @@ -2208,6 +2239,7 @@ class Window: else: return self.ReturnValues + def ReadNonBlocking(self, Message=''): if self.TKrootDestroyed: return None, None @@ -2238,7 +2270,6 @@ class Window: return self - def Refresh(self): if self.TKrootDestroyed: return @@ -2256,6 +2287,7 @@ class Window: element = _FindElementFromKeyInSubForm(self, key) if element is None: print('*** WARNING = FindElement did not find the key. Please check your key\'s spelling ***') + return ErrorElement(key=key) return element def SaveToDisk(self, filename):