Skip to content

Commit

Permalink
Fix Lora strength not being loaded in Style settings if it's the firs…
Browse files Browse the repository at this point in the history
…t Lora of all available

- strength widget was only updated if the lora name didn't match
  • Loading branch information
Acly committed Nov 20, 2024
1 parent 6a4aeeb commit 482bc27
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions ai_diffusion/ui/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ class LoraItem(QWidget):
changed = pyqtSignal()
removed = pyqtSignal(QWidget)

_current: File | None = None

def __init__(self, name_filter: str, parent=None):
super().__init__(parent)
self.setContentsMargins(0, 0, 0, 0)

self._loras = FileFilter(root.files.loras)
self._loras.available_only = True
self._loras.name_prefix = name_filter
self._current: File | None = None

completer = QCompleter(self._loras)
completer.setCaseSensitivity(Qt.CaseSensitivity.CaseInsensitive)
Expand Down Expand Up @@ -217,22 +216,31 @@ def _set_triggers(self):
root.files.loras.set_meta(self._current, "lora_triggers", value)

def _set_default_strength(self):
value = self._strength.value() / 100
if self._current and self._current.meta("lora_strength") != value:
root.files.loras.set_meta(self._current, "lora_strength", value)
if self._current and self._current.meta("lora_strength") != self.strength:
root.files.loras.set_meta(self._current, "lora_strength", self.strength)
self._update()

def remove(self):
self.removed.emit(self)

@property
def strength(self):
return self._strength.value() / 100

@strength.setter
def strength(self, value: float):
value_int = int(value * 100)
if value_int != self._strength.value():
self._strength.setValue(value_int)

@property
def value(self):
if self._current is None:
return dict(name="", strength=1.0)
return dict(name=self._current.id, strength=self._strength.value() / 100)
return dict(name=self._current.id, strength=self.strength)

@value.setter
def value(self, v):
def value(self, v: dict):
new_value = root.files.loras.find(v["name"]) or File.remote(v["name"])
if self._current is None or new_value.id != self._current.id:
self._current = new_value
Expand All @@ -241,8 +249,8 @@ def value(self, v):
self._select.setCurrentIndex(index)
else:
self._select.setEditText(self._current.name)
self._strength.setValue(int(v["strength"] * 100))
self._update()
self.strength = v["strength"]
self._update()

def apply_filter(self, name_filter: str):
with SignalBlocker(self._select):
Expand Down

0 comments on commit 482bc27

Please sign in to comment.