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
|
#!/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'
|
port = 'PySimpleGUI'
|
||||||
|
|
||||||
|
@ -126,6 +126,7 @@ import warnings
|
||||||
from math import floor
|
from math import floor
|
||||||
from math import fabs
|
from math import fabs
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
from copy import deepcopy
|
||||||
|
|
||||||
warnings.simplefilter('always', UserWarning)
|
warnings.simplefilter('always', UserWarning)
|
||||||
|
|
||||||
|
@ -6050,8 +6051,8 @@ class Window:
|
||||||
self.TKroot.quit() # kick the users out of the mainloop
|
self.TKroot.quit() # kick the users out of the mainloop
|
||||||
|
|
||||||
# @_timeit
|
# @_timeit
|
||||||
def Read(self, timeout=None, timeout_key=TIMEOUT_KEY):
|
def Read(self, timeout=None, timeout_key=TIMEOUT_KEY, close=False):
|
||||||
# type: (int, Any) -> Tuple[Any, Union[Dict, List]]
|
# 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.
|
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
|
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: (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
|
||||||
: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)
|
||||||
"""
|
"""
|
||||||
|
@ -6072,7 +6074,13 @@ 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
|
||||||
|
@ -6087,6 +6095,11 @@ 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
|
||||||
|
@ -6104,6 +6117,11 @@ 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
|
||||||
|
@ -6160,15 +6178,28 @@ 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
|
||||||
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
|
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 ***")
|
||||||
self.ReturnValues = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
results = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
||||||
return self.ReturnValues
|
else:
|
||||||
|
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