5
5
from pvi ._format .dls import DLSFormatter
6
6
from pvi .device import (
7
7
LED ,
8
- CheckBox ,
8
+ ButtonPanel ,
9
9
Component ,
10
10
Device ,
11
11
Grid ,
19
19
TextFormat ,
20
20
TextRead ,
21
21
TextWrite ,
22
+ ToggleButton ,
22
23
Tree ,
23
24
WriteWidget ,
24
25
)
@@ -42,18 +43,16 @@ class EpicsGUIOptions:
42
43
43
44
44
45
class EpicsGUI :
45
- def __init__ (self , mapping : Mapping ) -> None :
46
+ def __init__ (self , mapping : Mapping , pv_prefix : str ) -> None :
46
47
self ._mapping = mapping
48
+ self ._pv_prefix = pv_prefix
47
49
48
- @staticmethod
49
- def _get_pv (attr_path : str , name : str ):
50
+ def _get_pv (self , attr_path : str , name : str ):
50
51
if attr_path :
51
52
attr_path = ":" + attr_path
52
53
attr_path += ":"
53
54
54
- pv = attr_path .upper () + name .title ().replace ("_" , "" )
55
-
56
- return pv
55
+ return f"{ self ._pv_prefix } { attr_path .upper ()} { name .title ().replace ('_' , '' )} "
57
56
58
57
@staticmethod
59
58
def _get_read_widget (datatype : DataType ) -> ReadWidget :
@@ -71,43 +70,46 @@ def _get_read_widget(datatype: DataType) -> ReadWidget:
71
70
def _get_write_widget (datatype : DataType ) -> WriteWidget :
72
71
match datatype :
73
72
case Bool ():
74
- return CheckBox ()
73
+ return ToggleButton ()
75
74
case Int () | Float ():
76
75
return TextWrite ()
77
76
case String ():
78
77
return TextWrite (format = TextFormat .string )
79
78
case _:
80
79
raise FastCSException (f"Unsupported type { type (datatype )} : { datatype } " )
81
80
82
- @classmethod
83
- def _get_attribute_component (cls , attr_path : str , name : str , attribute : Attribute ):
84
- pv = cls ._get_pv (attr_path , name )
81
+ def _get_attribute_component (self , attr_path : str , name : str , attribute : Attribute ):
82
+ pv = self ._get_pv (attr_path , name )
85
83
name = name .title ().replace ("_" , "" )
86
84
87
85
match attribute :
88
86
case AttrRW ():
89
- read_widget = cls ._get_read_widget (attribute .datatype )
90
- write_widget = cls ._get_write_widget (attribute .datatype )
87
+ read_widget = self ._get_read_widget (attribute .datatype )
88
+ write_widget = self ._get_write_widget (attribute .datatype )
91
89
return SignalRW (
92
90
name = name ,
93
- pv = pv ,
94
- widget = write_widget ,
91
+ write_pv = pv ,
92
+ write_widget = write_widget ,
95
93
read_pv = pv + "_RBV" ,
96
94
read_widget = read_widget ,
97
95
)
98
96
case AttrR ():
99
- read_widget = cls ._get_read_widget (attribute .datatype )
100
- return SignalR (name = name , pv = pv , widget = read_widget )
97
+ read_widget = self ._get_read_widget (attribute .datatype )
98
+ return SignalR (name = name , read_pv = pv , read_widget = read_widget )
101
99
case AttrW ():
102
- write_widget = cls ._get_write_widget (attribute .datatype )
103
- return SignalW (name = name , pv = pv , widget = TextWrite ())
100
+ write_widget = self ._get_write_widget (attribute .datatype )
101
+ return SignalW (name = name , write_pv = pv , write_widget = TextWrite ())
104
102
105
- @classmethod
106
- def _get_command_component (cls , attr_path : str , name : str ):
107
- pv = cls ._get_pv (attr_path , name )
103
+ def _get_command_component (self , attr_path : str , name : str ):
104
+ pv = self ._get_pv (attr_path , name )
108
105
name = name .title ().replace ("_" , "" )
109
106
110
- return SignalX (name = name , pv = pv , value = "1" )
107
+ return SignalX (
108
+ name = name ,
109
+ write_pv = pv ,
110
+ value = "1" ,
111
+ write_widget = ButtonPanel (actions = {name : "1" }),
112
+ )
111
113
112
114
def create_gui (self , options : EpicsGUIOptions | None = None ) -> None :
113
115
if options is None :
@@ -136,7 +138,7 @@ def create_gui(self, options: EpicsGUIOptions | None = None) -> None:
136
138
137
139
device = Device (label = "Simple Device" , children = components )
138
140
139
- formatter .format (device , "MY-DEVICE-PREFIX" , options .output_path )
141
+ formatter .format (device , options .output_path )
140
142
141
143
def extract_mapping_components (self , mapping : SingleMapping ) -> list [Component ]:
142
144
components : Tree [Component ] = []
0 commit comments