EVT_KILL_FOCUS and menu events

Hi,

I have a problem with a text ctrl. I did bind the
text ctrl to EVT_KILL_FOCUS. When the event is triggered I update
the value.

The problem is if the user changes the text ctrl and does save from the menu without leavinge the
text ctrl. Then the EVT_KILL_FOCUS doesnt get triggered. So the old value will be saved.

Is there any event other event I can use that triggers when the user 'exits' a ctrl and which also
triggers on menu events.

I would prefer not to bind to evt_text and update the value for each char pressed.

Best regards,

/T

Toni Brkic wrote:

Hi,

I have a problem with a text ctrl. I did bind the
text ctrl to EVT_KILL_FOCUS. When the event is triggered I update
the value.

The problem is if the user changes the text ctrl and does save from the menu without leavinge the text ctrl. Then the EVT_KILL_FOCUS doesnt get triggered. So the old value will be saved.

Is there any event other event I can use that triggers when the user 'exits' a ctrl and which also
triggers on menu events.

You could have something that saves/validates the whole form before changing things from the menu handler.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Toni Brkic wrote:

I have a problem with a text ctrl. I did bind the
text ctrl to EVT_KILL_FOCUS. When the event is triggered I update
the value.

The problem is if the user changes the text ctrl and does save from the menu without leavinge the text ctrl. Then the EVT_KILL_FOCUS doesnt get triggered. So the old value will be saved.

Is there any event other event I can use that triggers when the user 'exits' a ctrl and which also
triggers on menu events.

I would prefer not to bind to evt_text and update the value for each char pressed.

This is a common problem in all development environments I've encountered so far. Make a method of the textbox called FlushValue() that you call from your onKillFocus() code. Make a method of your frame called ActiveControlFlushValue() that finds out what the active control is and calls its FlushValue() code. Call ActiveControlFlushValue in your menu save code as well as possibly from your form close code.

I don't know of an event that will do what you want.

···

--
Paul McNett
http://paulmcnett.com

Paul McNett wrote:

Toni Brkic wrote:

I have a problem with a text ctrl. I did bind the
text ctrl to EVT_KILL_FOCUS. When the event is triggered I update
the value.

The problem is if the user changes the text ctrl and does save from the menu without leavinge the text ctrl. Then the EVT_KILL_FOCUS doesnt get triggered. So the old value will be saved.

Is there any event other event I can use that triggers when the user 'exits' a ctrl and which also
triggers on menu events.

I would prefer not to bind to evt_text and update the value for each char pressed.

This is a common problem in all development environments I've encountered so far. Make a method of the textbox called FlushValue() that you call from your onKillFocus() code. Make a method of your frame called ActiveControlFlushValue() that finds out what the active control is and calls its FlushValue() code. Call ActiveControlFlushValue in your menu save code as well as possibly from your form close code.

I don't know of an event that will do what you want.

This sounds like a good solutions.

But how do you find out the active control?

Thanks,

Toni

Toni Brkic wrote:

Paul McNett wrote:

Toni Brkic wrote:

I have a problem with a text ctrl. I did bind the
text ctrl to EVT_KILL_FOCUS. When the event is triggered I update
the value.

This is a common problem in all development environments I've encountered so far. Make a method of the textbox called FlushValue() that you call from your onKillFocus() code. Make a method of your frame called ActiveControlFlushValue() that finds out what the active control is and calls its FlushValue() code. Call ActiveControlFlushValue in your menu save code as well as possibly from your form close code.

I don't know of an event that will do what you want.

This sounds like a good solutions.

But how do you find out the active control?

self = <a wx.Frame instance>
activeControl = self.FindFocus()

It'll descend into pages in notebooks and other containerships and find the actual control that has the keyboard focus.

···

--
Paul McNett
http://paulmcnett.com