ListCtrl in Dialog: list_item_activated == send ID_OK event - how ?

Hi,

I have a list inside a dialog (patients to select from
matching a search term). The dialog also has a button
"Select" with ID_OK and a button "Cancel" with ID_CANCEL.

The "Select" button is set to be the default button. The
list is set to be focussed initially.

All this was accomplished with the help of wxGlade.

Hitting "Cancel" or pressing ESC dutifully closes the dialog
and returns ID_CANCEL. Hitting "Select" closes the dialog,
too, and returns ID_OK from EndModal() as is expected.

Now I want my users to be able to simply hit ENTER on a list
item or double-click on one and also close the dialog
returning ID_OK. Catching the list_item_activated event on
ENTER or double-click works fine but how do I go about
closing the dialog and returning ID_OK ? I have tried
calling the dialogs OnOK() as was mentioned in the docs but
it doesn't seem to exist. Neither does OnOk().

I could certainly do

if IsModal():
  self.EndModal(wx.ID_OK)
else:
  self.Close(wx.ID_OK)

or a similar dance. I am wondering, however, whether there's
an easier/more elegant way, though, like "simulating"
pressing the "Select" button - or IOW sending the
corresponding button press event.

This is on:

python-wxgtk2.6:
  Installiert:2.6.3.2.1.5
  Mögliche Pakete:2.6.3.2.1.5
  Versions-Tabelle:
*** 2.6.3.2.1.5 0
        990 ftp://ftp.gwdg.de testing/main Packages
        100 /var/lib/dpkg/status

python:
  Installiert:2.4.3-11
  Mögliche Pakete:2.4.3-11
  Versions-Tabelle:
*** 2.4.3-11 0
        990 ftp://ftp.gwdg.de testing/main Packages
        100 /var/lib/dpkg/status
     2.3.5-2 0
        500 ftp://ftp.gwdg.de stable/main Packages
        500 ftp://ftp.de.debian.org stable/main Packages

Thanks,
Karsten

···

--
GPG key ID E4071346 @ wwwkeys.pgp.net
E167 67FD A291 2BEA 73BD 4537 78B9 A9F9 E407 1346

Karsten Hilbert wrote:

Now I want my users to be able to simply hit ENTER on a list
item or double-click on one and also close the dialog
returning ID_OK. Catching the list_item_activated event on
ENTER or double-click works fine but how do I go about
closing the dialog and returning ID_OK ? I have tried
calling the dialogs OnOK() as was mentioned in the docs but
it doesn't seem to exist. Neither does OnOk().

I could certainly do

if IsModal():
  self.EndModal(wx.ID_OK)
else:
  self.Close(wx.ID_OK)

or a similar dance.

This is the correct way.

I am wondering, however, whether there's
an easier/more elegant way, though, like "simulating"
pressing the "Select" button - or IOW sending the
corresponding button press event.

But this can be done too, and IIRC is used internally in a couple places. Something like creating a wx.CommandEvent with an ID of wx.ID_OK and a type of wx.wxEVT_COMMAND_BUTTON_CLICKED, and then send it with self.GetEventHandler().ProcessEvent(event)

···

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