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

Conversation

BigRoy
Copy link
Collaborator

@BigRoy BigRoy commented Jan 13, 2025

Changelog Description

Shows the logged in user in tray menu:

image

Instead of plain action labeled "Login"

Additional info

Not optimized, up for discussion - and just an idea.
I wonder whether it'd be better to show it in the launcher UI instead.

Here's a mockup of that (very quick and dirty) as launcher action:

image

from ayon_core.pipeline import LauncherAction

from qtpy import QtGui, QtCore, QtWidgets
import ayon_api
import webbrowser


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 CurrentUser(LauncherAction):
    name = "currentuser"
    order = 999999

    @property
    def icon(self):
        # 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)

        import tempfile

        filepath = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
        pixmap.save(filepath.name)

        return {
            "type": "path",
            "path": filepath.name
        }

    @property
    def label(self):
        user = ayon_api.get_user()
        return user.get("attrib", {}).get("fullName") or user["name"]

    def is_compatible(self, selection):
        return True

    def process(self, selection, **kwargs):
        url = ayon_api.get_server_api_connection().get_url()
        webbrowser.open(url + "/account/profile")

Testing notes:

  1. Start Tray Launcher
  2. Logged-in user with icon should be visible in the menu

@BigRoy BigRoy added the community Issues and PRs coming from the community members label Jan 13, 2025
@ynbot ynbot added type: enhancement Improvement of existing functionality or minor addition size/XS labels Jan 13, 2025
@BigRoy BigRoy self-assigned this Jan 13, 2025
@BigRoy
Copy link
Collaborator Author

BigRoy commented Jan 13, 2025

Probably nicer if we could have a top menu bar like e.g this in the menu:

image

(That's from Dropbox app)

Or even better - maybe just show it at the top of the launcher UI top right? Especially if we also implement e.g. user-specific tasks filtering #899

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Issues and PRs coming from the community members size/XS type: enhancement Improvement of existing functionality or minor addition
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants