Implement the pixmap mask hack for long/short pp icons

chart_mod_breakup
Tyler Goodlet 2021-09-13 17:40:14 -04:00
parent 3de4b9afbb
commit 66199bfe6f
1 changed files with 37 additions and 15 deletions

View File

@ -26,7 +26,9 @@ from typing import Optional
from PyQt5.QtWidgets import QStyle
from PyQt5.QtGui import QIcon
from PyQt5.QtGui import (
QIcon, QPixmap, QColor
)
from pyqtgraph import functions as fn
from ._annotate import LevelMarker
@ -40,7 +42,7 @@ from ..data._normalize import iterticks
from ..data.feed import Feed
from ._label import Label
from ._lines import LevelLine, order_line
from ._style import _font
from ._style import _font, hcolor
from ._forms import FieldsForm, FillStatusBar, QLabel
from ..log import get_logger
@ -114,8 +116,8 @@ async def display_pnl(
# https://www.pythonguis.com/faq/built-in-qicons-pyqt/
# account status icons taken from built-in set
_icon_names: dict[str, str] = {
# 'connected': 'SP_DialogYesButton',
'unavailable': 'SP_DockWidgetCloseButton',
# these two seem to work for our mask hack done below to
# change the coloring.
'long_pp': 'SP_TitleBarShadeButton',
'short_pp': 'SP_TitleBarUnshadeButton',
'ready': 'SP_MediaPlay',
@ -123,7 +125,6 @@ _icon_names: dict[str, str] = {
_icons: dict[str, QIcon] = {}
@dataclass
class SettingsPane:
'''Composite set of widgets plus an allocator model for configuring
@ -156,18 +157,39 @@ class SettingsPane:
if not _icons:
# load account selection using current style
for name, icon_name in _icon_names.items():
pixmap = getattr(QStyle, icon_name)
# TODO: set color to our default pp color
# https://stackoverflow.com/questions/13350631/simple-color-fill-qicons-in-qt
# mask = pixmap.createMaskFromColor(
# QColor('transparent'),
# Qt.MaskOutColor
# )
# pixmap.fill((QColor(hcolor('default_light'))))
# pixmap.setMask(mask)
stdpixmap = getattr(QStyle, icon_name)
stdicon = form.style().standardIcon(stdpixmap)
combo = form.fields['account']
size = combo.iconSize()
pixmap = stdicon.pixmap(combo.iconSize())
_icons[name] = form.style().standardIcon(pixmap)
# fill hack from SO to change icon color:
# https://stackoverflow.com/a/38369468
out_pixmap = QPixmap(size)
out_pixmap.fill(QColor(hcolor('default_spotlight')))
out_pixmap.setMask(pixmap.createHeuristicMask())
# TODO: not idea why this doesn't work / looks like
# trash. Sure would be nice to just generate our own
# pixmaps on the fly..
# p = QPainter(out_pixmap)
# p.setOpacity(1)
# p.setBrush(QColor(hcolor('papas_special')))
# p.setPen(QColor(hcolor('default_lightest')))
# path = mk_marker_path(style='|<')
# p.scale(6, 6)
# # p.translate(0, 0)
# p.drawPath(path)
# p.save()
# p.end()
# del p
# icon = QIcon(out_pixmap)
icon = QIcon()
icon.addPixmap(out_pixmap)
_icons[name] = icon
acct_select = form.fields['account']
keys = list(keys or acct_select._items.keys())