Docstring fixes. More cprint fun! Can have optional window and key parameters
This commit is contained in:
parent
a33be3f99d
commit
3441c740a4
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
version = __version__ = "4.21.0 Released 27-Jun-2020"
|
version = __version__ = "4.21.0.1 Unreleased\n cprint expanded using optional key and optional window"
|
||||||
|
|
||||||
port = 'PySimpleGUI'
|
port = 'PySimpleGUI'
|
||||||
|
|
||||||
|
@ -868,7 +868,7 @@ class Element():
|
||||||
Used to add tkinter events to an Element.
|
Used to add tkinter events to an Element.
|
||||||
The tkinter specific data is in the Element's member variable user_bind_event
|
The tkinter specific data is in the Element's member variable user_bind_event
|
||||||
:param bind_string: The string tkinter expected in its bind function
|
:param bind_string: The string tkinter expected in its bind function
|
||||||
:type bind_string: Mike_please_insert_type_here
|
:type bind_string: (str)
|
||||||
:param key_modifier: Additional data to be added to the element's key when event is returned
|
:param key_modifier: Additional data to be added to the element's key when event is returned
|
||||||
"""
|
"""
|
||||||
self.Widget.bind(bind_string, lambda evt: self._user_bind_callback(bind_string, evt))
|
self.Widget.bind(bind_string, lambda evt: self._user_bind_callback(bind_string, evt))
|
||||||
|
@ -879,6 +879,7 @@ class Element():
|
||||||
"""
|
"""
|
||||||
Removes a previously bound tkinter event from an Element.
|
Removes a previously bound tkinter event from an Element.
|
||||||
:param bind_string: The string tkinter expected in its bind function
|
:param bind_string: The string tkinter expected in its bind function
|
||||||
|
:type bind_string: (str)
|
||||||
"""
|
"""
|
||||||
self.Widget.unbind(bind_string)
|
self.Widget.unbind(bind_string)
|
||||||
self.user_bind_dict.pop(bind_string, None)
|
self.user_bind_dict.pop(bind_string, None)
|
||||||
|
@ -907,6 +908,7 @@ class Element():
|
||||||
"""
|
"""
|
||||||
self.TooltipObject = ToolTip(self.Widget, text=tooltip_text, timeout=DEFAULT_TOOLTIP_TIME)
|
self.TooltipObject = ToolTip(self.Widget, text=tooltip_text, timeout=DEFAULT_TOOLTIP_TIME)
|
||||||
|
|
||||||
|
|
||||||
def SetFocus(self, force=False):
|
def SetFocus(self, force=False):
|
||||||
"""
|
"""
|
||||||
Sets the current focus to be on this element
|
Sets the current focus to be on this element
|
||||||
|
@ -923,6 +925,7 @@ class Element():
|
||||||
except:
|
except:
|
||||||
print('Was unable to set focus. The Widget passed in was perhaps not present in this element? Check your elements .Widget property')
|
print('Was unable to set focus. The Widget passed in was perhaps not present in this element? Check your elements .Widget property')
|
||||||
|
|
||||||
|
|
||||||
def set_size(self, size=(None, None)):
|
def set_size(self, size=(None, None)):
|
||||||
"""
|
"""
|
||||||
Changes the size of an element to a specific size.
|
Changes the size of an element to a specific size.
|
||||||
|
@ -7039,7 +7042,6 @@ class Window:
|
||||||
|
|
||||||
# @_timeit_summary
|
# @_timeit_summary
|
||||||
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]]
|
|
||||||
"""
|
"""
|
||||||
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
|
||||||
|
@ -7066,7 +7068,6 @@ class Window:
|
||||||
|
|
||||||
# @_timeit
|
# @_timeit
|
||||||
def _read(self, timeout=None, timeout_key=TIMEOUT_KEY):
|
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.
|
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
|
||||||
|
@ -11915,6 +11916,8 @@ def EasyPrint(*args, size=(None, None), end=None, sep=None, location=(None, None
|
||||||
:type location: Tuple[int, int]
|
:type location: Tuple[int, int]
|
||||||
:param do_not_reroute_stdout: do not reroute stdout
|
:param do_not_reroute_stdout: do not reroute stdout
|
||||||
:type do_not_reroute_stdout: (bool)
|
:type do_not_reroute_stdout: (bool)
|
||||||
|
:return:
|
||||||
|
:rtype:
|
||||||
"""
|
"""
|
||||||
if _DebugWin.debug_window is None:
|
if _DebugWin.debug_window is None:
|
||||||
_DebugWin.debug_window = _DebugWin(size=size, location=location, font=font, no_titlebar=no_titlebar,
|
_DebugWin.debug_window = _DebugWin(size=size, location=location, font=font, no_titlebar=no_titlebar,
|
||||||
|
@ -11984,26 +11987,40 @@ def cprint(*args, **kwargs):
|
||||||
:type text_color: (str)
|
:type text_color: (str)
|
||||||
:param background_color: The background color of the line
|
:param background_color: The background color of the line
|
||||||
:type background_color: (str)
|
:type background_color: (str)
|
||||||
|
:param colors: Either a tuple or a string that has both the text and background colors
|
||||||
|
:type colors: (str) or Tuple[str, str]
|
||||||
:param t: Color of the text
|
:param t: Color of the text
|
||||||
:type t: (str)
|
:type t: (str)
|
||||||
:param b: The background color of the line
|
:param b: The background color of the line
|
||||||
:type b: (str)
|
:type b: (str)
|
||||||
:param b: The background color of the line
|
|
||||||
:type b: (str)
|
|
||||||
:param c: Either a tuple or a string that has both the text and background colors
|
:param c: Either a tuple or a string that has both the text and background colors
|
||||||
:type c: (str) or Tuple[str, str]
|
:type c: (str) or Tuple[str, str]
|
||||||
:param end: end character
|
:param end: end character
|
||||||
:type end: (str)
|
:type end: (str)
|
||||||
:param sep: separator character
|
:param sep: separator character
|
||||||
:type sep: (str)
|
:type sep: (str)
|
||||||
:return:
|
:param key: key of multiline to output to (if you want to override the one previously set)
|
||||||
:rtype:
|
:type key: (Any)
|
||||||
|
:param window: key of multiline to output to (if you want to override the one previously set)
|
||||||
|
:type window: (Window)
|
||||||
"""
|
"""
|
||||||
if CPRINT_DESTINATION_WINDOW is None or CPRINT_DESTINATION_MULTILINE_ELMENT_KEY is None:
|
|
||||||
print('** Warning ** Attempting to perform a cprint without first setting up the output window and element', 'Will instead print on Console')
|
|
||||||
print(*args)
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
|
destination_key = CPRINT_DESTINATION_MULTILINE_ELMENT_KEY
|
||||||
|
window = CPRINT_DESTINATION_WINDOW
|
||||||
|
|
||||||
|
if window is None or destination_key is None:
|
||||||
|
if 'key' not in kwargs and 'window' not in kwargs:
|
||||||
|
print('** Warning ** Attempting to perform a cprint without first setting up the output window and element',
|
||||||
|
'Will instead print on Console',
|
||||||
|
'You can also use the window, key arguments to route the output')
|
||||||
|
print(*args)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# loop through all keyword args. Some will be passed on to the print function, others control
|
||||||
|
# the location to send the print
|
||||||
new_kwargs = {}
|
new_kwargs = {}
|
||||||
for arg in kwargs:
|
for arg in kwargs:
|
||||||
if arg == 't':
|
if arg == 't':
|
||||||
|
@ -12021,19 +12038,29 @@ def cprint(*args, **kwargs):
|
||||||
new_kwargs['background_color'] = colors[1]
|
new_kwargs['background_color'] = colors[1]
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('* cprint warning * you messed up with color formatting', e)
|
print('* cprint warning * you messed up with color formatting', e)
|
||||||
|
elif arg == 'key':
|
||||||
|
destination_key = kwargs[arg]
|
||||||
|
elif arg == 'window':
|
||||||
|
window = kwargs[arg]
|
||||||
else:
|
else:
|
||||||
new_kwargs[arg] = kwargs[arg]
|
new_kwargs[arg] = kwargs[arg]
|
||||||
# Special code to control the "end". If no end is specified then the ENTIRE LINE will be displayed with
|
# Special code to control the "end". If no end is specified then the ENTIRE LINE will be displayed with
|
||||||
# the background color spanning across the entire width of the element. This is likely not the desired
|
# the background color spanning across the entire width of the element. This is likely not the desired
|
||||||
# outcome the user was hoping for. So, thi code provides that behavior of only the portion of the line
|
# outcome the user was hoping for. So, thi code provides that behavior of only the portion of the line
|
||||||
# with text will have a background color change
|
# with text will have a background color change
|
||||||
if new_kwargs.get('end', None) is None:
|
if window is None or destination_key is None:
|
||||||
new_kwargs['end'] = ''
|
print('** cprint Warning - Missing information. Window or Key is None **')
|
||||||
CPRINT_DESTINATION_WINDOW[CPRINT_DESTINATION_MULTILINE_ELMENT_KEY].print(*args, **new_kwargs)
|
return
|
||||||
CPRINT_DESTINATION_WINDOW[CPRINT_DESTINATION_MULTILINE_ELMENT_KEY].print('')
|
|
||||||
else:
|
|
||||||
CPRINT_DESTINATION_WINDOW[CPRINT_DESTINATION_MULTILINE_ELMENT_KEY].print(*args, **new_kwargs)
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
if new_kwargs.get('end', None) is None:
|
||||||
|
new_kwargs['end'] = ''
|
||||||
|
window[destination_key].print(*args, **new_kwargs)
|
||||||
|
window[destination_key].print('')
|
||||||
|
else:
|
||||||
|
window[destination_key].print(*args, **new_kwargs)
|
||||||
|
except Exception as e:
|
||||||
|
print('** cprint error trying to print to the multiline **', e)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------------------------ #
|
# ------------------------------------------------------------------------------------------------ #
|
||||||
# A print-like call that can be used to output to a multiline element as if it's an Output element #
|
# A print-like call that can be used to output to a multiline element as if it's an Output element #
|
||||||
|
@ -15674,7 +15701,7 @@ def show_debugger_window(location=(None, None), *args):
|
||||||
"""
|
"""
|
||||||
Shows the large main debugger window
|
Shows the large main debugger window
|
||||||
:param location: Locations (x,y) on the screen to place upper left corner of the window
|
:param location: Locations (x,y) on the screen to place upper left corner of the window
|
||||||
:ttype location: Tuple[int, int]
|
:type location: Tuple[int, int]
|
||||||
"""
|
"""
|
||||||
if _Debugger.debugger is None:
|
if _Debugger.debugger is None:
|
||||||
_Debugger.debugger = _Debugger()
|
_Debugger.debugger = _Debugger()
|
||||||
|
|
Loading…
Reference in New Issue