-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_gui.py
More file actions
94 lines (77 loc) · 3.3 KB
/
run_gui.py
File metadata and controls
94 lines (77 loc) · 3.3 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
#!/usr/bin/env python3
"""
Launcher script for the X Bot GUI application.
Windows-only version.
"""
import os
import sys
import subprocess
def check_venv():
"""Check if running in a virtual environment and activate if necessary."""
# Check if already in a virtual environment
if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
return True
# Check if venv directory exists
if os.path.isdir('venv'):
print("Virtual environment found. Activating...")
# Windows-specific paths
activate_script = os.path.join('venv', 'Scripts', 'activate')
python_path = os.path.join('venv', 'Scripts', 'python.exe')
# Re-launch the script using the venv python
if os.path.exists(python_path):
# Get the full path to this script
script_path = os.path.abspath(__file__)
# Execute the script with the venv python
os.execl(python_path, python_path, script_path)
else:
print("Error: Virtual environment exists but Python executable not found.")
return False
else:
print("No virtual environment found. Creating one...")
try:
# Create venv
subprocess.check_call([sys.executable, '-m', 'venv', 'venv'])
# Windows-specific paths
pip_path = os.path.join('venv', 'Scripts', 'pip.exe')
python_path = os.path.join('venv', 'Scripts', 'python.exe')
# Install requirements
if os.path.exists('requirements.txt'):
print("Installing requirements...")
subprocess.check_call([pip_path, 'install', '-r', 'requirements.txt'])
# Re-launch the script using the venv python
script_path = os.path.abspath(__file__)
os.execl(python_path, python_path, script_path)
except Exception as e:
print(f"Error setting up virtual environment: {e}")
return False
return False
def main():
"""Main function to run the GUI application."""
print("Starting AutoXAI...")
try:
# Import and run the GUI application
from gui import main as run_gui
run_gui()
except ImportError as e:
print(f"Error importing GUI module: {e}")
print("Make sure all dependencies are installed.")
# Try to install requirements if needed
if os.path.exists('requirements.txt'):
print("Attempting to install requirements...")
try:
subprocess.check_call([sys.executable, '-m', 'pip', 'install', '-r', 'requirements.txt'])
# Try importing again
print("Retrying import...")
from gui import main as run_gui
run_gui()
except Exception as install_error:
print(f"Error installing requirements: {install_error}")
sys.exit(1)
except Exception as e:
print(f"Error running GUI application: {e}")
sys.exit(1)
if __name__ == "__main__":
# Check and activate virtual environment if needed
if check_venv():
# Only run main if we're in the correct environment
main()