Skip to content

Commit

Permalink
Merge pull request #83 from wojtryb/development
Browse files Browse the repository at this point in the history
Deploy 1.5.2
  • Loading branch information
wojtryb authored Mar 25, 2024
2 parents 59240c7 + 1153a71 commit b93c547
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 26 deletions.
2 changes: 1 addition & 1 deletion shortcut_composer/INFO.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from api_krita.wrappers import Version

__version__ = Version(1, 5, 1)
__version__ = Version(1, 5, 2)
"""Version of the Shortcut Composer plugin."""

__required_krita_version__ = Version(5, 2, 2)
Expand Down
2 changes: 2 additions & 0 deletions shortcut_composer/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ def create_actions() -> list[templates.RawInstructions]: return [
templates.RotationSelector(
name="Rotate canvas",
controller=controllers.CanvasRotationController(),
is_widget_hidden=False,
is_counterclockwise=False,
offset=0,
inverse_zones=False,
Expand All @@ -355,6 +356,7 @@ def create_actions() -> list[templates.RawInstructions]: return [
templates.RotationSelector(
name="Rotate brush",
controller=controllers.BrushRotationController(),
is_widget_hidden=False,
is_counterclockwise=True,
offset=90,
inverse_zones=False,
Expand Down
23 changes: 14 additions & 9 deletions shortcut_composer/api_krita/core_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-FileCopyrightText: © 2022-2024 Wojciech Trybus <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later

import re
from typing import Callable, Protocol, Any

from krita import Krita as Api, Extension, qApp
Expand Down Expand Up @@ -147,19 +148,23 @@ def is_light_theme_active(self) -> bool:
@property
def version(self) -> Version:
"""Get version of krita."""
try:
raw_string: str = self.instance.version()
version, *additional_info = raw_string.split("-")
raw: str = self.instance.version()

major, minor, fix = version.split(".")
num = r"(0|[1-9]\d*)"
dot = r"\."
delimiter = r"[ -]?"
info = r"(.*)"

version = Version(int(major), int(minor), int(fix))
if additional_info:
version.additional_info = additional_info[0]
return version
except Exception:
regex = "^" + num + dot + num + dot + num + delimiter + info + "$"
result = re.search(regex, raw)

if result is None or len(result.groups()) != 4:
return UnknownVersion()

major, minor, fix, additional_info = result.groups()

return Version(int(major), int(minor), int(fix), additional_info)


class KritaWindow(Protocol):
"""Krita window received in createActions() of main extension file."""
Expand Down
4 changes: 4 additions & 0 deletions shortcut_composer/api_krita/enums/blending_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ class BlendingMode(EnumGroup):
HARD_OVERLAY = "hard overlay"
INTERPOLATION = "interpolation"
INTERPOLATION_2X = "interpolation 2x"
LAMBERT_lIGHTING_GAMMA_2_2 = "lambert_lighting_gamma2.2"
LAMBERT_lIGHTING_GAMMA_LINEAR = "lambert_lighting"
NORMAL = "normal"
OVERLAY = "overlay"
PARALLEL = "parallel"
Expand Down Expand Up @@ -225,6 +227,8 @@ def pretty_name(self) -> str:
BlendingMode.HARD_MIX_PHOTOSHOP: "Hard Mix (Photoshop)",
BlendingMode.HARD_MIX_SOFTER_PHOTOSHOP: "Hard Mix Softer (Photoshop)",
BlendingMode.INTERPOLATION_2X: "Interpolation - 2X",
BlendingMode.LAMBERT_lIGHTING_GAMMA_2_2: "Lambert Lighting (Gamma 2.2)",
BlendingMode.LAMBERT_lIGHTING_GAMMA_LINEAR: "Lambert Lighting (Linear)",
BlendingMode.DIVISIVE_MODULO_CONTINUOUS: "Divisive Modulo - Continuous",
BlendingMode.MODULO_CONTINUOUS: "Modulo - Continuous",
BlendingMode.MODULO_SHIFT_CONTINUOUS: "Modulo Shift - Continuous",
Expand Down
2 changes: 1 addition & 1 deletion shortcut_composer/api_krita/wrappers/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def version_as_int(version: Version) -> int:
def __str__(self) -> str:
if not self.additional_info:
return f"{self.major}.{self.minor}.{self.fix}"
return f"{self.major}.{self.minor}.{self.fix}-{self.additional_info}"
return f"{self.major}.{self.minor}.{self.fix} {self.additional_info}"


class UnknownVersion(Version):
Expand Down
2 changes: 1 addition & 1 deletion shortcut_composer/manual.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<body>

<h1 id="shortcut-composer-v1-5-1-">Shortcut composer <strong>v1.5.1</strong></h1>
<h1 id="shortcut-composer-v1-5-2-">Shortcut composer <strong>v1.5.2</strong></h1>
<hr>
<p><strong><code>Extension</code></strong> for painting application <strong><code>Krita</code></strong>, which allows to create custom, complex <strong><code>keyboard shortcuts</code></strong>.</p>
<p>The plugin adds new shortcuts of the following types:</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class RotationConfig(FieldGroup, Generic[T]):
def __init__(
self,
name: str,
is_widget_hidden: bool,
deadzone_strategy: RotationDeadzoneStrategy,
inverse_zones: bool,
divisions: int,
Expand All @@ -31,6 +32,10 @@ def __init__(
) -> None:
super().__init__(name)

self.IS_WIDGET_HIDDEN = self.field(
name="Is widget hidden",
default=is_widget_hidden)

self.DEADZONE_STRATEGY = self.field(
name="Deadzone strategy",
default=deadzone_strategy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ def __init__(

def start(self) -> None:
"""Show widget under the mouse and start the mouse tracking loop."""
self._rotation_widget.move_center(QCursor().pos())
self._rotation_widget.show()
if not self._config.IS_WIDGET_HIDDEN.read():
self._rotation_widget.move_center(QCursor().pos())
self._rotation_widget.show()

self._center_global = QCursor().pos()
self._rotation_widget.state.reset()
Expand All @@ -49,9 +50,6 @@ def stop(self, hide: bool = True) -> None:

def _handle_cursor(self) -> None:
"""Calculate zone and angle of the cursor."""
if not self._rotation_widget.isVisible():
return self.stop()

cursor = QCursor().pos()
circle = CirclePoints(self._center_global, 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ def __init__(self, config: RotationConfig) -> None:
self._config = config

self._general_tab = ConfigFormWidget([
Checkbox(
config_field=config.IS_WIDGET_HIDDEN,
parent=self,
pretty_name="Hide widget",
tooltip=""
"Hide the rotation widget entirely.\n\n"
"Option for those who prefer to preview the value directly\n"
"in krita. It works best with small deadzone scale and\n"
"inner zone scale set to zero."),
"Behavior",
EnumComboBox(
config_field=config.DEADZONE_STRATEGY,
Expand Down
36 changes: 27 additions & 9 deletions shortcut_composer/templates/rotation_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from functools import cached_property

from PyQt5.QtWidgets import QWidget
from PyQt5.QtCore import QPoint
from PyQt5.QtGui import QColor

Expand Down Expand Up @@ -37,6 +38,7 @@ class RotationSelector(RawInstructions):
- `controller` -- defines which krita property will be modified
- `instructions` -- (optional) list of additional instructions to
perform on key press and release
- `is_widget_hidden` -- (optional) allows to hide the widget
- `deadzone_scale` -- (optional) default deadzone size multiplier
- `inner_zone_scale` -- (optional) default inner zone size multiplier
- `is_counterclockwise` -- (optional) default rotation direction
Expand All @@ -46,7 +48,7 @@ class RotationSelector(RawInstructions):
- `active_color` -- (optional) default rgba color of active pie
- `deadzone strategy` -- (optional) default strategy what to do,
when mouse does not leave deadzone
- `outline_opacity` -- (optional) opacity in %
- `outline_opacity` -- (optional) default opacity in %
- `short_vs_long_press_time` -- (optional) time [s] that specifies
if key press is short or long.
Expand All @@ -73,6 +75,7 @@ def __init__(
name: str,
controller: Controller[int],
instructions: list[Instruction] | None = None,
is_widget_hidden: bool = False,
deadzone_scale: float = 1.0,
inner_zone_scale: float = 1.0,
is_counterclockwise: bool = False,
Expand All @@ -89,6 +92,7 @@ def __init__(

self._config = RotationConfig(
name=self.name,
is_widget_hidden=is_widget_hidden,
deadzone_strategy=deadzone_strategy,
inverse_zones=inverse_zones,
divisions=divisions,
Expand Down Expand Up @@ -121,8 +125,7 @@ def __init__(
config=self._config,
strategy_field=self._config.DEADZONE_STRATEGY)

@cached_property
def settings_button(self) -> RoundButton:
def _create_settings_button(self, parent: QWidget) -> RoundButton:
"""Create button with which user can enter the edit mode."""

settings_button = RoundButton(
Expand All @@ -131,17 +134,26 @@ def settings_button(self) -> RoundButton:
active_color_callback=Krita.get_active_color_from_theme,
icon=Krita.get_icon("properties"),
icon_scale=1.1,
parent=self._rotation_widget)
parent=parent)

def on_click() -> None:
self._rotation_widget.hide()
self.rotation_settings.show()
self._rotation_settings.show()
self._global_settings_button.hide()
settings_button.clicked.connect(on_click)

return settings_button

@cached_property
def rotation_settings(self) -> RotationSettings:
def _settings_button(self) -> RoundButton:
return self._create_settings_button(self._rotation_widget)

@cached_property
def _global_settings_button(self) -> RoundButton:
return self._create_settings_button(None) # type: ignore

@cached_property
def _rotation_settings(self) -> RotationSettings:
"""Create a settings widget which configures the menu."""
return RotationSettings(config=self._config)

Expand All @@ -152,12 +164,18 @@ def on_key_press(self) -> None:
self._rotation_manager.start()
self._rotation_actuator.start()

self.settings_button.move(QPoint(
self._rotation_widget.width()-self.settings_button.width(),
self._rotation_widget.height()-self.settings_button.height()))
self._settings_button.move(QPoint(
self._rotation_widget.width()-self._settings_button.width(),
self._rotation_widget.height()-self._settings_button.height()))

if (self._config.IS_WIDGET_HIDDEN.read()
and not self._rotation_settings.isVisible()):
self._global_settings_button.show()

def on_every_key_release(self) -> None:
"""Handle the key release event."""
super().on_every_key_release()
self._rotation_actuator.stop()
self._rotation_manager.stop()

self._global_settings_button.hide()

0 comments on commit b93c547

Please sign in to comment.