Skip to content

Commit

Permalink
Positive prompts in custom workflows honor the prompt_line_count set…
Browse files Browse the repository at this point in the history
…ting (#1416)

* Make custom positive prompts honor the line_count setting
* Added settings button to custom workflow UI
  • Loading branch information
mmuellerdm authored Nov 21, 2024
1 parent aede0e9 commit 995e404
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion ai_diffusion/ui/custom_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path
from typing import Any, Callable

from krita import Krita
from PyQt5.QtCore import Qt, pyqtSignal, QMetaObject, QUuid, QUrl, QPoint
from PyQt5.QtGui import QFontMetrics, QIcon, QDesktopServices
from PyQt5.QtWidgets import QComboBox, QFileDialog, QFrame, QGridLayout, QHBoxLayout, QMenu
Expand Down Expand Up @@ -246,7 +247,16 @@ class PromptParamWidget(TextPromptWidget):
value_changed = pyqtSignal()

def __init__(self, param: CustomParam, parent: QWidget | None = None):
super().__init__(is_negative=param.kind is ParamKind.prompt_negative, parent=parent)
line_count = (
settings.prompt_line_count
if param.kind is ParamKind.prompt_positive
else TextPromptWidget._line_count
)
super().__init__(
is_negative=param.kind is ParamKind.prompt_negative,
line_count=line_count,
parent=parent,
)
assert isinstance(param.default, str)
self.param = param

Expand All @@ -257,6 +267,7 @@ def __init__(self, param: CustomParam, parent: QWidget | None = None):
)
self.text = param.default
self.text_changed.connect(self.value_changed)
settings.changed.connect(self.update_settings)

@property
def value(self):
Expand All @@ -266,6 +277,10 @@ def value(self):
def value(self, value: str):
self.text = value

def update_settings(self, key: str, value):
if key == "prompt_line_count" and self.param.kind is ParamKind.prompt_positive:
self.line_count = value


class ChoiceParamWidget(QComboBox):
value_changed = pyqtSignal()
Expand Down Expand Up @@ -605,6 +620,12 @@ def __init__(self):
_("Open Web UI to create custom workflows"),
self._open_webui,
)
self._open_settings_button = _create_tool_button(
self._workflow_select_widgets,
theme.icon("settings"),
_("Open settings"),
self._show_settings,
)

self._workflow_edit_widgets = QWidget(self)
self._workflow_edit_widgets.setVisible(False)
Expand Down Expand Up @@ -669,6 +690,7 @@ def __init__(self):
select_layout.addWidget(self._save_workflow_button)
select_layout.addWidget(self._delete_workflow_button)
select_layout.addWidget(self._open_webui_button)
select_layout.addWidget(self._open_settings_button)
self._workflow_select_widgets.setLayout(select_layout)
edit_layout = QHBoxLayout()
edit_layout.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -698,12 +720,16 @@ def __init__(self):
self._layout.addWidget(self._live_preview, stretch=5)
self.setLayout(self._layout)

settings.changed.connect(self._update_current_workflow)
self._update_ui()

def _update_layout(self):
stretch = 1 if self._outputs.is_visible else 0
self._layout.setStretchFactor(self._outputs, stretch)

def _show_settings(self):
Krita.instance().action("ai_diffusion_settings").trigger()

@property
def model(self):
return self._model
Expand Down

0 comments on commit 995e404

Please sign in to comment.