|
26 | 26 |
|
27 | 27 | from .errors import AuthenticationCancelled |
28 | 28 | from .console_authentication import ConsoleLoginHandler, ConsoleRenewSessionHandler |
| 29 | +from .ui_authentication import UiAuthenticationHandler |
29 | 30 |
|
30 | 31 | from .. import LogManager |
31 | 32 |
|
32 | 33 | import threading |
33 | 34 | import os |
34 | 35 | from tank.util import is_windows |
35 | 36 |
|
| 37 | +# When importing qt_abstraction, a lot of code is executed to detects which |
| 38 | +# version of Qt is being used. Running business logic at import time is not |
| 39 | +# something usually done by the Toolkit. The worry is that the import may fail |
| 40 | +# in the context of a DCC, but occur too early for the Toolkit logging to be |
| 41 | +# fully in place to record it. |
| 42 | +try: |
| 43 | + from .ui.qt_abstraction import QtGui |
| 44 | +except Exception: |
| 45 | + QtGui = None |
36 | 46 |
|
37 | 47 | logger = LogManager.get_logger(__name__) |
38 | 48 |
|
@@ -60,23 +70,16 @@ def _get_current_os_user(): |
60 | 70 | return None |
61 | 71 |
|
62 | 72 |
|
63 | | -def _get_ui_state() -> bool: |
| 73 | +def _get_ui_state(): |
64 | 74 | """ |
65 | 75 | Returns the state of UI: do we have a ui or not. |
66 | 76 | :returns: True or False |
67 | 77 | """ |
| 78 | + if QtGui and QtGui.QApplication.instance() is not None: |
| 79 | + return True |
| 80 | + else: |
| 81 | + return False |
68 | 82 |
|
69 | | - # When importing qt_abstraction, a lot of code is executed to detects which |
70 | | - # version of Qt is being used. Running business logic at import time is not |
71 | | - # something usually done by the Toolkit. The worry is that the import may fail |
72 | | - # in the context of a DCC, but occur too early for the Toolkit logging to be |
73 | | - # fully in place to record it. |
74 | | - try: |
75 | | - from .ui.qt_abstraction import QtGui |
76 | | - except Exception: |
77 | | - QtGui = None |
78 | | - |
79 | | - return bool(QtGui and QtGui.QApplication.instance()) |
80 | 83 |
|
81 | 84 | class SessionRenewal(object): |
82 | 85 | """ |
@@ -219,7 +222,6 @@ def renew_session(user): |
219 | 222 | has_ui = _get_ui_state() |
220 | 223 | # If we have a gui, we need gui based authentication |
221 | 224 | if has_ui: |
222 | | - from .ui_authentication import UiAuthenticationHandler |
223 | 225 | authenticator = UiAuthenticationHandler( |
224 | 226 | is_session_renewal=True, session_metadata=user.get_session_metadata() |
225 | 227 | ) |
@@ -255,8 +257,6 @@ def authenticate(default_host, default_login, http_proxy, fixed_host): |
255 | 257 | # object instead of 5 element tuple. |
256 | 258 | # If we have a gui, we need gui based authentication |
257 | 259 | if has_ui: |
258 | | - from .ui_authentication import UiAuthenticationHandler |
259 | | - |
260 | 260 | # If we are renewing for a background thread, use the invoker |
261 | 261 | authenticator = UiAuthenticationHandler( |
262 | 262 | is_session_renewal=False, fixed_host=fixed_host |
|
0 commit comments