Skip to content

Gmoccapy Tool/Offset pages: Value verification and tool data checking - #4436

Open
Sigma1912 wants to merge 3 commits into
LinuxCNC:masterfrom
Sigma1912:Gmoccapy_fix-calc-input-tool
Open

Gmoccapy Tool/Offset pages: Value verification and tool data checking#4436
Sigma1912 wants to merge 3 commits into
LinuxCNC:masterfrom
Sigma1912:Gmoccapy_fix-calc-input-tool

Conversation

@Sigma1912

@Sigma1912 Sigma1912 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Discussion has shown that silent manipulation to make the user entered data fit the data type required by the cell is not wanted and that a rejected value should trigger a message to the user.

Value entries by the user to the offset or tool tables are currently 'verified' and manipulated in several places:

  • Calculator widget
  • entry_dialog
  • gmoccapy
  • tooledit / offsetpage widgets

This PR moves value verification to the end recipient (ie the tooledit - and offsetpage widgets). The value is verified in the same place regardless whether the user uses the keyboard directly, the buttons in the calculator widget or the keyboard in the calculator widget. The cell and it's data range is known and a clear user message can be generated.

Fixes #4435

Also in this commit:

  • Tool table is checked for duplicate tool numbers on save.

The second commit:

  • The tool number for a new tool is preset to the lowest available number found in the table instead of '0'

The third commit:

  • Lines that contain only white space are ignored instead of creating a new row with all '0'
    A message is shown on startup if the tool file contains
  • duplicated tool numbers
  • orientation values not in range 0...9
  • malformed lines (missing descriptors or values) these lines are copied to a file so they are not silently lost when the table is saved.

Example:
messages

@hansu

hansu commented Aug 21, 2026

Copy link
Copy Markdown
Member

That was quick, thanks.

I haven't dug deep into this but I wonder if we should fix it better in tooledit (or additionally).
It fails in line int(new_text) with new text = "5.000" for example.

if col in(1,2):
try:
self.model[path][col] = int(new_text)
except:
pass
# validate input for float columns
elif col in range(3,15):
try:
self.model[path][col] = f"{float(new_text.replace(',', '.')):10.4f}"
except:
pass

This would also fix it in this case. But it might be bad if this function gets accidentally a float value which is cut then.

    if col in(1,2):
        try:
            import re
            self.model[path][col] = int(re.split(r'[.,]', new_text)[0])

@Sigma1912
Sigma1912 force-pushed the Gmoccapy_fix-calc-input-tool branch from b1369d0 to bb1801a Compare August 21, 2026 14:17
@Sigma1912

Copy link
Copy Markdown
Contributor Author

I noticed that the pocket number column currently allows negative integer values, which I don't think is correct?
So Tool and Pocket number columns will now truncate any float to the absolute integer value. I'm not sure we still need the dot,comma replacement but kept it just in case.

@Sigma1912 Sigma1912 changed the title Gmoccapy: Fix calculator input for tool- and pocket-nr in tooltable Gmoccapy: Fixes in calculator and tooledit_widget Aug 21, 2026
Comment thread src/emc/usr_intf/gmoccapy/gmoccapy.py Outdated
@hansu

hansu commented Aug 22, 2026

Copy link
Copy Markdown
Member

I noticed that the pocket number column currently allows negative integer values, which I don't think is correct?

I don't know. Maybe one want to disable a tool by setting pocket to -1?
I think the bigger problem is that duplicated tool numbers and pocket numbers are allowed.

@grandixximo

Copy link
Copy Markdown
Contributor

I use duplicate pocket numbers, stacked tools

@Sigma1912

Copy link
Copy Markdown
Contributor Author

Just checked in Axis gui (if that is anything to go by):

  • allows duplicate pocket numbers
  • errors out on negative pocket numbers

And yes, there is definitely a use for duplicate pocket number.

@hansu

hansu commented Aug 22, 2026

Copy link
Copy Markdown
Member

Okay, but duplicated tool numbers? You would never know which one will be used.

@Sigma1912

Copy link
Copy Markdown
Contributor Author

Okay, but duplicated tool numbers?

Yes, those should indeed not be allowed.

@grandixximo

