commit
11f2163c66
|
@ -366,6 +366,24 @@ class Element():
|
||||||
self.ParentForm.FormRemainedOpen = True
|
self.ParentForm.FormRemainedOpen = True
|
||||||
self.ParentForm.TKroot.quit() # kick the users out of the mainloop
|
self.ParentForm.TKroot.quit() # kick the users out of the mainloop
|
||||||
|
|
||||||
|
def CheckboxHandler(self):
|
||||||
|
MyForm = self.ParentForm
|
||||||
|
if self.Key is not None:
|
||||||
|
self.ParentForm.LastButtonClicked = self.Key
|
||||||
|
else:
|
||||||
|
self.ParentForm.LastButtonClicked = ''
|
||||||
|
self.ParentForm.FormRemainedOpen = True
|
||||||
|
self.ParentForm.TKroot.quit()
|
||||||
|
|
||||||
|
def TabGroupSelectHandler(self, event):
|
||||||
|
MyForm = self.ParentForm
|
||||||
|
if self.Key is not None:
|
||||||
|
self.ParentForm.LastButtonClicked = self.Key
|
||||||
|
else:
|
||||||
|
self.ParentForm.LastButtonClicked = ''
|
||||||
|
self.ParentForm.FormRemainedOpen = True
|
||||||
|
self.ParentForm.TKroot.quit()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
try:
|
try:
|
||||||
self.TKStringVar.__del__()
|
self.TKStringVar.__del__()
|
||||||
|
@ -646,7 +664,7 @@ class Radio(Element):
|
||||||
# Checkbox #
|
# Checkbox #
|
||||||
# ---------------------------------------------------------------------- #
|
# ---------------------------------------------------------------------- #
|
||||||
class Checkbox(Element):
|
class Checkbox(Element):
|
||||||
def __init__(self, text, default=False, size=(None, None), auto_size_text=None, font=None, background_color=None, text_color=None, key=None, pad=None, tooltip=None):
|
def __init__(self, text, default=False, size=(None, None), auto_size_text=None, font=None, background_color=None, text_color=None, change_submits=False, key=None, pad=None, tooltip=None):
|
||||||
'''
|
'''
|
||||||
Check Box Element
|
Check Box Element
|
||||||
:param text:
|
:param text:
|
||||||
|
@ -661,6 +679,7 @@ class Checkbox(Element):
|
||||||
self.Value = None
|
self.Value = None
|
||||||
self.TKCheckbutton = None
|
self.TKCheckbutton = None
|
||||||
self.TextColor = text_color if text_color else DEFAULT_TEXT_COLOR
|
self.TextColor = text_color if text_color else DEFAULT_TEXT_COLOR
|
||||||
|
self.ChangeSubmits = change_submits
|
||||||
|
|
||||||
super().__init__(ELEM_TYPE_INPUT_CHECKBOX, size=size, auto_size_text=auto_size_text, font=font,
|
super().__init__(ELEM_TYPE_INPUT_CHECKBOX, size=size, auto_size_text=auto_size_text, font=font,
|
||||||
background_color=background_color, text_color=self.TextColor, key=key, pad=pad, tooltip=tooltip)
|
background_color=background_color, text_color=self.TextColor, key=key, pad=pad, tooltip=tooltip)
|
||||||
|
@ -1514,7 +1533,7 @@ class Tab(Element):
|
||||||
# TabGroup #
|
# TabGroup #
|
||||||
# ---------------------------------------------------------------------- #
|
# ---------------------------------------------------------------------- #
|
||||||
class TabGroup(Element):
|
class TabGroup(Element):
|
||||||
def __init__(self, layout, title_color=None, background_color=None, font=None, pad=None, border_width=None, key=None, tooltip=None):
|
def __init__(self, layout, title_color=None, background_color=None, font=None, change_submits=False, pad=None, border_width=None, key=None, tooltip=None):
|
||||||
|
|
||||||
self.UseDictionary = False
|
self.UseDictionary = False
|
||||||
self.ReturnValues = None
|
self.ReturnValues = None
|
||||||
|
@ -1526,6 +1545,7 @@ class TabGroup(Element):
|
||||||
self.TKNotebook = None
|
self.TKNotebook = None
|
||||||
self.BorderWidth = border_width
|
self.BorderWidth = border_width
|
||||||
self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR
|
self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR
|
||||||
|
self.ChangeSubmits = change_submits
|
||||||
|
|
||||||
self.Layout(layout)
|
self.Layout(layout)
|
||||||
|
|
||||||
|
@ -2628,13 +2648,18 @@ def BuildResultsForSubform(form, initialize_only, top_level_form):
|
||||||
element.TKText.delete('1.0', tk.END)
|
element.TKText.delete('1.0', tk.END)
|
||||||
except:
|
except:
|
||||||
value = None
|
value = None
|
||||||
|
elif element.Type == ELEM_TYPE_TAB_GROUP:
|
||||||
|
try:
|
||||||
|
value=element.TKNotebook.tab(element.TKNotebook.index('current'))['text']
|
||||||
|
except:
|
||||||
|
value = None
|
||||||
else:
|
else:
|
||||||
value = None
|
value = None
|
||||||
|
|
||||||
# if an input type element, update the results
|
# if an input type element, update the results
|
||||||
if element.Type != ELEM_TYPE_BUTTON and element.Type != ELEM_TYPE_TEXT and element.Type != ELEM_TYPE_IMAGE and\
|
if element.Type != ELEM_TYPE_BUTTON and element.Type != ELEM_TYPE_TEXT and element.Type != ELEM_TYPE_IMAGE and\
|
||||||
element.Type != ELEM_TYPE_OUTPUT and element.Type != ELEM_TYPE_PROGRESS_BAR and \
|
element.Type != ELEM_TYPE_OUTPUT and element.Type != ELEM_TYPE_PROGRESS_BAR and \
|
||||||
element.Type!= ELEM_TYPE_COLUMN and element.Type != ELEM_TYPE_FRAME and element.Type != ELEM_TYPE_TAB_GROUP \
|
element.Type!= ELEM_TYPE_COLUMN and element.Type != ELEM_TYPE_FRAME \
|
||||||
and element.Type != ELEM_TYPE_TAB:
|
and element.Type != ELEM_TYPE_TAB:
|
||||||
AddToReturnList(form, value)
|
AddToReturnList(form, value)
|
||||||
AddToReturnDictionary(top_level_form, element, value)
|
AddToReturnDictionary(top_level_form, element, value)
|
||||||
|
@ -2729,7 +2754,18 @@ 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}')
|
||||||
top_menu.add_command(label=sub_menu_info, command=lambda: Menu.MenuItemChosenCallback(element, sub_menu_info))
|
pos = sub_menu_info.find('_&')
|
||||||
|
if pos != -1:
|
||||||
|
_ = sub_menu_info[:pos]
|
||||||
|
try:
|
||||||
|
_ += sub_menu_info[pos+2:]
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
sub_menu_info = _
|
||||||
|
if sub_menu_info == '---':
|
||||||
|
top_menu.add('separator')
|
||||||
|
else:
|
||||||
|
top_menu.add_command(label=sub_menu_info, underline=pos-1, 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)):
|
||||||
|
@ -2892,7 +2928,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
||||||
tkbutton.bind('<ButtonRelease-1>', element.ButtonReleaseCallBack)
|
tkbutton.bind('<ButtonRelease-1>', element.ButtonReleaseCallBack)
|
||||||
tkbutton.bind('<ButtonPress-1>', element.ButtonPressCallBack)
|
tkbutton.bind('<ButtonPress-1>', element.ButtonPressCallBack)
|
||||||
if bc != (None, None) and bc != COLOR_SYSTEM_DEFAULT:
|
if bc != (None, None) and bc != COLOR_SYSTEM_DEFAULT:
|
||||||
tkbutton.config(foreground=bc[0], background=bc[1])
|
tkbutton.config(foreground=bc[0], background=bc[1], activebackground=bc[1])
|
||||||
element.TKButton = tkbutton # not used yet but save the TK button in case
|
element.TKButton = tkbutton # not used yet but save the TK button in case
|
||||||
wraplen = tkbutton.winfo_reqwidth() # width of widget in Pixels
|
wraplen = tkbutton.winfo_reqwidth() # width of widget in Pixels
|
||||||
if element.ImageFilename: # if button has an image on it
|
if element.ImageFilename: # if button has an image on it
|
||||||
|
@ -3064,12 +3100,19 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
||||||
default_value = element.InitialState
|
default_value = element.InitialState
|
||||||
element.TKIntVar = tk.IntVar()
|
element.TKIntVar = tk.IntVar()
|
||||||
element.TKIntVar.set(default_value if default_value is not None else 0)
|
element.TKIntVar.set(default_value if default_value is not None else 0)
|
||||||
element.TKCheckbutton = tk.Checkbutton(tk_row_frame, anchor=tk.NW, text=element.Text, width=width, variable=element.TKIntVar, bd=border_depth, font=font)
|
if element.ChangeSubmits:
|
||||||
|
element.TKCheckbutton = tk.Checkbutton(tk_row_frame, anchor=tk.NW, text=element.Text, width=width,
|
||||||
|
variable=element.TKIntVar, bd=border_depth, font=font,
|
||||||
|
command=element.CheckboxHandler)
|
||||||
|
else:
|
||||||
|
element.TKCheckbutton = tk.Checkbutton(tk_row_frame, anchor=tk.NW, text=element.Text, width=width,
|
||||||
|
variable=element.TKIntVar, bd=border_depth, font=font)
|
||||||
if default_value is None:
|
if default_value is None:
|
||||||
element.TKCheckbutton.configure(state='disable')
|
element.TKCheckbutton.configure(state='disable')
|
||||||
if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT:
|
if element.BackgroundColor is not None and element.BackgroundColor != COLOR_SYSTEM_DEFAULT:
|
||||||
element.TKCheckbutton.configure(background=element.BackgroundColor)
|
element.TKCheckbutton.configure(background=element.BackgroundColor)
|
||||||
element.TKCheckbutton.configure(selectcolor=element.BackgroundColor)
|
element.TKCheckbutton.configure(selectcolor=element.BackgroundColor)
|
||||||
|
element.TKCheckbutton.configure(activebackground=element.BackgroundColor)
|
||||||
if text_color is not None and text_color != COLOR_SYSTEM_DEFAULT:
|
if text_color is not None and text_color != COLOR_SYSTEM_DEFAULT:
|
||||||
element.TKCheckbutton.configure(fg=text_color)
|
element.TKCheckbutton.configure(fg=text_color)
|
||||||
element.TKCheckbutton.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1])
|
element.TKCheckbutton.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1])
|
||||||
|
@ -3193,21 +3236,23 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
||||||
element.TooltipObject = ToolTip(element._TKCanvas, text=element.Tooltip, timeout=DEFAULT_TOOLTIP_TIME)
|
element.TooltipObject = ToolTip(element._TKCanvas, text=element.Tooltip, timeout=DEFAULT_TOOLTIP_TIME)
|
||||||
# ------------------------- MENUBAR element ------------------------- #
|
# ------------------------- MENUBAR element ------------------------- #
|
||||||
elif element_type == ELEM_TYPE_MENUBAR:
|
elif element_type == ELEM_TYPE_MENUBAR:
|
||||||
menu_def = (('File', ('Open', 'Save')),
|
|
||||||
('Help', 'About...'),)
|
|
||||||
# ('Help',))
|
|
||||||
|
|
||||||
menu_def = element.MenuDefinition
|
menu_def = element.MenuDefinition
|
||||||
|
|
||||||
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')
|
||||||
baritem = tk.Menu(menubar, tearoff=element.Tearoff)
|
baritem = tk.Menu(menubar, tearoff=element.Tearoff)
|
||||||
menubar.add_cascade(label=menu_entry[0], menu=baritem)
|
pos = menu_entry[0].find('_&')
|
||||||
|
if pos != -1:
|
||||||
|
_ = menu_entry[0][:pos]
|
||||||
|
try:
|
||||||
|
_ += menu_entry[0][pos+2:]
|
||||||
|
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)
|
||||||
# ------------------------- Frame element ------------------------- #
|
# ------------------------- Frame element ------------------------- #
|
||||||
elif element_type == ELEM_TYPE_FRAME:
|
elif element_type == ELEM_TYPE_FRAME:
|
||||||
|
@ -3256,6 +3301,8 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
||||||
# highlightcolor=element.BackgroundColor)
|
# highlightcolor=element.BackgroundColor)
|
||||||
# if element.TextColor != COLOR_SYSTEM_DEFAULT and element.TextColor is not None:
|
# if element.TextColor != COLOR_SYSTEM_DEFAULT and element.TextColor is not None:
|
||||||
# element.TKNotebook.configure(foreground=element.TextColor)
|
# element.TKNotebook.configure(foreground=element.TextColor)
|
||||||
|
if element.ChangeSubmits:
|
||||||
|
element.TKNotebook.bind('<<NotebookTabChanged>>', element.TabGroupSelectHandler)
|
||||||
if element.BorderWidth is not None:
|
if element.BorderWidth is not None:
|
||||||
element.TKNotebook.configure(borderwidth=element.BorderWidth)
|
element.TKNotebook.configure(borderwidth=element.BorderWidth)
|
||||||
if element.Tooltip is not None:
|
if element.Tooltip is not None:
|
||||||
|
|
Loading…
Reference in New Issue