-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
146 lines (110 loc) · 4.99 KB
/
ui.py
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
import tkinter as tk
from multiprocessing import Process, Pipe
import sys , signal, os
from utility_functions import *
#! deprecated, using custom_ui now keeping, for future tests
#todo if text == "Cover image downloaded and saved" : add_cover_img() -> display downloaded cover-img.png file
def create_ui(pipe, proc_sem, queue,):
def reset():
run_button.pack(pady=5)
elink.delete(0, tk.END)
s_chap_entry.delete(0, tk.END)
e_chap_entry.delete(0, tk.END)
def update_debug(label):
if(not queue.empty()):
text = queue.get_nowait()
label.configure(text=text)
# if label says the download is completed put download button back
if text == "Download Completed" : reset()
#todo if text == "Cover image downloaded and saved" : add_cover_img()
# closing window handler function
def on_closing():
f.quit() # Quit the Tkinter event loop
f.destroy() # Destroy the window (optional)
print("Window close, exiting program")
pipe.close()
os.kill(os.getppid() , signal.SIGTERM) # send sigterm to close parent process
sys.exit()
def start_download():
print("download Button pressed")
run_button.pack_forget()
userURL = elink.get()
first_chapter = s_chap_entry.get()
last_chapter = e_chap_entry.get()
if download_all_var.get() :
first_chapter = 1
last_chapter = "getLastChapter"
removetxt = txt_var.get()
print(f"Sent user input: {userURL}, {first_chapter}, {last_chapter}, {removetxt}")
pipe.send((userURL, first_chapter, last_chapter, removetxt))
proc_sem.release()
# Define black and white colors
background_color = "#c5bcd6" # White background
text_color = "#000000" # Black text
entry_background_color = "#e0e0e0" # Light gray entry background
f = tk.Tk()
f.title("novel-dl by normalset")
f.geometry("700x400")
f.configure(background=background_color)
f.protocol("WM_DELETE_WINDOW", on_closing)
# Custom icon (if applicable)
# icon = tk.PhotoImage(file="icon.png")
# f.iconphoto(True, icon)
# Improved layout with frames for grouping
main_frame = tk.Frame(f, bg=background_color)
main_frame.pack(padx=20, pady=20)
# Link section
link_frame = tk.Frame(main_frame, bg=background_color)
link_frame.pack(pady=10)
link_text = tk.Label(link_frame, text="Novel Link", font=("Helvetica", 14), fg=text_color, bg=background_color)
link_text.pack()
link_text2 = tk.Label(link_frame, text="Enter the URL of the novel (without a chapter open) \nFormat of the link should be:\n https://novelhi.com/s/NovelName or https://www.lightnovelhub.org/novel/novelName ", font=("Helvetica", 9), fg=text_color, bg=background_color)
link_text2.pack()
elink = tk.Entry(link_frame, justify=tk.CENTER, bg=entry_background_color, fg=text_color)
elink.pack(pady=5, fill=tk.X, padx=15)
# Chapter section
chapter_frame = tk.Frame(main_frame, bg=background_color)
chapter_frame.pack(pady=10)
s_chap_text = tk.Label(chapter_frame, text="From Chapter", font=("Helvetica", 12), fg=text_color, bg=background_color)
s_chap_text.grid(row= 0, column=0)
s_chap_entry = tk.Entry(chapter_frame, bg=entry_background_color, fg=text_color)
s_chap_entry.grid(row=1 , column=0, pady=5, padx=5)
e_chap_text = tk.Label(chapter_frame, text="To Chapter", font=("Helvetica", 12), fg=text_color, bg=background_color)
e_chap_text.grid(row=0 , column=1)
e_chap_entry = tk.Entry(chapter_frame, bg=entry_background_color, fg=text_color)
e_chap_entry.grid(row=1 , column=1, pady=5, padx=5)
# Checkbox section
download_all_var = tk.BooleanVar()
txt_var = tk.BooleanVar()
download_all_check = tk.Checkbutton(
main_frame,
text="Download All Chapters",
command=lambda: print("download_all set to ",download_all_var.get()),
variable=download_all_var,
onvalue=True,
offvalue=False,
fg=text_color,
bg=background_color,
)
download_all_check.pack(pady=10)
txt_check = tk.Checkbutton(
main_frame,
text="Remove .txt file created while scanning, keep to add more chapters later",
command=lambda: print("removetxt set to ",txt_var.get()),
variable=txt_var,
onvalue=True,
offvalue=False,
fg=text_color,
bg=background_color,
)
txt_check.pack(pady=5)
run_button = tk.Button(main_frame, text="Download", font=("Helvetica", 14), fg=text_color, bg=background_color, command=start_download)
run_button.pack(pady=5)
debug_text = tk.Label(main_frame, text="", font=("Helvetica", 12), fg=text_color, bg=background_color)
debug_text.pack(pady = 10)
# Start a loop within the main event loop for updates
def loop():
update_debug(debug_text)
f.after(500, loop) # Schedule next update
loop() # Call loop to start periodic updates
f.mainloop()