Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
linkfrg committed Jul 30, 2024
1 parent db1d5f6 commit 4f2c32a
Show file tree
Hide file tree
Showing 56 changed files with 168 additions and 180 deletions.
6 changes: 3 additions & 3 deletions ignis/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def apply_css(self, style_path: str) -> None:
Apply CSS/SCSS/SASS style from a path.
If ``style_path`` has a ``.sass`` or ``.scss`` extension, it will be automatically compiled.
Requires ``dart-sass`` for SASS/SCSS compilation.
Args:
style_path (``str``): Path to the .css/.scss/.sass file.
"""
Expand All @@ -123,7 +123,7 @@ def apply_css(self, style_path: str) -> None:
if style_path.endswith(".scss") or style_path.endswith(".sass"):
compiled_scss = Utils.sass_compile(path=style_path)
else:
with open(style_path, "r") as file:
with open(style_path) as file:
compiled_scss = file.read()

self._style_path = style_path
Expand Down Expand Up @@ -273,7 +273,7 @@ def __RunPython(self, invocation, code: str) -> None:
eval(code)

def __RunFile(self, invocation, path: str) -> None:
with open(path, "r") as file:
with open(path) as file:
code = file.read()
exec(code)

Expand Down
14 changes: 7 additions & 7 deletions ignis/dbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __handle_method_call(
params,
invocation,
):

def callback(func: callable, unpacked_params) -> None:
result = func(invocation, *unpacked_params)
invocation.return_value(result)
Expand Down Expand Up @@ -139,7 +139,7 @@ def object_path(self) -> str:
@GObject.Property
def interface_name(self) -> str:
return self._proxy.get_interface_name()

@GObject.Property
def connection(self) -> str:
return self._proxy.get_connection()
Expand All @@ -151,11 +151,11 @@ def proxy(self) -> Gio.DBusProxy:
@GObject.Property
def methods(self) -> List[str]:
return self._methods

@GObject.Property
def properties(self) -> List[str]:
return self._properties

@GObject.Property
def has_owner(self) -> bool:
dbus = DBusProxy(
Expand All @@ -165,15 +165,15 @@ def has_owner(self) -> bool:
info=Utils.load_interface_xml("org.freedesktop.DBus"),
)
return dbus.NameHasOwner("(s)", self.name)

def __getattr__(self, name: str) -> Any:
if name in self.methods:
return getattr(self._proxy, name)
elif name in self.properties:
return self.__get_dbus_property(name)
else:
return super().__getattribute__(name)

def signal_subscribe(
self,
signal_name: str,
Expand Down Expand Up @@ -210,7 +210,7 @@ def __get_dbus_property(self, property_name: str) -> bool:
)[0]
except GLib.GError:
return None

def watch_name(
self, on_name_appeared: callable = None, on_name_vanished: callable = None
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion ignis/dbus_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, name: str, object_path: str):
self.__proxy.signal_subscribe(
"ItemsPropertiesUpdated", lambda *args: self.__update_menu()
)

self.__update_menu()

def __update_menu(self) -> None:
Expand Down
11 changes: 5 additions & 6 deletions ignis/gobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ def target_property(self) -> str:
@GObject.Property
def transform(self) -> callable:
return self._transform


class IgnisGObject(GObject.Object):
"""
Bases: `GObject.Object <https://lazka.github.io/pgi-docs/index.html#GObject-2.0/classes/Object.html>`_.
Expand Down Expand Up @@ -72,7 +72,7 @@ def notify_all(self, without: Union[List[str], str] = None) -> None:
if i.name in without:
continue
self.notify(i.name)

def set_property(self, property_name: str, value: Any) -> None:
"""
:meta private:
Expand Down Expand Up @@ -114,10 +114,10 @@ def bind(self, property_name: str, transform: callable = None) -> Binding:
:class:`~ignis.gobject.Binding`
"""
return Binding(self, property_name, transform)

