Force Qt validator to use C locale. #6241

Merged
merged 1 commit into from Mar 30, 2016

Conversation

Projects
None yet
4 participants
Contributor

anntzer commented Mar 29, 2016

PR for #6082: Cannot interactively edit axes limits using Qt5 backend

I found that this was a locale issue: I am on a French locale, where the decimal separator is ",".
On Qt4 (http://doc.qt.io/qt-4.8/qdoublevalidator.html),

QDoubleValidator uses its locale() to interpret the number. For example, in the German locale, "1,234" will be accepted as the fractional number 1.234. In Arabic locales, QDoubleValidator will accept Arabic digits.
In addition, QDoubleValidator is always guaranteed to accept a number formatted according to the "C" locale.

On Qt5 (http://doc.qt.io/qt-5/qdoublevalidator.html), the second provision has been removed.

Thus, on the French locale, "1.23" is considered an invalid input and rejected by QDoubleValidator. In fact, I can input instead "1,23", but this causes an exception later when Python tries to convert this to a float. (To reproduce this, set the locale appropriately and edit the axes parameters of a default plot.)

Given that matplotlib is not really localized anyways (except for axes.formatter.use_locale), this patch sets the validator's locale to C in all cases. Note that despite what the Qt docs indicate, this does not seem to prevent input of localized ("1,23") values, which still lead to an exception.

@anntzer anntzer Force Qt validator to use C locale.
Qt5's QDoubleValidator defaults to only accepting the default locale,
making the axes properties editor unusable when the locale's decimal
separator is not ".".
efe3341

mdboom added the needs_review label Mar 29, 2016

QuLogic added the GUI/Qt label Mar 29, 2016

Owner

mdboom commented Mar 30, 2016

Should we do this for ints as well?

Also, are there issues for dates? There, I think ISO dates is probably the only thing that's internationally understood.

Contributor

anntzer commented Mar 30, 2016

There isn't anywhere in the UI right now where an int is required as input (AFAICT) but I guess that if there was then something bad could happen with the use of "," as thousands separator in English.
Dates seem completely not handled by the property editor right now, say e.g. examples/api/date_demo.py: it would be nice if the editor provided a calendar widget or similar to input the x limits, but right now it just gives something that looks like a number of days since year 0.

tacaswell added this to the 2.1 (next point release) milestone Mar 30, 2016

@tacaswell tacaswell merged commit 3174f25 into matplotlib:master Mar 30, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

tacaswell removed the needs_review label Mar 30, 2016

anntzer deleted the anntzer:qt5-validator-locale branch Mar 30, 2016

Contributor

anntzer commented Apr 17, 2016

Any chance this can be backported to 1.5.x? It's a pretty annoying issue...

@tacaswell tacaswell added a commit that referenced this pull request Apr 18, 2016

@tacaswell tacaswell Merge pull request #6241 from anntzer/qt5-validator-locale
Force Qt validator to use C locale.
c1cd4f2
Owner

tacaswell commented Apr 18, 2016

backported to v1.5.x as c1cd4f2

@tacaswell tacaswell added a commit to tacaswell/matplotlib that referenced this pull request May 22, 2016

@tacaswell tacaswell Merge pull request #6241 from anntzer/qt5-validator-locale
Force Qt validator to use C locale.
6a1f3a5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment