2022-08-30 13:37:16 +03:00
|
|
|
from os import path
|
2022-08-29 12:13:34 +03:00
|
|
|
|
2022-08-30 13:37:16 +03:00
|
|
|
def readTextFile(*args):
|
2022-08-30 16:33:27 +03:00
|
|
|
dir = path.dirname(__file__)
|
|
|
|
entry = path.join(dir, *args)
|
2022-08-30 13:37:16 +03:00
|
|
|
with open(entry, "r", encoding="utf8") as f:
|
|
|
|
data = f.read()
|
|
|
|
return data
|
2022-08-29 17:05:28 +03:00
|
|
|
|
2022-08-30 13:37:16 +03:00
|
|
|
def css(opt):
|
|
|
|
styling = readTextFile("css", "styles.css")
|
|
|
|
if not opt.no_progressbar_hiding:
|
|
|
|
styling += readTextFile("css", "no_progress_bar.css")
|
|
|
|
return styling
|
2022-08-29 17:05:28 +03:00
|
|
|
|
2022-08-30 13:37:16 +03:00
|
|
|
def js(opt):
|
|
|
|
data = readTextFile("js", "index.js")
|
|
|
|
data = "(z) => {" + data + "; return z ?? [] }"
|
|
|
|
return data
|
2022-08-29 17:05:28 +03:00
|
|
|
|
2022-08-30 13:37:16 +03:00
|
|
|
# Wrap the typical SD method call into async closure for ease of use
|
|
|
|
# If you call frontend method without wrapping
|
|
|
|
# DONT FORGET to bind input argument if you need it: SD.with(x)
|
|
|
|
def w(sd_method_call):
|
|
|
|
return f"async (x) => {{ return await SD.with(x).{sd_method_call} ?? x ?? []; }}"
|
2022-08-29 01:40:48 +03:00
|
|
|
|
2022-08-30 13:37:16 +03:00
|
|
|
def js_move_image(from_id, to_id):
|
|
|
|
return w(f"moveImageFromGallery('{from_id}', '{to_id}')")
|
2022-08-29 01:40:48 +03:00
|
|
|
|
2022-08-30 13:37:16 +03:00
|
|
|
def js_copy_to_clipboard(from_id):
|
|
|
|
return w(f"copyImageFromGalleryToClipboard('{from_id}')")
|
2022-08-29 01:40:48 +03:00
|
|
|
|
2022-08-30 16:33:27 +03:00
|
|
|
def js_painterro_launch(to_id):
|
|
|
|
return w(f"Painterro.init('{to_id}')")
|
2022-08-29 01:40:48 +03:00
|
|
|
|
2022-08-30 22:18:29 +03:00
|
|
|
def js_img2img_submit(prompt_row_id):
|
|
|
|
return w(f"clickFirstVisibleButton('{prompt_row_id}')")
|