def __getattribute__(self, name: str) -> Any:
# This modified __getattribute__ method redirect all "set_" methods to set_property method to provive bindings support.
# "get_" method redirect need to widgets that override enums, to make "get_" return strings instead of enums.
# "get_" method redirect need to widgets that override enums, to make "get_" return strings instead of enums.

if name.startswith("set_"):
property_name = name.replace("set_", "")
Expand All @@ -129,4 +129,3 @@ def __getattribute__(self, name: str) -> Any:
return lambda: self.get_property(property_name)

return super().__getattribute__(name)

2 changes: 1 addition & 1 deletion ignis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class OrderedGroup(click.Group):
def __init__(self, name=None, commands=None, **attrs):
super(OrderedGroup, self).__init__(name, commands, **attrs)
super().__init__(name, commands, **attrs)
self.commands = commands or collections.OrderedDict()

def list_commands(self, ctx):
Expand Down
4 changes: 2 additions & 2 deletions ignis/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def get(self, service: str) -> IgnisGObject:
module = importlib.import_module(f".{service}", package=__name__)
service_class = getattr(module, self._services[service])
setattr(self, f"_{service}", service_class())

return getattr(self, f"_{service}")
else:
logger.error(f"Service '{service}' not found!")



Service = ServiceClass()
Service = ServiceClass()
12 changes: 6 additions & 6 deletions ignis/services/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ def __init__(self, app: Gio.DesktopAppInfo, action: str):
@GObject.Property
def action(self) -> str:
return self._action

@GObject.Property
def name(self) -> str:
return self._name

def launch(self) -> None:
"""
Launch action.
Expand Down Expand Up @@ -114,11 +114,11 @@ def desktop_file(self) -> str:
@GObject.Property
def executable(self) -> str:
return self._app.get_executable()

@GObject.Property
def exec_string(self) -> str:
return self._app.get_string("Exec")

@GObject.Property
def actions(self) -> List[ApplicationAction]:
return self._actions
Expand All @@ -131,7 +131,7 @@ def is_pinned(self) -> bool:
def is_pinned(self, value: bool) -> None:
if value == self._is_pinned:
return

self._is_pinned = value
if value:
self.emit("pinned")
Expand Down Expand Up @@ -194,7 +194,7 @@ def __init__(self):

@GObject.Property
def apps(self) -> List[Application]:
return sorted(list(self._apps.values()), key=lambda x: x.name)
return sorted(self._apps.values(), key=lambda x: x.name)

@GObject.Property
def pinned(self) -> List[Application]:
Expand Down
11 changes: 6 additions & 5 deletions ignis/services/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

class Stream(IgnisGObject):
"""
An audio stream.
An audio stream.
A general class for speakers, microphones, applications, and recorders.
Signals:
Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__(self, control: Gvc.MixerControl, stream: Gvc.MixerStream):
def _setup(self) -> None:
if not self._stream:
return

for property_name in [
"application_id",
"id",
Expand All @@ -61,7 +61,7 @@ def _setup(self) -> None:
"volume",
]:
id_ = self._stream.connect(
f"notify::{property_name}", lambda *args: self.notify(property_name)
f"notify::{property_name}", lambda *args, property_name=property_name: self.notify(property_name)
)
self.__connection_ids.append(id_)

Expand Down Expand Up @@ -140,7 +140,7 @@ def is_default(self) -> bool:
default_stream = self._control.get_default_source()
else:
return

if not default_stream:
return

Expand Down Expand Up @@ -210,6 +210,7 @@ class AudioService(IgnisGObject):
audio.connect("speaker-added", lambda x, speaker: print(speaker.description))
"""

__gsignals__ = {
"speaker-added": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, (Stream,)),
"microphone-added": (GObject.SignalFlags.RUN_FIRST, GObject.TYPE_NONE, (Stream,)),
Expand Down Expand Up @@ -276,7 +277,7 @@ def speakers(self) -> List[Stream]:
@GObject.Property
def microphones(self) -> List[Stream]:
return self._microphones.values()

@GObject.Property
def apps(self) -> List[Stream]:
return self._apps.values()
Expand Down
20 changes: 10 additions & 10 deletions ignis/services/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class FetchService(IgnisGObject):
from ignis.service import Service
fetch = Service.get("fetch")
print(fetch.os_name)
print(fetch.hostname)
print(fetch.kernel)
"""

def __init__(self):
super().__init__()
self._os_info = self.__get_os_info()
Expand Down Expand Up @@ -102,11 +102,11 @@ def os_privacy_policy_url(self) -> str:
@GObject.Property
def os_logo(self) -> str:
return self._os_info.get("LOGO", "Unknown")

@GObject.Property
def os_logo_dark(self) -> str:
return f"{self.os_logo}-dark"

@GObject.Property
def os_logo_text(self) -> str:
return f"{self.os_logo}-text"
Expand All @@ -125,7 +125,7 @@ def current_desktop(self) -> str:

@GObject.Property
def hostname(self) -> str:
with open("/etc/hostname", "r") as file:
with open("/etc/hostname") as file:
data = file.read()
return data

Expand All @@ -135,7 +135,7 @@ def kernel(self) -> str:

@GObject.Property
def uptime(self) -> Tuple[int, int, int, int]:
with open("/proc/uptime", "r") as f:
with open("/proc/uptime") as f:
uptime_seconds = float(f.readline().split()[0])

uptime_minutes, seconds = divmod(uptime_seconds, 60)
Expand All @@ -157,7 +157,7 @@ def cpu(self) -> str:
@GObject.Property
def mem_info(self) -> dict:
mem_info = {}
with open("/proc/meminfo", "r") as file:
with open("/proc/meminfo") as file:
for line in file:
key, value = line.split(":")
value = value.replace("kB", "")
Expand All @@ -180,21 +180,21 @@ def mem_used(self) -> int:

@GObject.Property
def board_vendor(self) -> str:
with open("/sys/devices/virtual/dmi/id/board_vendor", "r") as file:
with open("/sys/devices/virtual/dmi/id/board_vendor") as file:
data = file.read()

return data.strip()

@GObject.Property
def board_name(self) -> str:
with open("/sys/devices/virtual/dmi/id/board_name", "r") as file:
with open("/sys/devices/virtual/dmi/id/board_name") as file:
data = file.read()

return data.strip()

@GObject.Property
def bios_version(self) -> str:
with open("/sys/devices/virtual/dmi/id/bios_version", "r") as file:
with open("/sys/devices/virtual/dmi/id/bios_version") as file:
data = file.read()

return data.strip()
Expand Down
10 changes: 5 additions & 5 deletions ignis/services/hyprland.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ class HyprlandService(IgnisGObject):
hyprland.connect("notify::kb-layout", lambda x, y: print(hyprland.kb_layout))
"""

def __init__(self):
super().__init__()
if not os.path.exists(SOCKET_DIR):
logger.critical("Hyprland IPC not found! To use the Hyprland service, ensure that you are running Hyprland.")
exit(1)

self._workspaces = []
self._active_workspace = {}
self._kb_layout = ""
Expand Down Expand Up @@ -106,11 +107,11 @@ def __sync_kb_layout(self) -> None:
if kb["main"]:
self._kb_layout = kb["active_keymap"]
self.notify("kb_layout")

def __sync_active_window(self) -> None:
self._active_window = json.loads(self.send_command("j/activewindow"))
self.notify("active_window")


def send_command(self, cmd: str) -> str:
"""
Expand All @@ -120,7 +121,7 @@ def send_command(self, cmd: str) -> str:
Args:
cmd (``str``): A command.
Returns:
Response from Hyprland IPC.
"""
Expand All @@ -144,7 +145,6 @@ def switch_to_workspace(self, workspace_id: int) -> None:
Args:
workspace_id (``int``): ID of workspace to be switched to
"""
self.send_command(f"dispatch workspace {workspace_id}")

Loading

0 comments on commit 4f2c32a

Please sign in to comment.