-
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 #33 from wojtryb/development
Deploy v1.1.1
- Loading branch information
Showing
13 changed files
with
156 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
name: Bug report | ||
about: Create a report so that the bug can be fixed in future relase. | ||
title: '' | ||
labels: bug | ||
assignees: wojtryb | ||
|
||
--- | ||
|
||
**General info** | ||
- Plugin version: ... [example: v1.1.0] | ||
- Operating System: ... [example: Windows 10, Ubuntu 22.04, macOS Sierra] | ||
|
||
**Bug description** | ||
Describe the issue you encounter. | ||
- If the plugin crashes and you get a traceback window - make sure to paste its content here. | ||
- You can attach screenshots if it helps to describe your issue. | ||
|
||
Ideally: | ||
- check if the bug also occurs on the `development` branch (on github overview page, switch from 'main' to 'development', then download and install the plugin) | ||
- try to break down when the bug happens (always/occasionally), and what is needed for it to happen | ||
|
||
When the bug is fixed, close the issue. After not getting a response from you for a week, I will close it myself. |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"python.formatting.provider": "autopep8", | ||
"python.linting.flake8Enabled": true, | ||
"editor.formatOnSave": true, | ||
"python.analysis.typeCheckingMode": "basic", | ||
"python.analysis.diagnosticSeverityOverrides": { | ||
"reportMissingImports": "none" | ||
}, | ||
"[python]": { | ||
"editor.rulers": [ | ||
72, | ||
79 | ||
], | ||
}, | ||
} |
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
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
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
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,6 +1,8 @@ | ||
# SPDX-FileCopyrightText: © 2022 Wojciech Trybus <[email protected]> | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
from typing import List | ||
from dataclasses import dataclass | ||
from PyQt5.QtWidgets import QWidgetAction | ||
|
||
from api_krita import Krita, Extension # type: ignore | ||
|
@@ -10,35 +12,52 @@ | |
from input_adapter import ActionManager | ||
|
||
|
||
@dataclass | ||
class GarbageProtector: | ||
""" | ||
Stores plugin objects, to protect them from garbage collector. | ||
- TransformModeActions which create and store actions for transform modes | ||
- QDialog with plugin settings, | ||
- Action for displaying the settings dialog above | ||
- Manager for complex actions which which holds and binds them to krita | ||
- Action for reloading the complex action implementations | ||
""" | ||
transform_modes: TransformModeActions | ||
settings_dialog: SettingsDialog | ||
settings_action: QWidgetAction | ||
action_manager: ActionManager | ||
reload_action: QWidgetAction | ||
|
||
def is_alive(self): | ||
"""Return False if the action was deleted by C++""" | ||
try: | ||
self.settings_action.isEnabled() | ||
except RuntimeError: | ||
return False | ||
return True | ||
|
||
|
||
class ShortcutComposer(Extension): | ||
"""Krita extension that adds complex actions invoked with keyboard.""" | ||
|
||
_pie_settings_dialog: SettingsDialog | ||
_settings_action: QWidgetAction | ||
_reload_action: QWidgetAction | ||
_manager: ActionManager | ||
def __init__(self, parent) -> None: | ||
"""Add callback to reload actions on theme change.""" | ||
super().__init__(parent) | ||
self._protectors: List[GarbageProtector] = [] | ||
Krita.add_theme_change_callback(self._reload_composer) | ||
|
||
def setup(self) -> None: """Obligatory abstract method override.""" | ||
|
||
def createActions(self, window) -> None: | ||
""" | ||
Start the extension. Called by krita during plugin init phase. | ||
"""Create window components. Called by krita for each new window.""" | ||
self._protectors.append(GarbageProtector( | ||
transform_modes=TransformModeActions(window), | ||
settings_dialog=(settings := SettingsDialog()), | ||
settings_action=self._create_settings_action(window, settings), | ||
action_manager=ActionManager(window), | ||
reload_action=self._create_reload_action(window))) | ||
|
||
- Create usual actions for transform modes using `TransformModeActions` | ||
- Create usual actions for reloading the extension and settings dialog | ||
- Add a callback to reload plugin when krita theme changes | ||
- Create complex action manager which holds and binds them to krita | ||
""" | ||
self._transform_modes = TransformModeActions() | ||
self._transform_modes.create_actions(window) | ||
|
||
self._pie_settings_dialog = SettingsDialog() | ||
self._reload_action = self._create_reload_action(window) | ||
self._settings_action = self._create_settings_action(window) | ||
|
||
Krita.add_theme_change_callback(self._reload_composer) | ||
|
||
self._manager = ActionManager(window) | ||
self._reload_composer() | ||
|
||
def _create_reload_action(self, window) -> QWidgetAction: | ||
|
@@ -49,15 +68,24 @@ def _create_reload_action(self, window) -> QWidgetAction: | |
group="tools/scripts", | ||
callback=self._reload_composer) | ||
|
||
def _create_settings_action(self, window) -> QWidgetAction: | ||
def _create_settings_action( | ||
self, | ||
window, | ||
settings_dialog: SettingsDialog | ||
) -> QWidgetAction: | ||
"""Create krita action which opens the extension settings dialog.""" | ||
return Krita.create_action( | ||
window=window, | ||
name="Configure Shortcut Composer", | ||
group="tools/scripts", | ||
callback=self._pie_settings_dialog.show) | ||
callback=settings_dialog.show) | ||
|
||
def _reload_composer(self) -> None: | ||
"""Reload all core actions.""" | ||
for action in create_actions(): | ||
self._manager.bind_action(action) | ||
"""Reload all core actions for every window.""" | ||
for protector in reversed(self._protectors): | ||
if not protector.is_alive(): | ||
self._protectors.remove(protector) | ||
|
||
for protector in self._protectors: | ||
for action in create_actions(): | ||
protector.action_manager.bind_action(action) |
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