Opened 10 years ago

Closed 4 years ago

#9862 closed defect (duplicate)

wxComboBox does not receive wxEVT_KILL_FOCUS under OS X

Reported by: florian Owned by:
Priority: normal Milestone:
Component: wxOSX Version: 3.0.2
Keywords: Mac OS X, ComboBox, EVT_KILL_FOCUS Cc:
Blocked By: Blocking:
Patch: no

Description

myComboBox = wx.ComboBox(parent, id, size, choices)
myComboBox.Bind(wx.EVT_KILL_FOCUS, OnKillFocus)

The ComboBox will never receive the EVT_KILL_FOCUS event under Mac OS X (10.4.11, Python 2.5.2, wxPython 2.8.8.1). Above code works flawlessly under Windows XP.

Attachments (1)

9862.patch download (1.4 KB) - added by oneeyeman 4 years ago.

Download all attachments as: .zip

Change History (12)

comment:1 Changed 10 years ago by florian

Edit - First line should read:
myComboBox = wx.ComboBox(parent, id, "", size, choices)

comment:2 follow-up: Changed 10 years ago by csomor

  • Status changed from new to infoneeded_new

what other controls are on the window ? as under OS X not all controls can get the focus (unless full keyboard navigation is enabled) I'd like to make sure this isn't the root of the problem

Thanks,

Stefan

comment:3 in reply to: ↑ 2 Changed 10 years ago by florian

  • Status changed from infoneeded_new to new

Several others (Buttons, RadioButtons, TextCtrls, CheckBoxes, StaticTexts and a few BitmapButtons). All controls are children of a wxPanel, which is the (only) child of a wxFrame. All controls are positioned using Sizers.
I just discovered that the ComboBox also does not receive the EVT_SET_FOCUS, also.
Any more info you need? I have a prepared a test which illustrates the problem:

import wx

class MyApp(wx.App):
	def OnInit(self):
		frame = wx.Frame(None)
		self.SetTopWindow(frame)
		panel = wx.Panel(frame)
		sizer = wx.BoxSizer(wx.VERTICAL)
		panel.SetSizer(sizer)
		combobox = wx.ComboBox(panel, -1, "")
		sizer.Add(combobox)
		combobox.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
		combobox.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
		textctrl = wx.TextCtrl(panel)
		textctrl.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
		textctrl.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
		sizer.Add(textctrl)
		frame.Show()
		return True
	def OnSetFocus(self, event):
		print "Received EVT_SET_FOCUS: %s (ID %s)" % (event.GetEventObject().GetName(), event.GetId())
		event.Skip()
	def OnKillFocus(self, event):
		print "Received EVT_KILL_FOCUS: %s (ID %s)" % (event.GetEventObject().GetName(), event.GetId())
		event.Skip()

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

The TextCtrl receives the focus events, but not the ComboBox.

Thanks,

Florian

comment:4 Changed 10 years ago by robind

  • Status changed from new to confirmed

Confirmed. Only the textctrl in the sample is getting focus events. I do have full keyboard access turned on.

comment:5 Changed 4 years ago by oneeyeman

Here is what I have running the script from Robin on my Mac with SL using python 2.7.6 and wxPython 3.0 classic Cocoa version:

Received EVT_SET_FOCUS: comboBox (ID -2008)
Received EVT_SET_FOCUS: text (ID -2009)
Received EVT_KILL_FOCUS: text (ID -2009)
Received EVT_SET_FOCUS: comboBox (ID -2008)
Received EVT_SET_FOCUS: text (ID -2009)
Received EVT_KILL_FOCUS: text (ID -2009)
Exit status: 0
logout

The EVT_SET_FOCUS event has been received by the combobox, but there is still no EVT_KILL_FOCUS.

