From 305ce7529b279d130a6b9271841c7c8c1a7ca5c5 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Wed, 4 Mar 2020 19:08:24 -0500 Subject: [PATCH] Multiline colors fixed (broke when fixing another problem), added Multiline, MultilineOutput print method. Renamed print_to_element to be internal only --- PySimpleGUIQt/PySimpleGUIQt.py | 39 ++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/PySimpleGUIQt/PySimpleGUIQt.py b/PySimpleGUIQt/PySimpleGUIQt.py index 0ee709df..03716196 100644 --- a/PySimpleGUIQt/PySimpleGUIQt.py +++ b/PySimpleGUIQt/PySimpleGUIQt.py @@ -1,5 +1,5 @@ #!/usr/bin/python3 -version = __version__ = "0.31.0.10 Unreleased - fix for Listbox.update, Graph.change_coordinates, Added Image.Widget, return correct value with ComboBox has manual data entry, added print_to_element, multlineline update moves cursor to end, scrollable columns, listbox.get, fix for visible ignored in Text Element, Window.read close parm, move cursor to end when default text in Multiline, Multiline readonly parm" +version = __version__ = "0.31.0.11 Unreleased - fix for Listbox.update, Graph.change_coordinates, Added Image.Widget, return correct value with ComboBox has manual data entry, added print_to_element, multlineline update moves cursor to end, scrollable columns, listbox.get, fix for visible ignored in Text Element, Window.read close parm, move cursor to end when default text in Multiline, Multiline readonly parm" port = 'PySimpleGUIQt' @@ -1040,7 +1040,6 @@ class Multiline(Element): self.QT_TextEdit.setTextColor(text_color_for_value) if background_color_for_value is not None: self.QT_TextEdit.setTextBackgroundColor(background_color_for_value) - self.QT_TextEdit.moveCursor(QtGui.QTextCursor.End) self.QT_TextEdit.insertPlainText(str(value)) if self.Autoscroll: self.QT_TextEdit.moveCursor(QtGui.QTextCursor.End) @@ -1065,6 +1064,22 @@ class Multiline(Element): def SetFocus(self): self.QT_TextEdit.setFocus() + + def print(self, *args, end=None, sep=None, text_color=None, background_color=None): + """ + Print like Python normally prints except route the output to a multline element and also add colors if desired + + :param args: List[Any] The arguments to print + :param end: (str) The end char to use just like print uses + :param sep: (str) The separation character like print uses + :param text_color: The color of the text + :param background_color: The background color of the line + """ + _print_to_element(self, *args, end=end, sep=sep, text_color=text_color, background_color=background_color) + + + + get = Get set_focus = SetFocus update = Update @@ -1111,7 +1126,7 @@ class MultilineOutput(Element): return - def Update(self, value=None, disabled=None, append=False, background_color=None, text_color=None, font=None, visible=None): + def Update(self, value=None, disabled=None, append=False, background_color=None, text_color=None, font=None, text_color_for_value=None, background_color_for_value=None, visible=None): if value is not None and not append: self.QT_TextBrowser.setText(str(value)) elif value is not None and append: @@ -1127,6 +1142,21 @@ class MultilineOutput(Element): def Get(self): self.QT_TextBrowser.toPlainText() + + def print(self, *args, end=None, sep=None, text_color=None, background_color=None): + """ + Print like Python normally prints except route the output to a multline element and also add colors if desired + + :param args: List[Any] The arguments to print + :param end: (str) The end char to use just like print uses + :param sep: (str) The separation character like print uses + :param text_color: The color of the text + :param background_color: The background color of the line + """ + _print_to_element(self, *args, end=end, sep=sep, text_color=text_color, background_color=background_color) + + + get = Get update = Update @@ -5151,6 +5181,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win): toplevel_win.FocusElement = element.QT_TextEdit element.QT_TextEdit.setText(str(default_text)) + element.QT_TextEdit.moveCursor(QtGui.QTextCursor.End) if element.Tooltip: element.QT_TextEdit.setToolTip(element.Tooltip) # qt_row_layout.setContentsMargins(*full_element_pad) @@ -6295,7 +6326,7 @@ def EasyPrintClose(): # A print-like call that can be used to output to a multiline element as if it's an Output element # # ------------------------------------------------------------------------------------------------ # -def print_to_element(multiline_element, *args, end=None, sep=None, text_color=None, background_color=None): +def _print_to_element(multiline_element, *args, end=None, sep=None, text_color=None, background_color=None): """ Print like Python normally prints except route the output to a multline element and also add colors if desired