-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Gmoccapy fix various (localization) bugs #3500
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
base: master
Are you sure you want to change the base?
Conversation
Sigma1912
commented
Jul 5, 2025
- Calculator_widget: Fix locale handling
- Offsetpage_widget: force display of unlocalized float values, remove unused format template
- Tooledit_widget: use local.atof() instead of replacing commas with dot
- Gmoccapy offsetpage: Fix 'Rot' column not calling the calculator on editing
try: | ||
# convert to decimal dot format | ||
i = str( locale.atof( i ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will it works corectly with DE localization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did when I tested it with de_DE
Which case does this fix? (A short description would fit perfectly in the extended commit description 😉 ) |
@@ -476,7 +476,7 @@ def col_editted(self, widget, path, new_text, col, filter): | |||
# validate input for float columns | |||
elif col in range(3,15): | |||
try: | |||
self.model[path][col] = f"{float(new_text.replace(',', '.')):10.4f}" | |||
self.model[path][col] = "%10.4f" % locale.atof(new_text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.model[path][col] = "%10.4f" % locale.atof(new_text) | |
self.model[path][col] = f"{locale.atof(new_text):10.4f}" |
Please not re-introduce the old style formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As there is general disagreement with this commit you might want to cherry pick the others for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just about the line, not the whole commit.
I thought it's easy to change that line...
Good catch 👍 - didn't notice that |
[zz912)
Yeah we have to find a solution that the calculator also accepts a dot with "decimal-comma-locales", but only one and so on... |
Not sure I would agree with this statement.
However, since I'm in the decimal dot space I'll leave the decisions to you guys who live in the decimal comma space. |
Just to be clear, I'm not insisting on using 'locale.atof() but using this will give consistent behavior for all location settings. |
c5442ea
to
9f76861
Compare
Maybe something like this:
|
[Sigma1912]
That's just a theory. #3499 (comment)
This code tries to solve the problem with numbers in the format 1.523.785,45 . If (number of decimal points + number of decimal comma) > 1 I would name the function something other than "check". |
That is just example code in case somebody wants to try it out. |
9f76861
to
8559fc7
Compare
It was solved by replace(',', '.') in try function. You want make it better. I'm just trying to explain information that you can't possibly know. Please don't take it as criticism. On the other hand, you're thinking the same way I did when I was dealing with this. |
No problem, the contentious commit has been removed |
Do you want to consider remaking the other "atof" as well? While you're at it? If not, I'll focus on testing them thoroughly. I'd like to give you some more information so you can understand the context:
|
Agree, It would also do it this way |
Sure, go ahead. |
After your force-pushed I cloned your linuxcnc fork and switched to the Gmoccapy_Fix_various_bugs branch. I think, this is not your fault, but you are fixing something that works wrong by default. |
In order to allow dot AND comma decimals in the calculator we will likely need to remove all localization from calculatorwidget.py. Since we currently share this widget with some legacy guis like 'gscreen' and 'woodpecker' I'll need to have Gmoccapy use it's own version of calculator. I'll have a look at it tomorrow. |
8559fc7
to
4e88f64
Compare
The behavior of calculator in *.gif picture is exactly as I imagined and exactly as I think it is correct. I don't understand why you keep using "locale.atof" in your fix code? The fact that your code works is only because you hid "locale.atof" under the self.allow_dot_and_comma option.
If you want to make the calculator module perfect, the switch self.allow_show_comma would be useful if self.allow_show_comma == 0: In both cases, the calculator would be able to accept decimal comma and decimal dot. Gmoccapy will use self.allow_show_comma == 0 I would like to ask @hansu to comment on my opinions. I am convinced that my opinions are correct, but I don't want Sigma1912 to keep rewriting the codes. |
I'm not. If you compare the current code and my PR then you see that I'm just moving the existing code into an 'if' clause so this part of the code is no longer used in gmoccapy. I'm not willing to change the behavior of the calculator widget for the other guis if that is what you are expecting. |
I understand what you're doing. But I think this is the wrong approach to fix. If there's a bug somewhere, it should be fixed, not hidden under an if statement. I don't think any GUI wants to have 1.25 => 125 happen. |
A consequence of sharing these widgets with other GUIs is that changes to the default behavior would need to be tested in ALL of those GUIs. Thank you for your understanding. |
I think a simple rule should be made: I understand that it is impossible to test all GUIs. I know how much time it takes me to "only" test Gmoccapy. I always wonder how much time it must take to maintain Gmoccapy. I think that common widgets would deserve a history in the header of the file. Here you can write what you did and in which GUIs you tested it. Another source of information for maintainers could be here: |
You should always code on gladevcp general widgets as if they are used by other GUIs/panels. I agree, the GUI reference could be expanded to include practical 'coding' idiosyncrasy to prevent multiple reinventing of the wheel. QtVCP was a doc section on code snippets. Maybe that might be better to have similar for GladeVCP. |
Sorry for jumping in so late. IMHO entering 1.23+2,34 is an operator error and that may happen. This is just my personal opinion! Norbert |
[Norbert]
[Norbert]
Right now I feel like an absolute idiot for trying to convince Sigma1912 that a dot is a decimal separator. Have you changed your mind? And wouldn't you mind the decimal comma in the DRO? I think someone will crash the machine if they copy the DRO, but the machine will work with a different value: The decision to consider "dot" as the decimal separator is not just mine: |
So
But that is weird especially when editing the tool table. You see a dot - edit it and keep the dot and then the value is 1000 times greater than before. |
Hi Norbert, I wanted to ask you for instructions on how to continue with this fix. My arguments are:
I am convinced after a long time dealing with the float numbers issue that locale.atof should be removed from the entire LCNC.
I am convinced that value.replace('.', '') is the right way to go.
Zdeněk |