wxpython EVT_SET_FOCUS

Hi,
When I run this code and focus on choice it is raise a error. I close
this message but it is come back again. I want to see only one time
this message. How can i do this? What is error in my code ?

Note:
I'm sorry for my English. I know it isn't good.

#! -*- coding:utf-8 -*-
import wx

class MyPanel(wx.Panel):
    def __init__(self, parent, *args, **kwargs):
        wx.Panel.__init__(self, parent, *args, **kwargs)
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.my_choice = wx.Choice(self, wx.NewId())
        self.my_button = wx.Button(self, wx.NewId(), label =
"Procces")
        self.my_button.SetFocus()

        sizer.AddMany([(self.my_choice, 0, wx.ALL, 5),
                       (self.my_button, 0, wx.ALL, 5)])

        self.SetSizer(sizer)
        self.my_choice.Bind(wx.EVT_SET_FOCUS, self.my_choice_on_focus)
        self.my_button.Bind(wx.EVT_BUTTON, self.my_button_on_clicked)

    def my_choice_on_focus(self, evt):
        try:
            self.my_choice.Clear()
            print "Input some items in my_choice"
            raise RuntimeError
        except RuntimeError:
            dlg = wx.MessageDialog(self, "test EVT_SET_FOCUS",
"Error",
                                   wx.ICON_ERROR|wx.OK )
            dlg.ShowModal()
            dlg.Destroy()
            raise
        evt.Skip()

    def my_button_on_clicked(self, evt):
        print "Procces my choice value"
        evt.Skip()

class MyApp(wx.App):
    def OnInit(self):
        frame = wx.Frame(None, title = "Test")
        panel = MyPanel(frame)
        frame.Show()
        self.SetTopWindow(frame)
        return True

if __name__ == '__main__':
    app = MyApp(redirect = False)
    app.MainLoop()

Hi nozkan,

What is error in my code ?

1. Your program starts with focus on self.my_button.
2. You bind the 'my_choice'-widget with with the 'my_choice_on_focus'-
method.
3. By clicking on 'my_choice' the focus change from 'my_button' to
'my_choice'. Thereby the 'my_choice_on_focus'-method was entered.
4. Remember: The focus is on 'my_choice'.
5. After 'my_choice_on_focus'-method is processed, the focus is yet on
'my_choice' and you skip to 4.

If you set focus back on 'my_button', after the 'my_choice_on_focus'-
method is processed, the program is doing what you want.

I'm sorry for my English. I know it isn't good.

dto. :slight_smile:

Regards
Claus

Hi
My sample program starts with focus on self.my_buton because
if my_choice to be focus first program starts with error message
This code is part of my orginal code for show error in my orginal code
I want to insert my_choice items when my_choice is selected.
Because items not same always.
I take items on a database with a query in my orginal code.

···

2010/1/21 Claus Gaisser mutetella@yahoo.de

Hi nozkan,

What is error in my code ?

  1. Your program starts with focus on self.my_button.

  2. You bind the ‘my_choice’-widget with with the ‘my_choice_on_focus’-

method.

  1. By clicking on ‘my_choice’ the focus change from ‘my_button’ to

‘my_choice’. Thereby the ‘my_choice_on_focus’-method was entered.

  1. Remember: The focus is on ‘my_choice’.

  2. After ‘my_choice_on_focus’-method is processed, the focus is yet on

‘my_choice’ and you skip to 4.

If you set focus back on ‘my_button’, after the ‘my_choice_on_focus’-

method is processed, the program is doing what you want.

I’m sorry for my English. I know it isn’t good.

dto. :slight_smile:

Regards

Claus

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en