-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_dpg_ui.py
More file actions
executable file
·191 lines (158 loc) · 6.47 KB
/
test_dpg_ui.py
File metadata and controls
executable file
·191 lines (158 loc) · 6.47 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
#!/usr/bin/env python3
"""
Comprehensive test script for the Dear PyGui UI
This script allows testing various components of the Dear PyGui UI
without running the full application.
"""
import os
import sys
import dearpygui.dearpygui as dpg
import argparse
from typing import Optional, Dict, Any, List
# Import dark theme if available
try:
from dpg_ui.themes.dark_theme import apply_dark_theme
except ImportError:
# Fallback if theme is not available
def apply_dark_theme():
pass
# Add the parent directory to sys.path
parent_dir = os.path.abspath(os.path.dirname(__file__))
if parent_dir not in sys.path:
sys.path.insert(0, parent_dir)
# Import state manager
from dpg_ui.core.state_manager import StateManager
class TestApp:
"""Test application for Dear PyGui UI components"""
def __init__(self, test_component: str = "concept"):
"""
Initialize the test application
Args:
test_component: The component to test
"""
self.test_component = test_component
self.state = StateManager()
self.window_id = "main_window"
def run(self):
"""Run the test application"""
# Initialize DPG
dpg.create_context()
dpg.create_viewport(title=f"OneTrainer - {self.test_component.capitalize()} Test",
width=1024, height=768)
dpg.setup_dearpygui()
# Apply dark theme
apply_dark_theme()
# Create main window
with dpg.window(tag=self.window_id, label=f"OneTrainer - {self.test_component.capitalize()} Test"):
# Add the component to test
self.add_test_component()
# Show the viewport
dpg.show_viewport()
dpg.set_primary_window(self.window_id, True)
# Start the main loop
dpg.start_dearpygui()
# Clean up
dpg.destroy_context()
def add_test_component(self):
"""Add the component to test"""
if self.test_component == "concept":
self.test_concept_tab()
elif self.test_component == "concept_window":
self.test_concept_window()
elif self.test_component == "lora":
self.test_lora_tab()
elif self.test_component == "model":
self.test_model_tab()
elif self.test_component == "training":
self.test_training_tab()
elif self.test_component == "sampling":
self.test_sampling_tab()
else:
dpg.add_text(f"Unknown component: {self.test_component}")
def test_concept_tab(self):
"""Test the concept tab"""
try:
from dpg_ui.tabs.concept_tab import ConceptTab
dpg.add_text("Testing Concept Tab")
dpg.add_separator()
concept_tab = ConceptTab(dpg.last_item(), self.state)
except ImportError as e:
dpg.add_text(f"Error importing Concept Tab: {e}")
def test_concept_window(self):
"""Test the concept window"""
try:
from dpg_ui.windows.concept_window_simple import ConceptWindow
from modules.util.config.ConceptConfig import ConceptConfig
dpg.add_text("Testing Concept Window")
dpg.add_separator()
# Create a concept config
concept = ConceptConfig.default_values()
concept.name = "Test Concept"
concept.path = os.path.join(os.getcwd(), "training_concepts")
# Create a button to open the concept window
def open_concept_window():
def on_concept_updated(updated_concept):
if updated_concept:
print(f"Concept updated: {updated_concept.name}")
concept_window = ConceptWindow(concept, self.state, on_concept_updated)
dpg.add_button(label="Open Concept Window", callback=open_concept_window)
except ImportError as e:
dpg.add_text(f"Error importing Concept Window: {e}")
def test_lora_tab(self):
"""Test the lora tab"""
try:
# Try to import the lora tab
try:
from dpg_ui.tabs.lora_tab import LoraTab
dpg.add_text("Testing LoRA Tab")
dpg.add_separator()
lora_tab = LoraTab(dpg.last_item(), self.state)
except ImportError:
# Try the simplified version
from dpg_ui.tabs.lora_tab_simple import LoraTab
dpg.add_text("Testing Simplified LoRA Tab")
dpg.add_separator()
lora_tab = LoraTab(dpg.last_item(), self.state)
except ImportError as e:
dpg.add_text(f"Error importing LoRA Tab: {e}")
def test_model_tab(self):
"""Test the model tab"""
try:
from dpg_ui.tabs.model_tab import ModelTab
dpg.add_text("Testing Model Tab")
dpg.add_separator()
model_tab = ModelTab(dpg.last_item(), self.state)
except ImportError as e:
dpg.add_text(f"Error importing Model Tab: {e}")
def test_training_tab(self):
"""Test the training tab"""
try:
from dpg_ui.tabs.training_tab import TrainingTab
dpg.add_text("Testing Training Tab")
dpg.add_separator()
training_tab = TrainingTab(dpg.last_item(), self.state)
except ImportError as e:
dpg.add_text(f"Error importing Training Tab: {e}")
def test_sampling_tab(self):
"""Test the sampling tab"""
try:
from dpg_ui.tabs.sampling_tab import SamplingTab
dpg.add_text("Testing Sampling Tab")
dpg.add_separator()
sampling_tab = SamplingTab(dpg.last_item(), self.state)
except ImportError as e:
dpg.add_text(f"Error importing Sampling Tab: {e}")
def main():
"""Main entry point"""
# Parse command line arguments
parser = argparse.ArgumentParser(description="Test DPG UI components")
parser.add_argument("--component", type=str, default="concept",
choices=["concept", "concept_window", "lora", "model",
"training", "sampling"],
help="Component to test")
args = parser.parse_args()
# Create and run the test application
app = TestApp(args.component)
app.run()
if __name__ == "__main__":
main()