Skip to content

Commit 725d67b

Browse files
committed
feat: implement type-aware auto-completion utilities and variable frame for smartprop editor
1 parent b33945f commit 725d67b

2 files changed

Lines changed: 39 additions & 2 deletions

File tree

src/editors/smartprop_editor/completion_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def get_combobox_elements(var_type):
6161
'RadiusPlacementMode': ['SPHERE', 'CIRCLE'],
6262
'DistributionMode': ['RANDOM', 'REGULAR'],
6363
'PathPositions': ['ALL', 'NTH', 'START_AND_END', 'CONTROL_POINTS'],
64+
'Direction': ['RANDOM', 'REGULAR'],
6465
}
6566
return elements_dict.get(var_type, [])
6667

@@ -208,7 +209,7 @@ def _generate_type_specific_completions(var_name, var_type, context):
208209
# Enum-type variable completions (combobox types)
209210
elif var_type in ['CoordinateSpace', 'GridPlacementMode', 'GridOriginMode', 'PickMode',
210211
'ScaleMode', 'TraceNoHit', 'ApplyColorMode', 'ChoiceSelectionMode',
211-
'RadiusPlacementMode', 'DistributionMode', 'PathPositions']:
212+
'RadiusPlacementMode', 'DistributionMode', 'PathPositions', 'Direction']:
212213
# Get the possible values for this enum type
213214
enum_values = CompletionUtils.get_combobox_elements(var_type)
214215
for enum_value in enum_values:

src/editors/smartprop_editor/variable_frame.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def __init__(self, name, var_class, var_value, var_visible_in_editor, var_displa
103103
self.ui.show_child.clicked.connect(self.show_child)
104104

105105
self.init_ui()
106+
self.update_colors()
106107

107108
def _initialize_var_instance(self, var_class):
108109
if var_class == 'Int':
@@ -137,7 +138,7 @@ def _initialize_var_instance(self, var_class):
137138
)
138139
elif var_class in ['CoordinateSpace', 'GridPlacementMode', 'GridOriginMode', 'PickMode', 'ScaleMode',
139140
'TraceNoHit', 'ApplyColorMode', 'ChoiceSelectionMode', 'RadiusPlacementMode',
140-
'DistributionMode', 'PathPositions']:
141+
'DistributionMode', 'PathPositions', 'Direction']:
141142
from src.editors.smartprop_editor.variables.combobox import Var_class_combobox
142143
elements = self._get_combobox_elements(var_class)
143144
self.var_int_instance = Var_class_combobox(
@@ -161,6 +162,40 @@ def _initialize_var_instance(self, var_class):
161162
def _get_combobox_elements(self, var_class):
162163
return CompletionUtils.get_combobox_elements(var_class)
163164

165+
def update_colors(self):
166+
color_map = {
167+
'String': '#E67E22',
168+
'Model': '#E67E22',
169+
'Material': '#E67E22',
170+
'MaterialGroup': '#E67E22',
171+
'Bool': '#C0392B',
172+
'Float': '#2980B9',
173+
'Int': '#2471A3',
174+
'Vector2D': '#8E44AD',
175+
'Vector3D': '#8E44AD',
176+
'Vector4D': '#8E44AD',
177+
'Angles': '#8E44AD',
178+
'Color': '#1B5E20',
179+
}
180+
181+
enum_types = [
182+
'Direction', 'CoordinateSpace', 'GridPlacementMode', 'GridOriginMode',
183+
'PickMode', 'ScaleMode', 'TraceNoHit', 'ApplyColorMode',
184+
'ChoiceSelectionMode', 'RadiusPlacementMode', 'DistributionMode', 'PathPositions'
185+
]
186+
187+
target_color = color_map.get(self.var_class, '#242424')
188+
if self.var_class in enum_types:
189+
target_color = '#1D8348'
190+
191+
style = self.ui.label.styleSheet()
192+
import re
193+
if 'background-color:' in style:
194+
style = re.sub(r'background-color:\s*[^;]+;', f'background-color: {target_color};', style)
195+
else:
196+
style += f'\nbackground-color: {target_color};'
197+
self.ui.label.setStyleSheet(style)
198+
164199
def _setup_hide_expression_completer(self):
165200
"""Setup completer for hide expression input with filtered type-aware completions."""
166201
# For hide expressions, only show Bool, Int, and Float variables
@@ -216,6 +251,7 @@ def set_class(self, var_class):
216251
self.var_int_instance.edited.connect(self.on_changed)
217252
self.ui.layout.insertWidget(2, self.var_int_instance)
218253
# Emit content_changed directly (pre_change was already emitted above)
254+
self.update_colors()
219255
self.content_changed.emit()
220256

221257
def get_classes(self):

0 commit comments

Comments
 (0)