1.0
This commit is contained in:
216
main.py
Normal file
216
main.py
Normal file
@@ -0,0 +1,216 @@
|
||||
# This file is part of AutoDownloaderVedikaPDF.
|
||||
# Copyright (C) 2025 Andy Cahyono Putra
|
||||
# This program is distributed under the Aladdin Free Public License.
|
||||
# See LICENSE file for more information.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import importlib
|
||||
import signal
|
||||
import ctypes
|
||||
import atexit
|
||||
import tkinter as tk
|
||||
from tkinter import ttk, messagebox
|
||||
from typing import Optional
|
||||
|
||||
APP_TITLE = "JOBS EASIER"
|
||||
APP_SIZE = (520, 340)
|
||||
SPLASH_SIZE = (420, 260)
|
||||
SPLASH_DURATION_MS = 1800
|
||||
SPLASH_STEP_MS = 60
|
||||
LOGO_FILENAME = ""
|
||||
|
||||
if getattr(sys, "frozen", False):
|
||||
os.environ["PLAYWRIGHT_BROWSERS_PATH"] = os.path.join(sys._MEIPASS, "ms-playwright")
|
||||
|
||||
def _safe_exit():
|
||||
try:
|
||||
r = tk._default_root
|
||||
if r:
|
||||
try:
|
||||
for w in list(r.winfo_children()):
|
||||
try:
|
||||
w.destroy()
|
||||
except Exception:
|
||||
pass
|
||||
r.destroy()
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
os._exit(0)
|
||||
|
||||
try:
|
||||
signal.signal(signal.SIGINT, lambda s, f: _safe_exit())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
HANDLER_ROUTINE = ctypes.WINFUNCTYPE(ctypes.c_bool, ctypes.c_uint)
|
||||
def _console_handler(ctrl_type):
|
||||
_safe_exit()
|
||||
return True
|
||||
ctypes.windll.kernel32.SetConsoleCtrlHandler(HANDLER_ROUTINE(_console_handler), True)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
atexit.register(_safe_exit)
|
||||
|
||||
def _bind_close(win: tk.Misc):
|
||||
try:
|
||||
win.protocol("WM_DELETE_WINDOW", _safe_exit)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def resource_path(rel_path: str) -> str:
|
||||
base = getattr(sys, "_MEIPASS", os.path.abspath(os.path.dirname(__file__)))
|
||||
return os.path.join(base, rel_path)
|
||||
|
||||
def center_window(win: tk.Tk, w: int, h: int) -> None:
|
||||
win.update_idletasks()
|
||||
sw = win.winfo_screenwidth()
|
||||
sh = win.winfo_screenheight()
|
||||
x = (sw - w) // 2
|
||||
y = (sh - h) // 3
|
||||
win.geometry(f"{w}x{h}+{x}+{y}")
|
||||
|
||||
class Splash(tk.Toplevel):
|
||||
def __init__(self, parent: tk.Tk, on_finish):
|
||||
super().__init__(parent)
|
||||
self.parent = parent
|
||||
self.on_finish = on_finish
|
||||
self.overrideredirect(True)
|
||||
self.configure(bg="#ffffff")
|
||||
|
||||
wrapper = tk.Frame(self, bg="#ffffff", bd=0, highlightthickness=1, highlightbackground="#e5e5e5")
|
||||
wrapper.pack(fill="both", expand=True, padx=1, pady=1)
|
||||
content = tk.Frame(wrapper, bg="#ffffff", padx=16, pady=16)
|
||||
content.pack(fill="both", expand=True)
|
||||
|
||||
self._logo_img = None
|
||||
logo_path = resource_path(LOGO_FILENAME)
|
||||
if os.path.exists(logo_path):
|
||||
try:
|
||||
self._logo_img = tk.PhotoImage(file=logo_path)
|
||||
tk.Label(content, image=self._logo_img, bg="#ffffff").pack(pady=(4, 10))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
tk.Label(content, text="Auto Downloader Vedika & Veronisa", font=("", 14, "bold"), bg="#ffffff").pack()
|
||||
tk.Label(
|
||||
content,
|
||||
text="© 2025 Andy Cahyono Putra\nAladdin Free Public License",
|
||||
font=("", 9), fg="#555555", bg="#ffffff", justify="center"
|
||||
).pack(pady=(6, 14))
|
||||
|
||||
self.progress = ttk.Progressbar(content, mode="determinate", length=260, maximum=100)
|
||||
self.progress.pack(pady=(0, 8))
|
||||
tk.Label(content, text="Memuat komponen…", font=("", 9), fg="#777777", bg="#ffffff").pack()
|
||||
|
||||
self.update_idletasks()
|
||||
center_window(self, *SPLASH_SIZE)
|
||||
|
||||
_bind_close(self)
|
||||
|
||||
self._elapsed = 0
|
||||
self._tick()
|
||||
|
||||
def _tick(self):
|
||||
total = SPLASH_DURATION_MS
|
||||
step = SPLASH_STEP_MS
|
||||
self._elapsed += step
|
||||
pct = min(int(self._elapsed / total * 100), 100)
|
||||
self.progress["value"] = pct
|
||||
|
||||
if self._elapsed < total:
|
||||
self.after(step, self._tick)
|
||||
else:
|
||||
try:
|
||||
self.destroy()
|
||||
finally:
|
||||
if callable(self.on_finish):
|
||||
self.on_finish()
|
||||
|
||||
def launch_script_module(root: tk.Tk, module_path: str, entrypoint: Optional[str] = None, class_entry: Optional[str] = None):
|
||||
root.withdraw()
|
||||
try:
|
||||
mod = importlib.import_module(module_path)
|
||||
except Exception as e:
|
||||
root.deiconify()
|
||||
messagebox.showerror("Error", f"Gagal mengimpor modul:\n{module_path}\n\n{e}")
|
||||
return
|
||||
|
||||
try:
|
||||
if entrypoint and hasattr(mod, entrypoint):
|
||||
root.destroy()
|
||||
tk._default_root = None
|
||||
getattr(mod, entrypoint)()
|
||||
return
|
||||
|
||||
if class_entry and hasattr(mod, class_entry):
|
||||
cls = getattr(mod, class_entry)
|
||||
root.destroy()
|
||||
tk._default_root = None
|
||||
app = cls()
|
||||
if hasattr(app, "mainloop"):
|
||||
app.mainloop()
|
||||
return
|
||||
root.destroy()
|
||||
tk._default_root = None
|
||||
|
||||
except Exception as e:
|
||||
root.deiconify()
|
||||
messagebox.showerror("Error", f"Gagal menjalankan {module_path}:\n{e}")
|
||||
|
||||
def build_main_menu(root: tk.Tk):
|
||||
root.title(APP_TITLE)
|
||||
|
||||
try:
|
||||
style = ttk.Style()
|
||||
if "vista" in style.theme_names():
|
||||
style.theme_use("vista")
|
||||
elif "clam" in style.theme_names():
|
||||
style.theme_use("clam")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
root.geometry(f"{APP_SIZE[0]}x{APP_SIZE[1]}")
|
||||
center_window(root, *APP_SIZE)
|
||||
|
||||
container = ttk.Frame(root, padding=16)
|
||||
container.pack(fill="both", expand=True)
|
||||
|
||||
title = ttk.Label(
|
||||
container,
|
||||
text="Another Tools To Make Your Jobs Easier — Python Version",
|
||||
wraplength=420,
|
||||
font=("", 11, "bold"),
|
||||
)
|
||||
title.pack(pady=(0, 12))
|
||||
buttons = [
|
||||
("Ranap (Dengan Upload JKN)", lambda: launch_script_module(root, "SubModules.ranap", entrypoint="main")),
|
||||
("Ralan (Dengan Upload JKN)", lambda: launch_script_module(root, "SubModules.ralan", entrypoint="main")),
|
||||
("Mass Upload", lambda: launch_script_module(root, "SubModules.massupload", class_entry="JKNApp")),
|
||||
("Ralan (Tanpa Upload)", lambda: launch_script_module(root, "SubModules.ralannoupload", entrypoint="main")),
|
||||
("Ranap (Tanpa Upload)", lambda: launch_script_module(root, "SubModules.ranapnoupload", class_entry="RanapNonUpload")),
|
||||
("Veronisa", lambda: launch_script_module(root, "SubModules.veronisa")),
|
||||
]
|
||||
for text, cmd in buttons:
|
||||
ttk.Button(container, text=text, command=cmd).pack(pady=6, fill="x")
|
||||
_bind_close(root)
|
||||
root.bind("<Escape>", lambda e: _safe_exit())
|
||||
|
||||
def main():
|
||||
root = tk.Tk()
|
||||
root.withdraw()
|
||||
_bind_close(root)
|
||||
|
||||
def after_splash():
|
||||
build_main_menu(root)
|
||||
root.deiconify()
|
||||
|
||||
Splash(root, on_finish=after_splash)
|
||||
root.mainloop()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user