@@ -37,6 +37,9 @@ def get_value(self):
3737
3838
3939class PropColorPicker (BaseProperty ):
40+ """
41+ Color picker widget for a node property.
42+ """
4043
4144 def __init__ (self , parent = None ):
4245 super (PropColorPicker , self ).__init__ (parent )
@@ -58,24 +61,28 @@ def _on_vector_changed(self, o, value):
5861 self ._update_color ()
5962 self .value_changed .emit (self .toolTip (), value )
6063
61- def _update_vector (self ):
62- self ._vector .set_value (list (self ._color ))
63-
6464 def _on_select_color (self ):
6565 color = QtWidgets .QColorDialog .getColor (
6666 QtGui .QColor .fromRgbF (* self .get_value ())
6767 )
6868 if color .isValid ():
6969 self .set_value (color .getRgb ())
7070
71+ def _update_vector (self ):
72+ self ._vector .set_value (list (self ._color ))
73+
7174 def _update_color (self ):
7275 c = [int (max (min (i , 255 ), 0 )) for i in self ._color ]
7376 hex_color = '#{0:02x}{1:02x}{2:02x}' .format (* c )
7477 self ._button .setStyleSheet (
75- '''QPushButton {{background-color: rgba({0}, {1}, {2}, 255);}}
76- QPushButton::hover {{background-color: rgba({0}, {1}, {2}, 200);}}''' .format (* c ))
77- self ._button .setToolTip ('rgb: {}\n hex: {}'
78- .format (self ._color [:3 ], hex_color ))
78+ '''
79+ QPushButton {{background-color: rgba({0}, {1}, {2}, 255);}}
80+ QPushButton::hover {{background-color: rgba({0}, {1}, {2}, 200);}}
81+ ''' .format (* c )
82+ )
83+ self ._button .setToolTip (
84+ 'rgb: {}\n hex: {}' .format (self ._color [:3 ], hex_color )
85+ )
7986
8087 def get_value (self ):
8188 return self ._color [:3 ]
@@ -89,6 +96,9 @@ def set_value(self, value):
8996
9097
9198class PropSlider (BaseProperty ):
99+ """
100+ Slider widget for a node property.
101+ """
92102
93103 def __init__ (self , parent = None ):
94104 super (PropSlider , self ).__init__ (parent )
@@ -110,15 +120,15 @@ def _init(self):
110120 self ._spnbox .valueChanged .connect (self ._on_spnbox_changed )
111121 self ._slider .valueChanged .connect (self ._on_slider_changed )
112122 # store the original press event.
113- self ._slider_press_event = self ._slider .mousePressEvent
114- self ._slider .mousePressEvent = self .sliderMousePressEvent
115- self ._slider .mouseReleaseEvent = self .sliderMouseReleaseEvent
123+ self ._slider_mouse_press_event = self ._slider .mousePressEvent
124+ self ._slider .mousePressEvent = self ._on_slider_mouse_press
125+ self ._slider .mouseReleaseEvent = self ._on_slider_mouse_release
116126
117- def sliderMousePressEvent (self , event ):
127+ def _on_slider_mouse_press (self , event ):
118128 self ._block = True
119- self ._slider_press_event (event )
129+ self ._slider_mouse_press_event (event )
120130
121- def sliderMouseReleaseEvent (self , event ):
131+ def _on_slider_mouse_release (self , event ):
122132 self .value_changed .emit (self .toolTip (), self .get_value ())
123133 self ._block = False
124134
@@ -151,6 +161,9 @@ def set_max(self, value=0):
151161
152162
153163class PropLabel (QtWidgets .QLabel ):
164+ """
165+ Label widget for a node property.
166+ """
154167
155168 value_changed = QtCore .Signal (str , object )
156169
@@ -164,6 +177,9 @@ def set_value(self, value):
164177
165178
166179class PropLineEdit (QtWidgets .QLineEdit ):
180+ """
181+ LineEdit widget for a node property.
182+ """
167183
168184 value_changed = QtCore .Signal (str , object )
169185
@@ -185,6 +201,9 @@ def set_value(self, value):
185201
186202
187203class PropTextEdit (QtWidgets .QTextEdit ):
204+ """
205+ TextEdit widget for a node property.
206+ """
188207
189208 value_changed = QtCore .Signal (str , object )
190209
@@ -213,6 +232,9 @@ def set_value(self, value):
213232
214233
215234class PropComboBox (QtWidgets .QComboBox ):
235+ """
236+ ComboBox widget for a node property.
237+ """
216238
217239 value_changed = QtCore .Signal (str , object )
218240
@@ -224,9 +246,21 @@ def _on_index_changed(self):
224246 self .value_changed .emit (self .toolTip (), self .get_value ())
225247
226248 def items (self ):
249+ """
250+ returns items from the combobox.
251+
252+ Returns:
253+ list[str]: list of strings.
254+ """
227255 return [self .itemText (i ) for i in range (self .count ())]
228256
229257 def set_items (self , items ):
258+ """
259+ Set items on the combobox.
260+
261+ Args:
262+ items (list[str]): list of strings.
263+ """
230264 self .clear ()
231265 self .addItems (items )
232266
@@ -242,6 +276,9 @@ def set_value(self, value):
242276
243277
244278class PropCheckBox (QtWidgets .QCheckBox ):
279+ """
280+ CheckBox widget for a node property.
281+ """
245282
246283 value_changed = QtCore .Signal (str , object )
247284
@@ -262,6 +299,9 @@ def set_value(self, value):
262299
263300
264301class PropSpinBox (QtWidgets .QSpinBox ):
302+ """
303+ SpinBox widget for a node property.
304+ """
265305
266306 value_changed = QtCore .Signal (str , object )
267307
@@ -293,28 +333,19 @@ def __init__(self, parent=None):
293333 icon = self .style ().standardIcon (QtWidgets .QStyle .StandardPixmap (21 ))
294334 _button = QtWidgets .QPushButton ()
295335 _button .setIcon (icon )
336+ _button .clicked .connect (self ._on_select_file )
296337
297- hbox = QtWidgets .QHBoxLayout ()
338+ hbox = QtWidgets .QHBoxLayout (self )
298339 hbox .setContentsMargins (0 , 0 , 0 , 0 )
299340 hbox .addWidget (self ._ledit )
300341 hbox .addWidget (_button )
301- self .setLayout (hbox )
302- _button .clicked .connect (self ._on_select_file )
303342
304- self ._ledit .setStyleSheet ("QLineEdit{border:1px solid}" )
305- _button .setStyleSheet ("QPushButton{border:1px solid}" )
306- self ._ext = "*"
307- self ._file_dir = None
308-
309- def set_ext (self , ext ):
310- self ._ext = ext
311-
312- def set_file_dir (self , dir ):
313- self ._file_dir = dir
343+ self ._ext = '*'
344+ self ._file_directory = None
314345
315346 def _on_select_file (self ):
316347 file_path = FileDialog .getOpenFileName (self ,
317- file_dir = self ._file_dir ,
348+ file_dir = self ._file_directory ,
318349 ext_filter = self ._ext )
319350 file = file_path [0 ] or None
320351 if file :
@@ -325,6 +356,12 @@ def _on_value_change(self, value=None):
325356 value = self ._ledit .text ()
326357 self .value_changed .emit (self .toolTip (), value )
327358
359+ def set_file_ext (self , ext = None ):
360+ self ._ext = ext or '*'
361+
362+ def set_file_directory (self , directory ):
363+ self ._file_directory = directory
364+
328365 def get_value (self ):
329366 return self ._ledit .text ()
330367
@@ -339,7 +376,7 @@ class PropFileSavePath(PropFilePath):
339376
340377 def _on_select_file (self ):
341378 file_path = FileDialog .getSaveFileName (self ,
342- file_dir = self ._file_dir ,
379+ file_dir = self ._file_directory ,
343380 ext_filter = self ._ext )
344381 file = file_path [0 ] or None
345382 if file :
@@ -725,6 +762,7 @@ def get_value(self):
725762 NODE_PROP_QSPINBOX : PropSpinBox ,
726763 NODE_PROP_COLORPICKER : PropColorPicker ,
727764 NODE_PROP_SLIDER : PropSlider ,
765+
728766 NODE_PROP_FILE : PropFilePath ,
729767 NODE_PROP_FILE_SAVE : PropFileSavePath ,
730768 NODE_PROP_VECTOR2 : PropVector2 ,
@@ -737,6 +775,7 @@ def get_value(self):
737775
738776
739777# main property widgets.
778+ # ==============================================================================
740779
741780
742781class PropListWidget (QtWidgets .QWidget ):
0 commit comments