Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
linkfrg committed Jul 30, 2024
1 parent ed7a5ac commit 31977c7
Show file tree
Hide file tree
Showing 51 changed files with 214 additions and 59 deletions.
9 changes: 7 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,23 @@
html_static_path = ["_static"]

html_css_files = [
'css/custom.css',
"css/custom.css",
]

html_title = "Ignis Wiki"
smartquotes = False

add_module_names = False


def get_widget_template(name):
return f"""{name}
{'-'*len(name)}
.. autoclass:: ignis.widgets.Widget.{name}
"""


def get_service_template(name):
return f"""{name.capitalize().replace("_", "")}
{'-'*len(name)}
Expand All @@ -42,13 +44,15 @@ def get_service_template(name):
:members:
"""


def get_utils_function_template(name):
return f"""{name}
{'-'*len(name)}
.. autofunction:: ignis.utils.Utils.{name}
"""


def get_utils_class_template(name):
return f"""{name}
{'-'*len(name)}
Expand All @@ -57,6 +61,7 @@ def get_utils_class_template(name):
:members:
"""


for i in ["widgets", "services", "utils"]:
try:
shutil.rmtree(f"{i}/generated")
Expand All @@ -79,4 +84,4 @@ def get_utils_class_template(name):
if not filename.startswith("__"):
name = filename.replace(".py", "")
with open(f"utils/generated/{name}.rst", "w") as file:
file.write(get_utils_class_template(name))
file.write(get_utils_class_template(name))
12 changes: 6 additions & 6 deletions ignis/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import gi
from ctypes import CDLL

CDLL('libgtk4-layer-shell.so')
CDLL("libgtk4-layer-shell.so")

gi.require_version("Gtk", "4.0")
gi.require_version("Gdk", "4.0")
gi.require_version('Gtk4LayerShell', '1.0')
gi.require_version("Gtk4LayerShell", "1.0")
gi.require_version("GdkPixbuf", "2.0")
gi.require_version("GIRepository", "2.0")

from gi.repository import GIRepository # noqa: E402
GIRepository.Repository.prepend_library_path('/usr/lib/ignis')
GIRepository.Repository.prepend_search_path('/usr/lib/ignis')
GIRepository.Repository.prepend_library_path('/usr/lib/x86_64-linux-gnu/ignis')
GIRepository.Repository.prepend_search_path('/usr/lib/x86_64-linux-gnu/ignis')

GIRepository.Repository.prepend_library_path("/usr/lib/ignis")
GIRepository.Repository.prepend_search_path("/usr/lib/ignis")
GIRepository.Repository.prepend_library_path("/usr/lib/x86_64-linux-gnu/ignis")
GIRepository.Repository.prepend_search_path("/usr/lib/x86_64-linux-gnu/ignis")
4 changes: 3 additions & 1 deletion ignis/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def apply_css(self, style_path: str) -> None:
"""

if not os.path.exists(style_path):
raise FileNotFoundError(f"Provided style path doesn't exists: '{style_path}'")
raise FileNotFoundError(
f"Provided style path doesn't exists: '{style_path}'"
)

if style_path.endswith(".scss") or style_path.endswith(".sass"):
compiled_scss = Utils.sass_compile(path=style_path)
Expand Down
3 changes: 2 additions & 1 deletion ignis/client.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from ignis.dbus import DBusProxy
from ignis.utils import Utils


class IgnisClient:
def __init__(self):
self.__dbus = DBusProxy(
name="com.github.linkfrg.ignis",
object_path="/com/github/linkfrg/ignis",
interface_name="com.github.linkfrg.ignis",
info=Utils.load_interface_xml("com.github.linkfrg.ignis")
info=Utils.load_interface_xml("com.github.linkfrg.ignis"),
)

@property
Expand Down
6 changes: 4 additions & 2 deletions ignis/dbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from ignis.utils import Utils
from ignis.gobject import IgnisGObject


class DBusService(IgnisGObject):
def __init__(
self,
Expand Down Expand Up @@ -68,7 +69,6 @@ def __handle_method_call(
params,
invocation,
):

def callback(func: callable, unpacked_params) -> None:
result = func(invocation, *unpacked_params)
invocation.return_value(result)
Expand All @@ -77,7 +77,9 @@ def callback(func: callable, unpacked_params) -> None:
if func:
# params can contain pixbuf, very large amount of data
# and unpacking may take some time and block the main thread
Utils.ThreadTask(target=params.unpack, callback=lambda result: callback(func, result))
Utils.ThreadTask(
target=params.unpack, callback=lambda result: callback(func, result)
)

def __handle_get_property(self, connection, sender, object_path, interface, value):
func = self._properties.get(value, None)
Expand Down
21 changes: 18 additions & 3 deletions ignis/gobject.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from gi.repository import GObject, GLib
from typing import Union, Any, List


class Binding(GObject.Object):
"""
An object that describe binding.
Expand All @@ -11,6 +12,7 @@ class Binding(GObject.Object):
- **transform** (``GObject.Object``, optional, read-only): The function that accepts a new property value and returns the processed value.
"""

def __init__(
self, target: GObject.Object, target_property: str, transform: callable = None
):
Expand Down Expand Up @@ -43,6 +45,7 @@ class IgnisGObject(GObject.Object):
2. It offers easier control over properties (without the need for the ``.props`` attribute).
"""

def __init__(self):
super().__init__()

Expand Down Expand Up @@ -80,11 +83,22 @@ def set_property(self, property_name: str, value: Any) -> None:
if value is None:
return
elif isinstance(value, Binding):
self.bind_property(source_property=property_name, target=value.target, target_property=value.target_property, transform=value.transform)
self.bind_property(
source_property=property_name,
target=value.target,
target_property=value.target_property,
transform=value.transform,
)
else:
super().set_property(property_name, value)

