[wxPython-users] Combo box as grid cell editor
Robin Dunn
robin at alldunn.com
Wed Aug 1 13:43:48 PDT 2007
Yusdi Santoso wrote:
> Hi all,
>
> I attempted to make combo box as a grid cell editor based on the code
> given here:
> http://wiki.wxpython.org/index.cgi/wxGridCellChoiceEditor2
> by replacing the wx.Choice widget to wx.ComboBox. When nothing else was
> changed except for the Choice to ComboBox replacement, the combo box
> component failed to be displayed when the cell editor was activated.
> Tracing the code I realized that EndEdit was called immediately after
> BeginEdit without allowing the combo box to display itself.
>
> I then found a C++ example here:
> http://www.wxwidgets.org/wiki/index.php/WxGrid
> which is about the same, except that it does not call PushEventHandler
> on the combo box. As far as my understanding goes, this seems to mean
> that all of the events will be handled directly by the combo box instead
> of the window event handler. In any case, removing PushEventHandler
> allowed the combo box to be rendered, but...this time the application
> crashed everytime it was closed. It seemed to me that the event handling
> was screwed up by removing PushEventHandler, but by enabling
> PushEventHandler, the combo box was not even displayed.
The wxGrid expects that there has been an evthandler pushed so it will
do a pop. Since in your case it is trying to pop something that
shouldn't be (the default handler, which is the control itself) then it
ends up trying to use the deallocated control via a bad pointer, and it
crashes.
The evthandler passed to you has handlers for the key focus events so
the grid can take care of things like traversal to other cells, or
closing the cell editor if it looses focus. I expect that your original
problem is happening because there is a temporary focus change event
when the drop-down is shown, and so the grid thinks it needs to close
the editor. You can work around this by pushing a *different*
wx.EvtHandler so the grid has something to pop later on. It doesn't
have to do anything, it just has to be there. Of course you'll need to
try to handle the key events yourself and take care of Enter, ESC and
Tab as the grid would have.
self.control.PushEventHandler(wx.EvtHandler())
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list