Skip to content

qtvcp: make HAL pin type enums resolvable by uic again - #4846

Open
grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:qtvcp-pintype-enum
Open

grandixximo wants to merge 1 commit into
LinuxCNC:masterfrom
grandixximo:qtvcp-pintype-enum

Conversation

@grandixximo

@grandixximo grandixximo commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4843.

uic resolves <enum>HalBar::REAL</enum> with getattr(HalBar, 'REAL'). Since the HAL API break those class attributes are hal.Type members, which the HALPinType property rejects, so HalBar, PushButton and HALPad always come up with their default pin type. On qtdragon_lathe the load bars become SINT and lathe_postgui.hal fails to link them to joint.N.vel-cmd, so the config does not start.

I give the three classes a metaclass whose __getattr__ answers uic from HALPinType, instead of keeping a second hand-written list of class attributes. BIT, S32 and FLOAT are no longer HALPinType members, so Designer only offers and writes the current names; the metaclass maps the old names for .ui files saved before 2.10, with a warning to resave the file in Designer.

I ran sim.qtdragon_lathe.basic_xz_lathe before and after: before it stops after loading the postgui file, after it starts with both load pins real and linked. With the .ui rewritten to HalBar::FLOAT it also starts with real pins and logs the warning once.

@BsAtHome, this touches the type names from the API break, could you have a look?

@grandixximo
grandixximo requested a review from BsAtHome November 14, 2026 12:55
@BsAtHome

Copy link
Copy Markdown
Contributor

Wondering,... how long do we need to keep the old names?
This fix correctly ensures types and write-back. The only real issue is reading old ui files, I think. Isn't it then possible to do the same getattr trick and "fix" it there instead of having the old values still defined? The fix could also warn that the ui file needs upgrading.

@grandixximo

Copy link
Copy Markdown
Contributor Author

Agreed, they do not need to stay in the enum. I dropped BIT, S32 and FLOAT from HALPinType and moved the compatibility into a metaclass on HalBar, PushButton and HALPad: its __getattr__ answers uic's getattr(HalBar, 'REAL') from HALPinType, and maps the old names to the current ones with a warning, once per name, to open and save the .ui file in Designer. That also replaces the setattr loops. No .ui in the tree uses the old names, so the mapping can go in a later release once 2.9 .ui files are no longer expected. I ran qtdragon_lathe with its .ui as is and rewritten to HalBar::FLOAT: the load pins come up real both times, the second time with the warning.

uic resolves `<enum>HalBar::REAL</enum>` with getattr(HalBar, 'REAL'). Since the HAL API break those class attributes were hal.Type members, which the HALPinType property rejects, so HalBar, PushButton and HALPad always came up with their default pin type. On qtdragon_lathe the load bars became SINT and lathe_postgui.hal failed to link them to joint.N.vel-cmd.

Give the three classes a metaclass whose __getattr__ answers uic from HALPinType, instead of keeping a second hand-written list of class attributes. BIT, S32 and FLOAT are no longer HALPinType members; the metaclass maps them to BOOL, SINT and REAL for .ui files saved before 2.10, with a warning to resave the file in Designer.

Fixes LinuxCNC#4843
Comment on lines +101 to +104
# uic resolves <enum>HalBar::REAL</enum> with getattr(HalBar, 'REAL'), so
# the class must answer the names of its HALPinType. Names from .ui files
# saved before 2.10 map to the current ones, with a warning.
class HalPinTypeMeta(type(QDialog)):

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.

The comment suggests that it is only for HalBar, but it is now used as a base class to resolve the old types and warn for others as well.

if new in pintype.__members__:
if (cls.__name__, name) not in HalPinTypeMeta._warned:
HalPinTypeMeta._warned.add((cls.__name__, name))
LOG.warning('{0}::{1} is an old pin type name, use {0}::{2}. '

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.

Shouldn't the :: be a .?

Comment on lines +500 to 501

class ScaledLabel(QtWidgets.QLabel):

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.

Nitpicking ;-) Not sure why the extra empty line was added.

Comment on lines 647 to +648


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.

And this empty line too.

Comment on lines +474 to 475

if __name__ == '__main__':

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.

And one more empty line.

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.

qtdragon_lathe -> basic_xz_lathe fails to start

2 participants