commit c1f7967ff051ffd5896db13420e7c88bc39039c8 Author: Wei Hong Date: Fri Jul 10 20:57:31 2026 +0800 A small prototype is created! diff --git a/app.py b/app.py new file mode 100644 index 0000000..92f5356 --- /dev/null +++ b/app.py @@ -0,0 +1,17 @@ +from PySide6.QtWidgets import QApplication, QWidget, QMainWindow + +from core_lib.unclassified import move_window_to_center + + +class Launcher(QApplication): + def __init__(self): + super().__init__() + self.setApplicationName("TestLauncher") + self.main_window = QMainWindow() + self.main_window.setGeometry(0, 0, 800, 600) + + move_window_to_center(self.main_window) + + def exec(self): + self.main_window.show() + self.exec_() \ No newline at end of file diff --git a/core_lib/unclassified.py b/core_lib/unclassified.py new file mode 100644 index 0000000..05ae8dd --- /dev/null +++ b/core_lib/unclassified.py @@ -0,0 +1,10 @@ +from PySide6.QtGui import QScreen +from PySide6.QtWidgets import QMainWindow, QApplication + + +def move_window_to_center(window: QMainWindow): + main_screen = QApplication.primaryScreen() + center = QScreen.availableGeometry(main_screen).center() + geometry = window.frameGeometry() + geometry.moveCenter(center) + window.move(geometry.topLeft()) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..55680ce --- /dev/null +++ b/main.py @@ -0,0 +1,83 @@ +import os +import sys +import argparse +import logging +from app import Launcher +import tkinter as tk + +# Logger configure +logging.basicConfig(format='%(asctime)s:%(name)s:%(levelname)s: %(message)s', + level=logging.INFO, + datefmt='%H:%M:%S') + +def select_mode() -> None | str: + value = None + + def get_value(root: tk.Tk, listbox_obj: tk.Listbox): + nonlocal value + value = listbox.get(listbox_obj.curselection()[0]) if listbox_obj.curselection() else None + root.destroy() + + support_list = ["full", "lightweight"] + + r = tk.Tk() + r.title("TestLauncher") + r.geometry("300x300") + + label = tk.Label(r, text="Select a mode to continue") + label.pack(anchor="n") + + listbox = tk.Listbox(r, selectmode=tk.SINGLE) + listbox.pack(expand=True, fill="both") + listbox.bind("", lambda e: get_value(r, listbox)) + + for support in support_list: + listbox.insert(tk.END, support) + + listbox.selection_set(0) + + # move to center + r.eval('tk::PlaceWindow . center') + + r.mainloop() + + return value + + +def tui_entry(): + logger = logging.getLogger("TestLauncher.Tui") + logger.info("Wow tui is unfinished") + +def main(): + logger = logging.getLogger("Launcher.Main") + + parser = argparse.ArgumentParser() + parser.add_argument("-m", "--mode", choices=['lightweight', 'full', 'choice'], default='choice', + help="Select mode (lightweight for tui, full is gui," + "choice for a mode select window)", required=False) + + args, unknown = parser.parse_known_args() + for arg in unknown: + logging.warning("Unknown argument '%s'" % arg) + + if not hasattr(args, "mode") or args.mode == "choice": + mode = select_mode() + + if mode is None: + logging.warning("No mode selected. Exiting...") + sys.exit(0) + else: + mode = args.mode + + if mode == 'lightweight': + sys.exit(tui_entry()) + elif mode == 'full': + app = Launcher() + sys.exit(app.exec()) + else: + logger.error("Unknown mode '%s'" % mode) + sys.exit(1) + + +if __name__ == '__main__': + main()