Skip to content

Commit 42ddc85

Browse files
committed
wip
1 parent bb3ba52 commit 42ddc85

File tree

12 files changed

+253
-171
lines changed

12 files changed

+253
-171
lines changed

orangecanvas/application/application.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from AnyQt.QtCore import (
1515
Qt, QUrl, QEvent, QSettings, QLibraryInfo, pyqtSignal as Signal
1616
)
17+
from PyQt5.QtGui import QFont, QPalette
1718

1819
from orangecanvas.utils.after_exit import run_after_exit
1920
from orangecanvas.utils.asyncutils import get_event_loop
@@ -117,6 +118,12 @@ def __init__(self, argv):
117118
sh.setShowShortcutsInContextMenus(True)
118119
self.configureStyle()
119120

121+
if sys.platform != 'darwin':
122+
font = QFont('Titillium Web',
123+
self.font().pointSize(),
124+
self.font().weight())
125+
self.setFont(font)
126+
120127
def event(self, event):
121128
if event.type() == QEvent.FileOpen:
122129
self.fileOpenRequest.emit(event.url())

orangecanvas/application/widgettoolbox.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from ..gui.toolbox import ToolBox
2626
from ..gui.toolgrid import ToolGrid
2727
from ..gui.quickhelp import StatusTipPromoter
28-
from ..gui.utils import create_gradient
28+
from ..gui.utils import create_gradient, foreground_for_background
2929
from ..registry.qt import QtWidgetRegistry
3030

3131

@@ -415,26 +415,7 @@ def __insertItem(self, item, index):
415415
self.insertItem(index, grid, text, icon, tooltip)
416416
button = self.tabButton(index)
417417

418-
# Set the 'highlight' color if applicable
419-
highlight_foreground = None
420-
highlight = item_background(item)
421-
if highlight is None \
422-
and item.data(QtWidgetRegistry.BACKGROUND_ROLE) is not None:
423-
highlight = item.data(QtWidgetRegistry.BACKGROUND_ROLE)
424-
425-
if isinstance(highlight, QBrush) and highlight.style() != Qt.NoBrush:
426-
if not highlight.gradient():
427-
value = highlight.color().value()
428-
gradient = create_gradient(highlight.color())
429-
highlight = QBrush(gradient)
430-
highlight_foreground = Qt.black if value > 128 else Qt.white
431-
432-
palette = button.palette()
433-
434-
if highlight is not None:
435-
palette.setBrush(QPalette.Highlight, highlight)
436-
if highlight_foreground is not None:
437-
palette.setBrush(QPalette.HighlightedText, highlight_foreground)
418+
palette = item.data(QtWidgetRegistry.BACKGROUND_ROLE)
438419
button.setPalette(palette)
439420

440421
def __on_dataChanged(self, topLeft, bottomRight):

orangecanvas/canvas/items/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
"""
55

6-
from .nodeitem import NodeItem, NodeAnchorItem, NodeBodyItem, SHADOW_COLOR
6+
from .nodeitem import NodeItem, NodeAnchorItem, NodeBodyItem, DEFAULT_SHADOW_COLOR
77
from .nodeitem import SourceAnchorItem, SinkAnchorItem, AnchorPoint
88
from .linkitem import LinkItem, LinkCurveItem
99
from .annotationitem import TextAnnotation, ArrowAnnotation

orangecanvas/canvas/items/linkitem.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
from AnyQt.QtWidgets import (
1414
QGraphicsItem, QGraphicsPathItem, QGraphicsWidget,
1515
QGraphicsDropShadowEffect, QGraphicsSceneHoverEvent, QStyle,
16-
QGraphicsSceneMouseEvent
17-
)
16+
QGraphicsSceneMouseEvent,
17+
QApplication)
1818
from AnyQt.QtGui import (
1919
QPen, QBrush, QColor, QPainterPath, QTransform, QPalette,
2020
)
2121
from AnyQt.QtCore import Qt, QPointF, QRectF, QLineF, QEvent, QPropertyAnimation, Signal, QTimer
2222

23-
from .nodeitem import AnchorPoint, SHADOW_COLOR
23+
from .nodeitem import AnchorPoint, DEFAULT_SHADOW_COLOR
2424
from .graphicstextitem import GraphicsTextItem
2525
from .utils import stroke_path
2626
from ...registry import InputSignal, OutputSignal
@@ -52,7 +52,7 @@ def __init__(self, parent):
5252
self.setPen(QPen(QBrush(QColor("#9CACB4")), 2.0))
5353

5454
self.shadow = QGraphicsDropShadowEffect(
55-
blurRadius=5, color=QColor(SHADOW_COLOR),
55+
blurRadius=5, color=QColor(DEFAULT_SHADOW_COLOR),
5656
offset=QPointF(0, 0)
5757
)
5858
self.setGraphicsEffect(self.shadow)
@@ -809,6 +809,10 @@ def __updatePen(self):
809809
# type: () -> None
810810
self.prepareGeometryChange()
811811
self.__boundingRect = None
812+
813+
app = QApplication.instance()
814+
darkMode = app.property('darkMode')
815+
812816
if self.__dynamic:
813817
if self.__dynamicEnabled:
814818
color = QColor(0, 150, 0, 150)
@@ -818,8 +822,12 @@ def __updatePen(self):
818822
normal = QPen(QBrush(color), 2.0)
819823
hover = QPen(QBrush(color.darker(120)), 2.0)
820824
else:
821-
normal = QPen(QBrush(QColor("#9CACB4")), 2.0)
822-
hover = QPen(QBrush(QColor("#959595")), 2.0)
825+
if darkMode:
826+
brush = QBrush(QColor('#FFFFFF'))
827+
else:
828+
brush = QBrush(QColor('#878787'))
829+
normal = QPen(brush, 2.0)
830+
hover = QPen(brush.color().darker(105), 2.0)
823831

824832
if self.__state & LinkItem.Empty:
825833
pen_style = Qt.DashLine

orangecanvas/canvas/items/nodeitem.py

Lines changed: 58 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333

3434
from .graphicspathobject import GraphicsPathObject
3535
from .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

3839
from ...scheme.node import UserMessage
3940
from ...registry import NAMED_COLORS, WidgetDescription, CategoryDescription, \
@@ -48,48 +49,14 @@
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-
8452
def 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

9562
class 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

orangecanvas/canvas/items/utils.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
from AnyQt.QtWidgets import QGraphicsItem
1414

15+
from orangecanvas.registry.utils import saturated
16+
1517
if typing.TYPE_CHECKING:
1618
T = typing.TypeVar("T")
1719
A = typing.TypeVar("A")
@@ -93,19 +95,6 @@ def sample_path(path, num=10):
9395
return [path.pointAtPercent(p) for p in linspace(num)]
9496

9597

96-
def saturated(color, factor=150):
97-
# type: (QColor, int) -> QColor
98-
"""Return a saturated color.
99-
"""
100-
h = color.hsvHueF()
101-
s = color.hsvSaturationF()
102-
v = color.valueF()
103-
a = color.alphaF()
104-
s = factor * s / 100.0
105-
s = max(min(1.0, s), 0.0)
106-
return QColor.fromHsvF(h, s, v, a).convertTo(color.spec())
107-
108-
10998
def radial_gradient(color, color_light=50):
11099
# type: (QColor, Union[int, QColor]) -> QRadialGradient
111100
"""

0 commit comments

Comments
 (0)