-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspinrender_tab.py
More file actions
259 lines (213 loc) · 12.3 KB
/
spinrender_tab.py
File metadata and controls
259 lines (213 loc) · 12.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
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
"""
SpinRender Tab - Animation rendering tab UI
"""
import os
import json
import wx
import wx.lib.scrolledpanel as scrolled
def create_spinrender_tab(parent, dialog):
"""Create the SpinRender (animation) tab."""
import time
t0 = time.time()
# OPTIMIZATION: Freeze updates to prevent redraws during widget creation
parent.Freeze()
try:
from .tabs import (_on_template_selected, _show_manage_menu, _save_as_template,
_refresh_template_dropdown, _show_preview, _open_template_folder)
outer = wx.Panel(parent)
outer_sizer = wx.BoxSizer(wx.VERTICAL)
# Template selector at top
tmpl_sizer = wx.BoxSizer(wx.HORIZONTAL)
tmpl_sizer.Add(wx.StaticText(outer, label="Template:"), 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 5)
dialog.anim_template_choice = wx.Choice(outer, size=(180, -1))
dialog.anim_template_choice.Bind(wx.EVT_CHOICE, lambda e: _on_template_selected(dialog, "spinrender"))
tmpl_sizer.Add(dialog.anim_template_choice, 0, wx.RIGHT, 5)
manage_btn = wx.Button(outer, label="⚙", size=(30, -1))
manage_btn.SetToolTip("Manage templates")
manage_btn.Bind(wx.EVT_BUTTON, lambda e: _show_manage_menu(dialog, manage_btn, "spinrender"))
tmpl_sizer.Add(manage_btn, 0, wx.RIGHT, 2)
folder_btn = wx.Button(outer, label="📁", size=(30, -1))
folder_btn.SetToolTip("Open template folder")
folder_btn.Bind(wx.EVT_BUTTON, lambda e: _open_template_folder())
tmpl_sizer.Add(folder_btn, 0, wx.RIGHT, 2)
create_btn = wx.Button(outer, label="+", size=(30, -1))
create_btn.SetToolTip("Create new template")
create_btn.Bind(wx.EVT_BUTTON, lambda e: _save_as_template(dialog, "spinrender"))
tmpl_sizer.Add(create_btn, 0, wx.RIGHT, 5)
# CLI Validation status icon (just after +)
dialog.anim_validation_status = wx.StaticText(outer, label="")
dialog.anim_validation_status.SetFont(wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
dialog.anim_validation_status.SetToolTip("CLI parameter validation status")
tmpl_sizer.Add(dialog.anim_validation_status, 0, wx.ALIGN_CENTER_VERTICAL)
outer_sizer.Add(tmpl_sizer, 0, wx.ALL, 10)
# Defer template refresh for faster perceived load
wx.CallAfter(_refresh_template_dropdown, dialog, "spinrender")
# Use SplitterWindow for resizable JSON preview
splitter = wx.SplitterWindow(outer, style=wx.SP_LIVE_UPDATE | wx.SP_3DSASH)
splitter.SetMinimumPaneSize(80) # Minimum height for either pane
# Top pane: JSON Preview
json_panel = wx.Panel(splitter)
json_panel_sizer = wx.BoxSizer(wx.VERTICAL)
json_box = wx.StaticBox(json_panel, label="Template Parameters (edit via Manage → Edit)")
json_sizer = wx.StaticBoxSizer(json_box, wx.VERTICAL)
dialog.anim_json_preview = wx.TextCtrl(json_panel, style=wx.TE_MULTILINE | wx.TE_READONLY | wx.HSCROLL)
dialog.anim_json_preview.SetFont(wx.Font(9, wx.FONTFAMILY_TELETYPE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))
dialog.anim_json_preview.SetBackgroundColour(wx.Colour(245, 245, 245))
json_sizer.Add(dialog.anim_json_preview, 1, wx.EXPAND | wx.ALL, 5)
json_panel_sizer.Add(json_sizer, 1, wx.EXPAND | wx.ALL, 5)
json_panel.SetSizer(json_panel_sizer)
# Bottom pane: Scrolled settings panel
scroll = scrolled.ScrolledPanel(splitter, style=wx.VSCROLL)
sizer = wx.BoxSizer(wx.VERTICAL)
# Animation Settings (these are render-time settings, not template settings)
anim_box = wx.StaticBox(scroll, label="Animation Settings")
anim_sizer = wx.StaticBoxSizer(anim_box, wx.VERTICAL)
grid2 = wx.FlexGridSizer(3, 4, 5, 10)
grid2.AddGrowableCol(1)
grid2.AddGrowableCol(3)
grid2.Add(wx.StaticText(scroll, label="Frames:"), 0, wx.ALIGN_CENTER_VERTICAL)
dialog.anim_frames = wx.SpinCtrl(scroll, value=str(dialog.config.get('anim_frames', 120)), min=1, max=3600)
grid2.Add(dialog.anim_frames, 1, wx.EXPAND)
grid2.Add(wx.StaticText(scroll, label="FPS:"), 0, wx.ALIGN_CENTER_VERTICAL)
dialog.anim_fps = wx.SpinCtrl(scroll, value=str(dialog.config.get('anim_fps', 30)), min=1, max=120)
grid2.Add(dialog.anim_fps, 1, wx.EXPAND)
grid2.Add(wx.StaticText(scroll, label="Rotations:"), 0, wx.ALIGN_CENTER_VERTICAL)
dialog.anim_revs = wx.SpinCtrl(scroll, value="1", min=1, max=10)
grid2.Add(dialog.anim_revs, 1, wx.EXPAND)
grid2.Add(wx.StaticText(scroll, label="Format:"), 0, wx.ALIGN_CENTER_VERTICAL)
dialog.anim_format = wx.Choice(scroll, choices=["mp4", "gif", "webm", "png sequence"])
dialog.anim_format.SetSelection(0)
grid2.Add(dialog.anim_format, 1, wx.EXPAND)
# Parallel workers setting
from .parallel_render import get_cpu_count, get_recommended_workers
cpu_count = get_cpu_count()
recommended = get_recommended_workers()
worker_choices = [f"Auto ({recommended} cores)"] + [str(i) for i in range(1, min(cpu_count + 1, 17))]
grid2.Add(wx.StaticText(scroll, label="Workers:"), 0, wx.ALIGN_CENTER_VERTICAL)
dialog.anim_workers = wx.Choice(scroll, choices=worker_choices)
saved_workers = dialog.config.get('parallel_workers', 0)
if saved_workers == 0:
dialog.anim_workers.SetSelection(0) # Auto
elif saved_workers <= cpu_count:
dialog.anim_workers.SetSelection(saved_workers) # 1-based index matches worker count
else:
dialog.anim_workers.SetSelection(0)
dialog.anim_workers.SetToolTip(f"CPU cores: {cpu_count}. More workers = faster, but uses more RAM.")
grid2.Add(dialog.anim_workers, 1, wx.EXPAND)
anim_sizer.Add(grid2, 0, wx.EXPAND | wx.ALL, 5)
sizer.Add(anim_sizer, 0, wx.EXPAND | wx.ALL, 5)
# Rotation Settings
rot_box = wx.StaticBox(scroll, label="Rotation Settings")
rot_sizer = wx.StaticBoxSizer(rot_box, wx.VERTICAL)
dialog.axis_rb = wx.RadioBox(scroll, label="Rotation Axis",
choices=["Y (Spin/Orbit)", "Z (Turntable)", "X (Flip)"],
majorDimension=3, style=wx.RA_SPECIFY_COLS)
rot_sizer.Add(dialog.axis_rb, 0, wx.EXPAND | wx.ALL, 5)
tilt_grid = wx.FlexGridSizer(1, 6, 5, 10)
tilt_grid.Add(wx.StaticText(scroll, label="Tilt X:"), 0, wx.ALIGN_CENTER_VERTICAL)
dialog.tilt_x = wx.SpinCtrl(scroll, value="0", min=-180, max=180)
tilt_grid.Add(dialog.tilt_x, 0)
tilt_grid.Add(wx.StaticText(scroll, label="Tilt Y:"), 0, wx.ALIGN_CENTER_VERTICAL)
dialog.tilt_y = wx.SpinCtrl(scroll, value="0", min=-180, max=180)
tilt_grid.Add(dialog.tilt_y, 0)
tilt_grid.Add(wx.StaticText(scroll, label="Tilt Z:"), 0, wx.ALIGN_CENTER_VERTICAL)
dialog.tilt_z = wx.SpinCtrl(scroll, value="45", min=-180, max=180)
tilt_grid.Add(dialog.tilt_z, 0)
rot_sizer.Add(tilt_grid, 0, wx.EXPAND | wx.ALL, 5)
sizer.Add(rot_sizer, 0, wx.EXPAND | wx.ALL, 5)
# Output
out_box = wx.StaticBox(scroll, label="Output")
out_sizer = wx.StaticBoxSizer(out_box, wx.HORIZONTAL)
default_output = os.path.join(dialog.output_dirs['SpinRender'], f"{dialog.project_name}_spin.mp4")
dialog.anim_output = wx.TextCtrl(scroll, value=default_output)
browse_btn = wx.Button(scroll, label="Browse...")
browse_btn.Bind(wx.EVT_BUTTON, dialog.on_browse_anim)
out_sizer.Add(dialog.anim_output, 1, wx.EXPAND | wx.ALL, 5)
out_sizer.Add(browse_btn, 0, wx.ALL, 5)
sizer.Add(out_sizer, 0, wx.EXPAND | wx.ALL, 5)
# Setup scrolling AFTER populating sizer
scroll.SetSizer(sizer)
scroll.SetupScrolling(scroll_x=False)
# Split horizontally: JSON preview on top, settings below
initial_pos = dialog.config.get('anim_json_splitter_pos', 150)
splitter.SplitHorizontally(json_panel, scroll, initial_pos)
outer_sizer.Add(splitter, 1, wx.EXPAND)
# Store splitter reference for saving position later
dialog.anim_json_splitter = splitter
# Estimate row
estimate_row = wx.BoxSizer(wx.HORIZONTAL)
dialog.anim_estimate_label = wx.StaticText(outer, label="📊 Estimated: calculating...")
dialog.anim_estimate_label.SetForegroundColour(wx.Colour(100, 100, 100))
estimate_row.Add(dialog.anim_estimate_label, 1, wx.ALIGN_CENTER_VERTICAL)
outer_sizer.Add(estimate_row, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)
# Bind controls to update estimate
dialog.anim_frames.Bind(wx.EVT_SPINCTRL, lambda e: _update_estimate(dialog))
# Initial estimate update
wx.CallAfter(_update_estimate, dialog)
# Button row
btn_row = wx.BoxSizer(wx.HORIZONTAL)
preview_btn = wx.Button(outer, label="Preview", size=(80, 40))
preview_btn.SetToolTip("Quick preview render")
preview_btn.Bind(wx.EVT_BUTTON, lambda e: _show_preview(dialog, "spinrender"))
render_btn = wx.Button(outer, label="Render Animation", size=(-1, 40))
render_btn.SetFont(wx.Font(11, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD))
render_btn.Bind(wx.EVT_BUTTON, dialog.on_render_animation)
dialog.anim_cancel_btn = wx.Button(outer, label="Cancel", size=(80, 40))
dialog.anim_cancel_btn.Enable(False)
dialog.anim_cancel_btn.Bind(wx.EVT_BUTTON, dialog.on_cancel)
btn_row.Add(preview_btn, 0, wx.RIGHT, 5)
btn_row.Add(render_btn, 1, wx.EXPAND | wx.RIGHT, 5)
btn_row.Add(dialog.anim_cancel_btn, 0)
outer_sizer.Add(btn_row, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)
outer.SetSizer(outer_sizer)
finally:
parent.Thaw()
dialog.log(f" [SpinRender] UI created in {(time.time()-t0)*1000:.0f}ms")
return outer
def update_anim_json_preview(dialog, template=None):
"""
Update the JSON preview for the selected animation template.
Called when template selection changes. Shows raw template JSON.
"""
if not hasattr(dialog, 'anim_json_preview'):
return
if template is None:
dialog.anim_json_preview.SetValue("No template selected")
return
try:
# Show raw template JSON as-is
json_str = json.dumps(template, indent=2)
dialog.anim_json_preview.SetValue(json_str)
except Exception as e:
dialog.anim_json_preview.SetValue(f"Error: {e}")
def _update_estimate(dialog):
"""
Update the estimated render time display based on current settings.
Uses stored benchmarks or default values (11 sec/frame for high quality at 1080p).
"""
try:
from .config import estimate_render_time, format_time_estimate
# Get current settings - need to read from template now
frames = dialog.anim_frames.GetValue() if hasattr(dialog, 'anim_frames') else 120
# Get width/height from current template
width, height = 1920, 1080 # defaults
quality = 'high'
# Try to get from current template
if hasattr(dialog, '_current_anim_template') and dialog._current_anim_template:
params = dialog._current_anim_template.get("cli_params", {})
width = params.get("width", 1920)
height = params.get("height", 1080)
quality = params.get("quality", "high")
# Calculate estimate
total_seconds = estimate_render_time(width, height, frames, quality)
time_str = format_time_estimate(total_seconds)
# Calculate per-frame estimate for display
sec_per_frame = total_seconds / frames if frames > 0 else 0
# Update label
if hasattr(dialog, 'anim_estimate_label'):
dialog.anim_estimate_label.SetLabel(
f"📊 Estimated: ~{time_str} ({sec_per_frame:.1f}s/frame, {frames} frames)"
)
except Exception as e:
if hasattr(dialog, 'anim_estimate_label'):
dialog.anim_estimate_label.SetLabel(f"📊 Estimated: (error: {e})")