Merge pull request #4310 from PySimpleGUI/Dev-latest

Added Window.ding().  Added more error information when a "Finalize i…
This commit is contained in:
PySimpleGUI 2021-05-23 16:38:57 -04:00 committed by GitHub
commit 3433782079
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 32 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
version = __version__ = "4.42.0 Released 23-May-2021" version = __version__ = "4.42.0.1 Unreleased\nAdded Window.ding() - fun is a particularly important feature, better error reporting when finalize required"
__version__ = version.split()[0] # For PEP 396 and PEP 345 __version__ = version.split()[0] # For PEP 396 and PEP 345
@ -8901,7 +8901,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
""" """
Minimize this window to the task bar Minimize this window to the task bar
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.minimize'):
return return
self.TKroot.iconify() self.TKroot.iconify()
self.maximized = False self.maximized = False
@ -8914,7 +8914,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
The reason for the difference is the title bar is removed in some cases when using fullscreen option The reason for the difference is the title bar is removed in some cases when using fullscreen option
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.maximize'):
return return
if not running_linux(): if not running_linux():
self.TKroot.state('zoomed') self.TKroot.state('zoomed')
@ -8928,7 +8928,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
""" """
Restore a window to a non-maximized state. Does different things depending on platform. See Maximize for more. Restore a window to a non-maximized state. Does different things depending on platform. See Maximize for more.
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.normal'):
return return
if self.TKroot.state() == 'iconic': if self.TKroot.state() == 'iconic':
self.TKroot.deiconify() self.TKroot.deiconify()
@ -9192,7 +9192,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
""" """
Disables window from taking any input from the user Disables window from taking any input from the user
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.disable'):
return return
self.TKroot.attributes('-disabled', 1) self.TKroot.attributes('-disabled', 1)
# self.TKroot.grab_set_global() # self.TKroot.grab_set_global()
@ -9201,7 +9201,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
""" """
Re-enables window to take user input after having it be Disabled previously Re-enables window to take user input after having it be Disabled previously
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.enable'):
return return
self.TKroot.attributes('-disabled', 0) self.TKroot.attributes('-disabled', 0)
# self.TKroot.grab_release() # self.TKroot.grab_release()
@ -9210,7 +9210,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
""" """
Hides the window from the screen and the task bar Hides the window from the screen and the task bar
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.hide'):
return return
self._Hidden = True self._Hidden = True
self.TKroot.withdraw() self.TKroot.withdraw()
@ -9219,7 +9219,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
""" """
Used to bring back a window that was previously hidden using the Hide method Used to bring back a window that was previously hidden using the Hide method
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.un_hide'):
return return
if self._Hidden: if self._Hidden:
self.TKroot.deiconify() self.TKroot.deiconify()
@ -9231,7 +9231,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
channel to 0. NOTE that on some platforms alpha is not supported. The window will remain showing on these channel to 0. NOTE that on some platforms alpha is not supported. The window will remain showing on these
platforms. The Raspberry Pi for example does not have an alpha setting platforms. The Raspberry Pi for example does not have an alpha setting
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.disappear'):
return return
self.TKroot.attributes('-alpha', 0) self.TKroot.attributes('-alpha', 0)
@ -9239,7 +9239,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
""" """
Causes a window previously made to "Disappear" (using that method). Does this by restoring the alpha channel Causes a window previously made to "Disappear" (using that method). Does this by restoring the alpha channel
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.reappear'):
return return
self.TKroot.attributes('-alpha', 255) self.TKroot.attributes('-alpha', 255)
@ -9250,7 +9250,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
:param alpha: 0 to 1. 0 is completely transparent. 1 is completely visible and solid (can't see through) :param alpha: 0 to 1. 0 is completely transparent. 1 is completely visible and solid (can't see through)
:type alpha: (float) :type alpha: (float)
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.set_alpha'):
return return
self._AlphaChannel = alpha self._AlphaChannel = alpha
self.TKroot.attributes('-alpha', alpha) self.TKroot.attributes('-alpha', alpha)
@ -9272,7 +9272,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
:param alpha: 0 to 1. 0 is completely transparent. 1 is completely visible and solid (can't see through) :param alpha: 0 to 1. 0 is completely transparent. 1 is completely visible and solid (can't see through)
:type alpha: (float) :type alpha: (float)
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.alpha_channel'):
return return
self._AlphaChannel = alpha self._AlphaChannel = alpha
self.TKroot.attributes('-alpha', alpha) self.TKroot.attributes('-alpha', alpha)
@ -9282,7 +9282,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
Brings this window to the top of all other windows (perhaps may not be brought before a window made to "stay Brings this window to the top of all other windows (perhaps may not be brought before a window made to "stay
on top") on top")
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.bring_to_front'):
return return
if running_windows(): if running_windows():
try: try:
@ -9303,7 +9303,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
""" """
Pushes this window to the bottom of the stack of windows. It is the opposite of BringToFront Pushes this window to the bottom of the stack of windows. It is the opposite of BringToFront
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.send_to_back'):
return return
try: try:
self.TKroot.lower() self.TKroot.lower()
@ -9318,7 +9318,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
:return: The x and y location in tuple form (x,y) :return: The x and y location in tuple form (x,y)
:rtype: Tuple[(int), (int)] :rtype: Tuple[(int), (int)]
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.current_location'):
return return
return int(self.TKroot.winfo_x()), int(self.TKroot.winfo_y()) return int(self.TKroot.winfo_x()), int(self.TKroot.winfo_y())
@ -9331,7 +9331,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
:return: (width, height) of the window :return: (width, height) of the window
:rtype: Tuple[(int), (int)] or Tuple[None, None] :rtype: Tuple[(int), (int)] or Tuple[None, None]
""" """
if not self._is_window_created(): if not self._is_window_created('Tried to use Window.size property'):
return (None, None) return (None, None)
win_width = self.TKroot.winfo_width() win_width = self.TKroot.winfo_width()
win_height = self.TKroot.winfo_height() win_height = self.TKroot.winfo_height()
@ -9360,7 +9360,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
:param size: (width, height) tuple (int, int) of the desired window size in pixels :param size: (width, height) tuple (int, int) of the desired window size in pixels
:type size: Tuple[int, int] :type size: Tuple[int, int]
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.set_min_size'):
return return
self.TKroot.minsize(size[0], size[1]) self.TKroot.minsize(size[0], size[1])
self.TKroot.update_idletasks() self.TKroot.update_idletasks()
@ -9381,7 +9381,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
:param color: Color string that defines the transparent color :param color: Color string that defines the transparent color
:type color: (str) :type color: (str)
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.set_transparent_color'):
return return
try: try:
self.TKroot.attributes('-transparentcolor', color) self.TKroot.attributes('-transparentcolor', color)
@ -9395,7 +9395,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
Turns on Grab Anywhere functionality AFTER a window has been created. Don't try on a window that's not yet Turns on Grab Anywhere functionality AFTER a window has been created. Don't try on a window that's not yet
been Finalized or Read. been Finalized or Read.
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.grab_any_where_on'):
return return
self.TKroot.bind("<ButtonPress-1>", self._StartMove) self.TKroot.bind("<ButtonPress-1>", self._StartMove)
self.TKroot.bind("<ButtonRelease-1>", self._StopMove) self.TKroot.bind("<ButtonRelease-1>", self._StopMove)
@ -9407,7 +9407,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
Turns off Grab Anywhere functionality AFTER a window has been created. Don't try on a window that's not yet Turns off Grab Anywhere functionality AFTER a window has been created. Don't try on a window that's not yet
been Finalized or Read. been Finalized or Read.
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.grab_any_where_off'):
return return
self.TKroot.unbind("<ButtonPress-1>") self.TKroot.unbind("<ButtonPress-1>")
self.TKroot.unbind("<ButtonRelease-1>") self.TKroot.unbind("<ButtonRelease-1>")
@ -9444,7 +9444,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
:param key: The event that will be generated when the tkinter event occurs :param key: The event that will be generated when the tkinter event occurs
:type key: str | int | tuple | object :type key: str | int | tuple | object
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.bind'):
return return
self.TKroot.bind(bind_string, lambda evt: self._user_bind_callback(bind_string, evt)) self.TKroot.bind(bind_string, lambda evt: self._user_bind_callback(bind_string, evt))
self.user_bind_dict[bind_string] = key self.user_bind_dict[bind_string] = key
@ -9472,7 +9472,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
""" """
Enables the internal debugger. By default, the debugger IS enabled Enables the internal debugger. By default, the debugger IS enabled
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.enable_debugger'):
return return
self.TKroot.bind('<Cancel>', self._callback_main_debugger_window_create_keystroke) self.TKroot.bind('<Cancel>', self._callback_main_debugger_window_create_keystroke)
self.TKroot.bind('<Pause>', self._callback_popout_window_create_keystroke) self.TKroot.bind('<Pause>', self._callback_popout_window_create_keystroke)
@ -9483,7 +9483,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
""" """
Disable the internal debugger. By default the debugger is ENABLED Disable the internal debugger. By default the debugger is ENABLED
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.disable_debugger'):
return return
self.TKroot.unbind("<Cancel>") self.TKroot.unbind("<Cancel>")
self.TKroot.unbind("<Pause>") self.TKroot.unbind("<Pause>")
@ -9497,7 +9497,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
:param title: The string to set the title to :param title: The string to set the title to
:type title: (str) :type title: (str)
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.set_title'):
return return
self.TKroot.wm_title(str(title)) self.TKroot.wm_title(str(title))
@ -9509,7 +9509,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
NOTE - Sorry Mac users - you can't have modal windows.... lobby your tkinter Mac devs NOTE - Sorry Mac users - you can't have modal windows.... lobby your tkinter Mac devs
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.make_modal'):
return return
if running_mac(): if running_mac():
@ -9527,7 +9527,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
""" """
Forces this window to take focus Forces this window to take focus
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.force_focus'):
return return
self.TKroot.focus_force() self.TKroot.focus_force()
@ -9554,7 +9554,7 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
:type cursor: (str) :type cursor: (str)
""" """
if not self._is_window_created(): if not self._is_window_created('tried Window.set_cursor'):
return return
try: try:
self.TKroot.config(cursor=cursor) self.TKroot.config(cursor=cursor)
@ -9562,6 +9562,23 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
print('Warning bad cursor specified ', cursor) print('Warning bad cursor specified ', cursor)
print(e) print(e)
def ding(self, display_number=0):
"""
Make a "bell" sound. A capability provided by tkinter. Your window needs to be finalized prior to calling
Ring a display's bell is the tkinter description of the call
:param display_number: Passed to tkinter's bell method as parameter "displayof".
:type display_number: int
"""
if not self._is_window_created('tried Window.ding'):
return
try:
self.TKroot.bell(display_number)
except Exception as e:
if not SUPPRESS_ERROR_POPUPS:
_error_popup_with_traceback('Window.ding() - tkinter reported error from bell() call', e)
def _window_tkvar_changed_callback(self, *args): def _window_tkvar_changed_callback(self, *args):
""" """
Internal callback function for when the thread Internal callback function for when the thread
@ -9697,13 +9714,13 @@ Normally a tuple, but can be a simplified-dual-color-string "foreground on backg
""" """
return self.Read(*args, **kwargs) return self.Read(*args, **kwargs)
def _is_window_created(self): def _is_window_created(self, additional_message=''):
msg = str(additional_message)
if self.TKroot is None: if self.TKroot is None:
warnings.warn('You cannot perform operations on a Window until it is read or finalized. Adding a "finalize=True" parameter to your Window creation will fix this', UserWarning) warnings.warn('You cannot perform operations on a Window until it is read or finalized. Adding a "finalize=True" parameter to your Window creation will fix this. ' + msg, UserWarning)
if not SUPPRESS_ERROR_POPUPS: if not SUPPRESS_ERROR_POPUPS:
popup_error('You cannot perform operations on a Window until it is read or finalized.', _error_popup_with_traceback('You cannot perform operations on a Window until it is read or finalized.',
'Yea, I know, it\'s a weird thing, but just fix it and keep going.... ', 'Adding a "finalize=True" parameter to your Window creation will likely fix this', msg)
'Adding a "finalize=True" parameter to your Window creation will likely fix this', image=_random_error_emoji())
return False return False
return True return True