55import toolz
66from qtpy import QtWidgets
77from .comms import RM
8+ from .signals import plans_allowed_updated , devices_allowed_updated
89from bluesky_hwproxy import zmq_single_request as hwproxy_request
910
1011import WrightTools as wt
1112from bluesky_cmds .project import widgets as pw
1213from bluesky_cmds .project import classes as pc
1314
14- # TODO: rebuild uis on change to devices_allowed
15- devices_all_json = RM .devices_allowed ()["devices_allowed" ]
16- devices_all = {}
17-
1815
1916def get_all_components (k , v ):
2017 out = {k : v }
@@ -28,17 +25,30 @@ def get_units(device):
2825 key_name = device .replace ("." , "_" )
2926 else :
3027 base_name = key_name = device
31- return hwproxy_request ("describe" , {"device" : base_name })[0 ][ "return" ] .get (key_name , {}).get (
28+ return hwproxy_request ("describe" , {"device" : base_name })[0 ]. get ( "return" , {}) .get (key_name , {}).get (
3229 "units" , None
3330 )
3431
35- for k , v in devices_all_json .items ():
36- devices_all .update (get_all_components (k , v ))
3732
33+ devices_all = {}
34+ devices_all_json = {}
35+ devices_movable = []
36+ devices_not_movable = []
37+ devices_with_deps = []
38+
39+ def update_devices ():
40+ global devices_all , devices_all_json , devices_movable , devices_not_movable , devices_with_deps
41+ devices_all_json = RM .devices_allowed ()["devices_allowed" ]
42+ devices_all = {}
43+
44+ for k , v in devices_all_json .items ():
45+ devices_all .update (get_all_components (k , v ))
46+
47+ devices_movable = list (filter (lambda x : devices_all [x ]["is_movable" ], devices_all ))
48+ devices_not_movable = list (filter (lambda x : not devices_all [x ]["is_movable" ], devices_all ))
49+ devices_with_deps = list (filter (lambda x : "components" in devices_all [x ], devices_all ))
50+ update_plan_ui ()
3851
39- devices_movable = list (filter (lambda x : devices_all [x ]["is_movable" ], devices_all ))
40- devices_not_movable = list (filter (lambda x : not devices_all [x ]["is_movable" ], devices_all ))
41- devices_with_deps = list (filter (lambda x : "components" in devices_all [x ], devices_all ))
4252
4353
4454class PlanUI :
@@ -831,145 +841,151 @@ def on_method_selected(self):
831841
832842
833843plan_ui_lookup = defaultdict (PlanUI )
834- plan_ui_lookup ["sleep" ] = PlanUI (
835- [
836- FloatWidget ("time" , "time" , 1.0 ),
837- ]
838- )
839- plan_ui_lookup ["mv" ] = PlanUI (
840- [
841- MvArgsWidget (),
842- ]
843- )
844- plan_ui_lookup ["grid_scan_wp" ] = PlanUI (
845- [
846- MetadataWidget (),
847- DeviceListWidget (),
848- GridscanArgsWidget (),
849- ConstantWidget (),
850- ]
851- )
852- plan_ui_lookup ["rel_grid_scan_wp" ] = PlanUI (
853- [
854- MetadataWidget (),
855- DeviceListWidget (),
856- GridscanArgsWidget (),
857- ConstantWidget (),
858- ]
859- )
860- plan_ui_lookup ["scan_wp" ] = PlanUI (
861- [
862- MetadataWidget (),
863- DeviceListWidget (),
864- ScanArgsWidget (),
865- IntWidget ("Npts" , "num" , 11 ),
866- ConstantWidget (),
867- ]
868- )
869- plan_ui_lookup ["rel_scan_wp" ] = PlanUI (
870- [
871- MetadataWidget (),
872- DeviceListWidget (),
873- ScanArgsWidget (),
874- IntWidget ("Npts" , "num" , 11 ),
875- ConstantWidget (),
876- ]
877- )
878- plan_ui_lookup ["list_scan_wp" ] = PlanUI (
879- [
880- MetadataWidget (),
881- DeviceListWidget (),
882- ListscanArgsWidget (),
883- ConstantWidget (),
884- ]
885- )
886- plan_ui_lookup ["rel_list_scan_wp" ] = PlanUI (
887- [
888- MetadataWidget (),
889- DeviceListWidget (),
890- ListscanArgsWidget (),
891- ConstantWidget (),
892- ]
893- )
894- plan_ui_lookup ["list_grid_scan_wp" ] = PlanUI (
895- [
896- MetadataWidget (),
897- DeviceListWidget (),
898- ListscanArgsWidget (),
899- ConstantWidget (),
900- ]
901- )
902- plan_ui_lookup ["rel_list_grid_scan_wp" ] = PlanUI (
903- [
904- MetadataWidget (),
905- DeviceListWidget (),
906- ListscanArgsWidget (),
907- ConstantWidget (),
908- ]
909- )
910- plan_ui_lookup ["count" ] = PlanUI (
911- [
912- MetadataWidget (),
913- DeviceListWidget (),
914- IntWidget ("Npts" , "num" , 1 ),
915- FloatWidget ("Delay" , "delay" , 0 ),
916- ]
917- )
918-
919- if devices_with_deps :
920- plan_ui_lookup ["run_tune_test" ] = PlanUI (
844+
845+ def update_plan_ui ():
846+ plan_ui_lookup ["sleep" ] = PlanUI (
847+ [
848+ FloatWidget ("time" , "time" , 1.0 ),
849+ ]
850+ )
851+ plan_ui_lookup ["mv" ] = PlanUI (
852+ [
853+ MvArgsWidget (),
854+ ]
855+ )
856+ plan_ui_lookup ["grid_scan_wp" ] = PlanUI (
857+ [
858+ MetadataWidget (),
859+ DeviceListWidget (),
860+ GridscanArgsWidget (),
861+ ConstantWidget (),
862+ ]
863+ )
864+ plan_ui_lookup ["rel_grid_scan_wp" ] = PlanUI (
865+ [
866+ MetadataWidget (),
867+ DeviceListWidget (),
868+ GridscanArgsWidget (),
869+ ConstantWidget (),
870+ ]
871+ )
872+ plan_ui_lookup ["scan_wp" ] = PlanUI (
873+ [
874+ MetadataWidget (),
875+ DeviceListWidget (),
876+ ScanArgsWidget (),
877+ IntWidget ("Npts" , "num" , 11 ),
878+ ConstantWidget (),
879+ ]
880+ )
881+ plan_ui_lookup ["rel_scan_wp" ] = PlanUI (
921882 [
922883 MetadataWidget (),
923884 DeviceListWidget (),
924- OpaSelectorWidget (),
925- SpectrometerWidget (include_center = False ),
885+ ScanArgsWidget (),
886+ IntWidget ("Npts" , "num" , 11 ),
887+ ConstantWidget (),
926888 ]
927889 )
928- opa = OpaSelectorWidget ()
929- plan_ui_lookup ["run_setpoint" ] = PlanUI (
890+ plan_ui_lookup ["list_scan_wp" ] = PlanUI (
930891 [
931892 MetadataWidget (),
932893 DeviceListWidget (),
933- opa ,
934- OpaMotorSelectorWidget (opa_selector = opa ),
935- FloatWidget ("Width" , "width" , 1 ),
936- IntWidget ("Npts" , "npts" , 11 ),
937- SpectrometerWidget (include_center = False ),
894+ ListscanArgsWidget (),
895+ ConstantWidget (),
938896 ]
939897 )
940- opa = OpaSelectorWidget ()
941- plan_ui_lookup ["run_intensity" ] = PlanUI (
898+ plan_ui_lookup ["rel_list_scan_wp" ] = PlanUI (
942899 [
943900 MetadataWidget (),
944901 DeviceListWidget (),
945- opa ,
946- OpaMotorSelectorWidget (opa_selector = opa ),
947- FloatWidget ("Width" , "width" , 1 ),
948- IntWidget ("Npts" , "npts" , 11 ),
949- SpectrometerWidget (include_center = False ),
902+ ListscanArgsWidget (),
903+ ConstantWidget (),
950904 ]
951905 )
952- opa = OpaSelectorWidget ()
953- plan_ui_lookup ["run_holistic" ] = PlanUI (
906+ plan_ui_lookup ["list_grid_scan_wp" ] = PlanUI (
954907 [
955908 MetadataWidget (),
956909 DeviceListWidget (),
957- opa ,
958- OpaMotorSelectorWidget (opa_selector = opa ),
959- OpaMotorSelectorWidget (opa_selector = opa ),
960- FloatWidget ("Width" , "width" , 1 ),
961- IntWidget ("Npts" , "npts" , 11 ),
962- SpectrometerWidget (include_center = False ),
910+ ListscanArgsWidget (),
911+ ConstantWidget (),
963912 ]
964913 )
965- opa = OpaSelectorWidget ()
966- plan_ui_lookup ["motortune" ] = PlanUI (
914+ plan_ui_lookup ["rel_list_grid_scan_wp" ] = PlanUI (
967915 [
968916 MetadataWidget (),
969917 DeviceListWidget (),
970- opa ,
971- BoolWidget ("Use Tune Points" , "use_tune_points" ),
972- OpaMotorFullWidget (opa_selector = opa ),
973- SpectrometerWidget (),
918+ ListscanArgsWidget (),
919+ ConstantWidget (),
974920 ]
975921 )
922+ plan_ui_lookup ["count" ] = PlanUI (
923+ [
924+ MetadataWidget (),
925+ DeviceListWidget (),
926+ IntWidget ("Npts" , "num" , 1 ),
927+ FloatWidget ("Delay" , "delay" , 0 ),
928+ ]
929+ )
930+
931+ if devices_with_deps :
932+ plan_ui_lookup ["run_tune_test" ] = PlanUI (
933+ [
934+ MetadataWidget (),
935+ DeviceListWidget (),
936+ OpaSelectorWidget (),
937+ SpectrometerWidget (include_center = False ),
938+ ]
939+ )
940+ opa = OpaSelectorWidget ()
941+ plan_ui_lookup ["run_setpoint" ] = PlanUI (
942+ [
943+ MetadataWidget (),
944+ DeviceListWidget (),
945+ opa ,
946+ OpaMotorSelectorWidget (opa_selector = opa ),
947+ FloatWidget ("Width" , "width" , 1 ),
948+ IntWidget ("Npts" , "npts" , 11 ),
949+ SpectrometerWidget (include_center = False ),
950+ ]
951+ )
952+ opa = OpaSelectorWidget ()
953+ plan_ui_lookup ["run_intensity" ] = PlanUI (
954+ [
955+ MetadataWidget (),
956+ DeviceListWidget (),
957+ opa ,
958+ OpaMotorSelectorWidget (opa_selector = opa ),
959+ FloatWidget ("Width" , "width" , 1 ),
960+ IntWidget ("Npts" , "npts" , 11 ),
961+ SpectrometerWidget (include_center = False ),
962+ ]
963+ )
964+ opa = OpaSelectorWidget ()
965+ plan_ui_lookup ["run_holistic" ] = PlanUI (
966+ [
967+ MetadataWidget (),
968+ DeviceListWidget (),
969+ opa ,
970+ OpaMotorSelectorWidget (opa_selector = opa ),
971+ OpaMotorSelectorWidget (opa_selector = opa ),
972+ FloatWidget ("Width" , "width" , 1 ),
973+ IntWidget ("Npts" , "npts" , 11 ),
974+ SpectrometerWidget (include_center = False ),
975+ ]
976+ )
977+ opa = OpaSelectorWidget ()
978+ plan_ui_lookup ["motortune" ] = PlanUI (
979+ [
980+ MetadataWidget (),
981+ DeviceListWidget (),
982+ opa ,
983+ BoolWidget ("Use Tune Points" , "use_tune_points" ),
984+ OpaMotorFullWidget (opa_selector = opa ),
985+ SpectrometerWidget (),
986+ ]
987+ )
988+
989+ # TODO: Reload current UI state
990+ plans_allowed_updated .connect (update_plan_ui )
991+ devices_allowed_updated .connect (update_devices )
0 commit comments