cowpuncher's picture
download
raw
3.62 kB
"""Krita entry point of the Anima Reference add-on. See patch.py for what it does."""
import sys
from krita import Extension, Krita
try: # Krita 5
from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import QCheckBox, QDialog, QDialogButtonBox, QLabel, QMessageBox, QVBoxLayout
except ImportError: # Krita 6
from PyQt6.QtCore import Qt, QTimer
from PyQt6.QtWidgets import QCheckBox, QDialog, QDialogButtonBox, QLabel, QMessageBox, QVBoxLayout
from . import patch
SETTINGS = "anima_reference"
TITLE = "Anima Reference add-on"
def load_options():
try:
value = Krita.instance().readSetting(SETTINGS, "prefer_snapref", "false")
patch.options["prefer_snapref"] = str(value).strip().lower() == "true"
except Exception:
pass
def save_options():
try:
Krita.instance().writeSetting(SETTINGS, "prefer_snapref", "true" if patch.options["prefer_snapref"] else "false")
except Exception:
pass
class StatusDialog(QDialog):
"""Status of the add-on and its one option."""
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle(TITLE)
layout = QVBoxLayout(self)
self.text = QLabel(patch.status_text())
self.text.setTextInteractionFlags(Qt.TextInteractionFlag.TextSelectableByMouse)
layout.addWidget(self.text)
self.prefer = QCheckBox("Use SnapRef for Reference layers too")
self.prefer.setToolTip(
"Off: plain Reference layers use the Anima Ref Adapter, as before.\n"
"On: they use SnapRef (about 15% slower than no reference instead of about twice as slow).\n"
"Style and Face layers always use SnapRef. With Regions the Anima Ref Adapter is always used."
)
self.prefer.setChecked(bool(patch.options.get("prefer_snapref")))
self.prefer.toggled.connect(self.changed)
layout.addWidget(self.prefer)
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Close)
buttons.rejected.connect(self.reject)
buttons.accepted.connect(self.accept)
layout.addWidget(buttons)
def changed(self, checked):
patch.options["prefer_snapref"] = bool(checked)
save_options()
self.text.setText(patch.status_text())
class AnimaReferenceExtension(Extension):
def __init__(self, parent):
super().__init__(parent)
self._reported = False
self._dialog = None
def _start(self):
# Only hook into the AI plugin once Krita has loaded it. If it is disabled, do nothing.
if not patch.state.installed and "ai_diffusion" in sys.modules:
patch.install()
def setup(self):
load_options()
self._start()
QTimer.singleShot(8000, self._report_problem)
def createActions(self, window):
self._start()
action = window.createAction("anima_reference_status", "Anima Reference", "tools/scripts")
action.triggered.connect(self.show_status)
def _report_problem(self):
"""One message after start-up, and only if the add-on could not switch itself on."""
self._start()
if patch.state.installed or self._reported:
return
self._reported = True
QMessageBox.warning(None, TITLE, patch.status_text())
def show_status(self):
self._start()
self._dialog = StatusDialog() # kept on self: Qt only holds a weak reference
run = getattr(self._dialog, "exec", None) or self._dialog.exec_
run()
Krita.instance().addExtension(AnimaReferenceExtension(Krita.instance()))

Xet Storage Details

Size:
3.62 kB
·
Xet hash:
e4073c78f48f1b5ff2af42a8ac05a7bba6047a48931ae1ed601fe79341fa87da

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.