Skip to content

Commit

Permalink
Merge pull request #31 from molssi-seamm/dev
Browse files Browse the repository at this point in the history
Return the width of aligned labels
  • Loading branch information
seamm authored Jul 21, 2024
2 parents c3fa596 + 98ec794 commit ec4db9a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
5 changes: 4 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
=======
History
=======

2024.7.21 -- Return the width of aligned labels
* The align_labels procedure now returns the width of the labels. This is useful for
laying out indented widgets.

2024.5.1 -- Enhancement to ScrolledColumns
* Added optional separator columns for dividing sections of the table.

Expand Down
17 changes: 10 additions & 7 deletions seamm_widgets/labeled_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
}


def align_labels(widgets, sticky=None):
def align_labels(widgets, sticky=tk.E):
"""Align the labels of a given list of widgets"""
if len(widgets) <= 1:
return
if len(widgets) == 0:
return 0

widgets[0].update_idletasks()

Expand All @@ -56,10 +56,13 @@ def align_labels(widgets, sticky=None):

# Adjust the margins for the labels such that the child sites and
# labels line up.
for widget in widgets:
if sticky is not None:
widget.label.grid(sticky=sticky)
widget.grid_columnconfigure(0, minsize=max_width)
if len(widgets) > 1:
for widget in widgets:
if sticky is not None:
widget.label.grid(sticky=sticky)
widget.grid_columnconfigure(0, minsize=max_width)

return max_width


class LabeledWidget(ttk.Frame):
Expand Down

0 comments on commit ec4db9a

Please sign in to comment.