enter event in combobox

Hello,

I know that this has been asked before but ...
Anyway, I'have a combobox in a panel and I can't get the combobox to
react to enter.
I've tried both EVT_TEXT_ENTER and EVT_COMMAND_ENTER.
I tried creating the combobox with wxWANTS_CHARS style and the panel
with style 0.
but to no avail unfortunately.

What I haven't tried yet is not putting the combobox in a panel. I
don't really need the panel, I just use it for cosmetic reasons (not
using a panel makes the combobox "hang in the air").
So if anybody knows how to make it look like you're using a panel
without actually using one, please tell me and I will try it.

Or if anyone actually succeeded in having a combobox react to enter
could you please tell me how you did it?

Greetings,

Bas

Surely there has to be a better way than this, but here is one way
that seems to work:

#!/usr/bin/env python
from wxPython.wx import *

class MyComboBox(wxComboBox):
    def __init__(self, parent, id):
        wxComboBox.__init__(self, parent, id,
                            style=wxTE_PROCESS_ENTER)
        EVT_CHAR(self, self.onChar)

    def onChar(self, event):
        key = event.GetKeyCode()
        if key == 13:
            print 'enter pressed'
        event.Skip()

class MyPanel(wxPanel):
    def __init__(self, parent):
        # create panel
        wxPanel.__init__(self, parent, id=-1)
        # create the control
        text1 = wxStaticText(self, -1, "Testing Enter")
        combo1 = MyComboBox(self, -1)
        combo2 = MyComboBox(self, -1)

        # create the sizer
        sizer1 = wxBoxSizer(wxVERTICAL)

        # add controls to sizers
        sizer1.Add(text1, 1, wxEXPAND|wxALL, border=10)
        sizer1.Add(combo1, 1, wxEXPAND|wxALL, border=10)
        sizer1.Add(combo2, 1, wxEXPAND|wxALL, border=10)

        # enable sizers
        self.SetSizer(sizer1)
        self.SetAutoLayout(1)
        sizer1.Fit(self)
        sizer1.SetSizeHints(self)

class MyFrame(wxFrame):
    def __init__(self):
        wxFrame.__init__(self, None, -1, 'ComboBox')
        panel1 = MyPanel(self)
        sizer = wxBoxSizer()
        sizer.Add(panel1, 1, wxEXPAND)
        self.SetSizer(sizer)
        self.SetAutoLayout(1)
        sizer.Fit(self)
        sizer.SetSizeHints(self)

class MyApp(wxApp):
    def OnInit(self):
        frame = MyFrame()
        frame.Show(1)
        return 1

app = MyApp(0)
app.MainLoop()

···

--- Bas van der Peet <bas.vanderpeet@advalvas.be> wrote:

I know that this has been asked before but ...
Anyway, I'have a combobox in a panel and I can't get the combobox
to react to enter.
I've tried both EVT_TEXT_ENTER and EVT_COMMAND_ENTER.
I tried creating the combobox with wxWANTS_CHARS style and the
panel with style 0 but to no avail unfortunately.

Or if anyone actually succeeded in having a combobox react to
enter could you please tell me how you did it?

=====
Donnal Walter
Arkansas Children's Hospital

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.

Hello Donnal,

Saturday, December 14, 2002, 2:58:07 AM, you wrote:

I know that this has been asked before but ...
Anyway, I'have a combobox in a panel and I can't get the combobox
to react to enter.
I've tried both EVT_TEXT_ENTER and EVT_COMMAND_ENTER.
I tried creating the combobox with wxWANTS_CHARS style and the
panel with style 0 but to no avail unfortunately.

Or if anyone actually succeeded in having a combobox react to
enter could you please tell me how you did it?

Surely there has to be a better way than this, but here is one way
that seems to work:

[code removed]

=====
Donnal Walter
Arkansas Children's Hospital

Thanks, this works.

I tried something like this myself, but I couldn't get it to work
because I didn't know about EVT_CHAR() so thank you for the tip.

I agree that there ought to be a cleaner way to get the same results
(maybe there is such a way?) because this way I have to use some
tricks to get the text which has been typed in the combobox, nothing
too difficult but a cleaner solution would be nice.
Then again my program works now so I'm not complaining too hard :slight_smile:

···

--- Bas van der Peet <bas.vanderpeet@advalvas.be> wrote:

--
Best regards,
Bas