Skip to content

Commit fe8737d

Browse files
committed
Table element - better column width sizing for the row number column as well as other column when the header is wider than the data.
1 parent 2162ebc commit fe8737d

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

PySimpleGUI.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/python3
2-
version = __version__ = "4.55.1.7 Unreleased"
2+
version = __version__ = "4.55.1.8 Unreleased"
33

44
_change_log = """
55
Changelog since 4.55.1 released to PyPI on 7-Nov-2021
@@ -25,6 +25,12 @@
2525
New Table Element parameter - right_click_selects. Default is False. If True, then will select a row using the right mouse button, but only if
2626
zero or one rows are selected. If multiple rows are already selected, then the right click will not change the selection. This feature enables
2727
a right-click-menu to be combined with table selection for features such as "delete row" using a right click menu.
28+
Fixed bug in Column element - was incorrectly checking background color for None or COLOR_SYSTEM_DEFAULT
29+
4.55.1.8
30+
Changed docstring for Table.get_last_clicked_postition to indicate what's returned now. Was not useful for tkinter port until recently when cell clicks added.
31+
Better auto-sizing of Columns for Tables.
32+
Better sizing of the row number column using the font for the header in the calculation
33+
Use the column heading font to help determine if the header will be what determines the width instead of the data in the column
2834
"""
2935

3036
__version__ = version.split()[0] # For PEP 396 and PEP 345
@@ -8113,11 +8119,9 @@ def get(self):
81138119

81148120
def get_last_clicked_position(self):
81158121
"""
8116-
Dummy function for tkinter port. In the Qt port you can read back the values in the table in case they were
8117-
edited. Don't know yet how to enable editing of a Tree in tkinter so just returning the values provided by
8118-
user when Table was created or Updated.
8119-
8120-
:return: the current table values (for now what was originally provided up updated)
8122+
Returns a tuple with the row and column of the cell that was last clicked.
8123+
Headers will have a row == -1 and the Row Number Column (if present) will have a column == -1
8124+
:return: The (row,col) position of the last cell clicked in the table
81218125
:rtype: (int | None, int | None)
81228126
"""
81238127
return self.last_clicked_position
@@ -15168,14 +15172,16 @@ def _add_expansion(element, row_should_expand, row_fill_direction):
1516815172
treeview = element.TKTreeview
1516915173
if element.DisplayRowNumbers:
1517015174
treeview.heading(element.RowHeaderText, text=element.RowHeaderText) # make a dummy heading
15171-
treeview.column(element.RowHeaderText, width=_string_width_in_pixels(font, element.RowHeaderText) + 10, minwidth=10, anchor=anchor,
15172-
stretch=0)
15175+
row_number_header_width =_string_width_in_pixels(element.HeaderFont, element.RowHeaderText) + 10
15176+
row_number_width = _string_width_in_pixels(font, str(len(element.Values))) + 10
15177+
row_number_width = max(row_number_header_width, row_number_width)
15178+
treeview.column(element.RowHeaderText, width=row_number_width, minwidth=10, anchor=anchor, stretch=0)
1517315179

1517415180
headings = element.ColumnHeadings if element.ColumnHeadings is not None else element.Values[0]
1517515181
for i, heading in enumerate(headings):
1517615182
treeview.heading(heading, text=heading)
1517715183
if element.AutoSizeColumns:
15178-
width = max(column_widths[i], len(heading)) * _char_width_in_pixels(font)
15184+
width = max(column_widths[i] * _char_width_in_pixels(font), len(heading)*_char_width_in_pixels(element.HeaderFont))
1517915185
else:
1518015186
try:
1518115187
width = element.ColumnWidths[i] * _char_width_in_pixels(font)

0 commit comments

Comments
 (0)