Hi fellow pythonites!
Here's the code:
...
self.Bind(wx.EVT_MOVE,self.OnMove)
...
def OnMove( self, evt ):
pz = evt.GetPosition()
log.debug('Moved to (%d,%d) [evt]' % (pz.x,pz.y))
log.debug('Moved to (%d,%d) [self]' % self.GetPositionTuple())
...
Here's the output:
===cut===
16:19:00 DEBUG Moved to (104,142) [evt]
16:19:00 DEBUG Moved to (100,100) [self]
===end===
I noticed it using v2.5 of wxPython-w32-unicode, but now I downloaded the latest version and it is still here. It seems evt object contains the position of window's client area, is this intended behavior?
Bye!
A. D. G. (http://alexdeguy.nm.ru) (ICQ: 154305887)
Hi,
def OnMove( self, evt ):
pz = evt.GetPosition()
log.debug('Moved to (%d,%d) [evt]' % (pz.x,pz.y))
log.debug('Moved to (%d,%d) [self]' % self.GetPositionTuple())
...
Here's the output:
===cut===
16:19:00 DEBUG Moved to (104,142) [evt]
16:19:00 DEBUG Moved to (100,100) [self]
===end===
I noticed it using v2.5 of wxPython-w32-unicode, but now I downloaded the latest version and it is still here. It seems evt object contains the position of window's client area, is this intended behavior?
Yes. Mouse events contains position related to window client area. This is a "well known fact". I think I understand why you being confused. The wxWidgets documentation sometimes like to obscure things.
"""wxMouseEvent::GetPosition
Sets *x and *y to the position at which the event occurred. Returns the physical mouse position in pixels. Note that if the mouse event has been artificially generated from a special keyboard combination (e.g. under Windows when the "menu'' key is pressed), the returned position is wxDefaultPosition"""
Vladimir Ignatov
Hi!
Thursday, June 29, 2006, 7:12:30 PM, you wrote:
...
self.Bind(wx.EVT_MOVE,self.OnMove)
...
def OnMove( self, evt ):
pz = evt.GetPosition()
log.debug('Moved to (%d,%d) [evt]' % (pz.x,pz.y))
log.debug('Moved to (%d,%d) [self]' % self.GetPositionTuple())
...
===cut===
16:19:00 DEBUG Moved to (104,142) [evt]
16:19:00 DEBUG Moved to (100,100) [self]
===end===
What is self?
self is wx.Frame descendant. I've yet to see the need to override OnSize method in any other controls, sizers do the nice job. And I bind EVT_SIZE and EVT_MOVE in my frame only because I want to track the window size and position to write it to config file on app exit, so that it can be restored on next app start.
Bye!
A. D. G. (http://alexdeguy.nm.ru) (ICQ: 154305887)
You can do that in an EVT_CLOSE handler.
- Josiah
···
Aliaksei Hayeu <alex_de_guy@tut.by> wrote:
self is wx.Frame descendant. I've yet to see the need to override
OnSize method in any other controls, sizers do the nice job. And I
bind EVT_SIZE and EVT_MOVE in my frame only because I want to track the
window size and position to write it to config file on app exit, so
that it can be restored on next app start.
Hi,
self is wx.Frame descendant. I've yet to see the need to override
OnSize method in any other controls, sizers do the nice job. And I
bind EVT_SIZE and EVT_MOVE in my frame only because I want to track the
window size and position to write it to config file on app exit, so
that it can be restored on next app start.
You can do that in an EVT_CLOSE handler.
Small hint: pay attention to a frame state. It can be maximized or even iconized (!) [for example if Windows going to shutdown while application still running]. GetSize/Position functions returns some "crazy" values for iconized window.
Vladimir Ignatov
Hi!
self is wx.Frame descendant. I've yet to see the need to override
OnSize method in any other controls, sizers do the nice job. And I
bind EVT_SIZE and EVT_MOVE in my frame only because I want to track the
window size and position to write it to config file on app exit, so
that it can be restored on next app start.
You can do that in an EVT_CLOSE handler.
I wish I could! Unfortunately, it's not so simple. For example, there's no reason to save maximized window position/size - I need to save coords _before_ window got maximized. And window position if it's minimized (or iconized in wxPython terms) is (-32000,-32000) - what use are these values?
Another thing. Let's say, I have a normal frame. Then I maximize it, and IsMaximized() returns True. So far so good. But then I minimize this frame. IsIconized() returns True, again, as expected, but IsMaximized() now returns False. If I quit now and save the current state, next time I start the application I'll expect the window to be maximized after restoring, and it won't be.
So, I manually store real window position and maximized state in the EVT_SIZE and EVT_MOVE handlers and everything works fine.
Small hint: pay attention to a frame state. It can be maximized or even
iconized (!)
Of course I'm paying attention. It's the cornerstone of my window state saving system.
Bye!
A. D. G. (http://alexdeguy.nm.ru) (ICQ: 154305887)
Use a wx.Timer to post an event every few seconds. Use win.GetSize() .
Pay attention to EVT_MAXIMIZED and EVT_ICONIZED events, to determine
whether you should be performing win.GetSize(), and/or starting/stopping
the timer.
- Josiah
···
Aliaksei Hayeu <alex_de_guy@tut.by> wrote:
>>> self is wx.Frame descendant. I've yet to see the need to override
>>> OnSize method in any other controls, sizers do the nice job. And I
>>> bind EVT_SIZE and EVT_MOVE in my frame only because I want to track the
>>> window size and position to write it to config file on app exit, so
>>> that it can be restored on next app start.
>>
>> You can do that in an EVT_CLOSE handler.
I wish I could! Unfortunately, it's not so simple. For example,
there's no reason to save maximized window position/size - I need to
save coords _before_ window got maximized. And window position if it's
minimized (or iconized in wxPython terms) is (-32000,-32000) - what use
are these values?
Another thing. Let's say, I have a normal frame. Then I maximize it,
and IsMaximized() returns True. So far so good. But then I minimize
this frame. IsIconized() returns True, again, as expected, but IsMaximized()
now returns False. If I quit now and save the current state, next time I
start the application I'll expect the window to be maximized after
restoring, and it won't be.
So, I manually store real window position and maximized state in the
EVT_SIZE and EVT_MOVE handlers and everything works fine.