@@ -22,6 +22,10 @@ def __init__(self):
2222 self .widget .setWidgetResizable (True )
2323 self .reset ()
2424
25+ @property
26+ def selected (self ):
27+ return [obj for obj in self .scene .objects if obj .is_selected ]
28+
2529 def reset (self ):
2630 """Reset the content widget and layout to a clean state."""
2731 self .sub_widgets = {}
@@ -34,63 +38,59 @@ def reset(self):
3438 self .settings_layout .setContentsMargins (0 , 0 , 0 , 0 )
3539 self .scroll_layout .addLayout (self .settings_layout )
3640
37- @property
38- def selected (self ):
39- return [obj for obj in self .scene .objects if obj .is_selected ]
40-
41- def add_row (self , attr_name : str , widget : QWidget = None ) -> None :
42- """Create a setting row with label and widget, then add it to the layout."""
43- row_layout = QHBoxLayout ()
44- row_layout .setSpacing (0 )
45- row_layout .setContentsMargins (0 , 0 , 0 , 0 )
46-
47- label = QLabel (attr_name )
48- row_layout .addWidget (label )
49-
50- if widget :
51- row_layout .addWidget (widget )
52- self .sub_widgets [attr_name ] = widget
41+ def update (self ):
42+ """Update the layout with the latest object settings."""
43+ self .reset ()
5344
54- self .settings_layout .addLayout (row_layout )
45+ if len (self .selected ) == 1 :
46+ self ._populate ()
47+ self ._add_event_listeners ()
48+ elif len (self .selected ) > 1 :
49+ self ._add_row ("Multiple objects selected" )
50+ else :
51+ self ._add_row ("No object selected" )
5552
56- def populate (self ) -> None :
53+ def _populate (self ) -> None :
5754 """Populate the layout with the settings of the selected object."""
5855 obj = self .selected [0 ]
5956
6057 if not obj :
6158 return
6259
63- self .add_row ("name" , TextEdit (text = str (obj .name )))
60+ self ._add_row ("name" , TextEdit (text = str (obj .name )))
6461
6562 if hasattr (obj , "pointcolor" ) and obj .pointcolor is not None :
66- self .add_row ("pointcolor" , ColorDialog (obj = obj , attr = "pointcolor" ))
63+ self ._add_row ("pointcolor" , ColorDialog (obj = obj , attr = "pointcolor" ))
6764
6865 if hasattr (obj , "linecolor" ) and obj .linecolor is not None :
69- self .add_row ("linecolor" , ColorDialog (obj = obj , attr = "linecolor" ))
66+ self ._add_row ("linecolor" , ColorDialog (obj = obj , attr = "linecolor" ))
7067
7168 if hasattr (obj , "facecolor" ) and obj .facecolor is not None :
72- self .add_row ("facecolor" , ColorDialog (obj = obj , attr = "facecolor" ))
69+ self ._add_row ("facecolor" , ColorDialog (obj = obj , attr = "facecolor" ))
7370
7471 if hasattr (obj , "linewidth" ) and obj .linewidth is not None :
75- self .add_row ("linewidth" , DoubleEdit (title = None , value = obj .linewidth , min_val = 0.0 , max_val = 10.0 ))
72+ self ._add_row ("linewidth" , DoubleEdit (title = None , value = obj .linewidth , min_val = 0.0 , max_val = 10.0 ))
7673
7774 if hasattr (obj , "pointsize" ) and obj .pointsize is not None :
78- self .add_row ("pointsize" , DoubleEdit (title = None , value = obj .pointsize , min_val = 0.0 , max_val = 10.0 ))
75+ self ._add_row ("pointsize" , DoubleEdit (title = None , value = obj .pointsize , min_val = 0.0 , max_val = 10.0 ))
7976
8077 if hasattr (obj , "opacity" ) and obj .opacity is not None :
81- self .add_row ("opacity" , DoubleEdit (title = None , value = obj .opacity , min_val = 0.0 , max_val = 1.0 ))
78+ self ._add_row ("opacity" , DoubleEdit (title = None , value = obj .opacity , min_val = 0.0 , max_val = 1.0 ))
8279
83- def update (self ):
84- """Update the layout with the latest object settings."""
85- self .reset ()
80+ def _add_row (self , attr_name : str , widget : QWidget = None ) -> None :
81+ """Create a setting row with label and widget, then add it to the layout."""
82+ row_layout = QHBoxLayout ()
83+ row_layout .setSpacing (0 )
84+ row_layout .setContentsMargins (0 , 0 , 0 , 0 )
8685
87- if len (self .selected ) == 1 :
88- self .populate ()
89- self ._add_event_listeners ()
90- elif len (self .selected ) > 1 :
91- self .add_row ("Multiple objects selected" )
92- else :
93- self .add_row ("No object selected" )
86+ label = QLabel (attr_name )
87+ row_layout .addWidget (label )
88+
89+ if widget :
90+ row_layout .addWidget (widget )
91+ self .sub_widgets [attr_name ] = widget
92+
93+ self .settings_layout .addLayout (row_layout )
9494
9595 def _add_event_listeners (self ):
9696 """Add event listeners to the sub widgets."""
0 commit comments