mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
user module can execute callbacks on username change
This commit is contained in:
parent
0272d38c7e
commit
79245bcd00
2 changed files with 16 additions and 2 deletions
|
|
@ -19,8 +19,8 @@ class UserModule:
|
|||
log = pype.Logger().get_logger("UserModule", "user")
|
||||
|
||||
def __init__(self, main_parent=None, parent=None):
|
||||
self._callbacks_on_user_change = []
|
||||
self.cred = {}
|
||||
|
||||
self.cred_path = os.path.normpath(os.path.join(
|
||||
self.cred_folder_path, self.cred_filename
|
||||
))
|
||||
|
|
@ -28,6 +28,9 @@ class UserModule:
|
|||
|
||||
self.load_credentials()
|
||||
|
||||
def register_callback_on_user_change(self, callback):
|
||||
self._callbacks_on_user_change.append(callback)
|
||||
|
||||
def tray_start(self):
|
||||
"""Store credentials to env and preset them to widget"""
|
||||
username = ""
|
||||
|
|
@ -95,6 +98,17 @@ class UserModule:
|
|||
))
|
||||
return self.save_credentials(getpass.getuser())
|
||||
|
||||
def change_credentials(self, username):
|
||||
self.save_credentials(username)
|
||||
for callback in self._callbacks_on_user_change:
|
||||
try:
|
||||
callback()
|
||||
except Exception:
|
||||
self.log.warning(
|
||||
"Failed to execute callback \"{}\".".format(str(callback)),
|
||||
exc_info=True
|
||||
)
|
||||
|
||||
def save_credentials(self, username):
|
||||
"""Save credentials to JSON file, env and widget"""
|
||||
if username is None:
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class UserWidget(QtWidgets.QWidget):
|
|||
def click_save(self):
|
||||
# all what should happen - validations and saving into appsdir
|
||||
username = self.input_username.text()
|
||||
self.module.save_credentials(username)
|
||||
self.module.change_credentials(username)
|
||||
self._close_widget()
|
||||
|
||||
def closeEvent(self, event):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue