diff --git a/openpype/tools/settings/settings/widgets/eye.png b/openpype/tools/settings/settings/widgets/eye.png new file mode 100644 index 0000000000..fe37f0ab6e Binary files /dev/null and b/openpype/tools/settings/settings/widgets/eye.png differ diff --git a/openpype/tools/settings/settings/widgets/window.py b/openpype/tools/settings/settings/widgets/window.py index e632a1b2b6..14804ba54a 100644 --- a/openpype/tools/settings/settings/widgets/window.py +++ b/openpype/tools/settings/settings/widgets/window.py @@ -1,4 +1,5 @@ -from Qt import QtWidgets, QtGui +import os +from Qt import QtWidgets, QtGui, QtCore from .categories import ( CategoryState, SystemWidget, @@ -88,3 +89,101 @@ class MainWidget(QtWidgets.QWidget): if self._reset_on_show: self._reset_on_show = False + + +class PasswordDialog(QtWidgets.QDialog): + """Stupidly simple dialog to compare password from general settings.""" + finished = QtCore.Signal(str) + + def __init__(self, password, parent): + super(PasswordDialog, self).__init__(parent) + + self.setWindowTitle("Settings Password") + self.resize(300, 120) + + self._result = "" + self._expected_result = password + + # Password input + password_widget = QtWidgets.QWidget(self) + + password_label = QtWidgets.QLabel("Password:", password_widget) + + password_input = QtWidgets.QLineEdit(password_widget) + password_input.setEchoMode(QtWidgets.QLineEdit.Password) + + current_dir = os.path.join( + os.path.dirname(os.path.abspath(__file__)) + ) + show_password_icon_path = os.path.join(current_dir, "eye.png") + show_password_icon = QtGui.QIcon(show_password_icon_path) + show_password_btn = QtWidgets.QPushButton(password_widget) + show_password_btn.setIcon(show_password_icon) + show_password_btn.setStyleSheet(( + "border: none;padding:0.1em;" + )) + + password_layout = QtWidgets.QHBoxLayout(password_widget) + password_layout.setContentsMargins(0, 0, 0, 0) + password_layout.addWidget(password_label) + password_layout.addWidget(password_input) + password_layout.addWidget(show_password_btn) + + message_label = QtWidgets.QLabel("", self) + + # Buttons + buttons_widget = QtWidgets.QWidget(self) + + ok_btn = QtWidgets.QPushButton("Ok", buttons_widget) + cancel_btn = QtWidgets.QPushButton("Cancel", buttons_widget) + + buttons_layout = QtWidgets.QHBoxLayout(buttons_widget) + buttons_layout.setContentsMargins(0, 0, 0, 0) + buttons_layout.addStretch(1) + buttons_layout.addWidget(ok_btn) + buttons_layout.addWidget(cancel_btn) + + # Main layout + layout = QtWidgets.QVBoxLayout(self) + layout.addSpacing(10) + layout.addWidget(password_widget, 0) + layout.addWidget(message_label, 0) + layout.addStretch(1) + layout.addWidget(buttons_widget, 0) + + password_input.textChanged.connect(self._on_text_change) + ok_btn.clicked.connect(self._on_ok_click) + cancel_btn.clicked.connect(self._on_cancel_click) + show_password_btn.clicked.connect(self._on_show_password) + + self.password_input = password_input + self.message_label = message_label + + def keyPressEvent(self, event): + if event.key() in (QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter): + self._on_ok_click() + return event.accept() + super(PasswordDialog, self).keyPressEvent(event) + + def closeEvent(self, event): + self.finished.emit(self._result) + super(PasswordDialog, self).closeEvent(event) + + def _on_text_change(self, text): + self._result = text + + def _on_ok_click(self): + if self._result == self._expected_result: + self.close() + self.message_label.setText("Invalid password. Try it again...") + + def _on_show_password(self): + if self.password_input.echoMode() == QtWidgets.QLineEdit.Password: + echo_mode = QtWidgets.QLineEdit.Normal + else: + echo_mode = QtWidgets.QLineEdit.Password + self.password_input.setEchoMode(echo_mode) + + def _on_cancel_click(self): + self._result = "" + self.close()