-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResetDBWindow.py
134 lines (117 loc) · 5.8 KB
/
ResetDBWindow.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
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
from typing import Callable
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QMainWindow, QFileDialog
from torch.nn import Module
from transformers import CLIPVisionModelWithProjection, AutoProcessor
from DBReinitializer import DBReinitializer
from MultimediaDB import MultimediaDB
class ResetDBWindow(QMainWindow):
"""
Dialog window that is used to reset the database starting from a folder of choice. Can be opened from the settings.
"""
def __init__(self, db: MultimediaDB,
clip: CLIPVisionModelWithProjection,
clip_processor: AutoProcessor,
autoencoder: Module,
update_func: Callable) -> None:
"""
Initializes the database reinitialization window and its UI components.
Arguments:
----------
db : MultimediaDB
Database object for managing multimedia content.
clip : CLIPVisionModelWithProjection
The CLIP model used for semantic embeddings.
clip_processor : AutoProcessor
Processor for preparing inputs for the CLIP model.
autoencoder : torch.Module
Autoencoder model used for content embeddings.
update_func : Callable
Function to update the DB status label in the Settings window.
Behavior:
---------
- Sets up the central widget and UI elements including labels, text fields, buttons, and a progress bar.
- Connects button clicks to their respective functions:
- `path_button` triggers the folder selection dialog via `choose_folder`.
- `start_button` initiates the database reinitialization process via `reinit_db`.
- Stores the provided database, models, and update function in instance variables for later use.
Returns:
--------
None
"""
super().__init__()
self.centralwidget = QtWidgets.QWidget(self)
self.path_label = QtWidgets.QLabel(self.centralwidget)
self.path_text = QtWidgets.QLineEdit(self.centralwidget)
self.path_button = QtWidgets.QPushButton(self.centralwidget)
self.start_button = QtWidgets.QPushButton(self.centralwidget)
self.progressBar = QtWidgets.QProgressBar(self.centralwidget)
self.status_label = QtWidgets.QLabel(self.centralwidget)
self.setupUi()
self.path_button.clicked.connect(self.choose_folder)
self.start_button.clicked.connect(self.reinit_db)
self.setWindowIcon(QIcon('res/assets/icons/database_icon.png'))
self.db = db
self.clip = clip
self.clip_processor = clip_processor
self.autoencoder = autoencoder
self.update_func = update_func
self.db_reinitializer = None
def choose_folder(self) -> None:
"""
Opens a dialog for the user to select a directory and prepares the database for reinitialization.
Behavior:
---------
- Displays a directory selection dialog and captures the user's selected directory.
- Updates the `path_text` input field with the selected directory path.
- Initializes a `DBReinitializer` worker thread to handle the database reinitialization process without freezing
the GUI.
- Connects the `DBReinitializer`'s progress and status signals to update the progress bar (`progressBar`) and
status label (`status_label`) in real-time.
Returns:
--------
None
"""
selected_directory = QFileDialog.getExistingDirectory(self, "Select Directory")
self.path_text.setText(selected_directory)
self.db_reinitializer = DBReinitializer(self.db, selected_directory, self.clip, self.clip_processor,
self.autoencoder, self.update_func, self)
self.db_reinitializer.progress.connect(lambda x: self.progressBar.setValue(x))
self.db_reinitializer.status.connect(lambda x: self.status_label.setText(x))
def reinit_db(self) -> None:
"""
Starts the reinitialization process by starting the worker thread.
"""
if self.path_label.text() != '':
self.db_reinitializer.start()
# Again, autogenerated functions
def setupUi(self):
self.setObjectName("ResetDBWindow")
self.resize(502, 154)
self.centralwidget.setObjectName("centralwidget")
self.path_label.setGeometry(QtCore.QRect(10, 10, 31, 16))
self.path_label.setObjectName("path_label")
self.path_text.setGeometry(QtCore.QRect(50, 10, 401, 22))
self.path_text.setReadOnly(True)
self.start_button.setObjectName("start_button")
self.start_button.setGeometry(QtCore.QRect(150, 37, 201, 28))
self.path_text.setObjectName("path_text")
self.path_button.setGeometry(QtCore.QRect(460, 10, 31, 28))
self.path_button.setObjectName("pushButton")
self.progressBar.setGeometry(QtCore.QRect(10, 121, 481, 23))
self.progressBar.setProperty("value", 0)
self.progressBar.setTextVisible(False)
self.progressBar.setObjectName("progressBar")
self.status_label.setGeometry(QtCore.QRect(10, 100, 481, 16))
self.status_label.setObjectName("status_label")
self.setCentralWidget(self.centralwidget)
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
def retranslateUi(self):
_translate = QtCore.QCoreApplication.translate
self.setWindowTitle(_translate("ResetDBWindow", "Reinitialize Database"))
self.path_label.setText(_translate("ResetDBWindow", "Path:"))
self.path_button.setText(_translate("ResetDBWindow", "..."))
self.status_label.setText(_translate("ResetDBWindow", "Status"))
self.start_button.setText(_translate("ResetDBWindow", "Reinitialize Database"))