EVT_SET_FOCUS and EVT_KILL_FOCUS not working on wx.Choice in wx 3.0

Hello,

I just discovered that when i bind focus events using EVT_SET_FOCUS and EVT_KILL_FOCUS on a wx.Choice, they do not work in wx 3.0 as they did in wx 2.8.

#!/usr/bin/env python

import wx

class MyApp(wx.App):
def OnInit(self):
frame = wx.Frame(None, title=“Test”)
panel = wx.Panel(frame)

    choice = wx.Choice(panel, wx.NewId())
    for label, value in (('One', 1), ('Two', 2)):
        choice.Append(label, value)

    field = wx.TextCtrl(panel, wx.NewId())

    button = wx.Button(panel, wx.NewId(), label="Ok")
    button.Bind(wx.EVT_BUTTON, self._on_button_click)

    sizer = wx.BoxSizer(wx.HORIZONTAL)
    for ctrl in (choice, field, button):
        ctrl.Bind(wx.EVT_SET_FOCUS, self._on_set_focus)
        ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_kill_focus)
        sizer.Add(ctrl, 0, wx.ALL, 5)
    panel.SetSizer(sizer)

    button.SetFocus()
    frame.Show()
    self.SetTopWindow(frame)
    return True
   
def _on_set_focus(self, event):
    print "Focus received:", event.GetEventObject()
    event.Skip()
       
def _on_kill_focus(self, event):
    print "Focus lost:", event.GetEventObject()
    event.Skip()

def _on_button_click(self, event):
    print "Button clicked."
    event.Skip()

if name == ‘main’:
app = MyApp(redirect=False)
app.MainLoop()

``

This code emits the events for all controls (Choice, TextCtrl and Button) under 2.8 GTK Ubuntu, but under 3.0.1 GTK on Debian, the events are only emitted for TextCtrl and Button, not for the Choice. Just watch the output when tabbing through the form or when clicking by mouse.

Can someone else confirm this behavior? Does that look like a wx problem or wxPython’s? Any work arounds? Thank you for any ideas on this issue.

Hi,

Hello,

I just discovered that when i bind focus events using EVT_SET_FOCUS and
EVT_KILL_FOCUS on a wx.Choice, they do not work in wx 3.0 as they did in wx
2.8.

#!/usr/bin/env python

import wx

class MyApp(wx.App):
    def OnInit(self):
        frame = wx.Frame(None, title="Test")
        panel = wx.Panel(frame)

        choice = wx.Choice(panel, wx.NewId())
        for label, value in (('One', 1), ('Two', 2)):
            choice.Append(label, value)

        field = wx.TextCtrl(panel, wx.NewId())

        button = wx.Button(panel, wx.NewId(), label="Ok")
        button.Bind(wx.EVT_BUTTON, self._on_button_click)

        sizer = wx.BoxSizer(wx.HORIZONTAL)
        for ctrl in (choice, field, button):
            ctrl.Bind(wx.EVT_SET_FOCUS, self._on_set_focus)
            ctrl.Bind(wx.EVT_KILL_FOCUS, self._on_kill_focus)
            sizer.Add(ctrl, 0, wx.ALL, 5)
        panel.SetSizer(sizer)

        button.SetFocus()
        frame.Show()
        self.SetTopWindow(frame)
        return True

    def _on_set_focus(self, event):
        print "Focus received:", event.GetEventObject()
        event.Skip()

    def _on_kill_focus(self, event):
        print "Focus lost:", event.GetEventObject()
        event.Skip()

    def _on_button_click(self, event):
        print "Button clicked."
        event.Skip()

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

This code emits the events for all controls (Choice, TextCtrl and Button)
under 2.8 GTK Ubuntu, but under 3.0.1 GTK on Debian, the events are only
emitted for TextCtrl and Button, not for the Choice. Just watch the output
when tabbing through the form or when clicking by mouse.

Can someone else confirm this behavior? Does that look like a wx problem or
wxPython's? Any work arounds? Thank you for any ideas on this issue.

Can you reprodeuce it in a C++ 'widgets' sample?

Thank you.

···

On Wed, Dec 2, 2015 at 4:07 PM, TC <t.cerha@gmail.com> wrote:

--
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.

TC wrote:

Hello,

I just discovered that when i bind focus events using EVT_SET_FOCUS
and EVT_KILL_FOCUS on a wx.Choice, they do not work in wx 3.0 as they
did in wx 2.8.
...
This code emits the events for all controls (Choice, TextCtrl and
Button) under 2.8 GTK Ubuntu, but under 3.0.1 GTK on Debian, the
events are only emitted for TextCtrl and Button, not for the Choice.
Just watch the output when tabbing through the form or when clicking
by mouse.

