Skip to content

Keep widget theme metadata synchronized when width or height are changed via configure#17

Draft
ajkessel wants to merge 1 commit into
FedericoSpada:masterfrom
ajkessel:fix-cget-dimensions
Draft

Keep widget theme metadata synchronized when width or height are changed via configure#17
ajkessel wants to merge 1 commit into
FedericoSpada:masterfrom
ajkessel:fix-cget-dimensions

Conversation

@ajkessel

Copy link
Copy Markdown
Contributor

I've started running this code through updated unit tests based on my https://github.com/ajkessel/Custom2kinter/tree/m1-test-foundation branch. I will eventually propose those branch as a PR, but first I wanted to get some fixes through that the unit tests have surfaced.

This PR keeps widget theme metadata synchronized when width or height are changed via configure(). This fixes cget("width") / cget("height") returning stale constructor or theme defaults for widgets like CTkButton, CTkLabel, CTkFrame, and CTkEntry after resizing.

@FedericoSpada

Copy link
Copy Markdown
Owner

Unfortunately, it doesn't work for widgets that inherit from another widget rather than directly from CTkWidget, such as CTkSegmentedButton, CTkToggleButton, and CTkFloatingFrame, since they have dedicated _theme_info attributes, all with slightly different names.

The perfect solution would be to modify all cget() methods from:

elif attribute_name in self._theme_info:
    return self._theme_info[attribute_name]

to

elif attribute_name in self._theme_info and attribute_name not in CTkWidgetArgs.__annotations__:
    return self._theme_info[attribute_name]

I'll do it in the next commit.

@ajkessel

Copy link
Copy Markdown
Contributor Author

That makes sense. I think your fix will also cover the next failure I encountered with the pytest conversion work: CTkEntry.configure(bg_color="green") updates CTkWidget._bg_color, but CTkEntry.cget("bg_color") currently returns stale _theme_info["bg_color"] ("transparent") before it can delegate to CTkWidget.cget().

Since CTkWidgetArgs.__annotations__ includes width, height, and bg_color, excluding those keys from subclass _theme_info handling should fix both the dimension round-trip failures and the bg_color round-trip failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants