Top level wxFrame position changed after restart

Hi

I am trying to get the main window of my application into the same
position as it was before I closed the application.

Therefore, I get the position from
position = self.main_window.GetScreenPositionTuple()
and save it to a file.

When restarting, I read the file and set the position
self.SetPosition(position)

However, the position is off:
Position before exit: (351, 170)
Position after restart: (350, 141)

The difference looks similar to the border size to me.
I have attached a small example.

How do I set the Window position without such an offset?

My configuration:

Debian testing
Python 2.7.8
wxPython 3.0.1.1 gtk2 (classic)
Window manager E17 0.17.6

A user has reported a similar effect on Windows 8.

Martin

window_test.py (738 Bytes)

I do this in almost all my apps, and it works fine. The only difference I can see is that I save the coordinates in a sqlite database file, rather than ast (which I know nothing about). It seems clear from your code that the coordinates you are saving using ast are not being returned accurately. The problem is probably there, not in wxPython.

···

On Sun, Sep 28, 2014 at 4:30 PM, Martin Manns mmanns@gmx.net wrote:

Hi

I am trying to get the main window of my application into the same

position as it was before I closed the application.

Therefore, I get the position from

position = self.main_window.GetScreenPositionTuple()

and save it to a file.

When restarting, I read the file and set the position

self.SetPosition(position)

However, the position is off:

Position before exit: (351, 170)

Position after restart: (350, 141)

The difference looks similar to the border size to me.

I have attached a small example.

How do I set the Window position without such an offset?

My configuration:

Debian testing

Python 2.7.8

wxPython 3.0.1.1 gtk2 (classic)

Window manager E17 0.17.6

A user has reported a similar effect on Windows 8.

Martin

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.


Best Regards,
Michael Moriarity

The coordinates definitely remain the same when stored, i.e. both
positions in the example differ when the window is not moved.

I just noticed that on another Debian box with KDE instead of E17, this
does not occur.

Martin

···

On Sun, 28 Sep 2014 17:23:05 -0400 Michael Moriarity <datasmith@gmail.com> wrote:

I do this in almost all my apps, and it works fine. The only
difference I can see is that I save the coordinates in a sqlite
database file, rather than ast (which I know nothing about). It seems
clear from your code that the coordinates you are saving using ast
are not being returned accurately. The problem is probably there, not
in wxPython.

What I mean is, I can't run your test app, because I don't have ast
installed. However, in your code you print out the coordinates just before
you save them, and just after you restore them. In your original post, you
show these numbers as being different. If that is the case, then what you
are getting back seems to not be the same as what you are saving, but
perhaps I have misunderstood. Of course, if this differs from one Linux
desktop to another, you would naturally suspect the window manager.

···

On Sun, Sep 28, 2014 at 6:29 PM, Martin Manns <mmanns@gmx.net> wrote:

On Sun, 28 Sep 2014 17:23:05 -0400 > Michael Moriarity <datasmith@gmail.com> wrote:

> I do this in almost all my apps, and it works fine. The only
> difference I can see is that I save the coordinates in a sqlite
> database file, rather than ast (which I know nothing about). It seems
> clear from your code that the coordinates you are saving using ast
> are not being returned accurately. The problem is probably there, not
> in wxPython.

The coordinates definitely remain the same when stored, i.e. both
positions in the example differ when the window is not moved.

I just noticed that on another Debian box with KDE instead of E17, this
does not occur.

Martin

--
Best Regards,
Michael Moriarity

Oops, I just realized that ast is a standard module. I hadn't heard of it
before. I have just run your example code, and I can confirm that on
Xubuntu 12.04 it works as expected. Looks like the WM is the problem.

···

--
Best Regards,
Michael Moriarity

I can test on Win 7 and XP tomorrow, but right now on Ubuntu 14.04 with 3.0.1.1 gtk2 (classic) that I compiled last week, your program seems to work fine.

···

On Sunday, September 28, 2014 1:31:12 PM UTC-7, Martin Manns wrote:

My configuration:

Debian testing

Python 2.7.8

wxPython 3.0.1.1 gtk2 (classic)

Window manager E17 0.17.6

Hi,

···

On 9/28/2014 22:30, Martin Manns wrote:

Hi

I am trying to get the main window of my application into the same
position as it was before I closed the application.

Therefore, I get the position from
position = self.main_window.GetScreenPositionTuple()
and save it to a file.

When restarting, I read the file and set the position
self.SetPosition(position)

However, the position is off:
Position before exit: (351, 170)
Position after restart: (350, 141)

The difference looks similar to the border size to me.
I have attached a small example.

How do I set the Window position without such an offset?

My configuration:

Debian testing
Python 2.7.8
wxPython 3.0.1.1 gtk2 (classic)
Window manager E17 0.17.6

A user has reported a similar effect on Windows 8.

Hhm, I am on Windows 8 with Python 2.7.8 and wxPython 3.0.1.1 and your the position on close is used on restart, so works as expected.

If you persist more then the position you might want to link into wx.lib.agw.persist.

Werner

You might also try the functions with ‘client’ in the name… for example this is how I am getting the screen size that is available after considering the Window manager navigation bars:

topBarHeight, sideBarWidth, widthAvailable, heightAvailable = wx.ClientDisplayRect()

···

On Monday, September 29, 2014 12:24:13 AM UTC-7, werner wrote:

Hhm, I am on Windows 8 with Python 2.7.8 and wxPython 3.0.1.1 and your
the position on close is used on restart, so works as expected.

If you persist more then the position you might want to link into
wx.lib.agw.persist.

> If you persist more then the position you might want to link into
> wx.lib.agw.persist.

I will try this out.

You might also try the functions with 'client' in the name... for
example this is how I am getting the screen size that is available
after considering the Window manager navigation bars:
topBarHeight, sideBarWidth, widthAvailable, heightAvailable =
wx.ClientDisplayRect()

GetClientAreaOrigin() returns (0, 0) even though there are window
decorations.

Martin

···

On Mon, 29 Sep 2014 01:50:35 -0700 (PDT) Nathan McCorkle <nmz787@gmail.com> wrote:

Same effect with the agw persistence manager.
I have attached my test code.

Should I file a bug report?

Martin

window_test2.py (1.08 KB)

···

On Mon, 29 Sep 2014 01:50:35 -0700 (PDT) Nathan McCorkle <nmz787@gmail.com> wrote:

> If you persist more then the position you might want to link into
> wx.lib.agw.persist.

Not for persist, that just handles the loading and saving of data when you open or close your app.

You might try self.ClientToScreen((0,0))

See my modifications, when the frame is moved, stuff prints out.

testRemeberPos.py (1.03 KB)

···

On Monday, September 29, 2014 4:10:45 PM UTC-7, Martin Manns wrote:

On Mon, 29 Sep 2014 01:50:35 -0700 (PDT) > > Nathan McCorkle nmz...@gmail.com wrote:

If you persist more then the position you might want to link into
wx.lib.agw.persist.

Same effect with the agw persistence manager.

I have attached my test code.

Should I file a bug report?

Here is the printout (prints out when moving the mouse over the window)

xxx:~/tmp$ python testRemeberPos.py
(765, 576)
(0, 0, 1280, 1024)
(1280, 1024)
(0, 0)
(300, 200)
(764, 547)
(765, 576)

(0, 0, 1280, 1024)
(1280, 1024)
(0, 0)
(300, 200)
(764, 547)
(765, 576)

(0, 0, 1280, 1024)
(1280, 1024)
(0, 0)
(300, 200)
(764, 547)
(765, 576)

(0, 0, 1280, 1024)
(1280, 1024)
(0, 0)
(300, 200)
(764, 547)
(765, 576)

(0, 0, 1280, 1024)
(1280, 1024)
(0, 0)
(300, 200)
(764, 547)
(765, 576)

(764, 547)
xxx:~/tmp$

···

On Mon, 29 Sep 2014 16:17:30 -0700 (PDT) Nathan McCorkle <nmz787@gmail.com> wrote:

You might try self.ClientToScreen((0,0))

See my modifications, when the frame is moved, stuff prints out.

So that fixes it then, right? The difference between the ClientToScreen(0,0) and GetScreenPositionTuple() is the same as the difference in your first post… i.e. (1, 29)

