-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.py
More file actions
327 lines (294 loc) · 15.9 KB
/
Copy pathui.py
File metadata and controls
327 lines (294 loc) · 15.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
"""ui.py — builds the DPG window, dialogs, and three-column table layout."""
import os
import dearpygui.dearpygui as dpg
import state
import config
import toolbar
import prompt_io
import i18n
import colorwidget
import underlay as _underlay
import panels
import native_dialog
def _on_underlay_fallback(sender, app_data):
"""DPG fallback callback for underlay_dlg (used when tkinter is unavailable)."""
selections = app_data.get("selections", {})
path = next(iter(selections.values())) if selections else app_data.get("file_path_name", "")
if not path or not os.path.isfile(path):
return
_underlay.load(path)
panels.refresh_underlay_panel()
import draw
draw.redraw()
def _open_file(s, u):
native_dialog.open_file(
title=i18n.t("dialog_open_title"),
filetypes=[("JSON", "*.json"), ("Text", "*.txt"), ("All files", "*")],
initial_dir=config.PROMPTS_DIR,
on_done=prompt_io.open_file,
fallback_tag="open_dlg",
)
def _save_file(s, u):
native_dialog.save_file(
title=i18n.t("dialog_save_title"),
filetypes=[("JSON", "*.json"), ("All files", "*")],
initial_dir=config.PROMPTS_DIR,
default_ext=".json",
default_name="prompt.json",
on_done=prompt_io.save_file,
fallback_tag="save_dlg",
)
def refresh_ui_strings() -> None:
"""Update all tagged static UI items to the current language."""
text_tags = {
"ui_text_resolution": "toolbar_resolution",
"ui_text_layers_title": "panel_layers_title",
"ui_text_props_title": "panel_props_title",
"ui_text_high_label": "field_high_level",
"ui_text_style_type": "field_style_type",
"ui_text_style_aesthetics": "field_style_aesthetics",
"ui_text_style_lighting": "field_style_lighting",
"ui_text_style_photo": "field_style_photo",
"ui_text_style_art_style": "field_style_art_style",
"ui_text_style_medium": "field_style_medium",
"ui_text_style_palette": "field_style_palette",
"ui_text_bg_label": "field_background",
}
for tag, key in text_tags.items():
if dpg.does_item_exist(tag):
dpg.set_value(tag, i18n.t(key))
label_tags = {
"btn_new": "toolbar_btn_new",
"btn_copy": "toolbar_btn_copy",
"btn_open": "toolbar_btn_open",
"btn_save": "toolbar_btn_save",
"btn_undo": "toolbar_btn_undo",
"btn_add_text": "toolbar_btn_add_text",
"btn_add_obj": "toolbar_btn_add_obj",
"ui_style_header": "field_style",
}
for tag, key in label_tags.items():
if dpg.does_item_exist(tag):
dpg.set_item_label(tag, i18n.t(key))
if dpg.does_item_exist("status_bar"):
dpg.set_value("status_bar", i18n.t("status_initial"))
def _tooltip(parent, text: str) -> None:
with dpg.tooltip(parent):
dpg.add_text(text)
def build_ui() -> None:
# ── Color picker modal (pre-built, shared by all palette buttons) ─────────
colorwidget.build_ui()
# ── Overwrite confirmation dialog (pre-built, show/hide) ──────────────────
with dpg.window(
tag="overwrite_dlg",
label=i18n.t("dialog_overwrite_title"),
show=False, no_close=True,
width=340, height=115,
no_move=True, no_resize=True, no_collapse=True,
):
dpg.add_text("", tag="overwrite_dlg_text", wrap=320)
dpg.add_separator()
with dpg.group(horizontal=True):
dpg.add_button(
tag="overwrite_dlg_yes", label=i18n.t("dialog_overwrite_yes"),
width=100,
callback=lambda s, u: prompt_io.confirm_overwrite(),
)
dpg.add_button(
label=i18n.t("dialog_overwrite_no"), width=100,
callback=lambda s, u: dpg.hide_item("overwrite_dlg"),
)
# ── File dialogs ──────────────────────────────────────────────────────────
with dpg.file_dialog(
tag="open_dlg",
label=i18n.t("dialog_open_title"),
callback=prompt_io.on_open_selected,
cancel_callback=lambda s, a: None,
default_path=config.PROMPTS_DIR,
width=700, height=440,
show=False, modal=True,
):
dpg.add_file_extension(".*", color=(200, 200, 200, 255), custom_text=i18n.t("file_filter_all"))
dpg.add_file_extension(".json", color=(100, 220, 100, 255), custom_text=i18n.t("file_filter_json"))
dpg.add_file_extension(".txt", color=(220, 200, 80, 255), custom_text=i18n.t("file_filter_txt"))
with dpg.file_dialog(
tag="save_dlg",
label=i18n.t("dialog_save_title"),
callback=prompt_io.on_save_selected,
cancel_callback=lambda s, a: None,
default_path=config.PROMPTS_DIR,
default_filename="prompt.json",
width=700, height=440,
show=False, modal=True,
):
dpg.add_file_extension(".*", color=(200, 200, 200, 255), custom_text=i18n.t("file_filter_all"))
dpg.add_file_extension(".json", color=(100, 220, 100, 255), custom_text=i18n.t("file_filter_json"))
with dpg.file_dialog(
tag="underlay_dlg",
label=i18n.t("underlay_section"),
callback=_on_underlay_fallback,
cancel_callback=lambda s, a: None,
width=700, height=440,
show=False, modal=True,
):
dpg.add_file_extension(".*", color=(200, 200, 200, 255), custom_text=i18n.t("file_filter_all"))
dpg.add_file_extension(".png", color=(100, 200, 255, 255), custom_text=i18n.t("file_filter_image"))
dpg.add_file_extension(".jpg", color=(100, 200, 255, 255), custom_text=i18n.t("file_filter_image"))
dpg.add_file_extension(".jpeg", color=(100, 200, 255, 255), custom_text=i18n.t("file_filter_image"))
# ── Main window ───────────────────────────────────────────────────────────
with dpg.window(
tag="main",
label="Ideogram4 Layout Editor",
width=config.INIT_W, height=config.INIT_H,
no_resize=False, no_move=False, no_title_bar=True,
no_scrollbar=True, no_scroll_with_mouse=True,
):
# ── Toolbar (fixed child_window — never scrolls away) ─────────────────
with dpg.child_window(
tag="toolbar_panel",
height=36,
border=False,
no_scrollbar=True,
no_scroll_with_mouse=True,
):
with dpg.group(horizontal=True):
dpg.add_text(i18n.t("toolbar_resolution"), tag="ui_text_resolution")
dpg.add_combo(
state.PRESET_NAMES,
default_value=state.PRESET_NAMES[3],
width=185,
callback=toolbar.on_preset,
)
dpg.add_separator()
btn_new = dpg.add_button(tag="btn_new", label=i18n.t("toolbar_btn_new"), callback=toolbar.new_document)
_tooltip(btn_new, "New document (clear all)")
btn_undo = dpg.add_button(tag="btn_undo", label=i18n.t("toolbar_btn_undo"), callback=lambda s, u: __import__("history").undo())
_tooltip(btn_undo, "Undo (Ctrl+Z)")
btn_copy = dpg.add_button(tag="btn_copy", label=i18n.t("toolbar_btn_copy"), callback=prompt_io.copy_to_clipboard)
_tooltip(btn_copy, "Copy JSON to clipboard")
btn_open = dpg.add_button(tag="btn_open", label=i18n.t("toolbar_btn_open"), callback=_open_file)
_tooltip(btn_open, "Open prompt file")
btn_save = dpg.add_button(tag="btn_save", label=i18n.t("toolbar_btn_save"), callback=_save_file)
_tooltip(btn_save, "Save prompt")
dpg.add_separator()
dpg.add_text("Lang:")
dpg.add_combo(
i18n.AVAILABLE_LANGS,
default_value=i18n.get_lang(),
width=55,
callback=toolbar.on_lang_change,
)
dpg.add_separator()
# ── Content area (fills viewport minus status bar) ────────────────────
with dpg.child_window(
tag="content_area",
height=-26,
border=False,
no_scrollbar=True,
no_scroll_with_mouse=True,
):
# ── Three-panel table ─────────────────────────────────────────────
with dpg.table(
tag="main_table",
resizable=True, borders_innerV=True,
header_row=False,
width=-1, height=-1,
policy=dpg.mvTable_SizingStretchProp,
):
dpg.add_table_column(tag="col_left", init_width_or_weight=0.17, width_stretch=True)
dpg.add_table_column(tag="col_mid", init_width_or_weight=0.50, width_stretch=True)
dpg.add_table_column(tag="col_right", init_width_or_weight=0.33, width_stretch=True)
with dpg.table_row():
# ── LEFT: layer panel ─────────────────────────────────────
with dpg.table_cell():
with dpg.child_window(tag="panel_left", width=-1, height=-1, border=True):
dpg.add_text(i18n.t("panel_layers_title"), tag="ui_text_layers_title", color=(200, 200, 100, 255))
dpg.add_separator()
with dpg.group(horizontal=True):
btn_at = dpg.add_button(tag="btn_add_text", label=i18n.t("toolbar_btn_add_text"), width=32, callback=toolbar.add_text)
_tooltip(btn_at, "Add text layer")
btn_ao = dpg.add_button(tag="btn_add_obj", label=i18n.t("toolbar_btn_add_obj"), width=32, callback=toolbar.add_obj)
_tooltip(btn_ao, "Add object layer")
dpg.add_separator()
with dpg.child_window(tag="layer_list", width=-1, height=-150, border=False):
pass
with dpg.child_window(tag="underlay_panel", width=-1, height=140,
border=False, no_scrollbar=True):
pass
# ── MIDDLE: canvas + global fields ────────────────────────
with dpg.table_cell():
with dpg.child_window(
tag="panel_mid",
width=-1, height=-1,
border=False, no_scrollbar=True,
):
dpg.add_drawlist(tag="canvas_dl", width=400, height=10)
with dpg.child_window(
tag="splitter_h",
width=-1, height=6,
border=False,
no_scrollbar=True, no_scroll_with_mouse=True,
):
pass
with dpg.child_window(
tag="fields_panel",
width=-1, height=215,
border=False,
):
dpg.add_text(i18n.t("field_high_level"), tag="ui_text_high_label")
dpg.add_input_text(
tag="inp_high", width=-1,
multiline=True, height=52, default_value="",
)
with dpg.collapsing_header(
label=i18n.t("field_style"),
tag="ui_style_header",
default_open=True,
):
dpg.add_text(i18n.t("field_style_type"), tag="ui_text_style_type")
dpg.add_radio_button(
["art", "photo"],
tag="style_mode_radio",
default_value="art",
horizontal=True,
callback=toolbar.on_style_mode_change,
)
dpg.add_text(i18n.t("field_style_aesthetics"), tag="ui_text_style_aesthetics")
dpg.add_input_text(tag="inp_style_aesthetics", width=-1, default_value="")
dpg.add_text(i18n.t("field_style_lighting"), tag="ui_text_style_lighting")
dpg.add_input_text(tag="inp_style_lighting", width=-1, default_value="")
# photo field — shown only in photo mode (before medium)
dpg.add_text(i18n.t("field_style_photo"), tag="ui_text_style_photo", show=False)
dpg.add_input_text(tag="inp_style_photo", width=-1, default_value="", show=False)
dpg.add_text(i18n.t("field_style_medium"), tag="ui_text_style_medium")
dpg.add_input_text(tag="inp_style_medium", width=-1, default_value="")
# art_style field — shown only in art mode (after medium)
dpg.add_text(i18n.t("field_style_art_style"), tag="ui_text_style_art_style")
dpg.add_input_text(tag="inp_style_art_style", width=-1, default_value="")
dpg.add_text(i18n.t("field_style_palette"), tag="ui_text_style_palette")
with dpg.group(horizontal=True) as _style_pal_group:
dpg.add_input_text(tag="inp_style_palette", width=-30, default_value="")
colorwidget.build_palette_button(
parent=_style_pal_group,
target_input_tag="inp_style_palette",
)
dpg.add_text(i18n.t("field_background"), tag="ui_text_bg_label")
dpg.add_input_text(
tag="inp_bg", width=-1,
multiline=True, height=40, default_value="",
)
# ── RIGHT: properties ─────────────────────────────────────
with dpg.table_cell():
with dpg.child_window(tag="panel_right", width=-1, height=-1, border=True):
dpg.add_text(i18n.t("panel_props_title"), tag="ui_text_props_title", color=(200, 200, 100, 255))
dpg.add_separator()
with dpg.child_window(
tag="props_group",
width=-1, height=-1,
border=False,
):
dpg.add_text(i18n.t("props_no_selection"), color=(160, 160, 160, 255))
dpg.add_text(
tag="status_bar",
default_value=i18n.t("status_initial"),
)