Skip to content

Commit 3e2d5f1

Browse files
committed
loading image on item click
1 parent 8bd4c66 commit 3e2d5f1

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/dataset_image_annotator/__main__.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Sequence, Union
55

66
import rawpy
7-
from PySide6.QtCore import QFile, QIODevice, Qt, QDir, QFileInfo
7+
from PySide6.QtCore import QFile, QIODevice, Qt, QDir, QFileInfo, QModelIndex
88
from PySide6.QtGui import QPixmap, QScreen, QIcon
99
from PySide6.QtUiTools import QUiLoader
1010
from PySide6.QtWidgets import QApplication, QLabel, QGraphicsScene, QFileDialog, QFileSystemModel, QListView, \
@@ -96,13 +96,29 @@ def __init__(self, data_root_path: Path):
9696
print(loader.errorString())
9797
sys.exit(-1)
9898

99+
self.window.thumbnail_list_view.clicked.connect(self.on_file_selected)
100+
99101
self.window.show()
100102

101103
def browse_directory(self):
102104
path = QFileDialog.getExistingDirectory(self.window, 'Select dataset directory', str(self.data_root_path),
103105
options=QFileDialog.Option.ShowDirsOnly)
104106
self.set_data_root_path(path)
105107

108+
def on_file_selected(self, index: QModelIndex):
109+
file_name = index.data()
110+
file_path = Path(self.data_root_path, file_name)
111+
112+
thumb = get_raw_thumbnail(file_path)
113+
thumb_pixmap = QPixmap()
114+
thumb_pixmap.loadFromData(thumb.data)
115+
116+
image_label = QLabel()
117+
image_label.setPixmap(thumb_pixmap)
118+
scene = QGraphicsScene()
119+
scene.addWidget(image_label)
120+
self.window.photo_view.setScene(scene)
121+
106122
def set_data_root_path(self, path: str):
107123
self.window.path_edit.setText(path)
108124
self.data_root_path = Path(path)
@@ -123,16 +139,6 @@ def load_images(self):
123139
self.window.thumbnail_list_view.setModel(model)
124140
self.window.thumbnail_list_view.setRootIndex(model.index(str(self.data_root_path)))
125141

126-
thumb = get_raw_thumbnail(image_file_paths[0])
127-
thumb_pixmap = QPixmap()
128-
thumb_pixmap.loadFromData(thumb.data)
129-
130-
image_label = QLabel()
131-
image_label.setPixmap(thumb_pixmap)
132-
scene = QGraphicsScene()
133-
scene.addWidget(image_label)
134-
self.window.photo_view.setScene(scene)
135-
136142

137143
def main():
138144
args = get_parsed_args()

0 commit comments

Comments
 (0)