Skip to content

invalid_window

InvalidCredentialsWindow

Bases: QDialog

Source code in common/ayon_common/connection/ui/invalid_window.py
 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
class InvalidCredentialsWindow(QtWidgets.QDialog):
    default_width = 420
    default_height = 170

    def __init__(self, message, *args, **kwargs):
        super().__init__(*args, **kwargs)

        icon_path = get_icon_path()
        icon = QtGui.QIcon(icon_path)
        self.setWindowIcon(icon)
        self.setWindowTitle("Invalid credentials")

        info_widget = QtWidgets.QWidget(self)

        message_label = url_cred_sep = None
        if message:
            # --- Custom message ---
            message_label = QtWidgets.QLabel(message, info_widget)
            message_label.setWordWrap(True)
            message_label.setTextInteractionFlags(
                QtCore.Qt.TextBrowserInteraction
            )

            # --- URL separator ---
            url_cred_sep = QtWidgets.QFrame(info_widget)
            url_cred_sep.setObjectName("Separator")
            url_cred_sep.setMinimumHeight(2)
            url_cred_sep.setMaximumHeight(2)

        common_label = QtWidgets.QLabel(
            (
                " You are running AYON launcher in <b>'bypass login'</b>"
                " mode. Meaning your AYON connection information is"
                " defined by environment variables."
                "<br/><br/>Please contact your administrator or use valid"
                " credentials."
            ),
            info_widget
        )
        common_label.setWordWrap(True)
        common_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)

        info_layout = QtWidgets.QVBoxLayout(info_widget)
        info_layout.setContentsMargins(0, 0, 0, 0)
        if message_label is not None:
            info_layout.addWidget(message_label, 0)
            info_layout.addWidget(url_cred_sep, 0)
        info_layout.addWidget(common_label, 0)

        footer_widget = QtWidgets.QWidget(self)
        close_btn = QtWidgets.QPushButton("Close", footer_widget)

        footer_layout = QtWidgets.QHBoxLayout(footer_widget)
        footer_layout.setContentsMargins(0, 0, 0, 0)
        footer_layout.addStretch(1)
        footer_layout.addWidget(close_btn, 0)

        main_layout = QtWidgets.QVBoxLayout(self)
        main_layout.addWidget(info_widget, 0)
        main_layout.addStretch(1)
        main_layout.addWidget(footer_widget, 0)

        close_btn.clicked.connect(self._on_close_click)

        self._first_show = True
        self._message_label = message_label
        self._common_label = common_label

    def resizeEvent(self, event):
        super().resizeEvent(event)
        print(self.size())

    def showEvent(self, event):
        super().showEvent(event)
        if self._first_show:
            self._first_show = False
            self._on_first_show()

    def _on_first_show(self):
        self.setStyleSheet(load_stylesheet())
        self.resize(self.default_width, self.default_height)
        self._center_window()

    def _center_window(self):
        """Move window to center of screen."""

        if hasattr(QtWidgets.QApplication, "desktop"):
            desktop = QtWidgets.QApplication.desktop()
            screen_idx = desktop.screenNumber(self)
            screen_geo = desktop.screenGeometry(screen_idx)
        else:
            screen = self.screen()
            screen_geo = screen.geometry()

        geo = self.frameGeometry()
        geo.moveCenter(screen_geo.center())
        if geo.y() < screen_geo.y():
            geo.setY(screen_geo.y())
        self.move(geo.topLeft())

    def _on_close_click(self):
        self.close()

invalid_credentials(message, always_on_top=False)

Tell user that his credentials are invalid.

This functionality is used when credentials that user did use were not received from keyring or login window.

Parameters:

Name Type Description Default
message str

Some information that can caller define.

required
always_on_top Optional[bool]

Window will be drawn on top of other windows.

False
Source code in common/ayon_common/connection/ui/invalid_window.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
def invalid_credentials(message, always_on_top=False):
    """Tell user that his credentials are invalid.

    This functionality is used when credentials that user did use were
        not received from keyring or login window.

    Args:
        message (str): Some information that can caller define.
        always_on_top (Optional[bool]): Window will be drawn on top of
            other windows.
    """

    app_instance = get_qt_app()
    window = InvalidCredentialsWindow(message)
    if always_on_top:
        window.setWindowFlags(
            window.windowFlags()
            | QtCore.Qt.WindowStaysOnTopHint
        )

    if not app_instance.startingUp():
        window.exec_()
    else:
        window.open()
        # This can become main Qt loop. Maybe should live elsewhere
        app_instance.exec_()