Capture enter pressed on a field

105 views
Skip to first unread message

Jack Minardi

unread,
Sep 14, 2014, 11:13:57 PM9/14/14
to en...@googlegroups.com
I would like to allow the user to trigger an action when they press enter while editing a field. This action should trigger whether or not they edit the text in the field. I also want the user to be able to use a PushButton to trigger the action:

class Model(Atom):
    def action(self, text):
        print text

enamldef Main(Window):
    attr model : Model = Model()
    Container:
        Field: field:
            enter_pressed ::
                model.action(self.text)
        PushButton:
            clicked ::
                 model.action(field.text)

Is what I want to do possible?

Chris Colbert

unread,
Sep 15, 2014, 9:06:30 AM9/15/14
to en...@googlegroups.com
The PushButton will work as you've written it. The Field does not expose any of the underlying widget events, so if the text in the field doesn't change, you won't be able to get an indication that enter was pressed. You will need to create your own widget for that behavior.

Jack Minardi

unread,
Sep 15, 2014, 6:43:21 PM9/15/14
to en...@googlegroups.com
Ok, thanks Chris.

Jason Sachs

unread,
Apr 9, 2020, 12:08:17 PM4/9/20
to Enaml


On Monday, September 15, 2014 at 6:06:30 AM UTC-7, Chris Colbert wrote:
The PushButton will work as you've written it. The Field does not expose any of the underlying widget events, so if the text in the field doesn't change, you won't be able to get an indication that enter was pressed. You will need to create your own widget for that behavior.

On Sunday, September 14, 2014 11:13:57 PM UTC-4, Jack Minardi wrote:
I would like to allow the user to trigger an action when they press enter while editing a field. This action should trigger whether or not they edit the text in the field. I also want the user to be able to use a PushButton to trigger the action:


 I realize this is over 5 years ago, but I have the same issue, and you do *not* necessarily need to create your own widget... as long as you are willing to reach into the Field object and are willing to do some easy back-end-specific things.

I've posted a gist which demonstrates this: https://gist.github.com/jason-s/65a2aebd412e73a5be64fee780231373

the relevant excerpt from this is:

def field_signal_return_event(field, signal): field.proxy.widget.returnPressed.connect(lambda: signal.emit())

Reply all
Reply to author
Forward
0 new messages