Skip to content

Commit 417d230

Browse files
authored
Update preview_panel.py
update to correct file
1 parent c12969b commit 417d230

1 file changed

Lines changed: 108 additions & 27 deletions

File tree

ui/widgets/preview_panel.py

Lines changed: 108 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,108 @@
1-
from dataclasses import dataclass, asdict
2-
3-
4-
@dataclass
5-
class DepthState:
6-
input_video_path: str = ""
7-
output_dir: str = ""
8-
selected_model: str = " -- Select Model -- "
9-
inference_resolution: str = "Original"
10-
batch_size: int = 8
11-
vda_overlap: int = 1
12-
inference_steps: int = 5
13-
codec: str = "H.265 / HEVC (NVENC - NVIDIA GPU)"
14-
colormap: str = "Default"
15-
invert_depth: bool = False
16-
save_frames: bool = False
17-
use_fp16: bool = True
18-
disable_depth_normalizer: bool = False
19-
offload_mode: str = "none"
20-
target_fps: int = 8
21-
ignore_letterbox_bars: bool = True
22-
prefer_opencv_writer: bool = False
23-
is_processing: bool = False
24-
is_paused: bool = False
25-
26-
def to_dict(self) -> dict:
27-
return asdict(self)
1+
from PySide6.QtCore import Qt
2+
from PySide6.QtWidgets import QWidget, QVBoxLayout, QLabel, QFrame, QSizePolicy
3+
4+
import os
5+
os.environ["OPENCV_FFMPEG_LOGLEVEL"] = "-8"
6+
7+
import cv2
8+
9+
try:
10+
cv2.utils.logging.setLogLevel(cv2.utils.logging.LOG_LEVEL_ERROR)
11+
except Exception:
12+
try:
13+
cv2.setLogLevel(2)
14+
except Exception:
15+
pass
16+
17+
18+
class PreviewPanel(QWidget):
19+
def __init__(self):
20+
super().__init__()
21+
22+
self._translator = None
23+
self._placeholder_key = "Video / Depth preview will appear here"
24+
self._meta_key = "No media loaded"
25+
self._meta_is_custom = False
26+
27+
layout = QVBoxLayout(self)
28+
layout.setContentsMargins(0, 0, 0, 0)
29+
layout.setSpacing(8)
30+
31+
self.title = QLabel("Preview")
32+
33+
self.frame = QFrame()
34+
self.frame.setMinimumHeight(420)
35+
self.frame.setObjectName("PreviewFrame")
36+
37+
self.placeholder = QLabel("Video / Depth preview will appear here")
38+
self.placeholder.setAlignment(Qt.AlignCenter)
39+
self.placeholder.setWordWrap(True)
40+
self.placeholder.setScaledContents(False)
41+
self.placeholder.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
42+
self.placeholder.setMinimumSize(320, 180)
43+
44+
inner = QVBoxLayout(self.frame)
45+
inner.setContentsMargins(12, 12, 12, 12)
46+
inner.addWidget(self.placeholder)
47+
48+
self.meta_label = QLabel("No media loaded")
49+
self.meta_label.setWordWrap(True)
50+
51+
layout.addWidget(self.title)
52+
layout.addWidget(self.frame, 1)
53+
layout.addWidget(self.meta_label)
54+
55+
def _t(self, key: str) -> str:
56+
if callable(self._translator):
57+
try:
58+
return self._translator(key)
59+
except Exception:
60+
return key
61+
62+
return key
63+
64+
def set_translator(self, translator):
65+
"""
66+
Gives PreviewPanel access to the page translation helper.
67+
Example:
68+
self.preview_panel.set_translator(self._t)
69+
"""
70+
self._translator = translator
71+
self.refresh_labels()
72+
73+
def _has_preview_image(self) -> bool:
74+
pixmap = self.placeholder.pixmap()
75+
return pixmap is not None and not pixmap.isNull()
76+
77+
def refresh_labels(self):
78+
self.title.setText(self._t("Preview"))
79+
80+
# Do not call setText() when the preview QLabel is showing an image.
81+
# QLabel.setText() clears the pixmap, which blanks the loaded preview
82+
# during language changes.
83+
if not self._has_preview_image():
84+
self.placeholder.setText(self._t(self._placeholder_key))
85+
86+
if not self._meta_is_custom:
87+
self.meta_label.setText(self._t(self._meta_key))
88+
89+
def set_placeholder(self, key: str):
90+
self._placeholder_key = str(key)
91+
92+
# Only update placeholder text when no preview image is currently loaded.
93+
if not self._has_preview_image():
94+
self.placeholder.setText(self._t(self._placeholder_key))
95+
96+
def set_meta(self, text: str, translate: bool = False):
97+
if translate:
98+
self._meta_key = str(text)
99+
self._meta_is_custom = False
100+
self.meta_label.setText(self._t(self._meta_key))
101+
else:
102+
self._meta_is_custom = True
103+
self.meta_label.setText(str(text))
104+
105+
def reset_meta(self):
106+
self._meta_key = "No media loaded"
107+
self._meta_is_custom = False
108+
self.meta_label.setText(self._t(self._meta_key))

0 commit comments

Comments
 (0)