Skip to content

Commit

Permalink
Actually make PluginManager generic (#2437)
Browse files Browse the repository at this point in the history
  • Loading branch information
cschramm authored Jul 24, 2024
1 parent 77bfb45 commit 117199a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions blueman/gui/applet/PluginDialog.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from gettext import gettext as _
import logging
from typing import TYPE_CHECKING, Type, Dict, cast, Optional
from typing import TYPE_CHECKING, Type, Dict, cast, Optional, TypeVar

from blueman.main.Builder import Builder
from blueman.main.PluginManager import PluginManager
from blueman.plugins.AppletPlugin import AppletPlugin
from blueman.plugins.BasePlugin import Option
from blueman.plugins.BasePlugin import Option, BasePlugin

import gi
gi.require_version("Gtk", "3.0")
Expand Down Expand Up @@ -329,7 +329,9 @@ def populate(self) -> None:
self.model.insert_sorted(plugin_item, self._model_sort_func)
self.listbox.select_row(self.listbox.get_row_at_index(0))

def plugin_state_changed(self, _plugins: PluginManager, name: str, loaded: bool) -> None:
_T = TypeVar("_T", bound="BasePlugin")

def plugin_state_changed(self, _plugins: PluginManager[_T], name: str, loaded: bool) -> None:
logging.debug(f"{name} {loaded}")
action = self.lookup_action(name)
assert isinstance(action, Gio.SimpleAction)
Expand Down
2 changes: 1 addition & 1 deletion blueman/main/Applet.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def on_device_removed(self, _manager: Manager, path: str) -> None:
plugin.on_device_removed(path)


class Plugins(PersistentPluginManager):
class Plugins(PersistentPluginManager[AppletPlugin]):
def __init__(self, applet: BluemanApplet):
super().__init__(AppletPlugin, blueman.plugins.applet, applet)

Expand Down
6 changes: 3 additions & 3 deletions blueman/main/PluginManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import traceback
import importlib
from types import ModuleType
from typing import Dict, List, Type, TypeVar, Iterable, Optional
from typing import Dict, List, Type, TypeVar, Iterable, Optional, Generic

from gi.repository import GObject, Gio

Expand All @@ -22,7 +22,7 @@ class LoadException(Exception):
_T = TypeVar("_T", bound=BasePlugin)


class PluginManager(GObject.GObject):
class PluginManager(GObject.GObject, Generic[_T]):
__gsignals__: GSignals = {
'plugin-loaded': (GObject.SignalFlags.NO_HOOKS, None, (GObject.TYPE_STRING,)),
'plugin-unloaded': (GObject.SignalFlags.NO_HOOKS, None, (GObject.TYPE_STRING,)),
Expand Down Expand Up @@ -211,7 +211,7 @@ def get_loaded_plugins(self, protocol: Type[_U]) -> Iterable[_U]:
yield plugin


class PersistentPluginManager(PluginManager):
class PersistentPluginManager(PluginManager[_T]):
def __init__(self, plugin_class: Type[_T], module_path: ModuleType, parent: object) -> None:
super().__init__(plugin_class, module_path, parent)

Expand Down
2 changes: 1 addition & 1 deletion blueman/plugins/applet/ShowConnected.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,6 @@ def on_adapter_added(self, _path: str) -> None:
def on_adapter_removed(self, _path: str) -> None:
self.enumerate_connections()

def _on_plugins_changed(self, _pluginmngr: PluginManager, name: str) -> None:
def _on_plugins_changed(self, _pluginmngr: PluginManager[AppletPlugin], name: str) -> None:
if name == "PowerManager":
self.update_statusicon()
2 changes: 1 addition & 1 deletion blueman/plugins/applet/StatusIcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def on_manager_state_changed(self, state: bool) -> None:
if state:
launch('blueman-tray', icon_name='blueman', sn=False)

def _on_plugins_changed(self, _plugins: PluginManager, _name: str) -> None:
def _on_plugins_changed(self, _plugins: PluginManager[AppletPlugin], _name: str) -> None:
implementations = self._get_status_icon_implementations()
if not self._implementations or self._implementations != implementations:
self._implementations = implementations
Expand Down

0 comments on commit 117199a

Please sign in to comment.