Merge pull request #154 from MikeTheWatchGuy/Dev-latest

Added ability to disable a Combobox... can also create as disabled
This commit is contained in:
MikeTheWatchGuy 2018-09-07 13:26:22 -04:00 committed by GitHub
commit 439f8d981d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -298,7 +298,7 @@ class InputText(Element):
# Combo # # Combo #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class InputCombo(Element): class InputCombo(Element):
def __init__(self, values, default_value=None, scale=(None, None), size=(None, None), auto_size_text=None, background_color=None, text_color=None, change_submits=False, key=None, pad=None): def __init__(self, values, default_value=None, scale=(None, None), size=(None, None), auto_size_text=None, background_color=None, text_color=None, change_submits=False, disabled=False, key=None, pad=None):
''' '''
Input Combo Box Element (also called Dropdown box) Input Combo Box Element (also called Dropdown box)
:param values: :param values:
@ -309,14 +309,15 @@ class InputCombo(Element):
''' '''
self.Values = values self.Values = values
self.DefaultValue = default_value self.DefaultValue = default_value
self.TKComboBox = None
self.ChangeSubmits = change_submits self.ChangeSubmits = change_submits
self.TKCombo = None
self.InitializeAsDisabled = disabled
bg = background_color if background_color else DEFAULT_INPUT_ELEMENTS_COLOR bg = background_color if background_color else DEFAULT_INPUT_ELEMENTS_COLOR
fg = text_color if text_color is not None else DEFAULT_INPUT_TEXT_COLOR fg = text_color if text_color is not None else DEFAULT_INPUT_TEXT_COLOR
super().__init__(ELEM_TYPE_INPUT_COMBO, scale=scale, size=size, auto_size_text=auto_size_text, background_color=bg, text_color=fg, key=key, pad=pad) super().__init__(ELEM_TYPE_INPUT_COMBO, scale=scale, size=size, auto_size_text=auto_size_text, background_color=bg, text_color=fg, key=key, pad=pad)
def Update(self, value=None, values=None): def Update(self, value=None, values=None, disabled=False):
if values is not None: if values is not None:
try: try:
self.TKCombo['values'] = values self.TKCombo['values'] = values
@ -324,6 +325,8 @@ class InputCombo(Element):
except: pass except: pass
self.Values = values self.Values = values
self.TKCombo['state'] = 'disable' if disabled else 'enable'
for index, v in enumerate(self.Values): for index, v in enumerate(self.Values):
if v == value: if v == value:
try: try:
@ -335,7 +338,7 @@ class InputCombo(Element):
def __del__(self): def __del__(self):
try: try:
self.TKComboBox.__del__() self.TKCombo.__del__()
except: except:
pass pass
super().__del__() super().__del__()
@ -2302,6 +2305,8 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKCombo = ttk.Combobox(tk_row_frame, width=width, textvariable=element.TKStringVar,font=font ) element.TKCombo = ttk.Combobox(tk_row_frame, width=width, textvariable=element.TKStringVar,font=font )
# element.TKCombo['state']='readonly' # element.TKCombo['state']='readonly'
element.TKCombo['values'] = element.Values element.TKCombo['values'] = element.Values
if element.InitializeAsDisabled:
element.TKCombo['state'] = 'disabled'
# if element.BackgroundColor is not None: # if element.BackgroundColor is not None:
# element.TKCombo.configure(background=element.BackgroundColor) # element.TKCombo.configure(background=element.BackgroundColor)
element.TKCombo.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1]) element.TKCombo.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1])