- Posts: 1107
- Thank you received: 3
Connect PyQt Button to HAL at runtime
This is my current code that creates the HAL pins and they show up in halshow but I'm stumped as how to make the button clicked (or other signals) to change the HAL value.
def setup_hal_buttons(parent):
for button in parent.findChildren(QPushButton):
if button.property('function') == 'hal_pin':
props = button.dynamicPropertyNames()
for prop in props:
prop = str(prop, 'utf-8')
if prop.startswith('pin_'):
#print(prop)
pin_settings = button.property(prop).split(',')
name = button.objectName()
#print(name)
pin_name = pin_settings[0]
pin_type = getattr(hal, f'{pin_settings[1].upper().strip()}')
pin_dir = getattr(hal, f'{pin_settings[2].upper().strip()}')
setattr(parent, f'{prop}', parent.halcomp.newpin(pin_name, pin_type, pin_dir))
getattr(parent, f'{name}').toggled.connect(lambda: getattr(parent, f'{prop}').set(getattr(parent, f'{name}').isChecked()))
parent.halcomp.ready()
For some reason only the last button found with a Dynamic Property of function is toggling the pin in halshow. I gotta be missing something simple...
JT
Please Log in to join the conversation.
<PyQt6.QtWidgets.QPushButton object at 0x7ff158ceea70>
<hal.Pin object at 0x7ff15c8d95d0>
<PyQt6.QtWidgets.QPushButton object at 0x7ff158ceeb00>
<hal.Pin object at 0x7ff15c8d9210>
if prop.startswith('pin_'):
#print(prop)
pin_settings = button.property(prop).split(',')
name = button.objectName()
#print(name)
pin_name = pin_settings[0]
pin_type = getattr(hal, f'{pin_settings[1].upper().strip()}')
pin_dir = getattr(hal, f'{pin_settings[2].upper().strip()}')
setattr(parent, f'{prop}', parent.halcomp.newpin(pin_name, pin_type, pin_dir))
print(getattr(parent, f'{name}'))
print(getattr(parent, f'{prop}'))
getattr(parent, f'{name}').toggled.connect(lambda: getattr(parent, f'{prop}').set(getattr(parent, f'{name}').isChecked()))
parent.halcomp.ready()
Attachment not found
JT
Please Log in to join the conversation.
- MennilTossFlykune
- Offline
- Senior Member
-
- Posts: 42
- Thank you received: 0
Please Log in to join the conversation.
Please Log in to join the conversation.
I've tried a few things from the link above and while this works on the last button it still does not work on the first button found (only 2 buttons).
JT
Please Log in to join the conversation.
JT
Please Log in to join the conversation.
I think this strange looking code should work too.
Please Log in to join the conversation.
- MennilTossFlykune
- Offline
- Senior Member
-
- Posts: 42
- Thank you received: 0
Please Log in to join the conversation.
Please Log in to join the conversation.
