From eb51d3f36893e68ab3221196c00638bda49fcc39 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Mon, 3 May 2021 12:30:16 +0200 Subject: [PATCH] moved PasswordDialog to openpype.settings.widgets --- openpype/tools/settings/__init__.py | 2 + .../tools/settings/settings/widgets/window.py | 98 +---------------- openpype/tools/settings/widgets.py | 102 ++++++++++++++++++ 3 files changed, 105 insertions(+), 97 deletions(-) create mode 100644 openpype/tools/settings/widgets.py diff --git a/openpype/tools/settings/__init__.py b/openpype/tools/settings/__init__.py index f56704def5..0d02bb50e4 100644 --- a/openpype/tools/settings/__init__.py +++ b/openpype/tools/settings/__init__.py @@ -1,5 +1,6 @@ import sys from Qt import QtWidgets, QtGui +from .widgets import PasswordDialog from .local_settings import LocalSettingsWindow from .settings import ( style, @@ -30,6 +31,7 @@ def main(user_role=None): __all__ = ( "style", + "PasswordDialog", "MainWidget", "ProjectListWidget", "LocalSettingsWindow", diff --git a/openpype/tools/settings/settings/widgets/window.py b/openpype/tools/settings/settings/widgets/window.py index 7673783e2e..e24da1dc33 100644 --- a/openpype/tools/settings/settings/widgets/window.py +++ b/openpype/tools/settings/settings/widgets/window.py @@ -9,6 +9,7 @@ from .widgets import ShadowWidget from .. import style from openpype.api import get_system_settings +from openpype.tools.settings import PasswordDialog class MainWidget(QtWidgets.QWidget): @@ -123,100 +124,3 @@ 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() diff --git a/openpype/tools/settings/widgets.py b/openpype/tools/settings/widgets.py new file mode 100644 index 0000000000..a47bd2c008 --- /dev/null +++ b/openpype/tools/settings/widgets.py @@ -0,0 +1,102 @@ +import os +from Qt import QtWidgets, QtCore, QtGui + +from openpype.api import get_system_settings + + +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()