|
14 | 14 | from sgtk.util import is_windows, is_macos, is_linux |
15 | 15 |
|
16 | 16 |
|
| 17 | +class _AliasMenuCompat: |
| 18 | + """Compatibility wrapper for Alias 2027+ menu API. |
| 19 | +
|
| 20 | + Provides the same interface as the old Menu class (add_menu, add_command, |
| 21 | + clean, remove) but routes calls to the new standalone API functions. |
| 22 | + The new API uses string-based parent references instead of object handles. |
| 23 | + """ |
| 24 | + |
| 25 | + def __init__(self, alias_py, name): |
| 26 | + self._alias_py = alias_py |
| 27 | + self._name = name |
| 28 | + |
| 29 | + def add_menu(self, text): |
| 30 | + self._alias_py._alpy_make_submenu(self._name, text) |
| 31 | + return text |
| 32 | + |
| 33 | + def add_command(self, name, callback, parent=None, add_separator=False): |
| 34 | + parent_name = parent if isinstance(parent, str) else self._name |
| 35 | + on_submenu = parent is not None |
| 36 | + self._alias_py._alpy_make_menu_item(name, parent_name, on_submenu, callback) |
| 37 | + |
| 38 | + def clean(self): |
| 39 | + return None |
| 40 | + |
| 41 | + def remove(self): |
| 42 | + return None |
| 43 | + |
| 44 | + |
17 | 45 | class AliasMenuGenerator(object): |
18 | 46 | """Menu handling for Alias.""" |
19 | 47 |
|
@@ -65,7 +93,13 @@ def build(self): |
65 | 93 |
|
66 | 94 | if self.alias_menu is None: |
67 | 95 | # First, create the Flow Production Tracking menu in Alias. |
68 | | - self.__alias_menu = self.engine.alias_py.Menu(self.menu_name) |
| 96 | + if hasattr(self.engine.alias_py, "Menu"): |
| 97 | + self.__alias_menu = self.engine.alias_py.Menu(self.menu_name) |
| 98 | + else: |
| 99 | + self.engine.alias_py._alpy_make_main_menu(self.menu_name) |
| 100 | + self.__alias_menu = _AliasMenuCompat( |
| 101 | + self.engine.alias_py, self.menu_name |
| 102 | + ) |
69 | 103 | else: |
70 | 104 | # Make sure we're starting with a fresh menu |
71 | 105 | self.clean_menu() |
|
0 commit comments