Process Enter in SpinCtrl on Mac

Hi,

I have a couple of spinCtrls and entering a number in them and hitting enter on Windows and Linux will set the value of the spinCtrl. This doesn’t work on Mac… Is there something special I have to do to make spinCtrls process the Enter key on Mac?

Best,
Soren

More details and/or a runnable sample are needed. The context the spinctrl is in could make a difference, what you mean by "set the value" would help, etc.

http://wiki.wxpython.org/MakingSampleApps

···

On 4/5/10 6:50 AM, S�ren Nielsen wrote:

Hi,

I have a couple of spinCtrls and entering a number in them and hitting
enter on Windows and Linux will set the value of the spinCtrl. This
doesn't work on Mac.. Is there something special I have to do to make
spinCtrls process the Enter key on Mac?

--
Robin Dunn
Software Craftsman

Heres a sample file that’s basically the official converter.py SpinCtrl example where I inserted a bind to wx.EVT_SPINCTRL so it gets updated every time you click the spin buttons… If you instead of pressing the buttons just type a value and hit enter the calculation is performed as if you had pressed one of the spin buttons… but this only works on Linux and Windows… not on Mac.

Soren

spinCtrlTest.py (1.35 KB)

···

On Mon, Apr 5, 2010 at 1:38 PM, Robin Dunn robin@alldunn.com wrote:

On 4/5/10 6:50 AM, Søren Nielsen wrote:

Hi,

I have a couple of spinCtrls and entering a number in them and hitting

enter on Windows and Linux will set the value of the spinCtrl. This

doesn’t work on Mac… Is there something special I have to do to make

spinCtrls process the Enter key on Mac?

More details and/or a runnable sample are needed. The context the spinctrl is in could make a difference, what you mean by “set the value” would help, etc.

http://wiki.wxpython.org/MakingSampleApps

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, reply using “remove me” as the subject.

Ah, so you're talking about the wx.EVT_SPINCTRL event...

Looking at the code and the docs I don't think it is intended that the enter key would cause that event to be sent, and I think it is just a side effect of being on a dialog with no default button. The docs say that when text is entered by hand it is not validated until the control loses focus, and then at that point the value is adjusted to the required range and the spin event is sent if the value was changed. Normally Enter is used as a navigation key on a dialog and it will activate the default button or one with wx.ID_OK ID, but since you don't have that it is just shifting the focus to the next widget. On the Mac Enter is not supposed to behave that way so it doesn't. (But you can still use TAB.)

···

On 4/5/10 10:59 AM, S�ren Nielsen wrote:

Heres a sample file that's basically the official converter.py SpinCtrl
example where I inserted a bind to wx.EVT_SPINCTRL so it gets updated
every time you click the spin buttons.. If you instead of pressing the
buttons just type a value and hit enter the calculation is performed as
if you had pressed one of the spin buttons... but this only works on
Linux and Windows.. not on Mac.

--
Robin Dunn
Software Craftsman

Ok, thanks Robin! So I guess if I want to use enter, which I think is a neat feature, I’ll have to make my own spin spinctrl.

Soren

···

On Tue, Apr 6, 2010 at 12:19 AM, Robin Dunn robin@alldunn.com wrote:

On 4/5/10 10:59 AM, Søren Nielsen wrote:

Heres a sample file that’s basically the official converter.py SpinCtrl

example where I inserted a bind to wx.EVT_SPINCTRL so it gets updated

every time you click the spin buttons… If you instead of pressing the

buttons just type a value and hit enter the calculation is performed as

if you had pressed one of the spin buttons… but this only works on

Linux and Windows… not on Mac.

Ah, so you’re talking about the wx.EVT_SPINCTRL event…

Looking at the code and the docs I don’t think it is intended that the enter key would cause that event to be sent, and I think it is just a side effect of being on a dialog with no default button. The docs say that when text is entered by hand it is not validated until the control loses focus, and then at that point the value is adjusted to the required range and the spin event is sent if the value was changed. Normally Enter is used as a navigation key on a dialog and it will activate the default button or one with wx.ID_OK ID, but since you don’t have that it is just shifting the focus to the next widget. On the Mac Enter is not supposed to behave that way so it doesn’t. (But you can still use TAB.)

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, reply using “remove me” as the subject.

Btw, is there a way I instead could attach a Bind(EVT_TEXT_ENTER) and a style change (wx.PROCESS_ENTER) to the TextCtrl child of a wx.SpinCtrl instance?

Like:

spinctrl = wx.SpinCtrl(self, -1)
txtctrl = spinctrl.GetChildren[0]

txtctrl.Bind(wx.EVT_TEXT_ENTER, self.OnEnter)
and I don’t know how to add the wx.PROCESS_ENTER style…

I know it’d be a hack… but would it be possible at all?

Soren

···

2010/4/6 Søren Nielsen soren.skou.nielsen@gmail.com

