@@ -383,7 +383,87 @@ def set_value(self, text=''):
383
383
if text != self .get_value ():
384
384
self .get_custom_widget ().setText (text )
385
385
self .on_value_changed ()
386
+ class NodeButton (NodeBaseWidget ):
387
+ """
388
+ Displays as a ``QPushButton`` in a node.
389
+
390
+ .. inheritance-diagram:: NodeGraphQt.widgets.node_widgets.NodeButton
391
+ :parts: 1
392
+
393
+ .. note::
394
+ `To embed a` ``QPushButton`` `in a node, you would typically use a
395
+ helper function like` :meth:`NodeGraphQt.BaseNode.add_button`
396
+ """
397
+
398
+ def __init__ (self , parent = None , name = '' , label = '' , text = '' ):
399
+ super (NodeButton , self ).__init__ (parent , name , label )
400
+
401
+ # Create the core QPushButton widget.
402
+ self ._button = QtWidgets .QPushButton (text )
403
+
404
+ # --- Styling ---
405
+ # Calculate text color based on the viewer's background for good contrast.
406
+ text_color = tuple (map (lambda i , j : i - j , (255 , 255 , 255 ),
407
+ ViewerEnum .BACKGROUND_COLOR .value ))
408
+
409
+ # Define a clean, modern stylesheet for the button.
410
+ style_dict = {
411
+ 'QPushButton' : {
412
+ 'background-color' : 'rgba(40, 40, 40, 200)' ,
413
+ 'border' : '1px solid rgba(100, 100, 100, 255)' ,
414
+ 'border-radius' : '3px' ,
415
+ 'color' : 'rgba({0},{1},{2},150)' .format (* text_color ),
416
+ 'font-size' : '10pt' ,
417
+ 'padding' : '2px 15px' ,
418
+ 'max-height' : '20px' ,
419
+ },
420
+ 'QPushButton:hover' : {
421
+ 'background-color' : 'rgba(50, 50, 50, 220)' ,
422
+ 'border' : '1px solid rgba(150, 150, 150, 255)' ,
423
+ },
424
+ 'QPushButton:pressed' : {
425
+ 'background-color' : 'rgba(25, 25, 25, 200)' ,
426
+ 'border' : '1px solid rgba(80, 80, 80, 255)' ,
427
+ }
428
+ }
386
429
430
+ # Apply the stylesheet.
431
+ stylesheet = ''
432
+ for css_class , css in style_dict .items ():
433
+ style = '{} {{\n ' .format (css_class )
434
+ for elm_name , elm_val in css .items ():
435
+ style += ' {}:{};\n ' .format (elm_name , elm_val )
436
+ style += '}\n '
437
+ stylesheet += style
438
+ self ._button .setStyleSheet (stylesheet )
439
+
440
+ # --- Signal Connection ---
441
+ # When the button is clicked, it will trigger the base widget's
442
+ # 'on_value_changed' method, which in turn emits the 'value_changed'
443
+ # signal that the node can listen to.
444
+ self ._button .clicked .connect (self .on_value_changed )
445
+
446
+ # Embed the styled button into the node widget layout.
447
+ self .set_custom_widget (self ._button )
448
+
449
+ @property
450
+ def type_ (self ):
451
+ """
452
+ Returns the unique type identifier for this widget.
453
+ """
454
+ return 'ButtonNodeWidget'
455
+
456
+ def get_value (self ):
457
+ """
458
+ Returns the current text of the button.
459
+ """
460
+ return self ._button .text ()
461
+
462
+ def set_value (self , text ):
463
+ """
464
+ Sets the text displayed on the button.
465
+ """
466
+ self ._button .setText (text )
387
467
388
468
class NodeCheckBox (NodeBaseWidget ):
389
469
"""
0 commit comments