Merge pull request #931 from MikeTheWatchGuy/Dev-latest

New do_not_reroute_stdout parameter for Print/EasyPrint
This commit is contained in:
MikeTheWatchGuy 2018-12-14 23:19:30 -05:00 committed by GitHub
commit a88c3b2a73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 7 deletions

View File

@ -5473,7 +5473,6 @@ def StartupTK(window):
window.QT_QMainWindow.setWindowIcon(QtGui.QIcon(window.WindowIcon)) window.QT_QMainWindow.setWindowIcon(QtGui.QIcon(window.WindowIcon))
if window.DisableMinimize: if window.DisableMinimize:
# flags |= ~Qt.WindowMinimizeButtonHint
window.QT_QMainWindow.setWindowFlags(window.QT_QMainWindow.windowFlags()&~Qt.WindowMinimizeButtonHint) window.QT_QMainWindow.setWindowFlags(window.QT_QMainWindow.windowFlags()&~Qt.WindowMinimizeButtonHint)
window.QT_QMainWindow.setWindowFlags(window.QT_QMainWindow.windowFlags()&~Qt.WindowMaximizeButtonHint) window.QT_QMainWindow.setWindowFlags(window.QT_QMainWindow.windowFlags()&~Qt.WindowMaximizeButtonHint)
# window.QTWindow.setAttribute(Qt.WA_TranslucentBackground) # window.QTWindow.setAttribute(Qt.WA_TranslucentBackground)
@ -5746,18 +5745,21 @@ class DebugWin():
debug_window = None debug_window = None
def __init__(self, size=(None, None), location=(None, None), font=None, no_titlebar=False, no_button=False, def __init__(self, size=(None, None), location=(None, None), font=None, no_titlebar=False, no_button=False,
grab_anywhere=False, keep_on_top=False): grab_anywhere=False, keep_on_top=False, do_not_reroute_stdout=False):
# Show a form that's a running counter # Show a form that's a running counter
self.do_not_reroute_stdout = do_not_reroute_stdout
win_size = size if size != (None, None) else DEFAULT_DEBUG_WINDOW_SIZE win_size = size if size != (None, None) else DEFAULT_DEBUG_WINDOW_SIZE
self.window = Window('Debug Window', no_titlebar=no_titlebar, auto_size_text=True, location=location, self.window = Window('Debug Window', no_titlebar=no_titlebar, auto_size_text=True, location=location,
font=font or ('Courier New', 10), grab_anywhere=grab_anywhere, keep_on_top=keep_on_top) font=font or ('Courier New', 10), grab_anywhere=grab_anywhere, keep_on_top=keep_on_top)
self.output_element = Output(size=win_size) self.output_element = MultilineOutput(size=win_size, key='_MULTILINE_') if do_not_reroute_stdout else Output(size=win_size)
if no_button: if no_button:
self.layout = [[self.output_element]] self.layout = [[self.output_element]]
else: else:
self.layout = [ self.layout = [
[self.output_element], [self.output_element],
[DummyButton('Quit')] [DummyButton('Quit'), Stretch()]
] ]
self.window.AddRows(self.layout) self.window.AddRows(self.layout)
self.window.Read(timeout=0) # Show a non-blocking form, returns immediately self.window.Read(timeout=0) # Show a non-blocking form, returns immediately
@ -5775,7 +5777,14 @@ class DebugWin():
event, values = self.window.Read(timeout=0) event, values = self.window.Read(timeout=0)
if event == 'Quit' or event is None: if event == 'Quit' or event is None:
self.Close() self.Close()
print(*args, sep=sepchar, end=endchar) if self.do_not_reroute_stdout:
outstring = ''
for arg in args:
outstring += str(arg) + sepchar
outstring += endchar
self.output_element.Update(outstring, append=True)
else:
print(*args, sep=sepchar, end=endchar)
# TODO # TODO
# Add extra check to see if the window was closed... if closed by X sometimes am not told # Add extra check to see if the window was closed... if closed by X sometimes am not told
# try: # try:
@ -5794,12 +5803,12 @@ def PrintClose():
def EasyPrint(*args, size=(None, None), end=None, sep=None, location=(None, None), font=None, no_titlebar=False, def EasyPrint(*args, size=(None, None), end=None, sep=None, location=(None, None), font=None, no_titlebar=False,
no_button=False, grab_anywhere=False, keep_on_top=False): no_button=False, grab_anywhere=False, keep_on_top=False, do_not_reroute_stdout=False):
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,
no_button=no_button, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top) no_button=no_button, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top, do_not_reroute_stdout=do_not_reroute_stdout)
DebugWin.debug_window.Print(*args, end=end, sep=sep) DebugWin.debug_window.Print(*args, end=end, sep=sep)