wx.Dialog window size changes after using PyInstaller

I have a wxPython app that implements a number of sub-classed wx.Dialog frames. In the dialog constructor, I am using self.SetSize(x,y) to set the dialog frame size, and I’m also using sizers to build up the arrangement of buttons and controls. I use self.SetPosition(x,y) to align the dialog as desired with the parent frame.

When I run my code from Eclipse (with the PyDev plugin), everything works great; I get the expected frame size and positioning.

However, when I build a standalone application directory and exe using PyInstaller (3.3.1, latest) using the exact same code, the dialog frame size is slightly larger in both x and y dimensions (by about 1/8 inch) and it appears that the sizers are also spacing things a bit differently (e.g. a StretchSpacer results in a larger space in the PyInstaller .exe). I also notice that the title bar of the dialog is thinner.

I am completely dumbfounded by this. PyInstaller should be packaging the exact version of Python (3.6.4) and wxPython (4.0.1) that I’m using on my machine which is obviously also being used by Eclipse when running the code from there. Note that I have excluded Tcl and Tkinter from the PyInstaller build to reduce the output directory size, but this should have no bearing at all on wxPython.

This difference in size is a problem for me because of requirements for the app to position and align the right side of the dialog window with the parent window right side.
If the frame changes size, my calculations for setting the position are
off.

What could cause this? Why would a wx.Dialog frame size be rendered differently ON THE SAME MACHINE when run via Eclipse vs. run via a exe and directory created by PyInstaller?

Dave

Should have mentioned I am running Windows 10.

···

On Monday, August 27, 2018 at 6:39:23 PM UTC-4, Datro wrote:

I have a wxPython app that implements a number of sub-classed wx.Dialog frames. In the dialog constructor, I am using self.SetSize(x,y) to set the dialog frame size, and I’m also using sizers to build up the arrangement of buttons and controls. I use self.SetPosition(x,y) to align the dialog as desired with the parent frame.

When I run my code from Eclipse (with the PyDev plugin), everything works great; I get the expected frame size and positioning.

However, when I build a standalone application directory and exe using PyInstaller (3.3.1, latest) using the exact same code, the dialog frame size is slightly larger in both x and y dimensions (by about 1/8 inch) and it appears that the sizers are also spacing things a bit differently (e.g. a StretchSpacer results in a larger space in the PyInstaller .exe). I also notice that the title bar of the dialog is thinner.

I am completely dumbfounded by this. PyInstaller should be packaging the exact version of Python (3.6.4) and wxPython (4.0.1) that I’m using on my machine which is obviously also being used by Eclipse when running the code from there. Note that I have excluded Tcl and Tkinter from the PyInstaller build to reduce the output directory size, but this should have no bearing at all on wxPython.

This difference in size is a problem for me because of requirements for the app to position and align the right side of the dialog window with the parent window right side.
If the frame changes size, my calculations for setting the position are
off.

What could cause this? Why would a wx.Dialog frame size be rendered differently ON THE SAME MACHINE when run via Eclipse vs. run via a exe and directory created by PyInstaller?

Dave

Hi,

What happen is you launch the app using console?

python3 …/you_app

if this run fine, I think its a problem of PyInstaller

···

Saludos / Best regards

Mario Lacunza
Email:: mlacunza@gmail.com
Personal Website:: http://www.lacunza.biz/
Hosting:: http://mlv-host.com/
Skype: mlacunzav

Lima - Peru

No problems when run from command line. The problem only occurs after I’ve created the PyInstaller directory with exe.

···

On Monday, August 27, 2018 at 8:00:03 PM UTC-4, Mario Lacunza wrote:

Hi,

What happen is you launch the app using console?

python3 …/you_app

if this run fine, I think its a problem of PyInstaller

Saludos / Best regards

Mario Lacunza
Email:: mlac...@gmail.com
Personal Website:: http://www.lacunza.biz/
Hosting:: http://mlv-host.com/
Skype: mlacunzav

Lima - Peru

El lun., 27 de ago. de 2018 a la(s) 17:40, Datro (dtr...@cox.net) escribió:

Should have mentioned I am running Windows 10.

On Monday, August 27, 2018 at 6:39:23 PM UTC-4, Datro wrote:

I have a wxPython app that implements a number of sub-classed wx.Dialog frames. In the dialog constructor, I am using self.SetSize(x,y) to set the dialog frame size, and I’m also using sizers to build up the arrangement of buttons and controls. I use self.SetPosition(x,y) to align the dialog as desired with the parent frame.

When I run my code from Eclipse (with the PyDev plugin), everything works great; I get the expected frame size and positioning.

However, when I build a standalone application directory and exe using PyInstaller (3.3.1, latest) using the exact same code, the dialog frame size is slightly larger in both x and y dimensions (by about 1/8 inch) and it appears that the sizers are also spacing things a bit differently (e.g. a StretchSpacer results in a larger space in the PyInstaller .exe). I also notice that the title bar of the dialog is thinner.

I am completely dumbfounded by this. PyInstaller should be packaging the exact version of Python (3.6.4) and wxPython (4.0.1) that I’m using on my machine which is obviously also being used by Eclipse when running the code from there. Note that I have excluded Tcl and Tkinter from the PyInstaller build to reduce the output directory size, but this should have no bearing at all on wxPython.

This difference in size is a problem for me because of requirements for the app to position and align the right side of the dialog window with the parent window right side.
If the frame changes size, my calculations for setting the position are
off.

What could cause this? Why would a wx.Dialog frame size be rendered differently ON THE SAME MACHINE when run via Eclipse vs. run via a exe and directory created by PyInstaller?

Dave

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Can you provide de command you are using to run the pyinstaller?

···

On Aug 27, 2018, at 8:52 PM, Datro dtrout@cox.net wrote:

No problems when run from command line. The problem only occurs after I’ve created the PyInstaller directory with exe.

On Monday, August 27, 2018 at 8:00:03 PM UTC-4, Mario Lacunza wrote:

Hi,

What happen is you launch the app using console?

python3 …/you_app

if this run fine, I think its a problem of PyInstaller

Saludos / Best regards

Mario Lacunza
Email:: mlac...@gmail.com
Personal Website:: http://www.lacunza.biz/
Hosting:: http://mlv-host.com/
Skype: mlacunzav

Lima - Peru

El lun., 27 de ago. de 2018 a la(s) 17:40, Datro (dtr...@cox.net) escribió:

Should have mentioned I am running Windows 10.

On Monday, August 27, 2018 at 6:39:23 PM UTC-4, Datro wrote:

I have a wxPython app that implements a number of sub-classed wx.Dialog frames. In the dialog constructor, I am using self.SetSize(x,y) to set the dialog frame size, and I’m also using sizers to build up the arrangement of buttons and controls. I use self.SetPosition(x,y) to align the dialog as desired with the parent frame.

When I run my code from Eclipse (with the PyDev plugin), everything works great; I get the expected frame size and positioning.

However, when I build a standalone application directory and exe using PyInstaller (3.3.1, latest) using the exact same code, the dialog frame size is slightly larger in both x and y dimensions (by about 1/8 inch) and it appears that the sizers are also spacing things a bit differently (e.g. a StretchSpacer results in a larger space in the PyInstaller .exe). I also notice that the title bar of the dialog is thinner.

I am completely dumbfounded by this. PyInstaller should be packaging the exact version of Python (3.6.4) and wxPython (4.0.1) that I’m using on my machine which is obviously also being used by Eclipse when running the code from there. Note that I have excluded Tcl and Tkinter from the PyInstaller build to reduce the output directory size, but this should have no bearing at all on wxPython.

This difference in size is a problem for me because of requirements for the app to position and align the right side of the dialog window with the parent window right side.
If the frame changes size, my calculations for setting the position are
off.

What could cause this? Why would a wx.Dialog frame size be rendered differently ON THE SAME MACHINE when run via Eclipse vs. run via a exe and directory created by PyInstaller?

Dave

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-user...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

OK, further testing has revealed a few things:

  1. The change in y-dimension of the dialog frame is apparently due mainly to the thinner title bar. It is thinner by about 1/16 inch. For some reason, when run from the PyInstaller directory + exe, a wx.Dialog will get a thinner title bar. I have no idea why this would be the case. It would seem that something in the PyInstaller build is triggering the underlying OS (or wxWidgets) to take a different path when handling dialog windows.

  2. The change in x-dimension of the dialog frame is definitely related somehow to the use of sizers. In my code, I do the following at the end of the dialog constructor to complete the sizer layout:

self.SetSizer(sizer)

``

Just to see what would happen, I added an additional line to “fit” to the sizer:

self.SetSizer(sizer)
sizer.Fit(self)

``

The added line basically means "change the window size to fit the sizer. The result was quite a surprise…the window x-dimension size now matches what I get when running the code from command line or Eclipse but the window is still not quite aligned as expected. I think I can solve that by doing the self.SetPosition after sizer fit.