grandixximo commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

I used programs where the tool ID has to be unique, it is tricky to do it without getting in the way when the user is renumbering tools for whatever reason, some thought need be put into that. Although at the final state there should be no duplicates, when user is wanting to do a renumbering, not having any hard blocks (current behavior) allows to have a moment where there are two tools with the same number; the trick is finding a reasonable way to allow renumbering without getting in the way of the renumbering cleanup flow, some kind of message confirmation, same number already in the table, want to swap number? cancel?
Also when adding a tool, it would be nice to have the next available ID be ready for the user.
Also there could be tool tables with duplicates in the wild, a warning that those need be fixed should show up somewhere somehow without nagging the user too much...

Comment thread lib/python/gladevcp/tooledit_widget.py Outdated
except:
pass
# validate input for orientation: check if int and valid range
elif col == 15:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This did not get the same float-tolerant treatment: it still uses plain int(new_text). Direct cell entry of 3.0 is now accepted for tool/pocket but still silently rejected for orientation. Same int(float(...)) pattern, keeping the existing range check, would unify it.

@hansu hansu Aug 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the lines you are referring to? I think the above lines not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

525-531

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub displays it weird because is not in the diff

@hansu

hansu commented Aug 23, 2026

Copy link
Copy Markdown
Member

I used programs where the tool ID has to be unique, it is tricky to do it without getting in the way when the user is renumbering tools for whatever reason, some thought need be put into that. Although at the final state there should be no duplicates, when user is wanting to do a renumbering, not having any hard blocks (current behavior) allows to have a moment where there are two tools with the same number; the trick is finding a reasonable way to allow renumbering without getting in the way of the renumbering cleanup flow, some kind of message confirmation, same number already in the table, want to swap number? cancel? Also when adding a tool, it would be nice to have the next available ID be ready for the user. Also there could be tool tables with duplicates in the wild, a warning that those need be fixed should show up somewhere somehow without nagging the user too much...

I could imagine to do the check on save. So it's easy to rename the IDs and have duplicate IDs in between.

@Sigma1912

Copy link
Copy Markdown
Contributor Author

Generally I cannot really comment since I don't use the tool table much.
Maybe we also shouldn't silently truncate a float entry to integer either.

Check on save seems the most straight forward to me but we would probably also have to check on load since a tool table can easily be edited outside the gui.

This widget is shared with axis, gscreen and qtdragon

I thought this was only shared by gscreen.

@zz912

zz912 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

As a tester, I don't think silently truncating a decimal value is the right behavior here.

If the Tool Number or Pocket Number field expects an integer and a user accidentally enters, for example, 5.7, I would expect the application to report a validation error rather than silently changing the value to 5.

From a testing/UX perspective, silently modifying the user's input can hide an input error and potentially lead to a different tool or pocket being used than the operator intended.

In my opinion, it would be safer and clearer to reject the value and tell the user that an integer is required. The user can then correct the input explicitly.

@Sigma1912
Sigma1912 force-pushed the Gmoccapy_fix-calc-input-tool branch from 733754b to 361bc09 Compare August 25, 2026 14:22
@Sigma1912
Sigma1912 marked this pull request as draft August 25, 2026 14:22
@Sigma1912

Sigma1912 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

I agree that silent changes to the values entered is not the right thing to do so I made some deeper changes.

  1. The receiver of the data (eg the offsetpage_widget or the tooledit_widget) is responsible for checking the entered values and will now inform the user if an entry is rejected.
  2. The calculator no longer tries to shape the return values to what the receiver might want.
  3. Offset editing using the calculator is now handled by the same code as when editing with the keyboard.

Testers welcome.

return None
if self.use_localization:
try:
value = locale.atof( value )

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small reminder regarding the use of locale.atof() — perhaps it simply got overlooked in the context of the other changes. 🙂

We have spent quite a bit of time dealing with atof() and decimal separator localization in LCNC, and we even have a recommendation about this in the documentation: https://linuxcnc.org/docs/devel/html/en/gui/gui-dev-reference.html#_localization_of_float_numbers_in_guis

atof() can of course work correctly in some situations, but in combination with locales I find it rather tricky and potentially a bit of a time bomb — especially because the problem may not show up under the usual EN locale.

