Skip to content

shotgrid_tray

ShotgridTrayWrapper

Shotgrid menu entry for the AYON tray.

Displays the Shotgrid URL specified in the Server Addon Settings and allows the person to set a username to be used with the API.

There's the option to check if said user has permissions to connect to the API.

Source code in client/ayon_shotgrid/tray/shotgrid_tray.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class ShotgridTrayWrapper:
    """ Shotgrid menu entry for the AYON tray.

    Displays the Shotgrid URL specified in the Server Addon Settings and
    allows the person to set a username to be used with the API.

    There's the option to check if said user has permissions to connect to the
    API.
    """
    def __init__(self, addon):
        self.addon = addon

        server_url = self.addon.get_sg_url()

        if not server_url:
            server_url = "No Shotgrid Server set in AYON Settings."

        self.sg_server_label = QtWidgets.QAction("Server: {0}".format(
                server_url
            )
        )
        self.sg_server_label.setDisabled(True)
        self.sg_username_label = QtWidgets.QAction("")
        self.sg_username_label.triggered.connect(self.show_sg_username_dialog)

        self.sg_username_dialog = SgLoginDialog(self.addon)
        self.sg_username_dialog.dialog_closed.connect(self.set_username_label)

    def show_sg_username_dialog(self):
        """Display the Shotgrid Username dialog

        Used to set a Shotgrid Username, that will then be used by any API call
        and to check that the user can access the Shotgrid API.
        """
        self.sg_username_dialog.show()
        self.sg_username_dialog.activateWindow()
        self.sg_username_dialog.raise_()

    def tray_menu(self, tray_menu):
        """Add Shotgrid Submenu to AYON tray.

        A non-actionable action displays the Shotgrid URL and the other
        action allows the person to set and check their Shotgrid username.

        Args:
            tray_menu (QtWidgets.QMenu): The AYON Tray menu.
        """
        shotgrid_tray_menu = QtWidgets.QMenu("Shotgrid", tray_menu)
        shotgrid_tray_menu.addAction(self.sg_server_label)
        shotgrid_tray_menu.addSeparator()
        shotgrid_tray_menu.addAction(self.sg_username_label)
        tray_menu.addMenu(shotgrid_tray_menu)

    def set_username_label(self):
        """Set the Username Label based on local login setting.

        Depending on the login credentiasl we want to display one message or
        another in the Shotgrid submenu action.
        """
        sg_username, _ = credentials.get_local_login()

        if sg_username:
            self.sg_username_label.setText(
                "Username: {} (Click to change)".format(sg_username)
            )
            os.environ["AYON_SG_USERNAME"] = sg_username
        else:
            self.sg_username_label.setText("Specify a Username...")
            os.environ["AYON_SG_USERNAME"] = ""
            self.show_sg_username_dialog()

set_username_label()

Set the Username Label based on local login setting.

Depending on the login credentiasl we want to display one message or another in the Shotgrid submenu action.

Source code in client/ayon_shotgrid/tray/shotgrid_tray.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
def set_username_label(self):
    """Set the Username Label based on local login setting.

    Depending on the login credentiasl we want to display one message or
    another in the Shotgrid submenu action.
    """
    sg_username, _ = credentials.get_local_login()

    if sg_username:
        self.sg_username_label.setText(
            "Username: {} (Click to change)".format(sg_username)
        )
        os.environ["AYON_SG_USERNAME"] = sg_username
    else:
        self.sg_username_label.setText("Specify a Username...")
        os.environ["AYON_SG_USERNAME"] = ""
        self.show_sg_username_dialog()

show_sg_username_dialog()

Display the Shotgrid Username dialog

Used to set a Shotgrid Username, that will then be used by any API call and to check that the user can access the Shotgrid API.

Source code in client/ayon_shotgrid/tray/shotgrid_tray.py
37
38
39
40
41
42
43
44
45
def show_sg_username_dialog(self):
    """Display the Shotgrid Username dialog

    Used to set a Shotgrid Username, that will then be used by any API call
    and to check that the user can access the Shotgrid API.
    """
    self.sg_username_dialog.show()
    self.sg_username_dialog.activateWindow()
    self.sg_username_dialog.raise_()

tray_menu(tray_menu)

Add Shotgrid Submenu to AYON tray.

A non-actionable action displays the Shotgrid URL and the other action allows the person to set and check their Shotgrid username.

Parameters:

Name Type Description Default
tray_menu QMenu

The AYON Tray menu.

required
Source code in client/ayon_shotgrid/tray/shotgrid_tray.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def tray_menu(self, tray_menu):
    """Add Shotgrid Submenu to AYON tray.

    A non-actionable action displays the Shotgrid URL and the other
    action allows the person to set and check their Shotgrid username.

    Args:
        tray_menu (QtWidgets.QMenu): The AYON Tray menu.
    """
    shotgrid_tray_menu = QtWidgets.QMenu("Shotgrid", tray_menu)
    shotgrid_tray_menu.addAction(self.sg_server_label)
    shotgrid_tray_menu.addSeparator()
    shotgrid_tray_menu.addAction(self.sg_username_label)
    tray_menu.addMenu(shotgrid_tray_menu)