Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Force Qt validator to use C locale. #6241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 30, 2016

Conversation

anntzer
Copy link
Contributor

@anntzer 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.

Qt5's QDoubleValidator defaults to only accepting the default locale,
making the axes properties editor unusable when the locale's decimal
separator is not ".".
@mdboom
Copy link
Member

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.

@anntzer
Copy link
Contributor Author

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 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
@anntzer anntzer deleted the qt5-validator-locale branch March 30, 2016 03:49
@anntzer
Copy link
Contributor Author

anntzer commented Apr 17, 2016

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

tacaswell added a commit that referenced this pull request Apr 18, 2016
Force Qt validator to use C locale.
@tacaswell
Copy link
Member

backported to v1.5.x as c1cd4f2

@QuLogic QuLogic modified the milestones: 1.5.2 (Critical bug fix release), 2.1 (next point release) Apr 18, 2016
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request May 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.