Fixed bug in table element- computing bad width, added 10 pixels to tree column sizes, moved block of Image layout code so executes even if no image specified

This commit is contained in:
PySimpleGUI 2020-03-26 08:38:23 -04:00
parent e55b9a3e72
commit 689833b040
1 changed files with 20 additions and 20 deletions

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3 #!/usr/bin/python3
version = __version__ = "4.17.0.2 Unreleased - popup_animated title parm, checkbox update text" version = __version__ = "4.17.0.3 Unreleased - popup_animated title parm, checkbox update text, table width fix"
port = 'PySimpleGUI' port = 'PySimpleGUI'
@ -10364,7 +10364,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
photo = tk.PhotoImage(data=element.Data) photo = tk.PhotoImage(data=element.Data)
else: else:
photo = None photo = None
print('*ERROR laying out form.... Image Element has no image specified*') # print('*ERROR laying out form.... Image Element has no image specified*')
if photo is not None: if photo is not None:
if element_size == ( if element_size == (
@ -10386,19 +10386,20 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.tktext_label.image = photo element.tktext_label.image = photo
# tktext_label.configure(anchor=tk.NW, image=photo) # tktext_label.configure(anchor=tk.NW, image=photo)
element.tktext_label.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1]) element.tktext_label.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False:
element.tktext_label.pack_forget() if element.Visible is False:
if element.Tooltip is not None: element.tktext_label.pack_forget()
element.TooltipObject = ToolTip(element.tktext_label, text=element.Tooltip, if element.Tooltip is not None:
timeout=DEFAULT_TOOLTIP_TIME) element.TooltipObject = ToolTip(element.tktext_label, text=element.Tooltip,
if element.EnableEvents: timeout=DEFAULT_TOOLTIP_TIME)
element.tktext_label.bind('<ButtonPress-1>', element._ClickHandler) if element.EnableEvents:
if element.RightClickMenu or toplevel_form.RightClickMenu: element.tktext_label.bind('<ButtonPress-1>', element._ClickHandler)
menu = element.RightClickMenu or toplevel_form.RightClickMenu if element.RightClickMenu or toplevel_form.RightClickMenu:
top_menu = tk.Menu(toplevel_form.TKroot, tearoff=False) menu = element.RightClickMenu or toplevel_form.RightClickMenu
AddMenuItem(top_menu, menu[1], element) top_menu = tk.Menu(toplevel_form.TKroot, tearoff=False)
element.TKRightClickMenu = top_menu AddMenuItem(top_menu, menu[1], element)
element.tktext_label.bind('<Button-3>', element._RightClickMenuCallback) element.TKRightClickMenu = top_menu
element.tktext_label.bind('<Button-3>', element._RightClickMenuCallback)
# ------------------------- Canvas placement element ------------------------- # # ------------------------- Canvas placement element ------------------------- #
elif element_type == ELEM_TYPE_CANVAS: elif element_type == ELEM_TYPE_CANVAS:
width, height = element_size width, height = element_size
@ -10649,6 +10650,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
else: else:
anchor = tk.CENTER anchor = tk.CENTER
column_widths = {} column_widths = {}
# create column width list
for row in element.Values: for row in element.Values:
for i, col in enumerate(row): for i, col in enumerate(row):
col_width = min(len(str(col)), element.MaxColumnWidth) col_width = min(len(str(col)), element.MaxColumnWidth)
@ -10689,14 +10691,13 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
for i, heading in enumerate(headings): for i, heading in enumerate(headings):
treeview.heading(heading, text=heading) treeview.heading(heading, text=heading)
if element.AutoSizeColumns: if element.AutoSizeColumns:
width = max(column_widths[i], _string_width_in_pixels(font, heading) + 10) width = max(column_widths[i], len(heading)) * _char_width_in_pixels(font)
else: else:
try: try:
width = element.ColumnWidths[i] * _char_width_in_pixels(font) width = element.ColumnWidths[i] * _char_width_in_pixels(font)
except: except:
width = element.DefaultColumnWidth * _char_width_in_pixels(font) width = element.DefaultColumnWidth * _char_width_in_pixels(font)
treeview.column(heading, width=width, minwidth=10, anchor=anchor, stretch=0) treeview.column(heading, width=width, minwidth=10, anchor=anchor, stretch=0)
# Insert values into the tree # 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:
@ -10802,8 +10803,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
width = element.ColumnWidths[i] width = element.ColumnWidths[i]
except: except:
width = element.DefaultColumnWidth width = element.DefaultColumnWidth
treeview.column(heading, width=width * _char_width_in_pixels(font), anchor=anchor) treeview.column(heading, width=width * _char_width_in_pixels(font)+ 10, anchor=anchor)
def add_treeview_data(node): def add_treeview_data(node):
""" """
@ -15303,7 +15303,7 @@ def main():
tab4 = Tab('Variable Choice', [[Frame('Variable Choice Group', frame4, title_color='blue')]], tooltip='tab 4', title_color='red') tab4 = Tab('Variable Choice', [[Frame('Variable Choice Group', frame4, title_color='blue')]], tooltip='tab 4', title_color='red')
layout1 = [ layout1 = [
[Image(data=DEFAULT_BASE64_ICON), Image(data=DEFAULT_BASE64_LOADING_GIF, key='_IMAGE_'), [Image(data=DEFAULT_BASE64_ICON, enable_events=True, key='-LOGO-'), Image(data=DEFAULT_BASE64_LOADING_GIF, enable_events=True, key='_IMAGE_'),
Text('You are running the PySimpleGUI.py file instead of importing it.\nAnd are thus seeing a test harness instead of your code', font='ANY 15', Text('You are running the PySimpleGUI.py file instead of importing it.\nAnd are thus seeing a test harness instead of your code', font='ANY 15',
tooltip='My tooltip', key='_TEXT1_')], tooltip='My tooltip', key='_TEXT1_')],
[Frame('Input Text Group', frame1, title_color='red')], [Frame('Input Text Group', frame1, title_color='red')],