How to save window position on frame move?

Dear All,

I want my app to save it’s window position
so next time I run it, the window will place at the last position
But I cannot use close event to save position
since it is a tray application

I plan to use on move window
but cannot seem to find any documentation about it

Any suggestion?

Regards
Hendra

It’s easy to save the position of your window. And technically, you can
use
the onClose event, even with it being a Tray App.

The method in which this works, is that you would need to return false
from
your window to prevent the window from being destroyed.

An example of this:

class MyWin < Wx::Frame
def initialize()
super(nil,-1,“Sample Hide, not close”)
evt_close(self,:on_close)
end

def on_close(event)
@pos = self.position
self.hide
return false
end
end

HTH,

Mario

I already know how to save the position
but the reason for me not to use on_close event is
because I am making a simple and personal desktop calendar
with todo and event reminder
and I am not likely to close it before I shutdown my computer
therefore I need another event to save it

what comes in my mind is an event when a window is moved
but I cannot seem to find it
any other idea?

Hi Hendra

On 21/04/2010 02:59, penguinroad wrote:

I already know how to save the position
but the reason for me not to use on_close event is
because I am making a simple and personal desktop calendar
with todo and event reminder
and I am not likely to close it before I shutdown my computer
therefore I need another event to save it

Maybe Wx::ActivateEvent -
http://wxruby.rubyforge.org/doc/activateevent.html

You could use the evt_activate_app to detect when the whole application
loses focus, and serialise the window state then. I have not tried this
with tray-based apps, but there is a sample in etc/ that you could have
a look at and try easily.

best
alex

On Wed, Apr 21, 2010 at 1:01 PM, Alex F. [email protected] wrote:

therefore I need another event to save it

Thank you for the pointer
I found Wx::MoveEvent
and it works exactly as I need
Thank you

Well, thats exacly what I do
write 2 lines to a file to save x and y position of my window
I don’t know it it occurs frequently
but somehow it do just fine

thanks

On 22/04/2010 03:01, hendra kusuma wrote:

Thank you for the pointer
I found Wx::MoveEvent
and it works exactly as I need

Good, I’m glad it works. I was cautious about suggesting MoveEvent
because it occurs frequently when a Frame is, say, being dragged about
by its title bar. So it’s not desirable to do lengthy operations (e.g.
write to a File) each time it occurs.

best
alex

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs