Validated number input text control that works?

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
MrSurly
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Nov 26, 2020 6:52 pm

Validated number input text control that works?

Post by MrSurly »

I have a simple app where numbers need to be provided by the user.

Started with TextCtrl, and of course it allows any text. So I started looking to using a wx.Validator, but the OnChar only seems to work in Dialogs. So I went looking for something already created -- surely other people need to make apps that take numbers, right?

So I found IntCtrl, and immediately found a bug: If you start to type a negative number, you can't continue entering the number. So I filed a PR: https://github.com/wxWidgets/Phoenix/pull/1868

Get a little further along, and I realize some of my fields are floats, so I again go looking for something and find masked.NumCtrl, and I immediately find that if you delete the selected text -- you guessed it -- you can't enter a number anymore.

What I need (essentially) is:
  • Enter only numbers
  • Numbers are limited to a range
  • Some of my fields will be floating point
Is there an existing stable validated number entry field that "just works" for what I want to do?

I'm using Phoenix wxPython-4.1.1
Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 357
Joined: Tue Jun 07, 2016 1:07 pm

Re: Validated number input text control that works?

Post by Kvaz1r »

Why just not use wxSpinCtrl for integer and wxSpinCtrlDouble for float?
MrSurly
In need of some credit
In need of some credit
Posts: 6
Joined: Thu Nov 26, 2020 6:52 pm

Re: Validated number input text control that works?

Post by MrSurly »

I can try this. The only wrinkle is that the arrows are kinda weird given the number ranges are in the tens of thousands, and inc/dec by 1 (or any value really) doesn't make sense for the datatype.
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Validated number input text control that works?

Post by doublemax »

Did you try wxFloatingPointValidator? Assuming it exists in wxPython.

https://docs.wxwidgets.org/trunk/classw ... dator.html
Use the source, Luke!
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: Validated number input text control that works?

Post by Manolo »

wxFormatvalidator https://sourceforge.net/projects/wxcode ... Validator/ does everything you need.

It's C++. So, to use it in wxPython you need to compile it into a library and call it from python.
Post Reply