Merge pull request #2615 from PySimpleGUI/Dev-latest
Restructured window.read so that the close is done extrnally to the m…
This commit is contained in:
commit
46d04512de
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
version = __version__ = "4.15.1.14 Unreleased - Fix for draw_pixel, fix Multline.update with no value specified, listbox update no longer selects a default, all justifications can be shortened to single letter, fix for debug window closed with Quit button, removed f-string, draw_polygon added, print_to_element added, Listbox.get, Listbox update parm select_mode, check for None when creating Multiline, Element.unbind, Image now defaults to filename='', added Window.element_list(), close parameter for Window.read, SystemTray implemented, Menu font parameter"
|
version = __version__ = "4.15.1.15 Unreleased - Fix for draw_pixel, fix Multline.update with no value specified, listbox update no longer selects a default, all justifications can be shortened to single letter, fix for debug window closed with Quit button, removed f-string, draw_polygon added, print_to_element added, Listbox.get, Listbox update parm select_mode, check for None when creating Multiline, Element.unbind, Image now defaults to filename='', added Window.element_list(), close parameter for Window.read, SystemTray implemented, Menu font parameter, fix for window.read"
|
||||||
|
|
||||||
port = 'PySimpleGUI'
|
port = 'PySimpleGUI'
|
||||||
|
|
||||||
|
@ -6076,7 +6076,7 @@ class Window:
|
||||||
self.FormRemainedOpen = True
|
self.FormRemainedOpen = True
|
||||||
self.TKroot.quit() # kick the users out of the mainloop
|
self.TKroot.quit() # kick the users out of the mainloop
|
||||||
|
|
||||||
# @_timeit
|
|
||||||
def Read(self, timeout=None, timeout_key=TIMEOUT_KEY, close=False):
|
def Read(self, timeout=None, timeout_key=TIMEOUT_KEY, close=False):
|
||||||
# type: (int, Any, bool) -> Tuple[Any, Union[Dict, List]]
|
# type: (int, Any, bool) -> Tuple[Any, Union[Dict, List]]
|
||||||
"""
|
"""
|
||||||
|
@ -6087,6 +6087,25 @@ class Window:
|
||||||
:param timeout: (int) Milliseconds to wait until the Read will return IF no other GUI events happen first
|
:param timeout: (int) Milliseconds to wait until the Read will return IF no other GUI events happen first
|
||||||
:param timeout_key: (Any) The value that will be returned from the call if the timer expired
|
:param timeout_key: (Any) The value that will be returned from the call if the timer expired
|
||||||
:param close: (bool) if True the window will be closed prior to returning
|
:param close: (bool) if True the window will be closed prior to returning
|
||||||
|
:return: Tuple[(Any), Union[Dict[Any:Any]], List[Any], None] (event, values)
|
||||||
|
"""
|
||||||
|
results = self._read(timeout=timeout, timeout_key=timeout_key)
|
||||||
|
if close:
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
# @_timeit
|
||||||
|
def _read(self, timeout=None, timeout_key=TIMEOUT_KEY):
|
||||||
|
# type: (int, Any) -> Tuple[Any, Union[Dict, List]]
|
||||||
|
"""
|
||||||
|
THE biggest deal method in the Window class! This is how you get all of your data from your Window.
|
||||||
|
Pass in a timeout (in milliseconds) to wait for a maximum of timeout milliseconds. Will return timeout_key
|
||||||
|
if no other GUI events happen first.
|
||||||
|
|
||||||
|
:param timeout: (int) Milliseconds to wait until the Read will return IF no other GUI events happen first
|
||||||
|
:param timeout_key: (Any) The value that will be returned from the call if the timer expired
|
||||||
:return: Tuple[(Any), Union[Dict[Any:Any]], List[Any], None] (event, values)
|
:return: Tuple[(Any), Union[Dict[Any:Any]], List[Any], None] (event, values)
|
||||||
(event or timeout_key or None, Dictionary of values or List of values from all elements in the Window)
|
(event or timeout_key or None, Dictionary of values or List of values from all elements in the Window)
|
||||||
"""
|
"""
|
||||||
|
@ -6100,13 +6119,7 @@ class Window:
|
||||||
event = timeout_key
|
event = timeout_key
|
||||||
if values is None:
|
if values is None:
|
||||||
event = None
|
event = None
|
||||||
if not close:
|
|
||||||
return event, values # make event None if values was None and return
|
return event, values # make event None if values was None and return
|
||||||
else:
|
|
||||||
results = deepcopy((event, values)) # make a copy of the results
|
|
||||||
self.Close()
|
|
||||||
return results
|
|
||||||
|
|
||||||
# Read with a timeout
|
# Read with a timeout
|
||||||
self.Timeout = timeout
|
self.Timeout = timeout
|
||||||
self.TimeoutKey = timeout_key
|
self.TimeoutKey = timeout_key
|
||||||
|
@ -6121,11 +6134,6 @@ class Window:
|
||||||
# print(f'*** Found previous clicked saved {self.LastButtonClicked}')
|
# print(f'*** Found previous clicked saved {self.LastButtonClicked}')
|
||||||
results = _BuildResults(self, False, self)
|
results = _BuildResults(self, False, self)
|
||||||
self.LastButtonClicked = None
|
self.LastButtonClicked = None
|
||||||
if not close:
|
|
||||||
return results
|
|
||||||
else:
|
|
||||||
results = deepcopy(results)
|
|
||||||
self.Close()
|
|
||||||
return results
|
return results
|
||||||
InitializeResults(self)
|
InitializeResults(self)
|
||||||
# if the last button clicked was realtime, emulate a read non-blocking
|
# if the last button clicked was realtime, emulate a read non-blocking
|
||||||
|
@ -6143,11 +6151,6 @@ class Window:
|
||||||
# print('ROOT Destroyed')
|
# print('ROOT Destroyed')
|
||||||
results = _BuildResults(self, False, self)
|
results = _BuildResults(self, False, self)
|
||||||
if results[0] != None and results[0] != timeout_key:
|
if results[0] != None and results[0] != timeout_key:
|
||||||
if not close:
|
|
||||||
return results
|
|
||||||
else:
|
|
||||||
results = deepcopy(results)
|
|
||||||
self.Close()
|
|
||||||
return results
|
return results
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
@ -6204,28 +6207,15 @@ class Window:
|
||||||
results = _BuildResults(self, False, self)
|
results = _BuildResults(self, False, self)
|
||||||
if not self.LastButtonClickedWasRealtime:
|
if not self.LastButtonClickedWasRealtime:
|
||||||
self.LastButtonClicked = None
|
self.LastButtonClicked = None
|
||||||
if not close:
|
|
||||||
return results
|
|
||||||
else:
|
|
||||||
results = deepcopy(results)
|
|
||||||
self.Close()
|
|
||||||
return results
|
return results
|
||||||
else:
|
else:
|
||||||
if not self.XFound and self.Timeout != 0 and self.Timeout is not None and self.ReturnValues[
|
if not self.XFound and self.Timeout != 0 and self.Timeout is not None and self.ReturnValues[
|
||||||
0] is None: # Special Qt case because returning for no reason so fake timeout
|
0] is None: # Special Qt case because returning for no reason so fake timeout
|
||||||
results = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
self.ReturnValues = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
||||||
elif not self.XFound and self.ReturnValues[0] is None: # TODO HIGHLY EXPERIMENTAL... added due to tray icon interaction
|
elif not self.XFound and self.ReturnValues[0] is None: # TODO HIGHLY EXPERIMENTAL... added due to tray icon interaction
|
||||||
# print("*** Faking timeout ***")
|
# print("*** Faking timeout ***")
|
||||||
results = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
self.ReturnValues = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
||||||
else:
|
return self.ReturnValues
|
||||||
results = self.ReturnValues
|
|
||||||
|
|
||||||
if not close:
|
|
||||||
return results
|
|
||||||
else:
|
|
||||||
results = deepcopy(results)
|
|
||||||
self.Close()
|
|
||||||
return results
|
|
||||||
|
|
||||||
def _ReadNonBlocking(self):
|
def _ReadNonBlocking(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue