-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger_app.py
More file actions
67 lines (53 loc) · 2.67 KB
/
logger_app.py
File metadata and controls
67 lines (53 loc) · 2.67 KB
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
import tkinter as tk
from tkinter import ttk, scrolledtext, messagebox, filedialog
import sys
import argparse
from pathlib import Path
from phologtolabstreaminglayer.logger_app import LoggerApp
from phologtolabstreaminglayer.features.hide_console import auto_hide_console
from phopylslhelper.mixins.app_helpers import SingletonInstanceMixin
def main(xdf_folder: Path, unsafe: bool = False):
"""
unsafe: bool = False skips the singleton lock check on startup, the user should first confirmt that there aren't multiple instances running.
"""
# Check if another instance is already running (unless --unsafe)
if not unsafe and LoggerApp.is_instance_running():
messagebox.showerror("Instance Already Running",
"Another instance of LSL Logger is already running.\n"
"Only one instance can run at a time.\n"
"To override this safety check, launch with --unsafe.")
sys.exit(1)
root = tk.Tk()
app = LoggerApp(root, xdf_folder=xdf_folder)
# Try to acquire the singleton lock (unless --unsafe)
if not unsafe and not app.acquire_singleton_lock():
messagebox.showerror("Startup Error",
"Failed to acquire singleton lock.\n"
"Another instance may be running.\n"
"To override this safety check, launch with --unsafe.")
root.destroy()
sys.exit(1)
# Handle window closing - cleanly shut down the app
def on_closing():
if app is not None:
app.on_closing()
else:
root.destroy()
root.protocol("WM_DELETE_WINDOW", on_closing)
# Start the GUI
root.mainloop()
def console_main():
"""Console script entry point for uv run logger_app"""
# Hide the Windows console window (no-op on other platforms)
auto_hide_console()
parser = argparse.ArgumentParser(description='PhoLogToLabStreamingLayer')
parser.add_argument('--unsafe', action='store_true', help='Override safety checks and allow multiple instances')
args = parser.parse_args()
unsafe = args.unsafe
_default_xdf_folder = Path(r'E:\Dropbox (Personal)\Databases\UnparsedData\PhoLogToLabStreamingLayer_logs').resolve()
# _default_xdf_folder = Path('/media/halechr/MAX/cloud/University of Michigan Dropbox/Pho Hale/Personal/LabRecordedTextLog').resolve() ## Lab computer
# LoggerApp._default_xdf_folder = _default_xdf_folder
# assert _default_xdf_folder.exists(), f"XDF folder does not exist: {_default_xdf_folder}"
main(xdf_folder=_default_xdf_folder, unsafe=unsafe)
if __name__ == "__main__":
console_main()