If the intention here is to keep using locale.atof(), I would at least ask for it to be tested with the DE locale, where the decimal separator is a comma. That is where I would expect any potential problems to show up first.

Please don't take this as a blocker for the change, but rather as a reminder based on the experience we've already had with this in LCNC.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is current code that got moved around not something new. That is there for backwards compatibility aimed at Gscreen only not something that Gmoccapy uses.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I understand that this is existing code being moved around and that it is only there for Gscreen backwards compatibility.

The reason I mentioned it is precisely because this is how we ended up with problems in the past. atof() had been working without any apparent issues for a long time, and then some surrounding code changed and suddenly the locale-related problems started showing up.

So my concern is not that atof() is being introduced here as something new, but rather that moving it around can potentially change the context in which it runs. That's why I would still consider a quick test with the DE locale worthwhile, just to make sure the existing behaviour remains safe after the change.

If that has already been covered by the existing Gscreen compatibility testing, then of course that's fine.

@Sigma1912 Sigma1912 changed the title Gmoccapy: Fixes in calculator and tooledit_widget Gmoccapy: Move value verification to the widgets that recieve them Aug 25, 2026
@Sigma1912
Sigma1912 force-pushed the Gmoccapy_fix-calc-input-tool branch from 361bc09 to 4265bc8 Compare August 26, 2026 06:52
@Sigma1912
Sigma1912 marked this pull request as ready for review August 26, 2026 06:55
@Sigma1912
Sigma1912 force-pushed the Gmoccapy_fix-calc-input-tool branch from 4265bc8 to a27dfc9 Compare August 26, 2026 07:31
@Sigma1912 Sigma1912 changed the title Gmoccapy: Move value verification to the widgets that recieve them Gmoccapy Tool/Offset pages: Value verification and Tooln# handling Aug 26, 2026
@Sigma1912 Sigma1912 changed the title Gmoccapy Tool/Offset pages: Value verification and Tooln# handling Gmoccapy Tool/Offset pages: Value verification and Toolnr handling Aug 26, 2026
@Sigma1912
Sigma1912 force-pushed the Gmoccapy_fix-calc-input-tool branch from a27dfc9 to 4a9e629 Compare August 26, 2026 07:39
@Sigma1912
Sigma1912 marked this pull request as draft August 26, 2026 07:52
- value validation is done by the widgets the values are entered for
- the calculator returns the values that were entered and does not do validation
- offsetvalue editing is handled in the widget regardless whether directly with the keyboard or the calculator
- On save the table is checked for duplicate tool numbers
@Sigma1912
Sigma1912 force-pushed the Gmoccapy_fix-calc-input-tool branch from 4a9e629 to 4eac6cc Compare August 26, 2026 08:00
The tool number for a new tool is preset to the lowest available number found in the table instead of '0'
@Sigma1912

Copy link
Copy Markdown
Contributor Author

Also when adding a tool, it would be nice to have the next available ID be ready for the user.
Also there could be tool tables with duplicates in the wild, a warning that those need be fixed should show up somewhere somehow without nagging the user too much...

Both implemented.

@Sigma1912
Sigma1912 marked this pull request as ready for review August 26, 2026 09:23
@Sigma1912
Sigma1912 force-pushed the Gmoccapy_fix-calc-input-tool branch 4 times, most recently from 6de1203 to 6ee058f Compare August 26, 2026 13:27
@Sigma1912 Sigma1912 changed the title Gmoccapy Tool/Offset pages: Value verification and Toolnr handling Gmoccapy Tool/Offset pages: Value verification and tool data checking Aug 26, 2026
Lines containing whitespace only are skipped rather than creating a new line with all '0'

A message is shown on startup if
 - duplicate tool numbers have been found in the tool table
 - orientation is not in range 0...9
 - a line is malformed, these are saved to a separate file so they are not silently deleted on save
@Sigma1912
Sigma1912 force-pushed the Gmoccapy_fix-calc-input-tool branch from 6ee058f to 3399b5b Compare August 26, 2026 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gmoccapy: Tool number and pocket are not editable with calculator

4 participants