From c0b4cfc97dc727cfa3a8d34456637860a5856c8a Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Sun, 22 Sep 2024 21:58:19 -0400 Subject: progress for day --- fprintd_tk.py | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'fprintd_tk.py') diff --git a/fprintd_tk.py b/fprintd_tk.py index 8fe0ab6..3e815a6 100755 --- a/fprintd_tk.py +++ b/fprintd_tk.py @@ -6,17 +6,13 @@ # References: # stackrpms_tk.py # Improve: -# implement delete -# implement enroll -# +# flash the newly enrolled finger, and/or the failed verify on a finger. -import tkinter as tk, os, tkinter.filedialog, sys, threading +import tkinter as tk, os, tkinter.simpledialog, sys, threading, time import tkstackrpms as stk import fprintd_tk_lib as lib from PIL import Image, ImageTk -# todo: load images array? - ABOUT_TEXT = """ fprintd_tk \"Gui for fprintd\" (C) 2024 bgstack15 @@ -102,6 +98,8 @@ class App(tk.Frame): self.action.set(a) def load_data_into_form(self): + time.sleep(0.05) + # WORKHERE: if the fprintd-list fails because the device is open, we will want to keep the old enrolled_fingers list. maybe check if statustext contains "failed to open" or whatever the message is. if it does, do not update the self.enrolled_fingers? self.enrolled_fingers = lib.get_enrolled_fingers() print(f"DEBUG (load_data_into_form): got enrolled fingers {self.enrolled_fingers}") for i in self.fingers: @@ -123,25 +121,39 @@ class App(tk.Frame): def func_finger_button(self, finger): print(f"DEBUG: func_finger_button finger {finger}, action {self.action.get()}") action = self.action.get() - if 1 == action: # enroll + # position in array is same as the value coming from radio button for actions. + available_actions = ["none","enroll","verify"] + try: + action_str = available_actions[action] + except ValueError: + action_str = "OFF" + if action_str in available_actions: try: - # WORKHERE: pass a tk text var to set for intermediate operations? - self.statustext.set(lib.enroll_finger(finger, self.func_update_status)) + t1 = threading.Thread(target=lib.fprintd_action, args=(action_str, finger, self.func_update_status)) + t1.start() except Exception as e: self.statustext.set(e) - elif 2 == action: # verify - #print(f"stub action: verify, finger {finger}") - t1 = threading.Thread(target=lib.verify_finger,args=(finger, self.func_update_status)) - t1.run() - self.load_data_into_form() + else: + self.statustext.set(f"Invalid action {action}, string {action_str}.") + # This blocks everything! Do not use this. + #t1.join() + # unfortunately useless here, because of the threading. + #self.load_data_into_form() def func_update_status(self, msg): msg = msg.strip() - print(f"DEBUG: func_update_status called with msg {msg}",file=sys.stderr) + print(f"DEBUG (func_update_status: msg {msg}",file=sys.stderr) self.statustext.set(msg) + self.load_data_into_form() def func_delete(self): - print(f"stub, please ask user if he is certain to delete all enrolled fingerprints") + print(f"please ask user if he is certain to delete all enrolled fingerprints") + sure = tkinter.messagebox.askokcancel(title="Delete all enrolled fingerprints",message="Are you sure you want to delete all enrolled fingerprints?") + if sure: + t1 = threading.Thread(target=lib.fprintd_action, args=("delete", "none", self.func_update_status)) + t1.start() + else: + self.statustext.set("Cancelled the delete action.") # main root = tk.Tk() -- cgit