Repository navigation
Expand file tree
/
Copy pathGUI.py
More file actions
378 lines (288 loc) · 13.6 KB
/
Copy pathGUI.py
File metadata and controls
378 lines (288 loc) · 13.6 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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
"""Desktop Assistant - Swiss-style GUI by Hannan Mudassar.
Layout
blue sidebar (brand mark, navigation, author) | yellow stripe | light content area
with a dark terminal-style status strip along the bottom.
Colours come from the brand banner: blue #2B4CFF and yellow #FFD84D.
"""
import base64
import io
import threading
import customtkinter as ctk
from customtkinter import CTkImage
from PIL import Image, ImageTk
from fileTask import mAFolder, mAFile, multipleFinFol
from chatBot import askAI
from brand import MARK_WHITE_B64, ICON_B64
# ---------------------------------------------------------------------------
# Design tokens
# ---------------------------------------------------------------------------
BRAND = "#2B4CFF" # banner blue
BRAND_DARK = "#1F38D6" # hover state of the blue
SIGNAL = "#FFD84D" # banner yellow
BG = "#F4F5F8" # page background
INK = "#0B0D14" # text and heavy rules
MUTED = "#545A6B" # captions
PANEL = "#E6E9F2"
WHITE = "#FFFFFF"
SOFT_WHITE = "#C9D2FF" # secondary text on the blue sidebar
DISPLAY_FONT = "Arial Black"
BODY_FONT = "Arial"
MONO_FONT = "Consolas"
SIDEBAR_WIDTH = 270
STRIPE_WIDTH = 12
SIDEBAR_PAD = 28
PAGE_PAD = 40
ctk.set_appearance_mode("light")
ctk.set_default_color_theme("blue")
app = ctk.CTk()
app.geometry("1120x740")
app.minsize(1000, 700)
app.title("Desktop Assistant")
app.configure(fg_color=BG)
# Fonts must be created after the root window exists
f_display_xl = ctk.CTkFont(family=DISPLAY_FONT, size=30)
f_display_md = ctk.CTkFont(family=DISPLAY_FONT, size=22)
f_heading = ctk.CTkFont(family=BODY_FONT, size=20, weight="bold")
f_body = ctk.CTkFont(family=BODY_FONT, size=14)
f_body_bold = ctk.CTkFont(family=BODY_FONT, size=14, weight="bold")
f_mono = ctk.CTkFont(family=MONO_FONT, size=13)
f_mono_bold = ctk.CTkFont(family=MONO_FONT, size=13, weight="bold")
f_mono_small = ctk.CTkFont(family=MONO_FONT, size=11)
# ---------------------------------------------------------------------------
# Brand mark
# ---------------------------------------------------------------------------
def load_image(b64_data):
return Image.open(io.BytesIO(base64.b64decode(b64_data))).convert("RGBA")
mark_image = load_image(MARK_WHITE_B64)
mark = CTkImage(light_image=mark_image, dark_image=mark_image, size=(88, 88))
try:
# CustomTkinter sets its own icon after ~200 ms on Windows, so set ours later
icon_photo = ImageTk.PhotoImage(load_image(ICON_B64))
app.after(300, lambda: app.iconphoto(False, icon_photo))
except Exception:
pass
# ---------------------------------------------------------------------------
# Window frame: sidebar | stripe | main
# ---------------------------------------------------------------------------
app.grid_columnconfigure(0, weight=0)
app.grid_columnconfigure(1, weight=0)
app.grid_columnconfigure(2, weight=1)
app.grid_rowconfigure(0, weight=1)
sidebar = ctk.CTkFrame(app, width=SIDEBAR_WIDTH, fg_color=BRAND, corner_radius=0)
sidebar.grid(row=0, column=0, sticky="ns")
sidebar.grid_propagate(False)
sidebar.grid_columnconfigure(0, weight=1)
sidebar.grid_rowconfigure(4, weight=1)
stripe = ctk.CTkFrame(app, width=STRIPE_WIDTH, fg_color=SIGNAL, corner_radius=0)
stripe.grid(row=0, column=1, sticky="ns")
main = ctk.CTkFrame(app, fg_color=BG, corner_radius=0)
main.grid(row=0, column=2, sticky="nsew")
main.grid_columnconfigure(0, weight=1)
main.grid_rowconfigure(2, weight=1)
# ---------------------------------------------------------------------------
# Sidebar: brand, navigation, author
# ---------------------------------------------------------------------------
ctk.CTkLabel(sidebar, text="", image=mark, fg_color="transparent").grid(
row=0, column=0, sticky="w", padx=SIDEBAR_PAD, pady=(SIDEBAR_PAD + 6, 18))
ctk.CTkLabel(
sidebar, text="DESKTOP\nASSISTANT", font=f_display_md, text_color=WHITE,
justify="left", anchor="w",
).grid(row=1, column=0, sticky="w", padx=SIDEBAR_PAD)
ctk.CTkLabel(
sidebar, text="v2.0", font=f_mono_bold, text_color=SIGNAL, anchor="w",
).grid(row=2, column=0, sticky="w", padx=SIDEBAR_PAD, pady=(8, 0))
nav = ctk.CTkFrame(sidebar, fg_color="transparent", corner_radius=0)
nav.grid(row=3, column=0, sticky="ew", pady=(44, 0))
NAV_INDENT = " "
def make_nav_button(text, key):
return ctk.CTkButton(
nav, text=NAV_INDENT + text, anchor="w", height=48, corner_radius=0,
font=f_mono_bold, fg_color="transparent", text_color=WHITE,
hover_color=BRAND_DARK, command=lambda: show_page(key),
)
files_nav = make_nav_button("// FILES & FOLDERS", "files")
files_nav.pack(fill="x")
chat_nav = make_nav_button("// AI CHAT", "chat")
chat_nav.pack(fill="x", pady=(2, 0))
author = ctk.CTkFrame(sidebar, fg_color="transparent", corner_radius=0)
author.grid(row=5, column=0, sticky="ew", padx=SIDEBAR_PAD, pady=(0, SIDEBAR_PAD))
ctk.CTkFrame(author, height=2, fg_color=WHITE, corner_radius=0).pack(fill="x", pady=(0, 14))
ctk.CTkLabel(author, text="$ whoami", font=f_mono_bold, text_color=SIGNAL, anchor="w").pack(anchor="w")
ctk.CTkLabel(author, text="Hannan Mudassar", font=f_body_bold, text_color=WHITE, anchor="w").pack(anchor="w", pady=(2, 0))
ctk.CTkLabel(author, text="github.com/hannann404", font=f_mono_small, text_color=SOFT_WHITE, anchor="w").pack(anchor="w", pady=(2, 0))
# ---------------------------------------------------------------------------
# Main: page heading, rule, content, status strip
# ---------------------------------------------------------------------------
head = ctk.CTkFrame(main, fg_color="transparent", corner_radius=0)
head.grid(row=0, column=0, sticky="ew", padx=PAGE_PAD, pady=(34, 20))
page_kicker = ctk.CTkLabel(head, text="", font=f_mono_bold, text_color=BRAND, anchor="w")
page_kicker.pack(anchor="w")
page_title = ctk.CTkLabel(head, text="", font=f_display_xl, text_color=INK, anchor="w")
page_title.pack(anchor="w", pady=(6, 0))
ctk.CTkFrame(main, height=3, fg_color=INK, corner_radius=0).grid(
row=1, column=0, sticky="ew", padx=PAGE_PAD)
content = ctk.CTkFrame(main, fg_color="transparent", corner_radius=0)
content.grid(row=2, column=0, sticky="nsew", padx=PAGE_PAD, pady=(28, 28))
content.grid_columnconfigure(0, weight=1)
content.grid_rowconfigure(0, weight=1)
# Terminal-style status strip. mAFolder and mAFile write their messages here.
status_bar = ctk.CTkFrame(main, height=46, fg_color=INK, corner_radius=0)
status_bar.grid(row=3, column=0, sticky="ew")
status_bar.pack_propagate(False)
ctk.CTkLabel(status_bar, text="$", font=f_mono_bold, text_color=SIGNAL).pack(side="left", padx=(PAGE_PAD, 10))
status_label = ctk.CTkLabel(status_bar, text="ready", font=f_mono, text_color="#E8EBF5", anchor="w")
status_label.pack(side="left", fill="x", expand=True)
def set_status(text):
status_label.configure(text=text)
# ---------------------------------------------------------------------------
# Shared widget helpers
# ---------------------------------------------------------------------------
def make_entry(parent, placeholder, height=42):
return ctk.CTkEntry(
parent, placeholder_text=placeholder, height=height, corner_radius=0,
border_width=2, border_color=INK, fg_color=WHITE, text_color=INK,
placeholder_text_color=MUTED, font=f_body,
)
def make_button(parent, text, command, height=46, width=140):
return ctk.CTkButton(
parent, text=text, command=command, height=height, width=width, corner_radius=0,
font=f_mono_bold, fg_color=BRAND, hover_color=BRAND_DARK, text_color=WHITE,
)
# ---------------------------------------------------------------------------
# Page 1: files and folders
# ---------------------------------------------------------------------------
files_page = ctk.CTkFrame(content, fg_color="transparent", corner_radius=0)
files_page.grid(row=0, column=0, sticky="nsew")
files_page.grid_columnconfigure(0, weight=1, uniform="cols")
files_page.grid_columnconfigure(1, weight=0, minsize=40)
files_page.grid_columnconfigure(2, weight=1, uniform="cols")
files_page.grid_rowconfigure(0, weight=1)
def make_column(col, kicker, heading):
frame = ctk.CTkFrame(files_page, fg_color="transparent", corner_radius=0)
frame.grid(row=0, column=col, sticky="nsew")
frame.grid_columnconfigure(0, weight=1)
ctk.CTkFrame(frame, height=3, fg_color=INK, corner_radius=0).grid(row=0, column=0, sticky="ew")
ctk.CTkLabel(frame, text=kicker, font=f_mono_small, text_color=MUTED, anchor="w").grid(
row=1, column=0, sticky="ew", pady=(12, 0))
ctk.CTkLabel(frame, text=heading, font=f_heading, text_color=INK, anchor="w").grid(
row=2, column=0, sticky="ew", pady=(2, 8))
return frame
def add_field(frame, row, caption, placeholder):
ctk.CTkLabel(frame, text=caption, font=f_mono_small, text_color=MUTED, anchor="w").grid(
row=row, column=0, sticky="ew", pady=(14, 4))
entry = make_entry(frame, placeholder)
entry.grid(row=row + 1, column=0, sticky="ew")
return entry
# Left column: single operations
single_col = make_column(0, "// SINGLE", "One folder or one file")
folderName = add_field(single_col, 3, "FOLDER NAME", "Enter folder name")
def create_folder():
name = folderName.get().strip()
if not name:
set_status("enter a folder name first")
return
mAFolder(name, status_label)
make_button(single_col, "CREATE FOLDER →", create_folder).grid(
row=5, column=0, sticky="ew", pady=(16, 0))
fileName = add_field(single_col, 6, "FILE NAME", "Enter file name with extension")
def create_file():
name = fileName.get().strip()
if not name:
set_status("enter a file name first")
return
mAFile(name, status_label)
make_button(single_col, "CREATE FILE →", create_file).grid(
row=8, column=0, sticky="ew", pady=(16, 0))
# Right column: batch generation
batch_col = make_column(2, "// BATCH", "A folder with many files")
fileNameEntry = add_field(batch_col, 3, "BASE FILE NAME", "Base file name")
folderNameEntry = add_field(batch_col, 5, "TARGET FOLDER", "Target folder name")
numFilesEntry = add_field(batch_col, 7, "NUMBER OF FILES", "Number of files")
def on_click():
try:
f_name = fileNameEntry.get().strip()
f_fol = folderNameEntry.get().strip()
n_files = int(numFilesEntry.get())
if not f_name or not f_fol:
set_status("please enter valid file and folder names")
return
if n_files < 1:
set_status("number of files must be 1 or more")
return
multipleFinFol(f_name, f_fol, n_files)
set_status("batch files created successfully!")
except ValueError:
set_status("please enter a valid number for files")
make_button(batch_col, "CREATE MULTIPLE FILES →", on_click).grid(
row=9, column=0, sticky="ew", pady=(16, 0))
# ---------------------------------------------------------------------------
# Page 2: AI chat
# ---------------------------------------------------------------------------
chat_page = ctk.CTkFrame(content, fg_color="transparent", corner_radius=0)
chat_page.grid(row=0, column=0, sticky="nsew")
chat_page.grid_columnconfigure(0, weight=1)
chat_page.grid_rowconfigure(0, weight=1)
chatBox = ctk.CTkTextbox(
chat_page, wrap="word", corner_radius=0, border_width=2, border_color=INK,
border_spacing=14, fg_color=WHITE, text_color=INK, font=f_body,
scrollbar_button_color="#B8BECE", scrollbar_button_hover_color=BRAND,
)
chatBox.grid(row=0, column=0, sticky="nsew")
chatBox.tag_config("who_you", foreground=BRAND)
chatBox.tag_config("who_bot", foreground=MUTED)
input_row = ctk.CTkFrame(chat_page, fg_color="transparent", corner_radius=0)
input_row.grid(row=1, column=0, sticky="ew", pady=(14, 0))
input_row.grid_columnconfigure(0, weight=1)
chatEntry = make_entry(input_row, "Ask your assistant something...", height=46)
chatEntry.grid(row=0, column=0, sticky="ew", padx=(0, 10))
def addMessage(text, tag=None):
chatBox.configure(state="normal")
chatBox.insert("end", text, tag)
chatBox.see("end")
chatBox.configure(state="disabled")
def showReply(answer):
addMessage("ASSISTANT\n", "who_bot")
addMessage(f"{answer}\n\n")
sendButton.configure(state="normal")
set_status("ready")
def sendMessage(event=None):
user = chatEntry.get().strip()
if not user:
return
chatEntry.delete(0, "end")
addMessage("YOU\n", "who_you")
addMessage(f"{user}\n\n")
sendButton.configure(state="disabled")
set_status("waiting for reply...")
def worker():
answer = askAI(user)
app.after(0, lambda: showReply(answer))
threading.Thread(target=worker, daemon=True).start()
sendButton = make_button(input_row, "SEND →", sendMessage, height=46, width=130)
sendButton.grid(row=0, column=1)
chatEntry.bind("<Return>", sendMessage)
# Opening message
addMessage("ASSISTANT\n", "who_bot")
addMessage("Ask anything. Replies use your own Gemini API key from the .env file.\n\n")
# ---------------------------------------------------------------------------
# Navigation
# ---------------------------------------------------------------------------
PAGES = {
"files": (files_page, files_nav, "// FILES & FOLDERS", "Make files and folders."),
"chat": (chat_page, chat_nav, "// AI CHAT", "Ask the assistant."),
}
def show_page(name):
for key, (frame, button, _kicker, _title) in PAGES.items():
if key == name:
frame.grid()
button.configure(fg_color=WHITE, text_color=BRAND, hover_color=WHITE)
else:
frame.grid_remove()
button.configure(fg_color="transparent", text_color=WHITE, hover_color=BRAND_DARK)
page_kicker.configure(text=PAGES[name][2])
page_title.configure(text=PAGES[name][3])
if name == "chat":
chatEntry.focus()
show_page("files")
# Run application
app.mainloop()