Merge pull request #1826 from PySimpleGUI/Dev-latest

New capability! __getitem__ added to all ports of PySimpleGUI.  Enabl…
This commit is contained in:
MikeTheWatchGuy 2019-08-17 11:03:54 -04:00 committed by GitHub
commit 5cb39d5b47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 6 deletions

View File

@ -1,5 +1,5 @@
#!/usr/bin/python3 #!/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 # 888888ba .d88888b oo dP .88888. dP dP dP
@ -5047,6 +5047,7 @@ class Window:
if layout is not None: if layout is not None:
self.Layout(layout) self.Layout(layout)
@classmethod @classmethod
def GetAContainerNumber(cls): def GetAContainerNumber(cls):
""" """
@ -6014,6 +6015,22 @@ class Window:
""" """
return self 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): def __exit__(self, *a):
""" """
WAS used with context managers which are no longer needed nor advised. It is here for legacy support and 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.Move(-1, 0)
graph_elem.DrawLine((i, 0), (i, randint(0, 300)), width=1, color='#{:06x}'.format(randint(0, 0xffffff))) 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) window.Element('_IMAGE_').UpdateAnimation(DEFAULT_BASE64_LOADING_GIF, time_between_frames=50)
i += 1 i += 1
if event == 'Button': if event == 'Button':

View File

@ -1,5 +1,5 @@
#!/usr/bin/python3 #!/usr/bin/python3
version = __version__ = "0.27.0.3 Unreleased" version = __version__ = "0.27.0.4 Unreleased"
import sys import sys
import types import types
@ -3807,8 +3807,20 @@ class Window:
def Size(self, size): def Size(self, size):
self.QT_QMainWindow.resize(QSize(size[0], size[1])) 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): def __enter__(self):
return self return self

View File

@ -1,5 +1,5 @@
#usr/bin/python3 #usr/bin/python3
version = __version__ = "0.31.0.0 Unreleased" version = __version__ = "0.31.0.2 Unreleased"
import sys import sys
import types import types
@ -39,7 +39,7 @@ def TimerStop():
g_time_end = time.time() g_time_end = time.time()
g_time_delta = g_time_end - g_time_start 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.MasterFrame.SetSizer(self.OuterSizer)
self.OuterSizer.Fit(self.MasterFrame) 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): def __enter__(self):
return self return self