-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.py
More file actions
103 lines (84 loc) · 2.94 KB
/
main.py
File metadata and controls
103 lines (84 loc) · 2.94 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# main.py
import tkinter as tk
import sys
import traceback
import logging
import os
from datetime import datetime
from computeruse import ComputerInterface
def setup_logging() -> None:
"""Setup logging configuration"""
if not os.path.exists('logs'):
os.makedirs('logs')
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
log_file = os.path.join('logs', f'computeruse_{timestamp}.log')
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(log_file),
logging.StreamHandler(sys.stdout)
]
)
def check_requirements() -> bool:
"""Check if all required packages are installed"""
# Map pip package names to their import names
package_map = {
'anthropic': 'anthropic',
'Pillow': 'PIL', # Pillow imports as PIL
'PyAutoGUI': 'pyautogui'
}
missing_packages = []
for package, import_name in package_map.items():
try:
__import__(import_name)
logging.info(f"Found package: {package}")
except ImportError:
missing_packages.append(package)
logging.error(f"Missing package: {package}")
if missing_packages:
print("Missing required packages:")
print("\n".join(f"- {pkg}" for pkg in missing_packages))
print("\nPlease install missing packages using:")
print(f"pip install {' '.join(missing_packages)}")
return False
return True
def handle_exception(exc_type, exc_value, exc_traceback):
"""Global exception handler"""
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
logging.error("Uncaught exception:", exc_info=(exc_type, exc_value, exc_traceback))
def main() -> None:
"""Main application entry point"""
try:
# Setup logging
setup_logging()
logging.info("Application starting...")
# Check requirements
if not check_requirements():
logging.error("Missing required packages")
sys.exit(1)
# Create main window
root = tk.Tk()
# Set window icon if available
try:
if os.path.exists("img/icon.ico"):
root.iconbitmap("img/icon.ico")
except Exception as e:
logging.warning(f"Could not load window icon: {e}")
# Initialize application
app = ComputerInterface(root)
# Set exception handler
sys.excepthook = handle_exception
# Start application
logging.info("Starting main loop...")
root.mainloop()
except Exception as e:
logging.error(f"Fatal error: {str(e)}")
traceback.print_exc()
sys.exit(1)
finally:
logging.info("Application shutting down...")
if __name__ == "__main__":
main()