Skip to content

Commit 0ce022f

Browse files
committed
improve interactive panel
1 parent 0702d01 commit 0ce022f

3 files changed

Lines changed: 32 additions & 9 deletions

File tree

example.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import glob
3+
import sys
34

45
# Automatically scan all files ending with _example.py in the examples folder
56
examples_dir = os.path.join(os.path.dirname(__file__), 'examples')
@@ -12,13 +13,26 @@
1213
example_name = filename.replace('_example.py', '')
1314
EXAMPLE.append(example_name)
1415

15-
print("Choose an example:")
16-
17-
for i, example in enumerate(EXAMPLE):
18-
print(f"{i+1}.{example}")
16+
# Check if an example name is provided as a command-line argument
17+
if len(sys.argv) > 1:
18+
example_name = sys.argv[1]
19+
# Verify if the example exists in the scanned list to prevent arbitrary imports
20+
if example_name in EXAMPLE:
21+
import_path = f"examples.{example_name}_example"
22+
__import__(import_path)
23+
else:
24+
print(f"Error: Example '{example_name}' not found.")
25+
print("Available examples:")
26+
for i, ex in enumerate(EXAMPLE):
27+
print(f"{i+1}. {ex}")
28+
else:
29+
print("Choose an examples:")
30+
31+
for i, example in enumerate(EXAMPLE):
32+
print(f"{i+1}.{example}")
1933

20-
choice = int(input("Enter your choice: "))
34+
choice = int(input("Enter your choice: "))
2135

22-
import_path = f"examples.{EXAMPLE[choice-1]}_example"
36+
import_path = f"examples.{EXAMPLE[choice-1]}_example"
2337

24-
__import__(import_path)
38+
__import__(import_path)

examples/interactive_panel_example.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from dataclasses import asdict
55
from PySide6.QtWidgets import (
66
QApplication, QWidget, QVBoxLayout, QHBoxLayout,
7-
QLabel, QComboBox, QFrame, QCheckBox, QDoubleSpinBox
7+
QLabel, QComboBox, QFrame, QCheckBox, QDoubleSpinBox, QPushButton
88
)
99
from PySide6.QtCore import Qt
1010

@@ -397,6 +397,9 @@ def setup_ui(self):
397397
self.sc_line.setFrameShape(QFrame.HLine)
398398
self.control_layout.addWidget(self.sc_line)
399399

400+
self.ball_window_button = QPushButton('Show Ball Window')
401+
self.control_layout.addWidget(self.ball_window_button)
402+
400403
self.control_layout.addStretch()
401404

402405
self.main_layout.addWidget(self.control_widget)
@@ -459,6 +462,8 @@ def connect_signals(self):
459462
self.s_ra_y_spin.valueChanged.connect(self.on_scale_ratio_xyz_changed)
460463
self.s_ra_z_spin.valueChanged.connect(self.on_scale_ratio_xyz_changed)
461464

465+
self.ball_window_button.clicked.connect(self.on_ball_window_button_pressed)
466+
462467
def update_animation(self, animation_name='T.anim'):
463468
if not animation_name or animation_name not in self.animations:
464469
return
@@ -714,6 +719,10 @@ def on_scale_ratio_xyz_changed(self, value=None):
714719
print(f"Scale Ratio: {self.play_kwargs.scale_ratio}")
715720
self.update_graph()
716721

722+
def on_ball_window_button_pressed(self, button_name):
723+
import subprocess
724+
subprocess.Popen([sys.executable, 'example.py', 'qml_window'])
725+
717726
def update_graph(self):
718727
if not self.play_kwargs.path: return
719728

unity_animation_player/kwargs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class PlayKwargs:
3333
position_unit: Union[Literal['x', 'y', 'z', 'w'], Tuple[Literal['x', 'y', 'z', 'w'], ...]] = ('x', 'y')
3434
position_reverse: Union[bool, Tuple[bool, ...]] = False
3535
position_ratio: Union[float, Tuple[float, ...]] = 1.0
36-
scale_unit: Union[Literal['x', 'y', 'z', 'w'], Tuple[Literal['x', 'y', 'z', 'w'], ...]] = ('x', 'y', 'z')
36+
scale_unit: Union[Literal['x', 'y', 'z', 'w'], Tuple[Literal['x', 'y', 'z', 'w'], ...]] = ('x', 'y')
3737
scale_reverse: Union[bool, Tuple[bool, ...]] = False
3838
scale_ratio: Union[float, Tuple[float, ...]] = 1.0
3939

0 commit comments

Comments
 (0)