Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Info to clipboard #1421

Merged
merged 6 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions ai_diffusion/ui/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,22 @@ def add(self, job: Job):
"seed": _("Seed"),
}

def _job_info(self, params: JobParams):
def _job_info(self, params: JobParams, tooltip_header: bool = True):
title = params.name if params.name != "" else "<no prompt>"
if len(title) > 70:
title = title[:66] + "..."
if params.strength != 1.0:
title = f"{title} @ {params.strength*100:.0f}%"
style = Styles.list().find(params.style)
strings: list[str | list[str]] = [
title + "\n",
_("Click to toggle preview, double-click to apply."),
"",
]
strings: list[str | list[str]] = (
[
title + "\n",
_("Click to toggle preview, double-click to apply."),
"",
]
if tooltip_header
else []
)
for key, value in params.metadata.items():
if key == "style" and style:
value = style.name
Expand All @@ -172,7 +176,9 @@ def _job_info(self, params: JobParams):
if isinstance(value, list) and isinstance(value[0], dict):
value = "\n ".join((f"{v.get('name')} ({v.get('strength')})" for v in value))
s = f"{self._job_info_translations.get(key, key)}: {value}"
strings.append(wrap_text(s, 80, subsequent_indent=" "))
if tooltip_header:
s = wrap_text(s, 80, subsequent_indent=" ")
strings.append(s)
strings.append(_("Seed") + f": {params.seed}")
return "\n".join(flatten(strings))

Expand Down Expand Up @@ -340,6 +346,7 @@ def _show_context_menu(self, pos: QPoint):
if job is None or Styles.list().find(job.params.style) is None:
style_action.setEnabled(False)
menu.addAction(_("Copy Seed"), self._copy_seed)
menu.addAction(_("Info to Clipboard"), self._info_to_clipboard)
menu.addSeparator()
save_action = ensure(menu.addAction(_("Save Image"), self._save_image))
if self._model.document.filename == "":
Expand Down Expand Up @@ -381,6 +388,10 @@ def _copy_seed(self):
self._model.fixed_seed = True
self._model.seed = job.params.seed

def _info_to_clipboard(self):
if (job := self.selected_job) and (clipboard := QGuiApplication.clipboard()):
clipboard.setText(self._job_info(job.params, tooltip_header=False))

def _save_image(self):
items = self.selectedItems()
for item in items:
Expand Down
Loading