New read_only parameter for Combo, new feature - ability to read selected table rows!

This commit is contained in:
MikeTheWatchGuy 2018-10-19 14:52:21 -04:00
parent 15b4b9701b
commit 523231141a
1 changed files with 58 additions and 18 deletions

View File

@ -423,13 +423,12 @@ class Element():
# Input Class # # Input Class #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class InputText(Element): class InputText(Element):
def __init__(self, default_text ='', size=(None, None), disabled=False, auto_size_text=None, password_char='', def __init__(self, default_text ='', size=(None, None), disabled=False, password_char='',
justification=None, background_color=None, text_color=None, font=None, tooltip=None, do_not_clear=False, key=None, focus=False, pad=None): justification=None, background_color=None, text_color=None, font=None, tooltip=None, do_not_clear=False, key=None, focus=False, pad=None):
''' '''
Input a line of text Element Input a line of text Element
:param default_text: Default value to display :param default_text: Default value to display
:param size: Size of field in characters :param size: Size of field in characters
:param auto_size_text: True if should shrink field to fit the default text
:param password_char: If non-blank, will display this character for every character typed :param password_char: If non-blank, will display this character for every character typed
:param background_color: Color for Element. Text or RGB Hex :param background_color: Color for Element. Text or RGB Hex
''' '''
@ -441,7 +440,7 @@ class InputText(Element):
self.do_not_clear = do_not_clear self.do_not_clear = do_not_clear
self.Justification = justification self.Justification = justification
self.Disabled = disabled self.Disabled = disabled
super().__init__(ELEM_TYPE_INPUT_TEXT, size=size, auto_size_text=auto_size_text, background_color=bg, text_color=fg, key=key, pad=pad, font=font, tooltip=tooltip) super().__init__(ELEM_TYPE_INPUT_TEXT, size=size, background_color=bg, text_color=fg, key=key, pad=pad, font=font, tooltip=tooltip)
def Update(self, value=None, disabled=None): def Update(self, value=None, disabled=None):
@ -470,7 +469,7 @@ Input = InputText
# Combo # # Combo #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class InputCombo(Element): class InputCombo(Element):
def __init__(self, values, default_value=None, size=(None, None), auto_size_text=None, background_color=None, text_color=None, change_submits=False, disabled=False, key=None, pad=None, tooltip=None): def __init__(self, values, default_value=None, size=(None, None), auto_size_text=None, background_color=None, text_color=None, change_submits=False, disabled=False, key=None, pad=None, tooltip=None, readonly=False):
''' '''
Input Combo Box Element (also called Dropdown box) Input Combo Box Element (also called Dropdown box)
:param values: :param values:
@ -482,14 +481,15 @@ class InputCombo(Element):
self.DefaultValue = default_value self.DefaultValue = default_value
self.ChangeSubmits = change_submits self.ChangeSubmits = change_submits
self.TKCombo = None self.TKCombo = None
self.InitializeAsDisabled = disabled # self.InitializeAsDisabled = disabled
self.Disabled = disabled self.Disabled = disabled
self.Readonly=readonly
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, size=size, auto_size_text=auto_size_text, background_color=bg, text_color=fg, key=key, pad=pad, tooltip=tooltip) super().__init__(ELEM_TYPE_INPUT_COMBO, size=size, auto_size_text=auto_size_text, background_color=bg, text_color=fg, key=key, pad=pad, tooltip=tooltip)
def Update(self, value=None, values=None, set_to_index=None, disabled=None): def Update(self, value=None, values=None, set_to_index=None, disabled=None, readonly=None):
if values is not None: if values is not None:
try: try:
self.TKCombo['values'] = values self.TKCombo['values'] = values
@ -514,6 +514,10 @@ class InputCombo(Element):
self.TKCombo['state'] = 'disable' self.TKCombo['state'] = 'disable'
elif disabled == False: elif disabled == False:
self.TKCombo['state'] = 'enable' self.TKCombo['state'] = 'enable'
if readonly is not None:
self.Readonly = readonly
if self.Readonly:
self.TKCombo['state']='readonly'
def __del__(self): def __del__(self):
@ -2272,11 +2276,24 @@ class Table(Element):
self.NumRows = num_rows if num_rows is not None else size[1] self.NumRows = num_rows if num_rows is not None else size[1]
self.TKTreeview = None self.TKTreeview = None
self.AlternatingRowColor = alternating_row_color self.AlternatingRowColor = alternating_row_color
self.SelectedRows = []
super().__init__(ELEM_TYPE_TABLE, text_color=text_color, background_color=background_color, font=font, size=size, pad=pad, key=key, tooltip=tooltip) super().__init__(ELEM_TYPE_TABLE, text_color=text_color, background_color=background_color, font=font, size=size, pad=pad, key=key, tooltip=tooltip)
return return
def treeview_selected(self, event):
selections = self.TKTreeview.selection()
self.SelectedRows = [int(x[1:], 16)-1 for x in selections]
# ttk.Treeview.selection
# print(select)
# self.TKTreeview.TreeSelection.get_selected_rows()
#
# iid = self.TKTreeview.focus()
# # item = self.Values[iid]
# print('Selected item iid: %s' % iid)
# #self.process_directory(iid, path)
def __del__(self): def __del__(self):
super().__del__() super().__del__()
@ -2546,10 +2563,15 @@ class Window:
return self.ReturnValues return self.ReturnValues
# ------------------------- SetIcon - set the window's fav icon ------------------------- # # ------------------------- SetIcon - set the window's fav icon ------------------------- #
def SetIcon(self, icon): def SetIcon(self, icon=None, pngbase64=None):
self.WindowIcon = icon if pngbase64 != None:
img = tkinter.PhotoImage(data=pngbase64)
wicon = img
else:
wicon = icon
self.WindowIcon = wicon
try: try:
self.TKroot.iconbitmap(icon) self.TKroot.iconbitmap(wicon)
except: pass except: pass
def _GetElementAtLocation(self, location): def _GetElementAtLocation(self, location):
@ -3097,19 +3119,31 @@ def BuildResultsForSubform(form, initialize_only, top_level_form):
value = tab_key value = tab_key
except: except:
value = None value = None
elif element.Type == ELEM_TYPE_TABLE:
value = element.SelectedRows
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_OUTPUT and element.Type != ELEM_TYPE_PROGRESS_BAR and \ element.Type != ELEM_TYPE_TEXT and \
element.Type!= ELEM_TYPE_COLUMN and element.Type != ELEM_TYPE_FRAME \ element.Type != ELEM_TYPE_IMAGE 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: and element.Type != ELEM_TYPE_TAB:
AddToReturnList(form, value) AddToReturnList(form, value)
AddToReturnDictionary(top_level_form, element, value) AddToReturnDictionary(top_level_form, element, value)
elif (element.Type == ELEM_TYPE_BUTTON and element.BType == BUTTON_TYPE_CALENDAR_CHOOSER and element.Target == (None,None)) or \ elif (element.Type == ELEM_TYPE_BUTTON and
(element.Type == ELEM_TYPE_BUTTON and element.BType == BUTTON_TYPE_COLOR_CHOOSER and element.Target == (None,None)) or \ element.BType == BUTTON_TYPE_CALENDAR_CHOOSER and
(element.Type == ELEM_TYPE_BUTTON and element.Key is not None and (element.BType in (BUTTON_TYPE_SAVEAS_FILE, BUTTON_TYPE_BROWSE_FILE, BUTTON_TYPE_BROWSE_FILES, BUTTON_TYPE_BROWSE_FOLDER))): element.Target == (None,None)) or \
(element.Type == ELEM_TYPE_BUTTON and
element.BType == BUTTON_TYPE_COLOR_CHOOSER and
element.Target == (None,None)) or \
(element.Type == ELEM_TYPE_BUTTON
and element.Key is not None and
(element.BType in (BUTTON_TYPE_SAVEAS_FILE, BUTTON_TYPE_BROWSE_FILE, BUTTON_TYPE_BROWSE_FILES, BUTTON_TYPE_BROWSE_FOLDER))):
AddToReturnList(form, value) AddToReturnList(form, value)
AddToReturnDictionary(top_level_form, element, value) AddToReturnDictionary(top_level_form, element, value)
@ -3510,8 +3544,9 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKCombo.configure(height=element.Size[1]) element.TKCombo.configure(height=element.Size[1])
# 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.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])
@ -3524,7 +3559,9 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKCombo.current(0) element.TKCombo.current(0)
if element.ChangeSubmits: if element.ChangeSubmits:
element.TKCombo.bind('<<ComboboxSelected>>', element.ComboboxSelectHandler) element.TKCombo.bind('<<ComboboxSelected>>', element.ComboboxSelectHandler)
if element.Disabled == True: if element.Readonly:
element.TKCombo['state']='readonly'
if element.Disabled is True: # note overrides readonly if disabled
element.TKCombo['state'] = 'disabled' element.TKCombo['state'] = 'disabled'
if element.Tooltip is not None: if element.Tooltip is not None:
element.TooltipObject = ToolTip(element.TKCombo, text=element.Tooltip, timeout=DEFAULT_TOOLTIP_TIME) element.TooltipObject = ToolTip(element.TKCombo, text=element.Tooltip, timeout=DEFAULT_TOOLTIP_TIME)
@ -3930,6 +3967,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
width = element.DefaultColumnWidth width = element.DefaultColumnWidth
treeview.column(heading, width=width*CharWidthInPixels(), anchor=anchor) treeview.column(heading, width=width*CharWidthInPixels(), anchor=anchor)
# Insert values into the tree
for i, value in enumerate(element.Values): for i, value in enumerate(element.Values):
if element.DisplayRowNumbers: if element.DisplayRowNumbers:
value = [i] + value value = [i] + value
@ -3941,6 +3979,8 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
if element.TextColor is not None and element.TextColor != COLOR_SYSTEM_DEFAULT: if element.TextColor is not None and element.TextColor != COLOR_SYSTEM_DEFAULT:
ttk.Style().configure("Treeview", foreground=element.TextColor) ttk.Style().configure("Treeview", foreground=element.TextColor)
# scrollable_frame.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1], expand=True, fill='both') # scrollable_frame.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1], expand=True, fill='both')
treeview.bind("<<TreeviewSelect>>", element.treeview_selected)
element.TKTreeview.pack(side=tk.LEFT,expand=True, padx=0, pady=0, fill='both') element.TKTreeview.pack(side=tk.LEFT,expand=True, padx=0, pady=0, fill='both')
if element.Tooltip is not None: if element.Tooltip is not None:
element.TooltipObject = ToolTip(element.TKTreeview, text=element.Tooltip, timeout=DEFAULT_TOOLTIP_TIME) element.TooltipObject = ToolTip(element.TKTreeview, text=element.Tooltip, timeout=DEFAULT_TOOLTIP_TIME)