Merge pull request #3130 from PySimpleGUI/Dev-latest

Added reroute_cprint parameter to Multiline
This commit is contained in:
PySimpleGUI 2020-07-09 13:44:14 -04:00 committed by GitHub
commit 91aabdee18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3
version = __version__ = "4.24.0.6 Unreleased\nAdded k parameter to buttons, new text wrapping behavior for popups, new docstring for keys, new single-string button_color format ('white on red'), moved Tree image caching to be on a per-element basis rather than system wide, automatically refresh window when printing to multiline, Output element will now auto-refresh window after every print call"
version = __version__ = "4.24.0.7 Unreleased\nAdded k parameter to buttons, new text wrapping behavior for popups, new docstring for keys, new single-string button_color format ('white on red'), moved Tree image caching to be on a per-element basis rather than system wide, automatically refresh window when printing to multiline, Output element will now auto-refresh window after every print call, new paramters to Multiline to reroute stdout/stderr"
port = 'PySimpleGUI'
@ -2126,7 +2126,7 @@ class Multiline(Element):
def __init__(self, default_text='', enter_submits=False, disabled=False, autoscroll=False, border_width=None,
size=(None, None), auto_size_text=None, background_color=None, text_color=None, change_submits=False,
enable_events=False, do_not_clear=True, key=None, k=None, write_only=False, auto_refresh=False, reroute_stdout=False, reroute_stderr=False, focus=False, font=None, pad=None, tooltip=None,
enable_events=False, do_not_clear=True, key=None, k=None, write_only=False, auto_refresh=False, reroute_stdout=False, reroute_stderr=False, reroute_cprint=False, focus=False, font=None, pad=None, tooltip=None,
right_click_menu=None, visible=True, metadata=None):
"""
:param default_text: Initial text to show
@ -2165,6 +2165,8 @@ class Multiline(Element):
:type reroute_stdout: (bool)
:param reroute_stderr: If True then all output to stdout will be output to this element
:type reroute_stderr: (bool)
:param reroute_cprint: If True your cprint calls will output to this element. It's the same as you calling cprint_set_output_destination
:type reroute_cprint: (bool)
:param focus: if True initial focus will go to this element
:type focus: (bool)
:param font: specifies the font family, size, etc
@ -2199,11 +2201,13 @@ class Multiline(Element):
self.AutoRefresh = auto_refresh
key = key if key is not None else k
self.previous_stdout = self.previous_stderr = None
self.reroute_cprint = reroute_cprint
if reroute_stdout:
self.reroute_stdout_to_here()
if reroute_stderr:
self.reroute_stderr_to_here()
super().__init__(ELEM_TYPE_INPUT_MULTILINE, size=size, auto_size_text=auto_size_text, background_color=bg,
text_color=fg, key=key, pad=pad, tooltip=tooltip, font=font or DEFAULT_FONT, visible=visible, metadata=metadata)
return
@ -10941,6 +10945,10 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKText['state'] = 'disabled'
if element.Tooltip is not None:
element.TooltipObject = ToolTip(element.TKText, text=element.Tooltip, timeout=DEFAULT_TOOLTIP_TIME)
if element.reroute_cprint:
cprint_set_output_destination(toplevel_form, element.Key)
if element.RightClickMenu or toplevel_form.RightClickMenu:
menu = element.RightClickMenu or toplevel_form.RightClickMenu
top_menu = tk.Menu(toplevel_form.TKroot, tearoff=False)