44from trame_vuetify .widgets .vuetify3 import (
55 Template ,
66 VBtn ,
7- VBtnToggle ,
87 VCard ,
98 VCardItem ,
109 VCardText ,
11- VSlider ,
1210)
1311
1412from trame_slicer .segmentation import SegmentationOpacityEnum
1513
1614from ..control_button import ControlButton
1715from ..flex_container import FlexContainer
16+ from ..slider import Slider , SliderState
1817from ..text_components import Text
1918
2019
2120@dataclass
2221class SegmentDisplayState :
23- display_mode : SegmentationOpacityEnum = SegmentationOpacityEnum .BOTH
24- opacity_2d : float = 0.5
25- opacity_3d : float = 1.0
22+ opacity_mode : SegmentationOpacityEnum = SegmentationOpacityEnum .BOTH
23+ opacity_2d : SliderState = field ( default_factory = SliderState )
24+ opacity_3d : SliderState = field ( default_factory = SliderState )
2625 show_3d : bool = False
27- display_options : list [str ] = field (default_factory = lambda : ["filled" , "outlined" ])
2826 is_extended : bool = False
2927
3028
@@ -33,7 +31,9 @@ def __init__(self, typed_state: TypedState[SegmentDisplayState], **kwargs):
3331 super ().__init__ (** kwargs )
3432
3533 self ._typed_state = typed_state
36- self ._typed_state .bind_changes ({self ._typed_state .name .display_options : self ._on_display_options_changed })
34+ self ._typed_state .data .opacity_2d .step = 0.01
35+ self ._typed_state .data .opacity_3d .step = 0.01
36+ self ._typed_state .data .opacity_3d .value = 1
3737
3838 with self :
3939 with VCardItem ():
@@ -51,25 +51,32 @@ def __init__(self, typed_state: TypedState[SegmentDisplayState], **kwargs):
5151 justify = "space-between" ,
5252 row = True ,
5353 ):
54- with VBtnToggle (
55- v_model = (self ._typed_state .name .display_options ,),
56- classes = "align-center" ,
57- mandatory = True ,
58- multiple = True ,
54+ VBtn (
55+ active = (
56+ "["
57+ f"{ self ._typed_state .encode (SegmentationOpacityEnum .FILL )} , { self ._typed_state .encode (SegmentationOpacityEnum .BOTH )} "
58+ f"].includes({ self ._typed_state .name .opacity_mode } )" ,
59+ ),
60+ click = lambda : self ._on_display_options_changed (SegmentationOpacityEnum .FILL ),
61+ height = 35 ,
62+ prepend_icon = "mdi-circle" ,
5963 rounded = 0 ,
60- ):
61- VBtn (
62- prepend_icon = "mdi-circle" ,
63- text = "Filled" ,
64- value = "filled" ,
65- height = 35 ,
66- )
67- VBtn (
68- prepend_icon = "mdi-circle-outline" ,
69- text = "Outlined" ,
70- value = "outlined" ,
71- height = 35 ,
72- )
64+ text = "Filled" ,
65+ variant = "text" ,
66+ )
67+ VBtn (
68+ active = (
69+ "["
70+ f"{ self ._typed_state .encode (SegmentationOpacityEnum .OUTLINE )} , { self ._typed_state .encode (SegmentationOpacityEnum .BOTH )} "
71+ f"].includes({ self ._typed_state .name .opacity_mode } )" ,
72+ ),
73+ click = lambda : self ._on_display_options_changed (SegmentationOpacityEnum .OUTLINE ),
74+ height = 35 ,
75+ prepend_icon = "mdi-circle-outline" ,
76+ rounded = 0 ,
77+ text = "Outlined" ,
78+ variant = "text" ,
79+ )
7380
7481 ControlButton (
7582 icon = "mdi-video-3d" ,
@@ -79,29 +86,23 @@ def __init__(self, typed_state: TypedState[SegmentDisplayState], **kwargs):
7986 )
8087
8188 Text ("Opacity" , subtitle = True )
82- VSlider (
83- v_model = (self ._typed_state .name .opacity_2d ,),
84- hide_details = True ,
89+ Slider (
90+ typed_state = self ._typed_state .get_sub_state (self ._typed_state .name .opacity_2d ),
8591 prepend_icon = "mdi-video-2d" ,
86- min = 0.0 ,
87- max = 1.0 ,
88- step = 0.01 ,
8992 )
90- VSlider (
91- v_model = (self ._typed_state .name .opacity_3d ,),
92- disabled = (f"!{ self ._typed_state .name .show_3d } " ,),
93- hide_details = True ,
93+ Slider (
94+ typed_state = self ._typed_state .get_sub_state (self ._typed_state .name .opacity_3d ),
9495 prepend_icon = "mdi-video-3d" ,
95- min = 0.0 ,
96- max = 1.0 ,
97- step = 0.01 ,
9896 )
9997
100- def _on_display_options_changed (self , display_options ):
101- if "outlined" in display_options :
102- if "filled" in display_options :
103- self ._typed_state .data .display_mode = SegmentationOpacityEnum .BOTH
104- else :
105- self ._typed_state .data .display_mode = SegmentationOpacityEnum .OUTLINE
98+ def _on_display_options_changed (self , opacity_mode ):
99+ if self ._typed_state .data .opacity_mode == opacity_mode :
100+ return
101+ if self ._typed_state .data .opacity_mode == SegmentationOpacityEnum .BOTH :
102+ self ._typed_state .data .opacity_mode = (
103+ SegmentationOpacityEnum .FILL
104+ if opacity_mode == SegmentationOpacityEnum .OUTLINE
105+ else SegmentationOpacityEnum .OUTLINE
106+ )
106107 else :
107- self ._typed_state .data .display_mode = SegmentationOpacityEnum .FILL
108+ self ._typed_state .data .opacity_mode = SegmentationOpacityEnum .BOTH
0 commit comments