2021-06-04 09:33:36 +12:00
|
|
|
from PyQt5.QtCore import Qt
|
2021-12-24 22:09:50 +13:00
|
|
|
from PyQt5.QtWidgets import (
|
|
|
|
QHBoxLayout,
|
|
|
|
QPushButton,
|
|
|
|
QVBoxLayout,
|
|
|
|
QLabel,
|
|
|
|
QDialog,
|
|
|
|
QFileDialog,
|
|
|
|
)
|
2021-02-28 05:20:56 +13:00
|
|
|
|
2021-04-08 08:39:23 +12:00
|
|
|
from rare.utils.extra_widgets import PathEdit
|
2021-02-28 05:20:56 +13:00
|
|
|
|
|
|
|
|
|
|
|
class PathInputDialog(QDialog):
|
2021-03-18 23:35:07 +13:00
|
|
|
def __init__(self, title_text, text, path="Select Directory"):
|
2021-02-28 05:20:56 +13:00
|
|
|
super().__init__()
|
|
|
|
self.path = ""
|
2021-06-04 09:33:36 +12:00
|
|
|
self.setAttribute(Qt.WA_DeleteOnClose, True)
|
2021-02-28 05:20:56 +13:00
|
|
|
self.setWindowTitle(title_text)
|
|
|
|
self.info_label = QLabel(text)
|
|
|
|
self.info_label.setWordWrap(True)
|
|
|
|
|
2021-03-18 23:35:07 +13:00
|
|
|
self.input = PathEdit(path, QFileDialog.DirectoryOnly)
|
2021-02-28 05:20:56 +13:00
|
|
|
|
|
|
|
self.layout = QVBoxLayout()
|
|
|
|
self.layout.addWidget(self.info_label)
|
|
|
|
self.layout.addWidget(self.input)
|
|
|
|
|
|
|
|
self.child_layout = QHBoxLayout()
|
|
|
|
self.ok_button = QPushButton("Ok")
|
|
|
|
self.ok_button.clicked.connect(self.ok)
|
2021-03-12 00:56:38 +13:00
|
|
|
self.cancel_button = QPushButton(self.tr("Cancel"))
|
2021-02-28 05:20:56 +13:00
|
|
|
self.cancel_button.clicked.connect(self.cancel)
|
|
|
|
self.child_layout.addStretch()
|
|
|
|
self.child_layout.addWidget(self.ok_button)
|
|
|
|
self.child_layout.addWidget(self.cancel_button)
|
|
|
|
|
|
|
|
self.layout.addLayout(self.child_layout)
|
|
|
|
|
|
|
|
self.setLayout(self.layout)
|
|
|
|
|
|
|
|
def get_path(self):
|
|
|
|
self.exec_()
|
|
|
|
return self.path
|
|
|
|
|
|
|
|
def cancel(self):
|
|
|
|
self.path = ""
|
|
|
|
self.close()
|
|
|
|
|
|
|
|
def ok(self):
|
|
|
|
self.path = self.input.text()
|
2021-03-19 00:45:59 +13:00
|
|
|
self.close()
|