Merge pull request #2588 from PySimpleGUI/Dev-latest
Window.read gets a new "close" parameter (thinking of renaming to clo…
This commit is contained in:
commit
8c910188b1
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
version = __version__ = "4.15.1.11 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()"
|
||||
version = __version__ = "4.15.1.12 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"
|
||||
|
||||
port = 'PySimpleGUI'
|
||||
|
||||
|
@ -126,6 +126,7 @@ import warnings
|
|||
from math import floor
|
||||
from math import fabs
|
||||
from functools import wraps
|
||||
from copy import deepcopy
|
||||
|
||||
warnings.simplefilter('always', UserWarning)
|
||||
|
||||
|
@ -6050,8 +6051,8 @@ class Window:
|
|||
self.TKroot.quit() # kick the users out of the mainloop
|
||||
|
||||
# @_timeit
|
||||
def Read(self, timeout=None, timeout_key=TIMEOUT_KEY):
|
||||
# type: (int, Any) -> Tuple[Any, Union[Dict, List]]
|
||||
def Read(self, timeout=None, timeout_key=TIMEOUT_KEY, close=False):
|
||||
# type: (int, Any, bool) -> 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
|
||||
|
@ -6059,6 +6060,7 @@ class Window:
|
|||
|
||||
: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 close: (bool) if True the window will be closed prior to returning
|
||||
: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)
|
||||
"""
|
||||
|
@ -6072,7 +6074,13 @@ class Window:
|
|||
event = timeout_key
|
||||
if values is None:
|
||||
event = None
|
||||
if not close:
|
||||
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
|
||||
self.Timeout = timeout
|
||||
self.TimeoutKey = timeout_key
|
||||
|
@ -6087,6 +6095,11 @@ class Window:
|
|||
# print(f'*** Found previous clicked saved {self.LastButtonClicked}')
|
||||
results = _BuildResults(self, False, self)
|
||||
self.LastButtonClicked = None
|
||||
if not close:
|
||||
return results
|
||||
else:
|
||||
results = deepcopy(results)
|
||||
self.Close()
|
||||
return results
|
||||
InitializeResults(self)
|
||||
# if the last button clicked was realtime, emulate a read non-blocking
|
||||
|
@ -6104,6 +6117,11 @@ class Window:
|
|||
# print('ROOT Destroyed')
|
||||
results = _BuildResults(self, False, self)
|
||||
if results[0] != None and results[0] != timeout_key:
|
||||
if not close:
|
||||
return results
|
||||
else:
|
||||
results = deepcopy(results)
|
||||
self.Close()
|
||||
return results
|
||||
else:
|
||||
pass
|
||||
|
@ -6160,15 +6178,28 @@ class Window:
|
|||
results = _BuildResults(self, False, self)
|
||||
if not self.LastButtonClickedWasRealtime:
|
||||
self.LastButtonClicked = None
|
||||
if not close:
|
||||
return results
|
||||
else:
|
||||
results = deepcopy(results)
|
||||
self.Close()
|
||||
return results
|
||||
else:
|
||||
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
|
||||
self.ReturnValues = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
||||
results = 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
|
||||
# print("*** Faking timeout ***")
|
||||
self.ReturnValues = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
||||
return self.ReturnValues
|
||||
results = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
||||
else:
|
||||
results = self.ReturnValues
|
||||
|
||||
if not close:
|
||||
return results
|
||||
else:
|
||||
results = deepcopy(results)
|
||||
self.Close()
|
||||
return results
|
||||
|
||||
def _ReadNonBlocking(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue