From ec4545257038ac6fb0cee28118f430d94d0c41db Mon Sep 17 00:00:00 2001 From: Samuel Sloniker Date: Tue, 23 Jul 2024 09:15:30 -0700 Subject: [PATCH] Move code out of `gui.py` --- navpoint/gui.py | 66 ---------------------------------------- navpoint/phone_server.py | 28 ++++++++++++++++- navpoint/run.py | 40 ++++++++++++++++++++++-- 3 files changed, 64 insertions(+), 70 deletions(-) delete mode 100755 navpoint/gui.py diff --git a/navpoint/gui.py b/navpoint/gui.py deleted file mode 100755 index 7a1bd94..0000000 --- a/navpoint/gui.py +++ /dev/null @@ -1,66 +0,0 @@ -import tkinter as tk -from tkinter import ttk -import pyqrcode -import navpoint.fix_path -import navpoint.usb - - -def choose_mode(): - def _usb_clicked(): - window.destroy() - global mode - mode = "usb" - - def _mobile_clicked(): - window.destroy() - global mode - mode = "mobile" - - window = tk.Tk(className="navpoint") - window.title("Navpoint") - window.resizable(width=False, height=False) - - global mode - mode = "" - - ttk.Label(window, text="How should Navpoint obtain location data?").pack() - usb_button = ttk.Button( - window, text="USB GPS receiver (NMEA)", command=_usb_clicked - ) - usb_button.pack() - mobile_button = ttk.Button( - window, text="Phone running Navpoint Mobile", command=_mobile_clicked - ) - mobile_button.pack() - - try: - window.iconbitmap(navpoint.fix_path.fix_path("icon.ico")) - except tk.TclError: - pass - - window.mainloop() - return mode - - -def show_qr(link): - window = tk.Tk(className="navpoint") - window.title("Navpoint") - window.resizable(width=False, height=False) - - label = tk.Label(window, text="QR code here...") - label.pack() - - image = tk.BitmapImage( - data=pyqrcode.create(link).xbm(scale=int(window.winfo_fpixels("2m"))) - ) - image.config(background="white") - image.config(foreground="black") - - label.config(image=image) - - try: - window.iconbitmap(navpoint.fix_path.fix_path("icon.ico")) - except tk.TclError: - pass - - window.mainloop() diff --git a/navpoint/phone_server.py b/navpoint/phone_server.py index 2114cae..6bbb2b3 100755 --- a/navpoint/phone_server.py +++ b/navpoint/phone_server.py @@ -4,6 +4,10 @@ import navpoint.content import asyncio import secrets import threading +import tkinter as tk +from tkinter import ttk +import pyqrcode +import navpoint.fix_path class PostHandler(tornado.web.RequestHandler): @@ -43,4 +47,26 @@ def run(): daemon=True, ).start() - return f"http://{ip}:8888/{token}" + link = f"http://{ip}:8888/{token}" + + window = tk.Tk(className="navpoint") + window.title("Navpoint") + window.resizable(width=False, height=False) + + label = tk.Label(window, text="QR code here...") + label.pack() + + image = tk.BitmapImage( + data=pyqrcode.create(link).xbm(scale=int(window.winfo_fpixels("2m"))) + ) + image.config(background="white") + image.config(foreground="black") + + label.config(image=image) + + try: + window.iconbitmap(navpoint.fix_path.fix_path("icon.ico")) + except tk.TclError: + pass + + window.mainloop() diff --git a/navpoint/run.py b/navpoint/run.py index f67672a..10e2c13 100755 --- a/navpoint/run.py +++ b/navpoint/run.py @@ -1,15 +1,49 @@ +import tkinter as tk +from tkinter import ttk +import navpoint.fix_path import navpoint.local_server import navpoint.phone_server import navpoint.usb -import navpoint.gui def run(): - mode = navpoint.gui.choose_mode() + def _usb_clicked(): + window.destroy() + global mode + mode = "usb" + + def _mobile_clicked(): + window.destroy() + global mode + mode = "mobile" + + window = tk.Tk(className="navpoint") + window.title("Navpoint") + window.resizable(width=False, height=False) + + global mode + mode = "" + + ttk.Label(window, text="How should Navpoint obtain location data?").pack() + usb_button = ttk.Button( + window, text="USB GPS receiver (NMEA)", command=_usb_clicked + ) + usb_button.pack() + mobile_button = ttk.Button( + window, text="Phone running Navpoint Mobile", command=_mobile_clicked + ) + mobile_button.pack() + + try: + window.iconbitmap(navpoint.fix_path.fix_path("icon.ico")) + except tk.TclError: + pass + + window.mainloop() + if mode == "mobile": navpoint.local_server.run() link = navpoint.phone_server.run() - navpoint.gui.show_qr(link) elif mode == "usb": navpoint.local_server.run() navpoint.usb.run_ui()