3333
3434from .graphicspathobject import GraphicsPathObject
3535from .graphicstextitem import GraphicsTextItem
36- from .utils import saturated , radial_gradient
36+ from .utils import radial_gradient
37+ from ...registry .utils import default_palette , create_palette
3738
3839from ...scheme .node import UserMessage
3940from ...registry import NAMED_COLORS , WidgetDescription , CategoryDescription , \
4849 # from . import LinkItem
4950
5051
51- def create_palette (light_color , color ):
52- # type: (QColor, QColor) -> QPalette
53- """
54- Return a new :class:`QPalette` from for the :class:`NodeBodyItem`.
55- """
56- palette = QPalette ()
57-
58- palette .setColor (QPalette .Inactive , QPalette .Light ,
59- saturated (light_color , 50 ))
60- palette .setColor (QPalette .Inactive , QPalette .Midlight ,
61- saturated (light_color , 90 ))
62- palette .setColor (QPalette .Inactive , QPalette .Button ,
63- light_color )
64-
65- palette .setColor (QPalette .Active , QPalette .Light ,
66- saturated (color , 50 ))
67- palette .setColor (QPalette .Active , QPalette .Midlight ,
68- saturated (color , 90 ))
69- palette .setColor (QPalette .Active , QPalette .Button ,
70- color )
71- palette .setColor (QPalette .ButtonText , QColor ("#515151" ))
72- return palette
73-
74-
75- def default_palette ():
76- # type: () -> QPalette
77- """
78- Create and return a default palette for a node.
79- """
80- return create_palette (QColor (NAMED_COLORS ["light-yellow" ]),
81- QColor (NAMED_COLORS ["yellow" ]))
82-
83-
8452def animation_restart (animation ):
8553 # type: (QPropertyAnimation) -> None
8654 if animation .state () == QPropertyAnimation .Running :
8755 animation .pause ()
8856 animation .start ()
8957
9058
91- SHADOW_COLOR = "#9CACB4"
92- SELECTED_SHADOW_COLOR = "#609ED7"
59+ DEFAULT_SHADOW_COLOR = "#9CACB4"
9360
9461
9562class NodeBodyItem (GraphicsPathObject ):
@@ -120,7 +87,7 @@ def __init__(self, parent=None):
12087
12188 self .shadow = QGraphicsDropShadowEffect (
12289 blurRadius = 0 ,
123- color = QColor (SHADOW_COLOR ),
90+ color = QColor (DEFAULT_SHADOW_COLOR ),
12491 offset = QPointF (0 , 0 ),
12592 )
12693 self .shadow .setEnabled (False )
@@ -131,7 +98,7 @@ def __init__(self, parent=None):
13198 # non devicePixelRatio aware.
13299 shadowitem = GraphicsPathObject (self , objectName = "shadow-shape-item" )
133100 shadowitem .setPen (Qt .NoPen )
134- shadowitem .setBrush (QBrush (QColor (SHADOW_COLOR ).lighter ()))
101+ shadowitem .setBrush (QBrush (QColor (DEFAULT_SHADOW_COLOR ).lighter ()))
135102 shadowitem .setGraphicsEffect (self .shadow )
136103 shadowitem .setFlag (QGraphicsItem .ItemStacksBehindParent )
137104 self .__shadow = shadowitem
@@ -285,11 +252,7 @@ def __updateShadowState(self):
285252 if enabled and not self .shadow .isEnabled ():
286253 self .shadow .setEnabled (enabled )
287254
288- if self .__isSelected :
289- color = QColor (SELECTED_SHADOW_COLOR )
290- else :
291- color = QColor (SHADOW_COLOR )
292-
255+ color = self .palette .color (QPalette .Shadow )
293256 self .shadow .setColor (color )
294257
295258 if self .__animationEnabled :
@@ -352,8 +315,10 @@ def __init__(self, parent=None):
352315 self .setAcceptedMouseButtons (Qt .NoButton )
353316 self .setRect (- 3.5 , - 3.5 , 7. , 7. )
354317 self .setPen (QPen (Qt .NoPen ))
355- self .setBrush (QBrush (QColor ("#9CACB4" )))
356- self .hoverBrush = QBrush (QColor ("#959595" ))
318+
319+ color = QColor ("#9CACB4" )
320+ self .brush = QBrush (color )
321+ self .hover_brush = QBrush (color .darker (115 ))
357322
358323 self .__hover = False
359324
@@ -378,7 +343,7 @@ def setLinkState(self, state: 'LinkItem.State'):
378343 def paint (self , painter , option , widget = None ):
379344 # type: (QPainter, QStyleOptionGraphicsItem, Optional[QWidget]) -> None
380345 hover = self .__styleState & (QStyle .State_Selected | QStyle .State_MouseOver )
381- brush = self .hoverBrush if hover else self .brush ()
346+ brush = self .hover_brush if hover else self .brush
382347 if self .__linkState & (LinkItem .Pending | LinkItem .Invalidated ):
383348 brush = QBrush (Qt .red )
384349
@@ -639,15 +604,15 @@ def __init__(self, parent, **kwargs):
639604
640605 self .shadow = QGraphicsDropShadowEffect (
641606 blurRadius = 0 ,
642- color = QColor (SHADOW_COLOR ),
607+ # color=QColor(DEFAULT_SHADOW_COLOR ),
643608 offset = QPointF (0 , 0 ),
644609 )
645610 # self.setGraphicsEffect(self.shadow)
646611 self .shadow .setEnabled (False )
647612
648613 shadowitem = GraphicsPathObject (self , objectName = "shadow-shape-item" )
649614 shadowitem .setPen (Qt .NoPen )
650- shadowitem .setBrush (QBrush (QColor (SHADOW_COLOR )))
615+ # shadowitem.setBrush(QBrush(QColor(DEFAULT_SHADOW_COLOR )))
651616 shadowitem .setGraphicsEffect (self .shadow )
652617 shadowitem .setFlag (QGraphicsItem .ItemStacksBehindParent )
653618 self .__shadow = shadowitem
@@ -1345,6 +1310,9 @@ def __init__(self, widget_description=None, parent=None, **kwargs):
13451310 self .outputAnchorItem .setAnchorPath (output_path )
13461311 self .outputAnchorItem .setAnimationEnabled (self .__animationEnabled )
13471312
1313+ self .widget_palette = None
1314+ self .__updateAnchorBrushes ()
1315+
13481316 self .inputAnchorItem .hide ()
13491317 self .outputAnchorItem .hide ()
13501318
@@ -1428,11 +1396,34 @@ def setWidgetCategory(self, desc):
14281396 Set the widget category.
14291397 """
14301398 self .category_description = desc
1431- if desc and desc .background :
1432- background = NAMED_COLORS .get (desc .background , desc .background )
1433- color = QColor (background )
1434- if color .isValid ():
1435- self .setColor (color )
1399+
1400+ background = desc .background
1401+ if desc .background :
1402+ palette = create_palette (background )
1403+ else :
1404+ palette = default_palette ()
1405+ self .widget_palette = palette
1406+ self .setPalette (palette )
1407+
1408+ def __updateAnchorBrushes (self ):
1409+ app = QApplication .instance ()
1410+ darkMode = app .property ('darkMode' )
1411+ if darkMode :
1412+ link_brush = QBrush (QColor ('#FFFFFF' ))
1413+ else :
1414+ link_brush = QBrush (QColor ('#878787' ))
1415+ hover_brush = QBrush (link_brush .color ().darker (105 ))
1416+ con_hover_brush = QBrush (hover_brush .color ().darker (105 ))
1417+
1418+ for anchor in (self .outputAnchorItem , self .inputAnchorItem ):
1419+ anchor .connectedBrush = hover_brush
1420+ anchor .normalBrush = link_brush
1421+ anchor .connectedHoverBrush = con_hover_brush
1422+ anchor .normalHoverBrush = hover_brush
1423+ for point in anchor .anchorPoints ():
1424+ point .indicator .brush = link_brush
1425+ point .indicator .hover_brush = hover_brush
1426+ anchor .update ()
14361427
14371428 def setIcon (self , icon ):
14381429 # type: (QIcon) -> None
@@ -1444,18 +1435,8 @@ def setIcon(self, icon):
14441435 )
14451436 self .icon_item .setPos (- 18 , - 18 )
14461437
1447- def setColor (self , color , selectedColor = None ):
1448- # type: (QColor, Optional[QColor]) -> None
1449- """
1450- Set the widget color.
1451- """
1452- if selectedColor is None :
1453- selectedColor = saturated (color , 150 )
1454- palette = create_palette (color , selectedColor )
1455- self .shapeItem .setPalette (palette )
1456-
14571438 def setTitle (self , title ):
1458- # type: (str) -> None
1439+ # type: (str) -> Nne
14591440 """
14601441 Set the node title. The title text is displayed at the bottom of the
14611442 node.
@@ -1594,8 +1575,11 @@ def newInputAnchor(self, signal=None):
15941575 if not (self .widget_description and self .widget_description .inputs ):
15951576 raise ValueError ("Widget has no inputs." )
15961577
1578+ palette = self .palette ()
1579+
15971580 anchor = AnchorPoint (self , signal = signal )
15981581 self .inputAnchorItem .addAnchor (anchor )
1582+ self .__updateAnchorBrushes ()
15991583
16001584 return anchor
16011585
@@ -1614,8 +1598,11 @@ def newOutputAnchor(self, signal=None):
16141598 if not (self .widget_description and self .widget_description .outputs ):
16151599 raise ValueError ("Widget has no outputs." )
16161600
1601+ palette = self .palette ()
1602+
16171603 anchor = AnchorPoint (self , signal = signal )
16181604 self .outputAnchorItem .addAnchor (anchor )
1605+ self .__updateAnchorBrushes ()
16191606
16201607 return anchor
16211608
@@ -1806,8 +1793,14 @@ def itemChange(self, change, value):
18061793
18071794 def __updatePalette (self ):
18081795 # type: () -> None
1809- palette = self .palette ()
1796+ if self .widget_palette :
1797+ palette = self .widget_palette
1798+ else :
1799+ palette = self .palette ()
1800+
1801+ self .shapeItem .setPalette (palette )
18101802 self .captionTextItem .setPalette (palette )
1803+ self .__updateAnchorBrushes ()
18111804
18121805 def __updateFont (self ):
18131806 # type: () -> None
0 commit comments