@@ -25,8 +25,8 @@ class MenuItemDict(MenuItemDictBase, total=False):
2525
2626
2727class MenuItem :
28- def __init__ (self , menu_plugin : "Menu" , owner : AppletPlugin , priority : int , text : Optional [str ], markup : bool ,
29- icon_name : Optional [str ], tooltip : Optional [str ], callback : Optional [Callable [[], None ]],
28+ def __init__ (self , menu_plugin : "Menu" , owner : AppletPlugin , priority : Tuple [ int , int ], text : Optional [str ],
29+ markup : bool , icon_name : Optional [str ], tooltip : Optional [str ], callback : Optional [Callable [[], None ]],
3030 submenu_function : Optional [Callable [[], Iterable ["SubmenuItemDict" ]]], visible : bool , sensitive : bool ):
3131 self ._menu_plugin = menu_plugin
3232 self ._owner = owner
@@ -48,7 +48,7 @@ def owner(self) -> AppletPlugin:
4848 return self ._owner
4949
5050 @property
51- def priority (self ) -> int :
51+ def priority (self ) -> Tuple [ int , int ] :
5252 return self ._priority
5353
5454 @property
@@ -66,7 +66,7 @@ def _iter_base(self) -> Iterator[Tuple[str, Union[str, bool]]]:
6666 yield key , value
6767
6868 def __iter__ (self ) -> Iterator [Tuple [str , Union [int , str , bool , List [Dict [str , Union [str , bool ]]]]]]:
69- yield "id" , self .priority
69+ yield "id" , ( self ._priority [ 0 ] << 8 ) + self . _priority [ 1 ]
7070 yield from self ._iter_base ()
7171 submenu = self .submenu_items
7272 if submenu :
@@ -79,7 +79,7 @@ def submenu_items(self) -> List["SubmenuItem"]:
7979 submenu_items = self ._submenu_function ()
8080 if not submenu_items :
8181 return []
82- return [SubmenuItem (self ._menu_plugin , self ._owner , 0 , item .get ('text' ), item .get ('markup' , False ),
82+ return [SubmenuItem (self ._menu_plugin , self ._owner , ( 0 , 0 ) , item .get ('text' ), item .get ('markup' , False ),
8383 item .get ('icon_name' ), item .get ('tooltip' ), item .get ('callback' ), None , True ,
8484 item .get ('sensitive' , True ))
8585 for item in submenu_items ]
@@ -118,17 +118,21 @@ class Menu(AppletPlugin):
118118 __unloadable__ = False
119119
120120 def on_load (self ) -> None :
121- self .__menuitems : Dict [int , MenuItem ] = {}
121+ self .__menuitems : Dict [Tuple [ int , int ] , MenuItem ] = {}
122122
123123 self ._add_dbus_signal ("MenuChanged" , "aa{sv}" )
124124 self ._add_dbus_method ("GetMenu" , (), "aa{sv}" , self ._get_menu )
125125 self ._add_dbus_method ("ActivateMenuItem" , ("ai" ,), "" , self ._activate_menu_item )
126126
127- def add (self , owner : AppletPlugin , priority : int , text : Optional [str ] = None , markup : bool = False ,
128- icon_name : Optional [str ] = None , tooltip : Optional [str ] = None ,
127+ def add (self , owner : AppletPlugin , priority : Union [ int , Tuple [ int , int ]], text : Optional [str ] = None ,
128+ markup : bool = False , icon_name : Optional [str ] = None , tooltip : Optional [str ] = None ,
129129 callback : Optional [Callable [[], None ]] = None ,
130130 submenu_function : Optional [Callable [[], Iterable ["SubmenuItemDict" ]]] = None ,
131131 visible : bool = True , sensitive : bool = True ) -> MenuItem :
132+
133+ if isinstance (priority , int ):
134+ priority = (priority , 0 )
135+
132136 item = MenuItem (self , owner , priority , text , markup , icon_name , tooltip , callback , submenu_function , visible ,
133137 sensitive )
134138 self .__menuitems [item .priority ] = item
@@ -164,7 +168,7 @@ def _build_variant(self, value: Union[int, str, bool, Iterable[Mapping[str, Unio
164168 return GLib .Variant ("aa{sv}" , self ._prepare_menu (value ))
165169
166170 def _activate_menu_item (self , indexes : Sequence [int ]) -> None :
167- node = self .__menuitems [indexes [0 ]]
171+ node = self .__menuitems [( indexes [0 ] >> 8 , indexes [ 0 ] % ( 1 << 8 )) ]
168172 for index in list (indexes )[1 :]:
169173 node = node .submenu_items [index ]
170174 if node .callback :
0 commit comments