Originally you posted:

Position before exit: (351, 170)
Position after restart: (350, 141)

last two rows of printout blocks:

(764, 547)
(765, 576)

diff first:

(1, 29)

diff second:

(1, 29)

···

On Tuesday, September 30, 2014 12:20:46 PM UTC-7, Martin Manns wrote:

On Mon, 29 Sep 2014 16:17:30 -0700 (PDT) > > Nathan McCorkle nmz...@gmail.com wrote:

You might try self.ClientToScreen((0,0))

See my modifications, when the frame is moved, stuff prints out.

Here is the printout (prints out when moving the mouse over the window)

xxx:~/tmp$ python testRemeberPos.py
(765, 576)

(0, 0, 1280, 1024)

(1280, 1024)

(0, 0)

(300, 200)

(764, 547)

(765, 576)

(0, 0, 1280, 1024)

(1280, 1024)

(0, 0)

(300, 200)

(764, 547)

(765, 576)

(0, 0, 1280, 1024)

(1280, 1024)

(0, 0)

(300, 200)

(764, 547)

(765, 576)

(0, 0, 1280, 1024)

(1280, 1024)

(0, 0)

(300, 200)

(764, 547)

(765, 576)

(0, 0, 1280, 1024)

(1280, 1024)

(0, 0)

(300, 200)

(764, 547)

(765, 576)

(764, 547)

xxx:~/tmp$

Seems like it.
However now, I have to test all platforms and Window managers.

Thank you for your help.

Martin

···

On Tue, 30 Sep 2014 16:27:41 -0700 (PDT) Nathan McCorkle <nmz787@gmail.com> wrote:

So that fixes it then, right? The difference between the
ClientToScreen(0,0) and GetScreenPositionTuple() is the same as the
difference in your first post... i.e. (1, 29)

Originally you posted:
Position before exit: (351, 170)
Position after restart: (350, 141)

last two rows of printout blocks:
(764, 547)
(765, 576)

diff first:
(1, 29)

diff second:
(1, 29)

Please let us know if it works on the platforms you’re testing for!

All the best,

-Nathan

···

On Thursday, October 2, 2014 3:29:56 PM UTC-7, Martin Manns wrote:

Seems like it.

However now, I have to test all platforms and Window managers.

Thank you for your help.

Martin

Martin Manns wrote:

Hi

I am trying to get the main window of my application into the same
position as it was before I closed the application.

Therefore, I get the position from
position = self.main_window.GetScreenPositionTuple()
and save it to a file.

When restarting, I read the file and set the position
self.SetPosition(position)

However, the position is off:
Position before exit: (351, 170)
Position after restart: (350, 141)

The difference looks similar to the border size to me.
I have attached a small example.

How do I set the Window position without such an offset?

My configuration:

Debian testing
Python 2.7.8
wxPython 3.0.1.1 gtk2 (classic)
Window manager E17 0.17.6

A user has reported a similar effect on Windows 8.

IIRC there was a change in the 2.9 series that had to do with frame positions and sizes on GTK. Originally since there isn't a standard way to get frame sizes on X that works in all environments and window managers then it was pretty much just ignored and the size of the client area was used instead. Since then there is a common way to deal with sizes of window decorations which has gained traction and so wx is now trying to use that, if I understand correctly.

That should help things like this to work more consistently (compared with the other platforms) on GTK than before, but probably not in all situations. One way around for sizes as others have mentioned is to save and set the client size of the frame instead of the frame's size. For positions it might be a little more tricky, but using things like ClientToScreen and ScreenToClient will be helpful there.

···

--
Robin Dunn
Software Craftsman

No luck on Windows 8.1. The window still shifts there.

The user claims to have the following configuration:

Windows 8.1, wxPython 3.0.1.1 for py27 32bit, Python 2.7.6.

Two monitor main-1920×1080 & second-1280×1024

Regards

Martin

···

On Thu, 2 Oct 2014 16:15:27 -0700 (PDT) Nathan McCorkle <nmz787@gmail.com> wrote:

Please let us know if it works on the platforms you're testing for!