From 88e979e566ce91d1b4e47a0fdc9e584b6340807a Mon Sep 17 00:00:00 2001 From: 0xMRTT <0xMRTT@proton.me> Date: Sun, 7 May 2023 13:55:38 +0200 Subject: [PATCH] src: add doc for getting a token --- src/main.py | 34 ++++++++++++++++++++++++---------- src/window.blp | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/main.py b/src/main.py index 2ba4f35..c803a99 100644 --- a/src/main.py +++ b/src/main.py @@ -41,6 +41,16 @@ import re import unicodedata from time import gmtime, strftime +class ProvidersEnum(Enum): + STABLE_DIFFUSION = 0 + OPENAI = 1 + WAIFU_DIFFUSION = 2 + OPENJOURNEY = 3 + NITRO_DIFFUSION = 4 + ANALOG_DIFFUSION = 5 + PORTRAIT_PLUS = 6 + ANYTHING = 7 + class ImaginerApplication(Adw.Application): """The main application singleton class.""" @@ -57,6 +67,7 @@ class ImaginerApplication(Adw.Application): self.create_action("imagine", self.on_imagine_action, ["Return"]) self.create_action("choose_output", self.on_file_chooser, ["s"]) self.create_action("new_window", self.on_new_window_action, ["n"]) + self.create_action("open_doc", self.on_open_doc_action) def on_quit_action(self, action, _): """Callback for the app.quit action.""" @@ -93,6 +104,19 @@ class ImaginerApplication(Adw.Application): response = requests.post(url, headers=headers, json=payload) return response.content + def on_open_doc_action(self, action, _): + """Callback for the app.open_doc action.""" + url = "https://imaginer.codeberg.page/help/" + + provider = self.win.provider.props.selected + + if provider == ProvidersEnum.OPENAI.value: + url += "openai.html" + else: + url += "huggingface.html" + + GLib.spawn_command_line_async(f"xdg-open {url}") + def on_file_chooser(self, widget, _): """Callback for the app.choose_output action.""" self.file_chooser.show() @@ -153,16 +177,6 @@ class ImaginerApplication(Adw.Application): self.provider = self.win.provider.props.selected - class ProvidersEnum(Enum): - STABLE_DIFFUSION = 0 - OPENAI = 1 - WAIFU_DIFFUSION = 2 - OPENJOURNEY = 3 - NITRO_DIFFUSION = 4 - ANALOG_DIFFUSION = 5 - PORTRAIT_PLUS = 6 - ANYTHING = 7 - prompt = self.win.prompt.get_text() negative_prompt = self.win.negative_prompt.get_text() self.token = self.win.token.get_text() diff --git a/src/window.blp b/src/window.blp index cafd816..04063cb 100644 --- a/src/window.blp +++ b/src/window.blp @@ -86,6 +86,18 @@ template ImaginerWindow : Adw.ApplicationWindow { Adw.PasswordEntryRow token { title: _("API Token"); + + [suffix] + MenuButton menu_duplicate { + valign: center; + tooltip-text: _("How to get a token"); + icon-name: "info-symbolic"; + popover: popover_info_token; + + styles [ + "flat", + ] + } } } @@ -150,3 +162,13 @@ menu main_menu { Gtk.StringList provider_model{ strings [_("Stable Diffusion"), _("OpenAI"), _("Waifu Diffusion"), _("Open Journey"), _("Nitro Diffusion"), _("Analog Diffusion"), _("Portrait Plus"), _("Anything")] } + +Popover popover_info_token { + Button { + label: _("Open the documentation to see how to get a token"); + action-name: "app.open_doc"; + styles [ + "flat", + ] + } +} \ No newline at end of file