def bind_property(self, source_property: str, target: GObject.Object, target_property: str, transform: callable = None) -> None:
def bind_property(
self,
source_property: str,
target: GObject.Object,
target_property: str,
transform: callable = None,
) -> None:
"""
Bind ``source_property`` on ``self`` with ``target_property`` on ``target``.
Expand All @@ -94,8 +108,9 @@ def bind_property(self, source_property: str, target: GObject.Object, target_pro
target_property (``str``): the property on ``target`` to bind.
transform (``callable``, optional): The function that accepts a new property value and returns the processed value.
"""

def callback(*args):
value = target.get_property(target_property.replace('-', '_'))
value = target.get_property(target_property.replace("-", "_"))
if transform:
value = transform(value)
self.set_property(source_property, value)
Expand Down
33 changes: 31 additions & 2 deletions ignis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,47 @@ def __init__(self, name=None, commands=None, **attrs):
def list_commands(self, ctx):
return self.commands


def set_process_name(name):
libc = ctypes.CDLL("libc.so.6")
libc.prctl(15, ctypes.c_char_p(name.encode()), 0, 0, 0)


def print_version(ctx, param, value):
if value:
ctx.exit(print(f"Ignis {Utils.get_ignis_version()}"))


def call_client_func(name: str, *args) -> None:
client = IgnisClient()
if not client.has_owner:
print("Ignis is not running.")
exit(1)
getattr(client, name)(*args)


@click.group(cls=OrderedGroup)
@click.option('--version', is_flag=True, callback=print_version, expose_value=False, is_eager=True, help='Print version and exit')
@click.option(
"--version",
is_flag=True,
callback=print_version,
expose_value=False,
is_eager=True,
help="Print version and exit",
)
def main():
set_process_name("ignis")


@main.command(name="init", help="Initialize Ignis")
@click.option("--config", "-c", help=f"Path to the configuration file (default: {DEFAULT_CONFIG_PATH})", default=DEFAULT_CONFIG_PATH, type=str, metavar="PATH")
@click.option(
"--config",
"-c",
help=f"Path to the configuration file (default: {DEFAULT_CONFIG_PATH})",
default=DEFAULT_CONFIG_PATH,
type=str,
metavar="PATH",
)
@click.option("--debug", help="Print debug information to terminal", is_flag=True)
def init(config: str, debug: bool) -> None:
client = IgnisClient()
Expand All @@ -46,47 +65,57 @@ def init(config: str, debug: bool) -> None:
exit(1)
run_server(config)


@main.command(name="open", help="Open window")
@click.argument("window")
def open(window: str) -> None:
call_client_func("OpenWindow", window)


@main.command(name="close", help="Close window")
@click.argument("window")
def close(window: str) -> None:
call_client_func("CloseWindow", window)


@main.command(name="toggle", help="Toggle window")
@click.argument("window")
def toggle(window: str) -> None:
call_client_func("ToggleWindow", window)


@main.command(name="list-windows", help="List all windows")
def list_windows() -> None:
call_client_func("ListWindows")


@main.command(name="run-python", help="Execute inline python code")
@click.argument("code")
def run_python(code: str) -> None:
call_client_func("RunPython", code)


@main.command(name="run-file", help="Execute python file")
@click.argument("file")
def run_file(file: str) -> None:
call_client_func("RunFile", file)


@main.command(name="inspector", help="Open GTK Inspector")
def inspector() -> None:
call_client_func("Inspector")


@main.command(name="reload", help="Reload Ignis")
def reload() -> None:
call_client_func("Reload")


@main.command(name="quit", help="Quit Ignis")
def quit() -> None:
call_client_func("Quit")


def run_server(config: str) -> None:
from ignis.app import app

Expand Down
2 changes: 1 addition & 1 deletion ignis/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ignis.gobject import IgnisGObject
from ignis.logging import logger


class ServiceClass:
def __init__(self) -> None:
self._services = {
Expand Down Expand Up @@ -31,5 +32,4 @@ def get(self, service: str) -> IgnisGObject:
logger.error(f"Service '{service}' not found!")



Service = ServiceClass()
6 changes: 5 additions & 1 deletion ignis/services/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

options.create_option(name=PINNED_APPS_OPTION, default=[], exists_ok=True)


class ApplicationAction(IgnisGObject):
"""
Application action.
Expand All @@ -21,6 +22,7 @@ class ApplicationAction(IgnisGObject):
- **action** (``str``, read-only): ID of the action.
- **name** (``str``, read-only): Human-readable name of the action.
"""

def __init__(self, app: Gio.DesktopAppInfo, action: str):
super().__init__()

Expand All @@ -42,6 +44,7 @@ def launch(self) -> None:
"""
self._app.launch_action(self.action, None)


class Application(IgnisGObject):
"""
An application object.
Expand Down Expand Up @@ -154,7 +157,7 @@ def launch(self) -> None:
"""
Launch the application.
"""
exec_string = re.sub(r'%\S*', '', self.exec_string)
exec_string = re.sub(r"%\S*", "", self.exec_string)
subprocess.Popen(
exec_string,
shell=True,
Expand All @@ -163,6 +166,7 @@ def launch(self) -> None:
stderr=subprocess.DEVNULL,
)


class ApplicationsService(IgnisGObject):
"""
Provides a list of applications installed on the system.
Expand Down
Loading

0 comments on commit 31977c7

Please sign in to comment.