Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show logged-in user with their avatar in tray menu #1083

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions client/ayon_core/tools/tray/ui/tray.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@
)


def _crop_pixmap_to_circle(pixmap: QtGui.QPixmap) -> QtGui.QPixmap:
size = min(pixmap.width(), pixmap.height())
cropped_pixmap = QtGui.QPixmap(size, size)
cropped_pixmap.fill(QtCore.Qt.transparent)

painter = QtGui.QPainter(cropped_pixmap)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
path = QtGui.QPainterPath()
path.addEllipse(QtCore.QRectF(0, 0, size, size))
painter.setClipPath(path)
painter.drawPixmap(0, 0, pixmap)
painter.end()

return cropped_pixmap


class TrayManager:
"""Cares about context of application.

Expand Down Expand Up @@ -471,7 +487,20 @@ def _startup_validations(self):

def _add_version_item(self):
tray_menu = self.tray_widget.menu
login_action = QtWidgets.QAction("Login", self.tray_widget)

# Show logged-in user's name and icon
user = ayon_api.get_user()
username = user["name"]
response = ayon_api.get(f"users/{username}/avatar")
image = response.content
pixmap = QtGui.QPixmap()
pixmap.loadFromData(image)
pixmap = _crop_pixmap_to_circle(pixmap)
icon = QtGui.QIcon(pixmap)
name = user.get("attrib", {}).get("fullName") or user["name"]

login_action = QtWidgets.QAction(f"Login ({name})", self.tray_widget)
login_action.setIcon(icon)
login_action.triggered.connect(self._on_ayon_login)
tray_menu.addAction(login_action)
version_string = os.getenv("AYON_VERSION", "AYON Info")
Expand Down Expand Up @@ -771,4 +800,4 @@ def main():
u"ayon_tray"
)

sys.exit(app.exec_())
sys.exit(app.exec_())
Loading