Ok, thanks Robin! So I guess if I want to use enter, which I think is a neat feature, I’ll have to make my own spin spinctrl.

Soren

On Tue, Apr 6, 2010 at 12:19 AM, Robin Dunn robin@alldunn.com wrote:

On 4/5/10 10:59 AM, Søren Nielsen wrote:

Heres a sample file that’s basically the official converter.py SpinCtrl

example where I inserted a bind to wx.EVT_SPINCTRL so it gets updated

every time you click the spin buttons… If you instead of pressing the

buttons just type a value and hit enter the calculation is performed as

if you had pressed one of the spin buttons… but this only works on

Linux and Windows… not on Mac.

Ah, so you’re talking about the wx.EVT_SPINCTRL event…

Looking at the code and the docs I don’t think it is intended that the enter key would cause that event to be sent, and I think it is just a side effect of being on a dialog with no default button. The docs say that when text is entered by hand it is not validated until the control loses focus, and then at that point the value is adjusted to the required range and the spin event is sent if the value was changed. Normally Enter is used as a navigation key on a dialog and it will activate the default button or one with wx.ID_OK ID, but since you don’t have that it is just shifting the focus to the next widget. On the Mac Enter is not supposed to behave that way so it doesn’t. (But you can still use TAB.)

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, reply using “remove me” as the subject.

wx.TE_PROCESS_ENTER may be one of those styles that needs to be set before the widget is created, but it's worth a try at least.

   txtctrl.SetWindowStyle(textctrl.GetWindowStyle() | wx.TE_PROCESS_ENTER

or using the WindowStyle property:

   txtctrl.WindowStyle |= wx.TE_PROCESS_ENTER

···

On 4/6/10 7:33 AM, S�ren Nielsen wrote:

Btw, is there a way I instead could attach a Bind(EVT_TEXT_ENTER) and a
style change (wx.PROCESS_ENTER) to the TextCtrl child of a wx.SpinCtrl
instance?

Like:

spinctrl = wx.SpinCtrl(self, -1)
txtctrl = spinctrl.GetChildren[0]

txtctrl.Bind(wx.EVT_TEXT_ENTER, self.OnEnter)
and I don't know how to add the wx.PROCESS_ENTER style..

I know it'd be a hack.. but would it be possible at all?

--
Robin Dunn
Software Craftsman

The SetWindowStyle() worked perfectly.

I did however notice that on the Mac, using spinctrl.GetChildren() correctly returns the list of the underlying textctrl and spinbutton in a SpinCtrl, but under Linux that list is empty… how come??

Thanks,
Soren

···

On Tue, Apr 6, 2010 at 1:33 PM, Robin Dunn robin@alldunn.com wrote:

On 4/6/10 7:33 AM, Søren Nielsen wrote:

Btw, is there a way I instead could attach a Bind(EVT_TEXT_ENTER) and a

style change (wx.PROCESS_ENTER) to the TextCtrl child of a wx.SpinCtrl

instance?

Like:

spinctrl = wx.SpinCtrl(self, -1)

txtctrl = spinctrl.GetChildren[0]

txtctrl.Bind(wx.EVT_TEXT_ENTER, self.OnEnter)

and I don’t know how to add the wx.PROCESS_ENTER style…

I know it’d be a hack… but would it be possible at all?

wx.TE_PROCESS_ENTER may be one of those styles that needs to be set before the widget is created, but it’s worth a try at least.

txtctrl.SetWindowStyle(textctrl.GetWindowStyle() | wx.TE_PROCESS_ENTER

or using the WindowStyle property:

txtctrl.WindowStyle |= wx.TE_PROCESS_ENTER

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

To unsubscribe, reply using “remove me” as the subject.

I'm going to take a wild guess here, but I think that on Linux, the
SpinCtrl is a real widget whereas on Mac it's a generic.

···

On Apr 6, 1:47 pm, Søren Nielsen <soren.skou.niel...@gmail.com> wrote:

The SetWindowStyle() worked perfectly.

I did however notice that on the Mac, using spinctrl.GetChildren() correctly
returns the list of the underlying textctrl and spinbutton in a SpinCtrl,
but under Linux that list is empty.. how come??

Thanks,
Soren

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Yep. You can see the difference in the hierarchy if you look at the spinctrl in the WIT.

···

On 4/6/10 12:40 PM, Mike Driscoll wrote:

On Apr 6, 1:47 pm, S�ren Nielsen<soren.skou.niel...@gmail.com> wrote:

The SetWindowStyle() worked perfectly.

I did however notice that on the Mac, using spinctrl.GetChildren() correctly
returns the list of the underlying textctrl and spinbutton in a SpinCtrl,
but under Linux that list is empty.. how come??

Thanks,
Soren

I'm going to take a wild guess here, but I think that on Linux, the
SpinCtrl is a real widget whereas on Mac it's a generic.

--
Robin Dunn
Software Craftsman