moved PasswordDialog to openpype.settings.widgets

This commit is contained in:
iLLiCiTiT 2021-05-03 12:30:16 +02:00
parent d4af1cd0f3
commit eb51d3f368
3 changed files with 105 additions and 97 deletions

View file

@ -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",

View file

@ -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()

View file

@ -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()