Exemple #1
0
def update(t,apath=None):
    v = apath
    if apath == None:
        v = DefaultPath.getIconFile(t)
    if os.path.isfile(v):
        return init_default_icon(t,v)
    return defaultIcon
 def __init__(self):
     """
     Constructor. Widget is initially hidden.
     """
     image_path = DefaultPath.getIconFile("dialog_splash.png")
     super(DskSplash, self).__init__(QtT.QtGui.QPixmap(image_path))
    def __init__(self,
                 is_session_renewal,
                 hostname=None,
                 login=None,
                 fixed_host=False,
                 http_proxy=None,
                 parent=None,
                 session=None,
                 session_metadata=None):
        """
        Constructs a dialog.

        :param is_session_renewal: Boolean indicating if we are renewing a session or authenticating a user from
            scratch.
        :param hostname: The string to populate the site field with. If None, the field will be empty.
        :param login: The string to populate the login field with. If None, the field will be empty.
        :param fixed_host: Indicates if the hostname can be changed. Defaults to False.
        :param http_proxy: The proxy server to use when testing authentication. Defaults to None.
        :param parent: The Qt parent for the dialog (defaults to None)
        :param session_metadata: Metadata used in the context of SSO. This is an obscure blob of data.
        """

        super(LoginAuthDialog, self).__init__(parent)

        try:
            self._sso_saml2 = SsoSaml2Toolkit("Web Login", qt_modules=QtAll)
        except SsoSaml2MissingQtModuleError as e:
            logger.info(
                "Web login not supported due to missing Qt module: %s" % e)
            self._sso_saml2 = None

        hostname = hostname or ""
        login = login or ""

        self._is_session_renewal = is_session_renewal
        self._session_metadata = session_metadata
        self._session = session
        self._use_web = False

        # setup the gui
        self.ui = QtAll.uic.loadUi(DefaultPath.getUiFile("login_auth_dialog"),
                                   self)

        # icon path
        image_path = DefaultPath.getIconFile("dialog_splash_small.png")
        google_path = DefaultPath.getIconFile("google_authenticator.png")
        backup_path = DefaultPath.getIconFile("backup_codes_light_bg.png")

        self.ui.logo = AspectPreservingLabel(None)
        self.ui.headerLayout.addWidget(self.ui.logo)
        sizePolicy = QtAll.QtWidgets.QSizePolicy(
            QtAll.QtWidgets.QSizePolicy.Preferred,
            QtAll.QtWidgets.QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.ui.logo.sizePolicy().hasHeightForWidth())
        self.ui.logo.setSizePolicy(sizePolicy)
        self.ui.logo.setMaximumSize(QtAll.QtCore.QSize(512, 290))
        self.ui.logo.setText("")
        self.ui.logo.setPixmap(QtAll.QtGui.QPixmap(image_path))

        self.ui.logo.setAlignment(QtAll.QtCore.Qt.AlignCenter)
        self.ui.logo.setTextInteractionFlags(QtAll.QtCore.Qt.NoTextInteraction)
        self.ui.logo.setObjectName("logo")

        self.ui.credential_fa_label.setPixmap(QtAll.QtGui.QPixmap(google_path))
        self.ui.credential_backup_label.setPixmap(
            QtAll.QtGui.QPixmap(backup_path))

        # Set the title
        self.setWindowTitle("Dsk Login")

        self.ui.site = RecentBox(None)
        self.ui.login = RecentBox(None)
        self.ui.password = Qt5LikeLineEdit(None)
        self.ui.password.setEchoMode(QtAll.QtWidgets.QLineEdit.Password)
        self.ui.message = QtAll.QtWidgets.QLabel(None)

        self.ui.credential_login.addWidget(self.ui.site)
        self.ui.credential_login.addWidget(self.ui.login)
        self.ui.credential_login.addWidget(self.ui.password)
        self.ui.credential_login.addWidget(self.ui.message)

        self.ui.fa_code.setEchoMode(QtAll.QtWidgets.QLineEdit.Password)
        self.ui.backup_code.setEchoMode(QtAll.QtWidgets.QLineEdit.Password)
        # Assign credentials
        self._http_proxy = http_proxy
        recent_hosts = []
        if self._session != None:
            recent_hosts = self._session.get_recent_hosts()
        # If we have a recent host and it's not in the list, add it. This can happen if a user logs
        # on and while the process is running the host is removed from the host list.
        if hostname and hostname not in recent_hosts:
            recent_hosts.insert(0, hostname)

        self.ui.site.set_recent_items(recent_hosts)
        self.ui.site.set_selection(hostname)

        # Apply the stylesheet manually, Qt doesn't see it otherwise...
        completer_style = self.styleSheet() + ("\n\nQWidget {"
                                               "font-size: 12px;"
                                               "}")

        self.ui.site.set_style_sheet(completer_style)
        self.ui.site.set_placeholder_text("example.shotgunstudio.com")
        self.ui.login.set_style_sheet(completer_style)
        self.ui.login.set_placeholder_text("login")

        self._populate_user_dropdown(recent_hosts[0] if recent_hosts else None)

        # Timer to update the GUI according to the URL, if SSO is supported or not.
        # This is to make the UX smoother, as we do not check after each character
        # typed, but instead wait for a period of inactivity from the user.
        self._url_changed_timer = QtAll.QtCore.QTimer(self)
        self._url_changed_timer.setSingleShot(True)
        self._url_changed_timer.timeout.connect(
            self._update_ui_according_to_sso_support)

        # If the host is fixed, disable the site textbox.
        if fixed_host:
            self._disable_text_widget(
                self.ui.site,
                "The Shotgun site has been predefined and cannot be modified.")

        # Disable keyboard input in the site and login boxes if we are simply renewing the session.
        if is_session_renewal:
            self._disable_text_widget(
                self.ui.site,
                "You are renewing your session: you can't change your host.")
            self._disable_text_widget(
                self.ui.login,
                "You are renewing your session: you can't change your login.")
            self._set_login_message(
                "Your session has expired. Please enter your password.")
        else:
            self._set_login_message("Please enter your credentials.")

        # Set the focus appropriately on the topmost line edit that is empty.
        if self._get_current_site():
            if self._get_current_user():
                self.ui.password.setFocus(QtAll.QtCore.Qt.OtherFocusReason)
            else:
                self.ui.login.setFocus(QtAll.QtCore.Qt.OtherFocusReason)

        # Select the right first page.
        self.ui.stackedWidget.setCurrentWidget(self.ui.login_page)
        #self.ui.stackedWidget.setCurrentWidget(self.ui.fa_page)

        # hook up signals
        self.ui.sign_in.clicked.connect(self._ok_pressed)
        self.ui.cancel.clicked.connect(self._ok_reject)
        self.ui.cancel_backup.clicked.connect(self._ok_reject)
        self.ui.cancel_tfa.clicked.connect(self._ok_reject)

        self.ui.verify_2fa.clicked.connect(self._verify_2fa_pressed)
        self.ui.use_backup.clicked.connect(self._use_backup_pressed)

        self.ui.verify_backup.clicked.connect(self._verify_backup_pressed)
        self.ui.use_app.clicked.connect(self._use_app_pressed)

        self.ui.forgot_password_link.linkActivated.connect(
            self._link_activated)

        self.ui.site.lineEdit().editingFinished.connect(
            self._strip_whitespaces)
        self.ui.login.lineEdit().editingFinished.connect(
            self._strip_whitespaces)
        self.ui.fa_code.editingFinished.connect(self._strip_whitespaces)
        self.ui.backup_code.editingFinished.connect(self._strip_whitespaces)

        # While the user is typing, check the SSOness of the site so we can
        # show or hide the login and password fields.
        self.ui.site.lineEdit().textEdited.connect(self._site_url_changing)
        # If a site has been selected, we need to update the login field.
        self.ui.site.activated.connect(self._on_site_changed)
        self.ui.site.lineEdit().editingFinished.connect(self._on_site_changed)

        self._query_task = QuerySiteAndUpdateUITask(self, http_proxy)
        self._query_task.finished.connect(self._toggle_web)
        self._update_ui_according_to_sso_support()

        # We want to wait until we know if the site uses SSO or not, to avoid
        # flickering GUI.
        if not self._query_task.wait(THREAD_WAIT_TIMEOUT_MS):
            logger.warning(
                "Timed out awaiting check for SSO support on the site: %s" %
                self._get_current_site())
import os

from dsk.base.widgets.simpleqt import QtT

from dsk.base.lib.default_path import DefaultPath
from dsk.base.resources.icon_cache import init_default_pixmap

Icon_NF = 'icon_not_found'
Iconfile_default = DefaultPath.getIconFile('noeye_orange.png')

CashPix = dict()


def get_pixmap(iconfile, versionobject, force=False):
    global CashPix
    if iconfile in ["", None]:
        n = versionobject.getTypeName()
        if n in CashPix:
            return CashPix[n]
    else:
        n = versionobject.getTypeName()

    if n in CashPix and force == False:
        return CashPix[n]

    pix = None
    if os.path.isfile(iconfile):
        pix = QtT.QtGui.QPixmap(iconfile)
        CashPix[iconfile] = CashPix[n] = pix
        init_default_pixmap(n, pix)
        return pix