Dark style for menus and dialogs

This commit is contained in:
Rebecca Breu 2021-07-17 19:37:06 +02:00
parent d635a3ea3a
commit 50eda2875a
9 changed files with 96 additions and 8 deletions

View file

@ -5,6 +5,8 @@ Changed
-------
* Flipping an image now happens on mouse press instead of mouse release
* About dialog points to new website beeref.org
* Menus and dialogs now have a dark style to match the optics of the canvas
Fixed
-----

View file

@ -5,7 +5,7 @@ BeeRef — A Simple Reference Image Viewer
<img align="left" width="100" height="100" src="https://raw.githubusercontent.com/rbreu/beeref/main/beeref/assets/logo.png">
`BeeRef <https://rbreu.github.io/beeref/>`_ lets you quickly arrange your reference images and view them while you create. Its minimal interface is designed not to get in the way of your creative process.
`BeeRef <https://beeref.org>`_ lets you quickly arrange your reference images and view them while you create. Its minimal interface is designed not to get in the way of your creative process.
|python-version| |github-ci-flake8| |github-ci-pytest| |codecov|

View file

@ -21,9 +21,10 @@ import sys
from PyQt6 import QtCore, QtWidgets
from beeref import constants
from beeref.assets import BeeAssets
from beeref.config import CommandlineArgs, BeeSettings, logfile_name
from beeref import constants
from beeref.utils import create_palette_from_dict
from beeref.view import BeeGraphicsView
logger = logging.getLogger(__name__)
@ -79,6 +80,8 @@ def main():
logger.info(f'Logging to: {logfile_name()}')
CommandlineArgs(with_check=True) # Force checking
app = QtWidgets.QApplication(sys.argv)
palette = create_palette_from_dict(constants.COLORS)
app.setPalette(palette)
bee = BeeRefMainWindow(app) # NOQA:F841

View file

@ -16,5 +16,24 @@
APPNAME = 'BeeRef'
APPNAME_FULL = f'{APPNAME} Reference Image Viewer'
VERSION = '0.1.1'
WEBSITE = 'https://github.com/rbreu/beeref'
WEBSITE = 'https://beeref.org'
COPYRIGHT = 'Copyright © 2021 Rebecca Breu'
COLORS = {
# Qt:
'Active:Base': (60, 60, 60),
'Active:Window': (40, 40, 40),
'Active:Button': (40, 40, 40),
'Active:Text': (200, 200, 200),
'Active:HighlightedText': (255, 255, 255),
'Active:WindowText': (200, 200, 200),
'Active:ButtonText': (200, 200, 200),
'Active:Highlight': (83, 167, 165),
'Active:Link': (90, 181, 179),
'Disabled:Light': (0, 0, 0),
'Disabled:Text': (140, 140, 140),
# BeeRef specific:
'Scene:Selection': (116, 234, 231),
'Scene:Canvas': (60, 60, 60),
}

View file

@ -37,7 +37,6 @@ class WelcomeOverlay(QtWidgets.QWidget):
self.setAttribute(Qt.WidgetAttribute.WA_NoSystemBackground)
self.setAttribute(Qt.WidgetAttribute.WA_TransparentForMouseEvents)
label = QtWidgets.QLabel(self)
label.setStyleSheet("QLabel { color: #cccccc; }")
label.setText(self.txt)
label.setAlignment(Qt.AlignmentFlag.AlignVCenter
| Qt.AlignmentFlag.AlignCenter)

View file

@ -25,12 +25,13 @@ from PyQt6.QtWidgets import QGraphicsItem
from beeref.assets import BeeAssets
from beeref import commands
from beeref.config import CommandlineArgs
from beeref.constants import COLORS
from beeref import utils
commandline_args = CommandlineArgs()
logger = logging.getLogger(__name__)
SELECT_COLOR = QtGui.QColor(116, 234, 231, 255)
SELECT_COLOR = QtGui.QColor(*COLORS['Scene:Selection'])
def with_anchor(func):

