-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_provider.py
54 lines (44 loc) · 1.71 KB
/
run_provider.py
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
import io
from PIL import Image
from PySide6.QtCore import QBuffer, QIODevice, QObject, QThread
from PySide6.QtWidgets import QDialog, QProgressBar, QVBoxLayout
class RunProviderProgressDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Run Provider")
self.setMinimumSize(300, 100)
self.setMaximumSize(300, 100)
self.progress_bar = QProgressBar(self)
self.progress_bar.setMinimum(0)
self.progress_bar.setMaximum(0)
self.progress_bar.setTextVisible(False)
layout = QVBoxLayout(self)
layout.addWidget(self.progress_bar)
def start_animation(self):
self.progress_bar.setMaximum(0)
self.progress_bar.setMinimum(0)
self.progress_bar.setFormat("Processing...")
self.progress_bar.setRange(0, 0)
def stop_animation(self):
self.close()
class RunProvider(QThread):
def __init__(self, image, provider, annotation_type, color, parent: QObject | None = ...) -> None:
super().__init__(parent)
self.image = image
self.provider = provider
self.annotation_type = annotation_type
self.color = color
self.annotations = None
dialog = RunProviderProgressDialog(parent)
self.finished.connect(dialog.stop_animation)
self.start()
dialog.start_animation()
dialog.exec()
def run(self):
buffer = QBuffer()
buffer.open(QIODevice.OpenModeFlag.ReadWrite)
self.image.save(buffer, "PNG")
pil_im = Image.open(io.BytesIO(buffer.data()))
annotations = self.provider.run(
pil_im, self.annotation_type, self.color)
self.annotations = annotations