For what it's worth, your code works correctly with wxPython 3.0.3 under
Windows.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Dne čtvrtek 3. prosince 2015 19:44:03 UTC+1 Tim Roberts napsal(a):

For what it’s worth, your code works correctly with wxPython 3.0.3 under

Windows.

Thanks Tim, this is good to know. Anyone able to test it on 3.0.3 Linux/GTK?

Hi,

Dne čtvrtek 3. prosince 2015 19:44:03 UTC+1 Tim Roberts napsal(a):

For what it's worth, your code works correctly with wxPython 3.0.3 under
Windows.

Thanks Tim, this is good to know. Anyone able to test it on 3.0.3
Linux/GTK?

What is your GTK+ version?
Any special option when compiling wxWidgets?

Thank you.

···

On Thu, Dec 3, 2015 at 3:01 PM, TC <t.cerha@gmail.com> wrote:

--
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.

Dne středa 2. prosince 2015 22:10:48 UTC+1 Igor Korot napsal(a):

Can you reprodeuce it in a C++ ‘widgets’ sample?

Well, I haven’t been coding C for quite a few years now, but after some trial/error headache I’ve been able to come up with this code which compiles and runs on a Debian box:

#include <wx/wx.h>

class MyApp: public wxApp
{
public:
virtual bool OnInit();
protected:
void OnSetFocus(wxCommandEvent& event);
};

class MyFrame : public wxFrame {
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) :
wxFrame(NULL, wxID_ANY, title, pos, size) {}
void OnSetFocus(wxFocusEvent& event);
void OnKillFocus(wxFocusEvent& event);
};

void MyFrame::OnSetFocus(wxFocusEvent& event) {
wxWindow w = (wxWindow) event.GetEventObject();
wxMessageOutputDebug().Printf(“Focus received: %s”, w->GetName());
}

void MyFrame::OnKillFocus(wxFocusEvent& event) {
wxWindow w = (wxWindow) event.GetEventObject();
wxMessageOutputDebug().Printf(“Focus lost: %s”, w->GetName());
}

bool MyApp::OnInit() {
MyFrame *frame = new MyFrame(“Test”, wxPoint(50, 50), wxSize(450, 340));
wxPanel *panel = new wxPanel(frame, -1);

wxChoice *choice = new wxChoice(panel, -1, wxPoint(-1, -1));
choice->Append(“One”);
choice->Append(“Two”);
choice->SetName(“wxChoice”);
choice->Bind(wxEVT_SET_FOCUS, &MyFrame::OnSetFocus, frame);
choice->Bind(wxEVT_KILL_FOCUS, &MyFrame::OnKillFocus, frame);

wxTextCtrl *field = new wxTextCtrl(panel, -1, “”, wxPoint(-1, -1));
field->SetName(“wxTextCtrl”);
field->Bind(wxEVT_SET_FOCUS, &MyFrame::OnSetFocus, frame);
field->Bind(wxEVT_KILL_FOCUS, &MyFrame::OnKillFocus, frame);

wxButton *button = new wxButton(panel, -1, “Ok”, wxPoint(-1, -1));
button->SetName(“wxButton”);
button->Bind(wxEVT_SET_FOCUS, &MyFrame::OnSetFocus, frame);
button->Bind(wxEVT_KILL_FOCUS, &MyFrame::OnKillFocus, frame);

wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
sizer->Add(choice, 0, wxALL, 5);
sizer->Add(field, 0, wxALL, 5);
sizer->Add(button, 0, wxALL, 5);
panel->SetSizer(sizer);

frame->Show(true);
return true;
}

IMPLEMENT_APP(MyApp);

``

It gives me the same results as the Python code, so the problem must be in wxWidgets. I also upgraded wx to 3.0.2 (from previous 3.0.1) and the problem still persists.

Dne čtvrtek 3. prosince 2015 21:07:04 UTC+1 Igor Korot napsal(a):

What is your GTK+ version?

I’m using GTK from Debian unstable, version 3.12.2-2.

Any special option when compiling wxWidgets?

Also from Debian unstable package libwxgtk3.0-0v5:amd64, version 3.0.2+dfsg-1.2.

Hi,

Dne čtvrtek 3. prosince 2015 21:07:04 UTC+1 Igor Korot napsal(a):

What is your GTK+ version?

I'm using GTK from Debian unstable, version 3.12.2-2.

Any special option when compiling wxWidgets?

Also from Debian unstable package libwxgtk3.0-0v5:amd64, version
3.0.2+dfsg-1.2.

You best bet is to send this email to wx-dev with the sample code, OS and
GTK+ version.

You will get better response there.

Thank you.

···

On Thu, Dec 3, 2015 at 3:24 PM, TC <t.cerha@gmail.com> wrote:

--
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.