Skip to content

Commit

Permalink
domains: use custom metaclass for ActionMenuItem
Browse files Browse the repository at this point in the history
  • Loading branch information
fepitre committed Jan 8, 2025
1 parent b2836e8 commit c088f6f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions qui/tray/domains.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import subprocess
import sys
import traceback
import abc

import gi # isort:skip
import qubesadmin
Expand Down Expand Up @@ -82,7 +83,11 @@ def show_error(title, text):
GLib.idle_add(dialog.show)


class ActionMenuItem(Gtk.MenuItem):
class ABCGtkMenuItemMeta(abc.ABCMeta, type(Gtk.MenuItem)):
pass


class ActionMenuItem(Gtk.MenuItem, metaclass=ABCGtkMenuItemMeta):
def __init__(self, label, img=None, icon_cache=None, icon_name=None):
super().__init__()

Expand Down Expand Up @@ -112,11 +117,11 @@ def __init__(self, label, img=None, icon_cache=None, icon_name=None):
# Connect the "activate" signal to the async function
self.connect("activate", self.on_activate)

@abc.abstractmethod
async def perform_action(self):
"""
Action this item should perform (to be implemented by subclasses).
"""
raise NotImplementedError("Subclasses must implement this method.")

def on_activate(self, *_args, **_kwargs):
asyncio.create_task(self.perform_action())
Expand Down

0 comments on commit c088f6f

Please sign in to comment.