sync: lora gui

This commit is contained in:
raiots 2023-05-26 16:19:09 +08:00
parent 3e67606b76
commit 259ab2ada3
1 changed files with 18 additions and 51 deletions

View File

@ -4,68 +4,35 @@ import PySimpleGUI as sg
import os.path
# First the window layout in 2 columns
sg.theme('DarkAmber') # Add a touch of color
file_list_column = [
panel_view_column = [
[
sg.Text("Image Folder"),
sg.In(size=(25, 1), enable_events=True, key="-FOLDER-"),
sg.FolderBrowse(),
sg.Text("字符识别结果:", font=("微软雅黑", 20), size=(23, 1))
],
[
sg.Listbox(
values=[], enable_events=True, size=(40, 20), key="-FILE LIST-"
)
],
]
# For now will only show the name of the file that was chosen
image_viewer_column = [
[sg.Text("Choose an image from list on left:")],
[sg.Text(size=(40, 1), key="-TOUT-")],
[sg.Image(key="-IMAGE-")],
]
# ----- Full layout -----
layout = [
[
sg.Column(file_list_column),
sg.VSeperator(),
sg.Column(image_viewer_column),
sg.Text("未识别", key="-CHARACTER-", font=("微软雅黑", 25), size=(5, 1))
]
]
window = sg.Window("Image Viewer", layout)
# ----- Full layout -----
layout = [[sg.VPush()],
[
sg.Push(),
sg.Column(panel_view_column, vertical_alignment="center", justification="center"),
sg.Push(),
],
[sg.VPush()],
]
window = sg.Window("Lora 回传显示模块", layout, resizable=True, size=(500, 300), finalize=True)
# Run the Event Loop
while True:
event, values = window.read()
if event == "Exit" or event == sg.WIN_CLOSED:
break
# Folder name was filled in, make a list of files in the folder
if event == "-FOLDER-":
folder = values["-FOLDER-"]
try:
# Get list of files in folder
file_list = os.listdir(folder)
except:
file_list = []
fnames = [
f
for f in file_list
if os.path.isfile(os.path.join(folder, f))
and f.lower().endswith((".png", ".gif"))
]
window["-FILE LIST-"].update(fnames)
elif event == "-FILE LIST-": # A file was chosen from the listbox
try:
filename = os.path.join(
values["-FOLDER-"], values["-FILE LIST-"][0]
)
window["-TOUT-"].update(filename)
window["-IMAGE-"].update(filename=filename)
except:
pass
window.close()