comment:6 Changed 4 years ago by vadz

  • Component changed from wxOSX-Carbon to wxOSX (any toolkit)
  • Summary changed from Mac OS X: ComboBox does not receive EVT_KILL_FOCUS to wxComboBox does not receive wxEVT_KILL_FOCUS under OS X
  • Version changed from 2.8.8 to 3.0.2

comment:7 follow-up: Changed 4 years ago by johnr

This must be wxPython specific as it was fixed some time ago in trunk for C++ and works for me. See #14269
Perhaps I read the meaning of 'wxOSX (any toolkit)' incorrectly.

Changed 4 years ago by oneeyeman

comment:8 in reply to: ↑ 7 Changed 4 years ago by oneeyeman

John,
Replying to johnr:

This must be wxPython specific as it was fixed some time ago in trunk for C++ and works for me. See #14269
Perhaps I read the meaning of 'wxOSX (any toolkit)' incorrectly.

I just tried to test this ticket with the patch attached.
I turn on the "Full Keyboard Support" and ran the sample. Then selected the combobox on the left panel and tried to click on the combobox and then on the text control.
No messages was generated in the log file.

This is on the HEAD from couple of days ago. And the ticket 14269 is not marked as fixed.

comment:9 Changed 4 years ago by johnr

The patch against the git master combo sample I used shows "kill focus" in the xCode output on losing focus from the bound wxComboBox shown in the modal dialog. I did have to change some include <...> to include "..."

You should swap your wxLogWarning with a wxLogDebug method of notification or put a debug breakpoint there. There is a problem showing a wxLogWarning dialog from a focus event.

diff --git a/samples/combo/combo.cpp b/samples/combo/combo.cpp
index b14a0ba..c460c99 100644
--- a/samples/combo/combo.cpp
+++ b/samples/combo/combo.cpp
@@ -83,6 +83,8 @@ public:
     void OnComboBoxUpdate( wxCommandEvent& event );
 
     void OnIdle( wxIdleEvent& event );
+    
+    void OnFocus( wxFocusEvent& event );
 
 
 protected:
@@ -273,7 +275,7 @@ public:
 // wxListView Custom popup interface
 // ----------------------------------------------------------------------------
 
-#include <wx/listctrl.h>
+#include "wx/listctrl.h"
 
 class ListViewComboPopup : public wxListView, public wxComboPopup
 {
@@ -367,7 +369,7 @@ wxEND_EVENT_TABLE()
 // wxTreeCtrl Custom popup interface
 // ----------------------------------------------------------------------------
 
-#include <wx/treectrl.h>
+#include "wx/treectrl.h"
 
 class TreeCtrlComboPopup : public wxTreeCtrl, public wxComboPopup
 {
@@ -1050,6 +1052,8 @@ void MyFrame::OnShowComparison( wxCommandEvent& WXUNUSED(event) )
                         m_arrItems,
                         wxCB_SORT // wxNO_BORDER|wxCB_READONLY
                        );
+    
+    cb->Bind( wxEVT_KILL_FOCUS, &MyFrame::OnFocus, this );
 
     cb->Append(wxT("H - Appended Item")); // test sorting in append
 
@@ -1109,6 +1113,11 @@ MyFrame::~MyFrame()
     delete wxLog::SetActiveTarget(m_logOld);
 }
 
+void MyFrame::OnFocus( wxFocusEvent& event )
+{
+    wxLogDebug("kill focus");
+}
+

comment:10 Changed 4 years ago by oneeyeman

  • Component changed from wxOSX (any toolkit) to wxPython

Re-classifying as wxPython-specific.
C++ part was fixed.

comment:11 Changed 4 years ago by disc

  • Component changed from wxPython to wxOSX-Cocoa
  • Resolution set to duplicate
  • Status changed from confirmed to closed

This is not specific to wxPython but related to it being fixed in master (currently 3.1) but the problem remaining in the 3.0 branch (which wxPython is based on).
Continuing in #14269 which is newer but has relevant commits for convenience.

Note: See TracTickets for help on using tickets.