alejandroautalan / pygubu-designer

A simple GUI designer for the python tkinter module
GNU General Public License v3.0
800 stars 98 forks source link

Generate code type hints for app and script + optional run parameter to center main window #214

Closed BloodyRain2k closed 1 year ago

BloodyRain2k commented 1 year ago

I wanted some type hinting support for the defined TkVars in VSCode, so I've expanded the app and script mako files for that.

And I also found it way to bothersome to write some code that (optionally) centers the window upon creation, so I've added that to the mako files as well.

This is what it then looks like for variables: image

BloodyRain2k commented 1 year ago

While fixing the oversight of expecting geometry to be set, I've noticed something odd: if only height and width are set, winfo_reqwidth() and winfo_reqheight() will return those values before window init, but the window will not end up using them at all.

I thought at first that my code of setting geometry without a size and only a position was the cause for that, but even when I left that last line out, the window reported to be "800x600" (which is what I did set in it's .ui), only to appear as 300x200 or something, for whatever reason.

alejandroautalan commented 1 year ago

Hello @BloodyRain2k, sorry for the late response.

I like the type hints for variables.

But to center the window, I'd like to use this other approach that I show in this example:

https://github.com/alejandroautalan/pygubu-designer/blob/9d4fdfd3e288a0947959a2fc635e7c9ba5e02a46/examples/toplevel_centered/centered_demo2.py#L9-L40

This waits until the Map event occurs. At this time the sizes are known and the center calculation can be done more clear.

While fixing the oversight of expecting geometry to be set, I've noticed something odd: if only height and width are set, winfo_reqwidth() and winfo_reqheight() will return those values before window init, but the window will not end up using them at all.

I thought at first that my code of setting geometry without a size and only a position was the cause for that, but even when I left that last line out, the window reported to be "800x600" (which is what I did set in it's .ui), only to appear as 300x200 or something, for whatever reason.

Regarding this problem. The configured width and height for container widgets, depends on the layout manager used. Pack and Grid does not allow the user to force a width o height (unless you set the propagate property to False) So, if you have a Toplevel configured with widht=800 height=600 and no geometry set, the manager used for the children will configure the size of the window at his will. The only way to force the size of a Toplevel widget is to use the geometry property.

Let me know. Regards

BloodyRain2k commented 1 year ago

I've removed my centering code from the PR and I'll play around with the code you linked later.

I remember that I've seen some window centering code which did center the window too, but it made the window appear in the default position for a few frames first, which irritated me.