-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_and_launch_dpg_ui.sh
More file actions
executable file
·201 lines (175 loc) · 7.78 KB
/
fix_and_launch_dpg_ui.sh
File metadata and controls
executable file
·201 lines (175 loc) · 7.78 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env bash
# Script to fix DearPyGui UI compatibility issues in OneTrainer
# and properly install/update DearPyGui if needed
set -e
echo "=== OneTrainer DearPyGui UI Fixer and Launcher ==="
echo "This script will check your DearPyGui installation and"
echo "apply necessary fixes to make the UI work correctly."
# Use python3 as backup if python command isn't available
if ! command -v python &> /dev/null && command -v python3 &> /dev/null; then
export OT_PYTHON_CMD="python3"
fi
source "${BASH_SOURCE[0]%/*}/lib.include.sh"
prepare_runtime_environment
# Function to check if DearPyGui is installed and get its version
check_dpg_installed() {
if run_python_in_active_env -c "import dearpygui" &>/dev/null; then
echo "✓ DearPyGui is installed"
local dpg_version
dpg_version=$(run_python_in_active_env -c "import dearpygui; print(getattr(dearpygui, '__version__', 'unknown'))")
echo " Version: $dpg_version"
if [[ "$dpg_version" == "unknown" ]]; then
# Try to get version from package metadata
dpg_version=$(run_pip_in_active_env show dearpygui | grep Version | awk '{print $2}')
echo " Package version: $dpg_version"
fi
# Check if version is compatible
if [[ "$dpg_version" =~ ^1\. ]]; then
echo "! DearPyGui 1.x detected. OneTrainer works best with DearPyGui 1.8.0."
echo " Would you like to install the recommended version? (y/n)"
read -r response
if [[ "$response" =~ ^[Yy] ]]; then
echo "Installing DearPyGui 1.8.0..."
run_pip_in_active_env install dearpygui==1.8.0
return 2 # Reinstalled
fi
elif [[ "$dpg_version" =~ ^0\. ]]; then
echo "! DearPyGui 0.x detected. OneTrainer works best with DearPyGui 1.8.0."
echo " Would you like to install the recommended version? (y/n)"
read -r response
if [[ "$response" =~ ^[Yy] ]]; then
echo "Installing DearPyGui 1.8.0..."
run_pip_in_active_env install dearpygui==1.8.0
return 2 # Reinstalled
fi
fi
return 0 # Already installed
else
echo "✗ DearPyGui is not installed"
echo "Installing DearPyGui 1.8.0..."
run_pip_in_active_env install dearpygui==1.8.0
return 1 # Newly installed
fi
}
# Function to fix file_selector.py for different DearPyGui versions
fix_file_selector() {
file_selector="dpg_ui/components/file_selector.py"
echo "Checking file_selector.py..."
if [ -f "$file_selector" ]; then
# Create a backup if it doesn't exist
if [ ! -f "${file_selector}.bak" ]; then
cp "$file_selector" "${file_selector}.bak"
echo " Created backup: ${file_selector}.bak"
fi
# Check if this is a version that needs the add_file_extension_info fix
if grep -q "add_file_extension_info" "$file_selector"; then
echo " Applying file_selector.py compatibility fix..."
# Update the file directly with python
run_python_in_active_env -c "
with open('$file_selector', 'r') as f:
content = f.read()
# Replace the problematic section with version that works for both DearPyGui 1.x and 2.x
old_section = ''' # Add extension filters if specified
if filter_ext:
ext_id = dpg.add_file_extension_info(parent=dialog_id)
for ext in filter_ext:
dpg.add_file_extension(extension=ext, parent=ext_id, custom_text=f\"*{ext} Files\")'''
new_section = ''' # Add extension filters if specified
if filter_ext:
# Apply compatibility fix for different DearPyGui versions
try:
# Try DearPyGui 1.x style
ext_id = dpg.add_file_extension_info(parent=dialog_id)
for ext in filter_ext:
dpg.add_file_extension(extension=ext, parent=ext_id, custom_text=f\"*{ext} Files\")
except (TypeError, AttributeError):
try:
# Try DearPyGui 2.x style
for ext in filter_ext:
dpg.add_file_extension(extension=ext, parent=dialog_id, custom_text=f\"*{ext} Files\")
except Exception as e:
print(f\"Warning: Could not add file extension {ext}: {e}\")'''
if old_section in content:
content = content.replace(old_section, new_section)
with open('$file_selector', 'w') as f:
f.write(content)
print('File updated successfully')
else:
print('Old section not found, file may already be fixed or has a different structure')
"
else:
echo " file_selector.py already fixed or doesn't need fixing"
fi
else
echo "✗ file_selector.py not found at expected location"
fi
}
# Function to fix switch component in basic.py for compatibility
fix_basic_switch() {
basic_components="dpg_ui/components/basic.py"
echo "Checking basic.py for switch component..."
if [ -f "$basic_components" ]; then
# Create a backup if it doesn't exist
if [ ! -f "${basic_components}.bak" ]; then
cp "$basic_components" "${basic_components}.bak"
echo " Created backup: ${basic_components}.bak"
fi
# Check if the file needs the switch component fix
if grep -q "Components.generate_id(\"switch\")" "$basic_components" && ! grep -q "callback.*in kwargs" "$basic_components"; then
echo " Applying switch component fix..."
# Update the file directly with python
run_python_in_active_env -c "
with open('$basic_components', 'r') as f:
content = f.read()
# Look for the pattern that needs to be replaced
import re
pattern = r'(\s+tag = tag or Components\.generate_id\(\"switch\"\)\s+)dpg\.add_checkbox\(label=label, default_value=default_value,\s+callback=on_change, parent=parent, tag=tag, \*\*kwargs\)'
replacement = r'''\1# Make sure we don't pass callback if it's already in kwargs
if 'callback' not in kwargs:
dpg.add_checkbox(label=label, default_value=default_value,
callback=on_change, parent=parent, tag=tag, **kwargs)
else:
# Remove on_change if callback is provided in kwargs
dpg.add_checkbox(label=label, default_value=default_value,
parent=parent, tag=tag, **kwargs)'''
# Apply the replacement
new_content = re.sub(pattern, replacement, content)
if new_content != content:
with open('$basic_components', 'w') as f:
f.write(new_content)
print('File updated successfully')
else:
print('Pattern not found, file may already be fixed or has a different structure')
"
else:
echo " basic.py switch component already fixed or doesn't need fixing"
fi
else
echo "✗ basic.py not found at expected location"
fi
}
# Main execution
echo "Checking and fixing DearPyGui installation..."
check_dpg_installed
dpg_result=$?
# Apply code fixes
if [ -d "dpg_ui" ]; then
echo ""
echo "Applying fixes to OneTrainer DearPyGui UI code..."
fix_file_selector
fix_basic_switch
else
echo "✗ dpg_ui directory not found. Make sure you're in the OneTrainer directory."
exit 1
fi
echo ""
if [ $dpg_result -eq 2 ]; then
echo "DearPyGui was reinstalled to a compatible version. UI should now work correctly."
elif [ $dpg_result -eq 1 ]; then
echo "DearPyGui was newly installed. UI should now work correctly."
else
echo "Using existing DearPyGui installation with applied compatibility fixes."
fi
echo ""
echo "Launching the OneTrainer DearPyGui UI..."
./start-dpg-ui.sh