-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from wojtryb/development
Deploy v1.0.1
- Loading branch information
Showing
13 changed files
with
225 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
# SPDX-FileCopyrightText: © 2022 Wojciech Trybus <[email protected]> | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from krita import Krita as Api, Extension | ||
from krita import Krita as Api, Extension, qApp | ||
from typing import Callable, Protocol, Any | ||
|
||
from PyQt5.QtWidgets import QMainWindow, QDesktopWidget, QWidgetAction | ||
from PyQt5.QtGui import QKeySequence | ||
from PyQt5.QtGui import QKeySequence, QColor | ||
from PyQt5.QtCore import QTimer | ||
|
||
from .wrappers import ( | ||
ToolDescriptor, | ||
|
@@ -25,6 +26,7 @@ class KritaInstance: | |
def __init__(self) -> None: | ||
self.instance = Api.instance() | ||
self.screen_size = QDesktopWidget().screenGeometry(-1).width() | ||
self.main_window: Any = None | ||
|
||
def get_active_view(self) -> View: | ||
"""Return wrapper of krita `View`.""" | ||
|
@@ -89,9 +91,30 @@ def add_extension(self, extension: Extension) -> None: | |
"""Add extension/plugin/add-on to krita.""" | ||
self.instance.addExtension(extension(self.instance)) | ||
|
||
def add_theme_change_callback(self, callback: Callable[[], None]) -> Any: | ||
""" | ||
Add method which should be run after the theme is changed. | ||
Method is delayed with a timer to allow running it on plugin | ||
initialization phase. | ||
""" | ||
def connect_callback(): | ||
self.main_window = self.instance.activeWindow() | ||
if self.main_window is not None: | ||
self.main_window.themeChanged.connect(callback) | ||
QTimer.singleShot(1000, connect_callback) | ||
|
||
@property | ||
def is_light_theme_active(self) -> bool: | ||
"""Return if currently set theme is light using it's main color.""" | ||
main_color: QColor = qApp.palette().window().color() | ||
average = (main_color.red()+main_color.green()+main_color.blue()) // 3 | ||
return average > 128 | ||
|
||
|
||
class KritaWindow(Protocol): | ||
"""Krita window received in createActions() of main extension file.""" | ||
|
||
def createAction( | ||
self, | ||
name: str, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,31 @@ | ||
# SPDX-FileCopyrightText: © 2022 Wojciech Trybus <[email protected]> | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from collections import defaultdict | ||
from enum import Enum | ||
|
||
from PyQt5.QtGui import QColor | ||
|
||
from api_krita import Krita | ||
from ..enums import BlendingMode | ||
|
||
|
||
class Color(Enum): | ||
"""Named custom colors.""" | ||
|
||
ORANGE = QColor(236, 109, 39) | ||
WHITE = QColor(248, 248, 248) | ||
LIGHT_GRAY = QColor(170, 170, 170) | ||
BLUE = QColor(110, 217, 224) | ||
DARK_GRAY = QColor(90, 90, 90) | ||
BLACK = QColor(0, 0, 0) | ||
YELLOW = QColor(253, 214, 56) | ||
RED = QColor(245, 49, 116) | ||
ORANGE = QColor(236, 109, 39) | ||
GREEN = QColor(169, 224, 69) | ||
DARK_GREEN = QColor(119, 184, 55) | ||
RED = QColor(245, 49, 116) | ||
YELLOW = QColor(253, 214, 56) | ||
VIOLET = QColor(173, 133, 251) | ||
BLUE = QColor(110, 217, 224) | ||
DARK_BLUE = QColor(42, 160, 251) | ||
WHITE = QColor(248, 248, 242) | ||
VERY_DARK_BLUE = QColor(22, 130, 221) | ||
VIOLET = QColor(173, 133, 251) | ||
|
||
|
||
class Colorizer(QColor): | ||
|
@@ -29,7 +34,9 @@ class Colorizer(QColor): | |
@classmethod | ||
def blending_mode(cls, mode: BlendingMode) -> QColor: | ||
"""Return a QColor associated with blending mode. Gray by default.""" | ||
return cls.BLENDING_MODES_MAP.get(mode, Color.LIGHT_GRAY).value | ||
if Krita.is_light_theme_active: | ||
return cls.BLENDING_MODES_LIGHT[mode].value | ||
return cls.BLENDING_MODES_DARK[mode].value | ||
|
||
@classmethod | ||
def percentage(cls, percent: int) -> QColor: | ||
|
@@ -39,24 +46,46 @@ def percentage(cls, percent: int) -> QColor: | |
@staticmethod | ||
def _percentage(percent: int) -> Color: | ||
"""Mapping of percentage values to custom colors.""" | ||
if percent >= 100: | ||
return Color.DARK_GREEN | ||
if percent >= 80: | ||
return Color.GREEN | ||
if percent >= 50: | ||
return Color.WHITE | ||
if percent > 25: | ||
return Color.LIGHT_GRAY | ||
if percent > 10: | ||
return Color.YELLOW | ||
return Color.RED | ||
|
||
BLENDING_MODES_MAP = { | ||
if Krita.is_light_theme_active: | ||
if percent >= 100: | ||
return Color.DARK_GREEN | ||
if percent >= 80: | ||
return Color.GREEN | ||
if percent >= 50: | ||
return Color.BLACK | ||
if percent > 25: | ||
return Color.DARK_GRAY | ||
if percent > 10: | ||
return Color.ORANGE | ||
return Color.RED | ||
else: | ||
if percent >= 100: | ||
return Color.DARK_GREEN | ||
if percent >= 80: | ||
return Color.GREEN | ||
if percent >= 50: | ||
return Color.WHITE | ||
if percent > 25: | ||
return Color.LIGHT_GRAY | ||
if percent > 10: | ||
return Color.YELLOW | ||
return Color.RED | ||
|
||
BLENDING_MODES_DARK = defaultdict(lambda: Color.LIGHT_GRAY, { | ||
BlendingMode.NORMAL: Color.WHITE, | ||
BlendingMode.OVERLAY: Color.RED, | ||
BlendingMode.SCREEN: Color.GREEN, | ||
BlendingMode.COLOR: Color.YELLOW, | ||
BlendingMode.ADD: Color.DARK_BLUE, | ||
BlendingMode.MULTIPLY: Color.BLUE, | ||
} | ||
"""Mapping of blending modes to custom colors.""" | ||
}) | ||
"""Mapping of blending modes to custom colors in dark theme.""" | ||
BLENDING_MODES_LIGHT = defaultdict(lambda: Color.DARK_GRAY, { | ||
BlendingMode.NORMAL: Color.BLACK, | ||
BlendingMode.OVERLAY: Color.RED, | ||
BlendingMode.SCREEN: Color.ORANGE, | ||
BlendingMode.COLOR: Color.VIOLET, | ||
BlendingMode.ADD: Color.DARK_BLUE, | ||
BlendingMode.MULTIPLY: Color.VERY_DARK_BLUE, | ||
}) | ||
"""Mapping of blending modes to custom colors in light theme.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.