I’m still looking further into this, but for now it seems I can mostly get what I want. I’m still wondering though why the title bar is different.

Dave

Dave,

How do you have font scaling enabled? Are you running with high DPI awareness enabled in python.exe but not on the generated .exe (or vice versa)?

Stick this somewhere in startup code and see what happens:

try:
    from ctypes import OleDLL
    # Turn on high-DPI awareness to make sure rendering is sharp on big
    # monitors with font scaling enabled.
    OleDLL('shcore').SetProcessDpiAwareness(1)
except AttributeError:
    # We're on a non-Windows box.
    pass
except OSError:
    # exc.winerror is often E_ACCESSDENIED (-2147024891/0x80070005).
    #  This occurs after the first run, when the parameter is reset in the
    # executable's manifest and then subsequent calls raise this exception
    # See last paragraph of Remarks at
    # https://msdn.microsoft.com/en-us/library/dn302122(v=vs.85).aspx
    pass

``

A good suggestion, however I have already fully investigated this angle. High DPI awareness is NOT enabled in the python.exe manifest, nor is it enabled in the manifest of the exe built by PyInstaller. So I don’t think there is anything there which is affecting this behavior. I am running my Windows machine with font scaling at 100% (default setting).

The distinctly noticeable change in the thickness of the wx.Dialog title bar in the PyInstaller version still troubles me and pretty much tells me that something is triggering a different path somewhere in the underlying windowing software. I have done a lot of further testing with various PyInstaller options for the Windows environment (e.g. “–win-private-assemblies” and “–win-no-prefer-redirects”, all with no affect on the results.

My x-dimension problems continue: As mentioned in my previous post, I thought I would be able to fix the y-dimension positioning now that I can generate consistent x-dimensions in both versions. However this is not the case. Even when self.GetSize() returns the exact same dimensions in both cases for the wx.Dialog frame, my calculation for determining self.SetPosition results in different positioning relative to the parent window in the two cases. My current thinking is that somehow the Window shadowing logic introduced in Windows 10 may be at play here, though I haven’t found the exact behavior yet.

I have determined that in Windows 10 an active window has a left shadow of 17 pixels, and a right shadow of 21 pixels. Windows 10 changes the shadow to 13 pixels on both left and right for a non-active window. Maybe GetSize in the PyInstaller environment is somehow getting confused by the shadows? If that is true, it still doesn’t explain why there is different behavior between standalone Python/wxPython vs the PyInstaller build.

Still no closer to figuring this out…

Dave

···

On Tuesday, August 28, 2018 at 3:17:01 PM UTC-4, efahl wrote:

Dave,

How do you have font scaling enabled? Are you running with high DPI awareness enabled in python.exe but not on the generated .exe (or vice versa)?

Stick this somewhere in startup code and see what happens:

try:
    from ctypes import OleDLL
    # Turn on high-DPI awareness to make sure rendering is sharp on big
    # monitors with font scaling enabled.
    OleDLL('shcore').SetProcessDpiAwareness(1)
except AttributeError:
    # We're on a non-Windows box.
    pass
except OSError:
    # exc.winerror is often E_ACCESSDENIED (-2147024891/0x80070005).
    #  This occurs after the first run, when the parameter is reset in the
    # executable's manifest and then subsequent calls raise this exception
    # See last paragraph of Remarks at
    # [https://msdn.microsoft.com/en-us/library/dn302122(v=vs.85).aspx](https://msdn.microsoft.com/en-us/library/dn302122(v=vs.85).aspx)
    pass

``

Slight correction to the above post:

"My x-dimension problems continue: As mentioned in my previous post, I thought I would be able to fix the y-dimension positioning" should read:

*My x-dimension problems continue: As mentioned in my previous post, I thought I would be able to fix the x-dimension positioning *

···

On Wednesday, August 29, 2018 at 11:52:44 AM UTC-4, Datro wrote:

A good suggestion, however I have already fully investigated this angle. High DPI awareness is NOT enabled in the python.exe manifest, nor is it enabled in the manifest of the exe built by PyInstaller. So I don’t think there is anything there which is affecting this behavior. I am running my Windows machine with font scaling at 100% (default setting).

The distinctly noticeable change in the thickness of the wx.Dialog title bar in the PyInstaller version still troubles me and pretty much tells me that something is triggering a different path somewhere in the underlying windowing software. I have done a lot of further testing with various PyInstaller options for the Windows environment (e.g. “–win-private-assemblies” and “–win-no-prefer-redirects”, all with no affect on the results.

My x-dimension problems continue: As mentioned in my previous post, I thought I would be able to fix the y-dimension positioning now that I can generate consistent x-dimensions in both versions. However this is not the case. Even when self.GetSize() returns the exact same dimensions in both cases for the wx.Dialog frame, my calculation for determining self.SetPosition results in different positioning relative to the parent window in the two cases. My current thinking is that somehow the Window shadowing logic introduced in Windows 10 may be at play here, though I haven’t found the exact behavior yet.

I have determined that in Windows 10 an active window has a left shadow of 17 pixels, and a right shadow of 21 pixels. Windows 10 changes the shadow to 13 pixels on both left and right for a non-active window. Maybe GetSize in the PyInstaller environment is somehow getting confused by the shadows? If that is true, it still doesn’t explain why there is different behavior between standalone Python/wxPython vs the PyInstaller build.

Still no closer to figuring this out…

Dave

On Tuesday, August 28, 2018 at 3:17:01 PM UTC-4, efahl wrote:

Dave,

How do you have font scaling enabled? Are you running with high DPI awareness enabled in python.exe but not on the generated .exe (or vice versa)?

Stick this somewhere in startup code and see what happens:

try:
    from ctypes import OleDLL
    # Turn on high-DPI awareness to make sure rendering is sharp on big
    # monitors with font scaling enabled.
    OleDLL('shcore').SetProcessDpiAwareness(1)
except AttributeError:
    # We're on a non-Windows box.
    pass
except OSError:
    # exc.winerror is often E_ACCESSDENIED (-2147024891/0x80070005).
    #  This occurs after the first run, when the parameter is reset in the
    # executable's manifest and then subsequent calls raise this exception
    # See last paragraph of Remarks at
    # [https://msdn.microsoft.com/en-us/library/dn302122(v=vs.85).aspx](https://msdn.microsoft.com/en-us/library/dn302122(v=vs.85).aspx)
    pass

``

Ok, just to give you some more data to churn…

We switched from py2exe to PyInstaller about 18 months ago. Our distributions are run on Win 7 and 10 machines (all x64), some with font scaling, some without (most notably, my primary dev workstation has a 32" main monitor set to 125%). We run Python 3.6.6, wxPython 4.0.3 (moving to latest stable a few days after they are released and we’ve tested them). Our in-dev code running via ‘python main.py’ looks identical in every regard to our bundled ‘main.exe’, all the windows, frames and title bars stay the same size. We use AUI to manage a tiled collection of “top-level” widgets (model tree, property editor, graphics window, task manager, task dialog, etc). We even tear off windows programmatically (when we record animations in the graphics window, we tear off the control panel so we can reposition and resize the graphics window without moving the start/stop controls), then redock them, all with no apparent differences between .py and .exe…

I’d suspect local environment settings, LOCALE(???) or something? Maybe dump os.environ in both dev and .exe to see if anything jumps out?

Thanks again for another good suggestion. It is encouraging to know that you are not having similar problems in your environment.

To get a further idea of whether the OS is at play, I installed the PyInstaller exe bundle on a separate “virgin” Windows 10 machine I have here, and also a Windows 7 machine. I get the exact same behavior on the separate Windows 10 machine, i.e. thinner wx.Dialog title bar and incorrect positioning. Interestingly, on the Windows 7 machine the wx.Dialog title bar is NOT thinner, but the positioning alignment problem still persists. So perhaps I am dealing with two separate issues here. I should also mention that my PyInstaller app bundle of identical code works correctly and as expected on macOS 10.13.6.

Next I will have a look at os.environ differences, if any.

Dave

···

On Wednesday, August 29, 2018 at 12:39:43 PM UTC-4, efahl wrote:

Ok, just to give you some more data to churn…

We switched from py2exe to PyInstaller about 18 months ago. Our distributions are run on Win 7 and 10 machines (all x64), some with font scaling, some without (most notably, my primary dev workstation has a 32" main monitor set to 125%). We run Python 3.6.6, wxPython 4.0.3 (moving to latest stable a few days after they are released and we’ve tested them). Our in-dev code running via ‘python main.py’ looks identical in every regard to our bundled ‘main.exe’, all the windows, frames and title bars stay the same size. We use AUI to manage a tiled collection of “top-level” widgets (model tree, property editor, graphics window, task manager, task dialog, etc). We even tear off windows programmatically (when we record animations in the graphics window, we tear off the control panel so we can reposition and resize the graphics window without moving the start/stop controls), then redock them, all with no apparent differences between .py and .exe…

I’d suspect local environment settings, LOCALE(???) or something? Maybe dump os.environ in both dev and .exe to see if anything jumps out?

More information on this interesting problem. It seems when running in the PyInstaller exe, wxPython gets different (and confusing) information regarding the size of a wx.Dialog window. Here’s my test results of various methods on the wx.Dialog window comparing command-line execution vs. PyInstaller execution of my code:

Command Line Results

self.GetSize() returns (400,399)
self.GetWindowBorderSize returns (0,0)
self.GetClientSize() returns (384,360)

``

``

PyInstaller Results

self.GetSize() returns (390,389)
self.GetWindowBorderSize returns (0,0)
self.GetClientSize() returns (384,360)

``

Note: GetSize returns the entire size of the window, including borders, title bar, menu bar, scrollbars, etc. GetClientSize returns the part of the window for placing user controls, panels, etc. In my case, the wx.Dialog has no scrollbars, no menubar; only a title bar (which is thinner in the PyInstaller case) and various controls, buttons, etc.

As can be seen by the above numbers, in the PyInstaller case, the Dialog full window size is reported as exactly 10 pixels smaller in both dimensions, however the ClientSize IS REPORTED AS EXACTLY THE SAME !?? How can the full window be smaller but the client area be the same??

And to make it even more interesting, when I visually compare the x-dimension of the command-line dialog window with the PyInstaller dialog window, they are rendered exactly the same on my display !! (The y-dimension is still different though because of the thinner title bar in the PyInstaller version). Something clearly doesn’t add up here.

Regarding os.environ: The only difference I see is that the following is removed from my PATH variable when running via PyInstaller:

C:\Users\dave\AppData\Local\Programs\Python\Python36-32\lib\site-packages\pywin32_system32;
C:\Users\dave\AppData\Local\Programs\Python\Python36-32\lib\site-packages\numpy\.libs

So I am still no closer to understanding where the problem is at this point. wxPython is clearly getting different (and non-sensical) sizing information when run under PyInstaller, but I don’t know if this is a problem with wxPython or PyInstaller. I tried installing the latest DEV version of PyInstaller but it did not affect anything. I’m reluctant to upgrade to wxPython 4.0.3 at this point but may have to cave in and try it anyway. (CAUTION: Uninstalling PyInstaller requires MORE than just doing “pip uninstall”…it took me quite a while to figure this out after trying to re-install the current stable release)

Can anyone recommend some next steps for figuring out if we have a wxPython problem or a PyInstaller problem?

Thanks,

Dave

···

On Wednesday, August 29, 2018 at 6:41:53 PM UTC-4, Datro wrote:

Thanks again for another good suggestion. It is encouraging to know that you are not having similar problems in your environment.

To get a further idea of whether the OS is at play, I installed the PyInstaller exe bundle on a separate “virgin” Windows 10 machine I have here, and also a Windows 7 machine. I get the exact same behavior on the separate Windows 10 machine, i.e. thinner wx.Dialog title bar and incorrect positioning. Interestingly, on the Windows 7 machine the wx.Dialog title bar is NOT thinner, but the positioning alignment problem still persists. So perhaps I am dealing with two separate issues here. I should also mention that my PyInstaller app bundle of identical code works correctly and as expected on macOS 10.13.6.

Next I will have a look at os.environ differences, if any.

Dave

On Wednesday, August 29, 2018 at 12:39:43 PM UTC-4, efahl wrote:

Ok, just to give you some more data to churn…

We switched from py2exe to PyInstaller about 18 months ago. Our distributions are run on Win 7 and 10 machines (all x64), some with font scaling, some without (most notably, my primary dev workstation has a 32" main monitor set to 125%). We run Python 3.6.6, wxPython 4.0.3 (moving to latest stable a few days after they are released and we’ve tested them). Our in-dev code running via ‘python main.py’ looks identical in every regard to our bundled ‘main.exe’, all the windows, frames and title bars stay the same size. We use AUI to manage a tiled collection of “top-level” widgets (model tree, property editor, graphics window, task manager, task dialog, etc). We even tear off windows programmatically (when we record animations in the graphics window, we tear off the control panel so we can reposition and resize the graphics window without moving the start/stop controls), then redock them, all with no apparent differences between .py and .exe…

I’d suspect local environment settings, LOCALE(???) or something? Maybe dump os.environ in both dev and .exe to see if anything jumps out?