spc-group / haven

Bluesky tools for beamlines managed by the spectroscopy group
https://haven-spc.readthedocs.io/en/latest/
Other
4 stars 6 forks source link

component selector returns arbitrary device if line edit is empty #257

Closed Cathyhjj closed 3 months ago

Cathyhjj commented 3 months ago

when doing motor = self.motor_box.current_component(), even though the combo box is empty, it tried to get the first motor

A

when doing

motor = self.motor_box.current_component()
print(motor)

FakeRobot(prefix='255idAustin', name='A', read_attrs=['i', 'i.user_readback', 'i.user_setpoint', 'j', 'j.user_readback', 'j.user_setpoint', 'k', 'k.user_readback', 'k.user_setpoint', 'l', 'l.user_readback', 'l.user_setpoint', 'm', 'm.user_readback', 'm.user_setpoint', 'n', 'n.user_readback', 'n.user_setpoint', 'x', 'x.user_readback', 'x.user_setpoint', 'y', 'y.user_readback', 'y.user_setpoint', 'z', 'z.user_readback', 'z.user_setpoint', 'rx', 'rx.user_readback', 'rx.user_setpoint', 'ry', 'ry.user_readback', 'ry.user_setpoint', 'rz', 'rz.user_readback', 'rz.user_setpoint', 'gripper_rbv', 'gripper_val', 'samples', 'samples.sample8', 'samples.sample8.present', 'samples.sample8.empty', 'samples.sample8.x', 'samples.sample8.y', 'samples.sample8.z', 'samples.sample8.rx', 'samples.sample8.ry', 'samples.sample8.rz', 'samples.sample9', 'samples.sample9.present', 'samples.sample9.empty', 'samples.sample9.x', 'samples.sample9.y', 'samples.sample9.z', 'samples.sample9.rx', 'samples.sample9.ry', 'samples.sample9.rz', 'samples.sample10', 'samples.sample10.present', 'samples.sample10.empty', 'samples.sample10.x', 'samples.sample10.y', 'samples.sample10.z', 'samples.sample10.rx', 'samples.sample10.ry', 'samples.sample10.rz', 'samples.sample14', 'samples.sample14.present', 'samples.sample14.empty', 'samples.sample14.x', 'samples.sample14.y', 'samples.sample14.z', 'samples.sample14.rx', 'samples.sample14.ry', 'samples.sample14.rz', 'samples.sample15', 'samples.sample15.present', 'samples.sample15.empty', 'samples.sample15.x', 'samples.sample15.y', 'samples.sample15.z', 'samples.sample15.rx', 'samples.sample15.ry', 'samples.sample15.rz', 'samples.sample16', 'samples.sample16.present', 'samples.sample16.empty', 'samples.sample16.x', 'samples.sample16.y', 'samples.sample16.z', 'samples.sample16.rx', 'samples.sample16.ry', 'samples.sample16.rz', 'samples.sample20', 'samples.sample20.present', 'samples.sample20.empty', 'samples.sample20.x', 'samples.sample20.y', 'samples.sample20.z', 'samples.sample20.rx', 'samples.sample20.ry', 'samples.sample20.rz', 'samples.sample21', 'samples.sample21.present', 'samples.sample21.empty', 'samples.sample21.x', 'samples.sample21.y', 'samples.sample21.z', 'samples.sample21.rx', 'samples.sample21.ry', 'samples.sample21.rz', 'samples.sample22', 'samples.sample22.present', 'samples.sample22.empty', 'samples.sample22.x', 'samples.sample22.y', 'samples.sample22.z', 'samples.sample22.rx', 'samples.sample22.ry', 'samples.sample22.rz'], configuration_attrs=['i', 'i.user_offset', 'i.user_offset_dir', 'i.velocity', 'i.acceleration', 'i.motor_egu', 'j', 'j.user_offset', 'j.user_offset_dir', 'j.velocity', 'j.acceleration', 'j.motor_egu', 'k', 'k.user_offset', 'k.user_offset_dir', 'k.velocity', 'k.acceleration', 'k.motor_egu', 'l', 'l.user_offset', 'l.user_offset_dir', 'l.velocity', 'l.acceleration', 'l.motor_egu', 'm', 'm.user_offset', 'm.user_offset_dir', 'm.velocity', 'm.acceleration', 'm.motor_egu', 'n', 'n.user_offset', 'n.user_offset_dir', 'n.velocity', 'n.acceleration', 'n.motor_egu', 'x', 'x.user_offset', 'x.user_offset_dir', 'x.velocity', 'x.acceleration', 'x.motor_egu', 'y', 'y.user_offset', 'y.user_offset_dir', 'y.velocity', 'y.acceleration', 'y.motor_egu', 'z', 'z.user_offset', 'z.user_offset_dir', 'z.velocity', 'z.acceleration', 'z.motor_egu', 'rx', 'rx.user_offset', 'rx.user_offset_dir', 'rx.velocity', 'rx.acceleration', 'rx.motor_egu', 'ry', 'ry.user_offset', 'ry.user_offset_dir', 'ry.velocity', 'ry.acceleration', 'ry.motor_egu', 'rz', 'rz.user_offset', 'rz.user_offset_dir', 'rz.velocity', 'rz.acceleration', 'rz.motor_egu', 'acc', 'vel', 'remote_control', 'program_rbv', 'installation', 'close_safety_popup', 'unlock_protective_stop', 'restart_safety', 'program_running', 'safety_status', 'power_rbv', 'gripper_activated', 'gripper_force', 'current_sample', 'home', 'cal_stage', 'samples', 'samples.sample8', 'samples.sample9', 'samples.sample10', 'samples.sample14', 'samples.sample15', 'samples.sample16', 'samples.sample20', 'samples.sample21', 'samples.sample22'])

`

canismarko commented 3 months ago

Thanks for the report @Cathyhjj.

The selector uses the comboBox's currentText() which returns the line-edit's text. If nothing is entered, this should be an empty string. I would expect the registry to then throw and error because such a device doesn't exist.

I'll look into this further soon.

canismarko commented 3 months ago

I'm not able to reproduce this bug. In my test, if the combobox is empty, then combo_box.currentText() return an empty string. This causes a keyerror when trying to find the "" device in the registry, but does not return an incorrect device. @Cathyhjj, do you have a reliable way to reproduce this bug?

canismarko commented 3 months ago

I can't seem to reproduce this bug. If I leave the combo box blank, then the result of QComboBox.currentText() is an empty string. That empty string triggers a KeyError when trying to look it up in the registry, but does not return an item. I put in a PR to check for this condition and return None as the selected component.

@Cathyhjj, can you provide any more information about how to reproduce this error?

I'm wondering if that robot device you're seeing has an empty string in its _ophyd_labels_ set? If so, it should be fixed in the PR I submitted that checks for an empty string before querying the registry.

Cathyhjj commented 3 months ago

I noticed that if you put a try statement in front, this will return the "A" motor for me

try:
    motor = self.motor_box.current_component()
    print(motor)