mirror of
https://github.com/Sygil-Dev/sygil-webui.git
synced 2024-12-14 22:13:41 +03:00
add gallery window
This commit is contained in:
parent
064a7e9554
commit
46ea2be0db
@ -51,7 +51,7 @@ def get_user_settings_from_config():
|
||||
with open(path_to_user_config) as f:
|
||||
user_settings = yaml.safe_load(f)
|
||||
settings.update(user_settings)
|
||||
# regardless, return settings
|
||||
# regardless, return settings as dict
|
||||
return settings
|
||||
|
||||
def save_user_settings_to_config(settings):
|
||||
@ -63,10 +63,14 @@ def save_user_settings_to_config(settings):
|
||||
path_to_assets = "webui/flet/assets"
|
||||
path_to_uploads = "webui/flet/uploads"
|
||||
|
||||
# creates blank image (to do: take size as arg)
|
||||
def create_blank_image():
|
||||
img = Image.new('RGBA',(512,512),(0,0,0,0))
|
||||
return img
|
||||
|
||||
# takes name of image
|
||||
# returns dict
|
||||
# name of image : image handle
|
||||
def get_image_from_uploads(name):
|
||||
path_to_image = os.path.join(path_to_uploads, name)
|
||||
if os.path.exists(path_to_image):
|
||||
@ -77,6 +81,31 @@ def get_image_from_uploads(name):
|
||||
return {name:None}
|
||||
|
||||
|
||||
# takes name of gallery as arg ('assets','output','uploads')
|
||||
# returns list of dicts
|
||||
# name of image:
|
||||
# 'img_path' : path_to_image
|
||||
# 'info_path' : path_to_yaml
|
||||
def get_gallery_images(gallery_name):
|
||||
path_to_gallery = None
|
||||
if gallery_name == 'uploads':
|
||||
path_to_gallery = path_to_uploads
|
||||
else:
|
||||
log_message(f'gallery not found: "{gallery_name}"')
|
||||
return None
|
||||
images = []
|
||||
files = os.listdir(path_to_gallery)
|
||||
for f in files:
|
||||
if f.endswith(('.jpg','.jpeg','.png')):
|
||||
path_to_file = os.path.join(path_to_gallery,f)
|
||||
images.append({f:{'img_path':path_to_file}})
|
||||
if f.endswith(('.yaml')):
|
||||
path_to_file = os.path.join(path_to_gallery,f)
|
||||
images.append({f:{'info_path':path_to_file}})
|
||||
#pprint(images)
|
||||
return images
|
||||
|
||||
|
||||
# textual inversion
|
||||
textual_inversion_grid_row_list = [
|
||||
'model', 'medium', 'artist', 'trending', 'movement', 'flavors', 'techniques', 'tags',
|
||||
|
@ -121,20 +121,86 @@ def main(page: ft.Page):
|
||||
page.update()
|
||||
|
||||
def open_gallery_window(e):
|
||||
init_gallery_display_images()
|
||||
page.dialog = gallery_window
|
||||
gallery_window.open = True
|
||||
page.update()
|
||||
|
||||
def get_gallery_images(gallery_name):
|
||||
return flet_utils.get_gallery_images(gallery_name)
|
||||
|
||||
def init_gallery_display_images():
|
||||
gallery = gallery_window.current_gallery
|
||||
for i in range(len(gallery)):
|
||||
image = gallery[i]
|
||||
image_name = list(image.keys())[0]
|
||||
image_path = image[image_name]['img_path']
|
||||
image_data = None
|
||||
if 'info_path' in image[image_name]:
|
||||
image_data = image[image_name]['info_path']
|
||||
gallery_display.controls[0].controls.append(
|
||||
ft.Image(
|
||||
src = image_path,
|
||||
tooltip = image_name,
|
||||
gapless_playback = True,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
gallery_display = ft.Stack(
|
||||
[
|
||||
ft.Row(
|
||||
controls = None,
|
||||
wrap = False,
|
||||
scroll = 'always',
|
||||
expand = True,
|
||||
),
|
||||
ft.Column(
|
||||
controls = [
|
||||
ft.Row(
|
||||
controls = [
|
||||
ft.IconButton(
|
||||
height = page.height * 0.75,
|
||||
icon_size = 50,
|
||||
content = ft.Icon(ft.icons.ARROW_CIRCLE_LEFT_OUTLINED),
|
||||
tooltip = 'last image',
|
||||
on_click = None,
|
||||
),
|
||||
ft.IconButton(
|
||||
height = page.height * 0.75,
|
||||
icon_size = 50,
|
||||
content = ft.Icon(ft.icons.ARROW_CIRCLE_RIGHT_OUTLINED),
|
||||
tooltip = 'next image',
|
||||
on_click = None,
|
||||
),
|
||||
],
|
||||
expand = True,
|
||||
alignment = 'spaceBetween',
|
||||
),
|
||||
],
|
||||
alignment = 'center',
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
gallery_window = GalleryWindow(
|
||||
title = ft.Text('Gallery'),
|
||||
content = ft.Row(
|
||||
controls = [
|
||||
ft.Text('Under Construction.'),
|
||||
ft.Container(
|
||||
width = page.width * 0.75,
|
||||
height = page.height * 0.75,
|
||||
),
|
||||
],
|
||||
content = ft.Container(
|
||||
width = page.width * 0.5,
|
||||
content = ft.Tabs(
|
||||
selected_index = 0,
|
||||
animation_duration = 300,
|
||||
tabs = [
|
||||
ft.Tab(
|
||||
text = "Uploads",
|
||||
content = gallery_display,
|
||||
),
|
||||
ft.Tab(
|
||||
text = "Output",
|
||||
content = gallery_display,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions = [
|
||||
ft.ElevatedButton(
|
||||
@ -151,6 +217,10 @@ def main(page: ft.Page):
|
||||
actions_alignment="end",
|
||||
)
|
||||
|
||||
gallery_window.uploads = get_gallery_images('uploads')
|
||||
gallery_window.current_gallery = gallery_window.uploads
|
||||
gallery_window.current_image_position = 0
|
||||
|
||||
|
||||
# upload window ######################################################
|
||||
def close_upload_window(e):
|
||||
|
Loading…
Reference in New Issue
Block a user