Merge pull request #380 from MikeTheWatchGuy/Dev-latest

New window methods - Hide, UnHide!  Fix for menu letter underlining, …
This commit is contained in:
MikeTheWatchGuy 2018-09-29 02:03:42 -04:00 committed by GitHub
commit 3e676c94c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 96 additions and 91 deletions

View File

@ -2353,6 +2353,12 @@ class Window:
def Enable(self): def Enable(self):
self.TKroot.grab_release() self.TKroot.grab_release()
def Hide(self):
self.TKroot.withdraw()
def UnHide(self):
self.TKroot.deiconify()
def __enter__(self): def __enter__(self):
return self return self
@ -2760,18 +2766,14 @@ def AddMenuItem(top_menu, sub_menu_info, element, is_sub_menu=False, skip=False)
if type(sub_menu_info) is str: if type(sub_menu_info) is str:
if not is_sub_menu and not skip: if not is_sub_menu and not skip:
# print(f'Adding command {sub_menu_info}') # print(f'Adding command {sub_menu_info}')
pos = sub_menu_info.find('_&') pos = sub_menu_info.find('&')
if pos != -1: if pos != -1:
_ = sub_menu_info[:pos] if pos == 0 or sub_menu_info[pos-1] != "\\":
try: sub_menu_info = sub_menu_info[:pos] + sub_menu_info[pos+1:]
_ += sub_menu_info[pos+2:]
except Exception as e:
print(e)
sub_menu_info = _
if sub_menu_info == '---': if sub_menu_info == '---':
top_menu.add('separator') top_menu.add('separator')
else: else:
top_menu.add_command(label=sub_menu_info, underline=pos-1, command=lambda: Menu.MenuItemChosenCallback(element, sub_menu_info)) top_menu.add_command(label=sub_menu_info, underline=pos, command=lambda: Menu.MenuItemChosenCallback(element, sub_menu_info))
else: else:
i = 0 i = 0
while i < (len(sub_menu_info)): while i < (len(sub_menu_info)):
@ -3246,17 +3248,14 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKMenu = tk.Menu(toplevel_form.TKroot, tearoff=element.Tearoff) # create the menubar element.TKMenu = tk.Menu(toplevel_form.TKroot, tearoff=element.Tearoff) # create the menubar
menubar = element.TKMenu menubar = element.TKMenu
for menu_entry in menu_def: for menu_entry in menu_def:
# print(f'Adding a Menubar ENTRY') # print(f'Adding a Menubar ENTRY {menu_entry}')
baritem = tk.Menu(menubar, tearoff=element.Tearoff) baritem = tk.Menu(menubar, tearoff=element.Tearoff)
pos = menu_entry[0].find('_&') pos = menu_entry[0].find('&')
# print(pos)
if pos != -1: if pos != -1:
_ = menu_entry[0][:pos] if pos == 0 or menu_entry[0][pos-1] != "\\":
try: menu_entry[0] = menu_entry[0][:pos] + menu_entry[0][pos+1:]
_ += menu_entry[0][pos+2:] menubar.add_cascade(label=menu_entry[0], menu=baritem, underline = pos)
except:
pass
menu_entry[0] = _
menubar.add_cascade(label=menu_entry[0], menu=baritem, underline = pos-1)
if len(menu_entry) > 1: if len(menu_entry) > 1:
AddMenuItem(baritem, menu_entry[1], element) AddMenuItem(baritem, menu_entry[1], element)
toplevel_form.TKroot.configure(menu=element.TKMenu) toplevel_form.TKroot.configure(menu=element.TKMenu)
@ -3947,13 +3946,15 @@ def PopupGetFolder(message, default_path='', no_window=False, size=(None,None),
root.destroy() root.destroy()
return folder_name return folder_name
with Window(title=message, icon=icon, auto_size_text=True, button_color=button_color, background_color=background_color,
font=font, no_titlebar=no_titlebar, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top, location=location) as form:
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()],
[Ok(), Cancel()]] [Ok(), Cancel()]]
(button, input_values) = form.LayoutAndRead(layout) window = Window(title=message, icon=icon, auto_size_text=True, button_color=button_color, background_color=background_color,
font=font, no_titlebar=no_titlebar, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top, location=location)
(button, input_values) = window.LayoutAndRead(layout)
if button != 'Ok': if button != 'Ok':
return None return None
else: else:
@ -3999,13 +4000,14 @@ def PopupGetFile(message, default_path='', default_extension='', save_as=False,
browse_button = SaveAs(file_types=file_types) if save_as else FileBrowse(file_types=file_types) browse_button = SaveAs(file_types=file_types) if save_as else FileBrowse(file_types=file_types)
with Window(title=message, icon=icon, auto_size_text=True, button_color=button_color, font=font, background_color=background_color,
no_titlebar=no_titlebar, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top, location=location) as form:
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],
[Ok(), Cancel()]] [Ok(), Cancel()]]
(button, input_values) = form.LayoutAndRead(layout) window = Window(title=message, icon=icon, auto_size_text=True, button_color=button_color, font=font, background_color=background_color,
no_titlebar=no_titlebar, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top, location=location)
(button, input_values) = window.Layout(layout).Read()
if button != 'Ok': if button != 'Ok':
return None return None
else: else:
@ -4033,13 +4035,16 @@ def PopupGetText(message, default_text='', password_char='', size=(None,None), b
:param location: :param location:
:return: Text entered or None if window was closed :return: Text entered or None if window was closed
""" """
with Window(title=message, icon=icon, auto_size_text=True, button_color=button_color, no_titlebar=no_titlebar,
background_color=background_color, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top, location=location) as form:
layout = [[Text(message, auto_size_text=True, text_color=text_color, background_color=background_color, font=font)], layout = [[Text(message, auto_size_text=True, text_color=text_color, background_color=background_color, font=font)],
[InputText(default_text=default_text, size=size, password_char=password_char)], [InputText(default_text=default_text, size=size, password_char=password_char)],
[Ok(), Cancel()]] [Ok(), Cancel()]]
(button, input_values) = form.LayoutAndRead(layout) window = Window(title=message, icon=icon, auto_size_text=True, button_color=button_color, no_titlebar=no_titlebar,
background_color=background_color, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top, location=location)
(button, input_values) = window.Layout(layout).Read()
if button != 'Ok': if button != 'Ok':
return None return None
else: else:
@ -4389,7 +4394,7 @@ def Popup(*args, button_color=None, background_color=None, text_color=None, butt
else: else:
local_line_width = MESSAGE_BOX_LINE_WIDTH local_line_width = MESSAGE_BOX_LINE_WIDTH
title = args_to_print[0] if args_to_print[0] is not None else 'None' title = args_to_print[0] if args_to_print[0] is not None else 'None'
with Window(title, auto_size_text=True, background_color=background_color, button_color=button_color, auto_close=auto_close, auto_close_duration=auto_close_duration, icon=icon, font=font, no_titlebar=no_titlebar, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top, location=location) as form: form = Window(title, auto_size_text=True, background_color=background_color, button_color=button_color, auto_close=auto_close, auto_close_duration=auto_close_duration, icon=icon, font=font, no_titlebar=no_titlebar, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top, location=location)
max_line_total, total_lines = 0,0 max_line_total, total_lines = 0,0
for message in args_to_print: for message in args_to_print:
# fancy code to check if string and convert if not is not need. Just always convert to string :-) # fancy code to check if string and convert if not is not need. Just always convert to string :-)