6
6
from pvi .device import (
7
7
LED ,
8
8
ButtonPanel ,
9
+ ComboBox ,
9
10
Component ,
10
11
Device ,
11
12
Grid ,
27
28
28
29
from fastcs .attributes import Attribute , AttrR , AttrRW , AttrW
29
30
from fastcs .cs_methods import Command
30
- from fastcs .datatypes import Bool , DataType , Float , Int , String
31
+ from fastcs .datatypes import Bool , Float , Int , String
31
32
from fastcs .exceptions import FastCSException
32
33
from fastcs .mapping import Mapping , SingleMapping , _get_single_mapping
33
34
from fastcs .util import snake_to_pascal
@@ -55,27 +56,33 @@ def _get_pv(self, attr_path: list[str], name: str):
55
56
return f"{ attr_prefix } :{ name .title ().replace ('_' , '' )} "
56
57
57
58
@staticmethod
58
- def _get_read_widget (datatype : DataType ) -> ReadWidget :
59
- match datatype :
59
+ def _get_read_widget (attribute : AttrR ) -> ReadWidget :
60
+ match attribute . datatype :
60
61
case Bool ():
61
62
return LED ()
62
63
case Int () | Float ():
63
64
return TextRead ()
64
65
case String ():
65
66
return TextRead (format = TextFormat .string )
66
- case _ :
67
+ case datatype :
67
68
raise FastCSException (f"Unsupported type { type (datatype )} : { datatype } " )
68
69
69
70
@staticmethod
70
- def _get_write_widget (datatype : DataType ) -> WriteWidget :
71
- match datatype :
71
+ def _get_write_widget (attribute : AttrW ) -> WriteWidget :
72
+ match attribute .allowed_values :
73
+ case allowed_values if allowed_values is not None :
74
+ return ComboBox (choices = allowed_values )
75
+ case _:
76
+ pass
77
+
78
+ match attribute .datatype :
72
79
case Bool ():
73
80
return ToggleButton ()
74
81
case Int () | Float ():
75
82
return TextWrite ()
76
83
case String ():
77
84
return TextWrite (format = TextFormat .string )
78
- case _ :
85
+ case datatype :
79
86
raise FastCSException (f"Unsupported type { type (datatype )} : { datatype } " )
80
87
81
88
def _get_attribute_component (
@@ -86,8 +93,8 @@ def _get_attribute_component(
86
93
87
94
match attribute :
88
95
case AttrRW ():
89
- read_widget = self ._get_read_widget (attribute . datatype )
90
- write_widget = self ._get_write_widget (attribute . datatype )
96
+ read_widget = self ._get_read_widget (attribute )
97
+ write_widget = self ._get_write_widget (attribute )
91
98
return SignalRW (
92
99
name = name ,
93
100
write_pv = pv ,
@@ -96,10 +103,10 @@ def _get_attribute_component(
96
103
read_widget = read_widget ,
97
104
)
98
105
case AttrR ():
99
- read_widget = self ._get_read_widget (attribute . datatype )
106
+ read_widget = self ._get_read_widget (attribute )
100
107
return SignalR (name = name , read_pv = pv , read_widget = read_widget )
101
108
case AttrW ():
102
- write_widget = self ._get_write_widget (attribute . datatype )
109
+ write_widget = self ._get_write_widget (attribute )
103
110
return SignalW (name = name , write_pv = pv , write_widget = write_widget )
104
111
105
112
def _get_command_component (self , attr_path : list [str ], name : str ):
0 commit comments