many new parms for Print funcion, fix for no_window option for PopupGetFile, initial_folder for Popup

This commit is contained in:
MikeTheWatchGuy 2018-11-01 00:25:24 -04:00
parent 11ec70ed77
commit 7d43dae749
1 changed files with 46 additions and 38 deletions

View File

@ -949,7 +949,6 @@ class Multiline(Element):
self.Autoscroll = autoscroll self.Autoscroll = autoscroll
self.Disabled = disabled self.Disabled = disabled
self.ChangeSubmits = change_submits self.ChangeSubmits = change_submits
print(font or DEFAULT_FONT)
super().__init__(ELEM_TYPE_INPUT_MULTILINE, size=size, auto_size_text=auto_size_text, background_color=bg, 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) text_color=fg, key=key, pad=pad, tooltip=tooltip, font=font or DEFAULT_FONT)
@ -2944,13 +2943,11 @@ class Window:
else: else:
return self.ReturnValues return self.ReturnValues
def ReadNonBlocking(self, Message=''): def ReadNonBlocking(self):
if self.TKrootDestroyed: if self.TKrootDestroyed:
return None, None return None, None
if not self.Shown: if not self.Shown:
self.Show(non_blocking=True) self.Show(non_blocking=True)
if Message:
print(Message)
try: try:
rc = self.TKroot.update() rc = self.TKroot.update()
except: except:
@ -3105,7 +3102,7 @@ class Window:
# IT FINALLY WORKED! 29-Oct-2018 was the first time this damned thing got called # IT FINALLY WORKED! 29-Oct-2018 was the first time this damned thing got called
def OnClosingCallback(self): def OnClosingCallback(self):
# print('Got closing callback') print('Got closing callback')
self.TKroot.quit() # kick the users out of the mainloop self.TKroot.quit() # kick the users out of the mainloop
if self.CurrentlyRunningMainloop: # quit if this is the current mainloop, otherwise don't quit! if self.CurrentlyRunningMainloop: # quit if this is the current mainloop, otherwise don't quit!
self.TKroot.destroy() # kick the users out of the mainloop self.TKroot.destroy() # kick the users out of the mainloop
@ -3155,6 +3152,10 @@ class Window:
except: except:
pass pass
def CurrentLocation(self):
return int(self.TKroot.winfo_x()), int(self.TKroot.winfo_y())
def __enter__(self): def __enter__(self):
return self return self
@ -5044,54 +5045,49 @@ _easy_print_data = None # global variable... I'm cheating
class DebugWin(): class DebugWin():
def __init__(self, size=(None, None)): def __init__(self, size=(None, None), location=(None, None), font=None, no_titlebar=False, no_button=False, grab_anywhere=False, keep_on_top=False):
# Show a form that's a running counter # Show a form that's a running counter
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.form = Window('Debug Window', auto_size_text=True, font=('Courier New', 12)) 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)
self.output_element = Output(size=win_size) self.output_element = Output(size=win_size)
self.form_rows = [[Text('EasyPrint Output')], if no_button:
self.layout = [[self.output_element]]
else:
self.layout = [
[self.output_element], [self.output_element],
[DummyButton('Quit')]] [DummyButton('Quit')]
self.form.AddRows(self.form_rows) ]
self.form.Show(non_blocking=True) # Show a ;non-blocking form, returns immediately self.window.AddRows(self.layout)
self.window.Show(non_blocking=True) # Show a ;non-blocking form, returns immediately
return return
def Print(self, *args, end=None, sep=None): def Print(self, *args, end=None, sep=None):
sepchar = sep if sep is not None else ' ' sepchar = sep if sep is not None else ' '
endchar = end if end is not None else '\n' endchar = end if end is not None else '\n'
event, values = self.window.Read(timeout=0)
if event == 'Quit' or event is None:
self.Close()
print(*args, sep=sepchar, end=endchar) print(*args, sep=sepchar, end=endchar)
# for a in args:
# msg = str(a)
# print(msg, end="", sep=sepchar)
# print(1, 2, 3, sep='-')
# if end is None:
# print("")
self.form.Read(timeout=0)
def Close(self): def Close(self):
self.form.CloseNonBlockingForm() self.window.Close()
self.form.__del__() self.window.__del__()
def Print(*args, size=(None, None), end=None, sep=None):
EasyPrint(*args, size=size, end=end, sep=sep)
def PrintClose(): def PrintClose():
EasyPrintClose() EasyPrintClose()
def eprint(*args, size=(None, None), end=None, sep=None): 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):
EasyPrint(*args, size=size, end=end, sep=sep)
def EasyPrint(*args, size=(None, None), end=None, sep=None):
global _easy_print_data global _easy_print_data
if _easy_print_data is None: if _easy_print_data is None:
_easy_print_data = DebugWin(size=size) _easy_print_data = 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)
_easy_print_data.Print(*args, end=end, sep=sep) _easy_print_data.Print(*args, end=end, sep=sep)
Print = EasyPrint
eprint = EasyPrint
def EasyPrintold(*args, size=(None, None), end=None, sep=None): def EasyPrintold(*args, size=(None, None), end=None, sep=None):
if 'easy_print_data' not in EasyPrint.__dict__: # use a function property to save DebugWin object (static variable) if 'easy_print_data' not in EasyPrint.__dict__: # use a function property to save DebugWin object (static variable)
@ -6101,7 +6097,7 @@ def PopupYesNo(*args, button_color=None, background_color=None, text_color=None,
def PopupGetFolder(message, default_path='', no_window=False, size=(None, None), button_color=None, def PopupGetFolder(message, default_path='', no_window=False, size=(None, None), button_color=None,
background_color=None, text_color=None, icon=DEFAULT_WINDOW_ICON, font=None, no_titlebar=False, background_color=None, text_color=None, icon=DEFAULT_WINDOW_ICON, font=None, no_titlebar=False,
grab_anywhere=False, keep_on_top=False, location=(None, None)): grab_anywhere=False, keep_on_top=False, location=(None, None), initial_folder=None):
""" """
Display popup with text entry field and browse button. Browse for folder Display popup with text entry field and browse button. Browse for folder
:param message: :param message:
@ -6119,7 +6115,13 @@ def PopupGetFolder(message, default_path='', no_window=False, size=(None, None),
:param location: :param location:
:return: Contents of text field. None if closed using X or cancelled :return: Contents of text field. None if closed using X or cancelled
""" """
global _my_windows
if no_window: if no_window:
if _my_windows.NumOpenWindows:
root = tk.Toplevel()
else:
root = tk.Tk() root = tk.Tk()
try: try:
root.attributes('-alpha', 0) # hide window while building it. makes for smoother 'paint' root.attributes('-alpha', 0) # hide window while building it. makes for smoother 'paint'
@ -6130,7 +6132,7 @@ def PopupGetFolder(message, default_path='', no_window=False, size=(None, None),
return folder_name return folder_name
layout = [[Text(message, auto_size_text=True, text_color=text_color, background_color=background_color)], layout = [[Text(message, auto_size_text=True, text_color=text_color, background_color=background_color)],
[InputText(default_text=default_path, size=size), FolderBrowse()], [InputText(default_text=default_path, size=size), FolderBrowse(initial_folder=initial_folder)],
[CloseButton('Ok', size=(5, 1), bind_return_key=True), CloseButton('Cancel', size=(5, 1))]] [CloseButton('Ok', size=(5, 1), bind_return_key=True), CloseButton('Cancel', size=(5, 1))]]
window = Window(title=message, icon=icon, auto_size_text=True, button_color=button_color, window = Window(title=message, icon=icon, auto_size_text=True, button_color=button_color,
@ -6152,7 +6154,7 @@ def PopupGetFolder(message, default_path='', no_window=False, size=(None, None),
def PopupGetFile(message, default_path='', default_extension='', save_as=False, file_types=(("ALL Files", "*.*"),), def PopupGetFile(message, default_path='', default_extension='', save_as=False, file_types=(("ALL Files", "*.*"),),
no_window=False, size=(None, None), button_color=None, background_color=None, text_color=None, no_window=False, size=(None, None), button_color=None, background_color=None, text_color=None,
icon=DEFAULT_WINDOW_ICON, font=None, no_titlebar=False, grab_anywhere=False, keep_on_top=False, icon=DEFAULT_WINDOW_ICON, font=None, no_titlebar=False, grab_anywhere=False, keep_on_top=False,
location=(None, None)): location=(None, None), initial_folder=None):
""" """
Display popup with text entry field and browse button. Browse for file Display popup with text entry field and browse button. Browse for file
:param message: :param message:
@ -6173,7 +6175,13 @@ def PopupGetFile(message, default_path='', default_extension='', save_as=False,
:param location: :param location:
:return: string representing the path chosen, None if cancelled or window closed with X :return: string representing the path chosen, None if cancelled or window closed with X
""" """
global _my_windows
if no_window: if no_window:
if _my_windows.NumOpenWindows:
root = tk.Toplevel()
else:
root = tk.Tk() root = tk.Tk()
try: try:
root.attributes('-alpha', 0) # hide window while building it. makes for smoother 'paint' root.attributes('-alpha', 0) # hide window while building it. makes for smoother 'paint'
@ -6188,7 +6196,7 @@ def PopupGetFile(message, default_path='', default_extension='', save_as=False,
root.destroy() root.destroy()
return filename return filename
browse_button = SaveAs(file_types=file_types) if save_as else FileBrowse(file_types=file_types) browse_button = SaveAs(file_types=file_types, initial_folder=initial_folder) if save_as else FileBrowse(file_types=file_types, initial_folder=initial_folder)
layout = [[Text(message, auto_size_text=True, text_color=text_color, background_color=background_color)], layout = [[Text(message, auto_size_text=True, text_color=text_color, background_color=background_color)],
[InputText(default_text=default_path, size=size), browse_button], [InputText(default_text=default_path, size=size), browse_button],