-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_visualizer.py
More file actions
78 lines (65 loc) · 2.25 KB
/
input_visualizer.py
File metadata and controls
78 lines (65 loc) · 2.25 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
67
68
69
70
71
72
73
74
75
76
77
78
import os
import sys
import threading
import time
try:
import webview
except ImportError:
print("pywebview is not installed. Please run: pip install pywebview")
sys.exit(1)
import json
class Api:
def get_data(self):
# Path to user_inputs.json in home/ directory
# Persistence: MUST be in valid write location.
if getattr(sys, 'frozen', False):
# In frozen mode, data should be in the directory of the executable,
# NOT in _MEIPASS (which is temporary).
# We follow the same logic as glass_window fallback: root of exe or home/ inside it if present.
base_dir = os.path.dirname(sys.executable)
possible_home = os.path.join(base_dir, 'home')
if os.path.exists(possible_home):
cpath = possible_home
else:
cpath = base_dir
# Filename is just user_inputs.json in that cpath
json_file = os.path.join(cpath, 'user_inputs.json')
else:
cpath = os.path.dirname(os.path.abspath(__file__))
json_file = os.path.join(cpath, 'home', 'user_inputs.json')
if not os.path.exists(json_file):
return []
try:
with open(json_file, 'r') as f:
content = json.load(f)
return content
except Exception as e:
print(f"Error reading JSON: {e}")
return []
def main():
# Calculate path to the new HTML file in home/
if getattr(sys, 'frozen', False):
cpath = sys._MEIPASS # For HTML assets, use bundled
else:
cpath = os.path.dirname(os.path.abspath(__file__))
html_file = os.path.join(cpath, 'home', 'index.html')
if not os.path.exists(html_file):
print(f"File not found: {html_file}")
return
file_url = f"file:///{html_file.replace(os.sep, '/')}"
print(f"Opening: {file_url}")
api = Api()
# Window Dimensions (Landscape)
width = 1200
height = 800
webview.create_window(
'Activity Feed',
file_url,
width=width,
height=height,
resizable=True,
js_api=api
)
webview.start(debug=False)
if __name__ == "__main__":
main()