From 40abc2e20a2c4eecfca8e4bed54c21d4e9fcdf0a Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Sat, 17 Aug 2019 11:03:36 -0400 Subject: [PATCH] New capability! __getitem__ added to all ports of PySimpleGUI. Enables skipping the FindElement call --- PySimpleGUI.py | 21 +++++++++++++++++++-- PySimpleGUIQt/PySimpleGUIQt.py | 16 ++++++++++++++-- PySimpleGUIWeb/PySimpleGUIWeb.py | 19 +++++++++++++++++-- 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/PySimpleGUI.py b/PySimpleGUI.py index 6f3bdead..935416d9 100644 --- a/PySimpleGUI.py +++ b/PySimpleGUI.py @@ -1,5 +1,5 @@ #!/usr/bin/python3 -version = __version__ = "4.2.0.7 Unreleased" +version = __version__ = "4.2.0.8 Unreleased" # 888888ba .d88888b oo dP .88888. dP dP dP @@ -5047,6 +5047,7 @@ class Window: if layout is not None: self.Layout(layout) + @classmethod def GetAContainerNumber(cls): """ @@ -6014,6 +6015,22 @@ class Window: """ return self + def __getitem__(self, key): + """ + Returns Element that matches the passed in key. + This is "called" by writing code as thus: + window['element key'].Update + + :param key: (Any) The key to find + :return: Union[Element, None] The element found or None if no element was found + """ + try: + return self.Element(key) + except Exception as e: + warnings.warn('The key you passed in is no good. Key = {}*'.format(key)) + return None + + def __exit__(self, *a): """ WAS used with context managers which are no longer needed nor advised. It is here for legacy support and @@ -11118,7 +11135,7 @@ def main(): graph_elem.Move(-1, 0) graph_elem.DrawLine((i, 0), (i, randint(0, 300)), width=1, color='#{:06x}'.format(randint(0, 0xffffff))) - window.FindElement('+PROGRESS+').UpdateBar(i % 800) + window['+PROGRESS+'].UpdateBar(i % 800) window.Element('_IMAGE_').UpdateAnimation(DEFAULT_BASE64_LOADING_GIF, time_between_frames=50) i += 1 if event == 'Button': diff --git a/PySimpleGUIQt/PySimpleGUIQt.py b/PySimpleGUIQt/PySimpleGUIQt.py index 327114c2..3e8f8f96 100644 --- a/PySimpleGUIQt/PySimpleGUIQt.py +++ b/PySimpleGUIQt/PySimpleGUIQt.py @@ -1,5 +1,5 @@ #!/usr/bin/python3 -version = __version__ = "0.27.0.3 Unreleased" +version = __version__ = "0.27.0.4 Unreleased" import sys import types @@ -3807,8 +3807,20 @@ class Window: def Size(self, size): self.QT_QMainWindow.resize(QSize(size[0], size[1])) + def __getitem__(self, key): + """ + Returns Element that matches the passed in key. + This is "called" by writing code as thus: + window['element key'].Update - + :param key: (Any) The key to find + :return: Union[Element, None] The element found or None if no element was found + """ + try: + return self.Element(key) + except Exception as e: + print('The key you passed in is no good. Key = {}*'.format(key)) + return None def __enter__(self): return self diff --git a/PySimpleGUIWeb/PySimpleGUIWeb.py b/PySimpleGUIWeb/PySimpleGUIWeb.py index 1fe8c16b..6e1df36b 100644 --- a/PySimpleGUIWeb/PySimpleGUIWeb.py +++ b/PySimpleGUIWeb/PySimpleGUIWeb.py @@ -1,5 +1,5 @@ #usr/bin/python3 -version = __version__ = "0.31.0.0 Unreleased" +version = __version__ = "0.31.0.2 Unreleased" import sys import types @@ -39,7 +39,7 @@ def TimerStop(): g_time_end = time.time() g_time_delta = g_time_end - g_time_start - print(g_time_delta) + print(g_time_delta*1000) ###### ##### ##### # # ### # # # # # # # # # # # ##### # ###### # # # # # # # # ###### ##### @@ -3493,6 +3493,21 @@ class Window: self.MasterFrame.SetSizer(self.OuterSizer) self.OuterSizer.Fit(self.MasterFrame) + def __getitem__(self, key): + """ + Returns Element that matches the passed in key. + This is "called" by writing code as thus: + window['element key'].Update + + :param key: (Any) The key to find + :return: Union[Element, None] The element found or None if no element was found + """ + try: + return self.Element(key) + except Exception as e: + print('The key you passed in is no good. Key = {}*'.format(key)) + return None + def __enter__(self): return self