View file

@ -17,7 +17,37 @@ import logging.handlers
import os
import os.path
from PyQt6 import QtCore
from PyQt6 import QtCore, QtGui
def create_palette_from_dict(conf):
"""Create a palette from a config dictionary. Keys are a string of
'ColourGroup:ColorRole' and values are a (r, g, b) tuple. E.g:
{
'Active:WindowText': (80, 100, 0),
...
}
Colors from the Active group will automatically be applied to the
Inactive group as well. Unknown color groups will be ignored.
"""
palette = QtGui.QPalette()
for key, value in conf.items():
group, role = key.split(':')
if hasattr(QtGui.QPalette.ColorGroup, group):
palette.setColor(
getattr(QtGui.QPalette.ColorGroup, group),
getattr(QtGui.QPalette.ColorRole, role),
QtGui.QColor(*value))
if group == 'Active':
# Also set the Inactive colour group.
palette.setColor(
QtGui.QPalette.ColorGroup.Inactive,
getattr(QtGui.QPalette.ColorRole, role),
QtGui.QColor(*value))
return palette
def get_rect_from_points(point1, point2):

View file

@ -43,7 +43,8 @@ class BeeGraphicsView(QtWidgets.QGraphicsView, ActionsMixin):
self.settings = BeeSettings()
self.welcome_overlay = gui.WelcomeOverlay(self)
self.setBackgroundBrush(QtGui.QBrush(QtGui.QColor(60, 60, 60)))
self.setBackgroundBrush(
QtGui.QBrush(QtGui.QColor(*constants.COLORS['Scene:Canvas'])))
self.setFrameShape(QtWidgets.QFrame.Shape.NoFrame)
self.setAcceptDrops(True)

View file

@ -2,11 +2,44 @@ import logging
import os.path
import pytest
from PyQt6 import QtCore
from PyQt6 import QtCore, QtGui
from beeref import utils
def test_create_palette_from_dict_sets_qt_group():
conf = {'Disabled:WindowText': (44, 55, 66)}
palette = utils.create_palette_from_dict(conf)
color = palette.color(QtGui.QPalette.ColorGroup.Disabled,
QtGui.QPalette.ColorRole.WindowText)
assert color.getRgb() == (44, 55, 66, 255)
color_inactive = palette.color(QtGui.QPalette.ColorGroup.Inactive,
QtGui.QPalette.ColorRole.WindowText)
assert color_inactive.getRgb() != (44, 55, 66, 255)
def test_create_palette_from_dict_active_group_also_sets_inactive():
conf = {'Active:WindowText': (44, 55, 66)}
palette = utils.create_palette_from_dict(conf)
color = palette.color(QtGui.QPalette.ColorGroup.Active,
QtGui.QPalette.ColorRole.WindowText)
assert color.getRgb() == (44, 55, 66, 255)
color_inactive = palette.color(QtGui.QPalette.ColorGroup.Inactive,
QtGui.QPalette.ColorRole.WindowText)
assert color_inactive.getRgb() == (44, 55, 66, 255)
def test_create_palette_from_dict_ignores_unknown_group():
conf = {'Foo:WindowText': (44, 55, 66)}
palette = utils.create_palette_from_dict(conf)
color = palette.color(QtGui.QPalette.ColorGroup.Active,
QtGui.QPalette.ColorRole.WindowText)
assert color.getRgb() != (44, 55, 66, 255)
color_inactive = palette.color(QtGui.QPalette.ColorGroup.Inactive,
QtGui.QPalette.ColorRole.WindowText)
assert color_inactive.getRgb() != (44, 55, 66, 255)
def test_get_rect_from_points_given_topleft_bottomright():
rect = utils.get_rect_from_points(QtCore.QPointF(-10, -20),
QtCore.QPointF(30, 40))