style: enforce consistent codestyle via ruff config and auto-fixes
- Configure ruff: isort, pyupgrade, bugbear, flake8 rules - Auto-fix import sorting, redundant parens, exception chaining - Remove from __future__ import annotations (Python 3.13+) - Convert debug print() to logger calls - Fix typo applicaiton → application in icon_resolver - Remove bare returns in animator setters - Move TYPE_CHECKING imports to runtime where used at runtime
This commit is contained in:
60 files changed
+243
-217
No files matched your search
+12
-4
@@ -1,20 +1,28 @@
|
||||
from fabric.utils import logger
|
||||
|
||||
from fabric.utils import GLib, get_relative_path, os
|
||||
from fabric.utils import GLib, get_relative_path, logger, os
|
||||
|
||||
from utils.functions import parse_timeout_string
|
||||
from utils.utils import toml_file
|
||||
|
||||
HOME_DIR = GLib.get_home_dir()
|
||||
APP_NAME = "modus1"
|
||||
|
||||
CACHE_DIR = str(GLib.get_user_cache_dir()) + f"/{APP_NAME}"
|
||||
|
||||
CONFIG_DIR = os.path.expanduser(f"~/.config/{APP_NAME}")
|
||||
|
||||
SYSTEM_CACHE_DIR = GLib.get_user_cache_dir()
|
||||
WALLPAPER_PATH = f"{HOME_DIR}/Pictures/Wallpapers"
|
||||
WALLPAPER_THUMBS_PATH = f"{WALLPAPER_PATH}/.thumbnails"
|
||||
WALLPAPERS_THUMBNAILS_SIZE = 200
|
||||
WALLPAPERS_DIR_DEFAULT = get_relative_path("../assets/wallpapers_example/")
|
||||
|
||||
CONFIG_FILE = toml_file("config.toml")
|
||||
|
||||
|
||||
CLIPBOARD_THUMBS_DIR = f"{GLib.get_user_cache_dir()}/{APP_NAME}/clipboard_thumbs"
|
||||
CLIPBOARD_DB_PATH = f"{GLib.get_user_cache_dir()}/cliphist/db"
|
||||
|
||||
|
||||
def load_config():
|
||||
"""Load the configuration from config.toml"""
|
||||
try:
|
||||
@@ -30,7 +38,7 @@ def load_config():
|
||||
try:
|
||||
import tomlkit
|
||||
|
||||
with open(CONFIG_FILE, "r") as f:
|
||||
with open(CONFIG_FILE) as f:
|
||||
config = dict(tomlkit.load(f))
|
||||
except Exception as e:
|
||||
logger.error(f"Error loading config: {e}")
|
||||
|
||||
@@ -138,7 +138,7 @@ def get_app_info(wmclass):
|
||||
continue
|
||||
try:
|
||||
full_path = os.path.join(path, f)
|
||||
with open(full_path, "r", encoding="utf-8") as df:
|
||||
with open(full_path, encoding="utf-8") as df:
|
||||
content = df.read()
|
||||
if (
|
||||
f"StartupWMClass={wmclass}" in content
|
||||
@@ -151,7 +151,7 @@ def get_app_info(wmclass):
|
||||
|
||||
if desktop_file:
|
||||
try:
|
||||
with open(desktop_file, "r", encoding="utf-8") as f:
|
||||
with open(desktop_file, encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
|
||||
name = wmclass.title()
|
||||
@@ -178,9 +178,7 @@ def get_app_info(wmclass):
|
||||
name = value
|
||||
elif key == "Version":
|
||||
version = value
|
||||
elif key == "Comment":
|
||||
comment = value
|
||||
elif key == "GenericName" and not comment:
|
||||
elif key == "Comment" or (key == "GenericName" and not comment):
|
||||
comment = value
|
||||
elif key == "Icon":
|
||||
icon = value
|
||||
|
||||
@@ -93,7 +93,6 @@ class Animator(Service):
|
||||
self._timing_function = lambda progress=0.0, **_: cubic_bezier(
|
||||
*value, progress=progress
|
||||
)
|
||||
return
|
||||
|
||||
@Property(TimingFunctionCallback, "read-write")
|
||||
def timing_function(self) -> TimingFunctionCallback:
|
||||
@@ -102,7 +101,6 @@ class Animator(Service):
|
||||
@timing_function.setter
|
||||
def timing_function(self, value: TimingFunctionCallback):
|
||||
self._timing_function = value
|
||||
return
|
||||
|
||||
@Property(float, "read-write")
|
||||
def duration(self):
|
||||
@@ -114,7 +112,6 @@ class Animator(Service):
|
||||
raise ValueError("duration can't be smaller than or equal to 0.0")
|
||||
|
||||
self._duration = value
|
||||
return
|
||||
|
||||
@Property(float, "read-write")
|
||||
def value(self):
|
||||
@@ -123,7 +120,6 @@ class Animator(Service):
|
||||
@value.setter
|
||||
def value(self, value: float):
|
||||
self._value = value
|
||||
return
|
||||
|
||||
@Property(float, "read-write")
|
||||
def max_value(self):
|
||||
@@ -132,7 +128,6 @@ class Animator(Service):
|
||||
@max_value.setter
|
||||
def max_value(self, value: float):
|
||||
self._max_value = value
|
||||
return
|
||||
|
||||
@Property(float, "read-write")
|
||||
def min_value(self):
|
||||
@@ -141,7 +136,6 @@ class Animator(Service):
|
||||
@min_value.setter
|
||||
def min_value(self, value: float):
|
||||
self._min_value = value
|
||||
return
|
||||
|
||||
@Property(bool, "read-write", default_value=False)
|
||||
def playing(self):
|
||||
@@ -150,7 +144,6 @@ class Animator(Service):
|
||||
@playing.setter
|
||||
def playing(self, value: bool): # this setter is intended for internal usage only
|
||||
self._playing = value
|
||||
return
|
||||
|
||||
@Property(bool, "read-write", default_value=False)
|
||||
def repeat(self):
|
||||
@@ -159,7 +152,6 @@ class Animator(Service):
|
||||
@repeat.setter
|
||||
def repeat(self, value: bool):
|
||||
self._repeat = value
|
||||
return
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -203,7 +195,7 @@ class Animator(Service):
|
||||
if not self._playing:
|
||||
return
|
||||
|
||||
elapsed_time = delta_time - cast(float, self._start_time)
|
||||
elapsed_time = delta_time - cast("float", self._start_time)
|
||||
|
||||
self._timeline_pos = min(1.0, elapsed_time / self._duration)
|
||||
|
||||
@@ -225,7 +217,6 @@ class Animator(Service):
|
||||
|
||||
self._start_time = delta_time
|
||||
self._timeline_pos = 0.0
|
||||
return
|
||||
|
||||
def do_handle_tick(self, *_):
|
||||
current_time = self.do_get_time_now()
|
||||
@@ -241,7 +232,6 @@ class Animator(Service):
|
||||
else:
|
||||
GLib.source_remove(self._tick_handler)
|
||||
self._tick_handler = None
|
||||
return
|
||||
|
||||
def play(self):
|
||||
if self._playing:
|
||||
@@ -270,5 +260,5 @@ class Animator(Service):
|
||||
if not self._tick_handler:
|
||||
self._timeline_pos = 0
|
||||
self.playing = False
|
||||
return
|
||||
return None
|
||||
return self.do_remove_tick_handlers()
|
||||
@@ -1,6 +1,7 @@
|
||||
from typing import Literal
|
||||
|
||||
from fabric.core.service import Property
|
||||
from fabric.utils import Gdk, GdkPixbuf, Gtk, cairo, math # noqa: E402
|
||||
from fabric.utils import Gdk, GdkPixbuf, Gtk, cairo, math
|
||||
from fabric.widgets.widget import Widget
|
||||
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class ClippingBox(Box):
|
||||
self.get_allocated_width(),
|
||||
self.get_allocated_height(),
|
||||
cast(
|
||||
int,
|
||||
"int",
|
||||
self.get_style_context().get_property(
|
||||
"border-radius", self.get_state_flags()
|
||||
),
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import math
|
||||
from typing import cast
|
||||
|
||||
from fabric.utils import cairo, Gtk
|
||||
|
||||
from fabric.utils import Gtk, cairo
|
||||
from fabric.widgets.image import Image
|
||||
|
||||
|
||||
@@ -30,7 +29,7 @@ class CustomImage(Image):
|
||||
cr,
|
||||
width,
|
||||
height,
|
||||
cast(int, context.get_property("border-radius", Gtk.StateFlags.NORMAL)),
|
||||
cast("int", context.get_property("border-radius", Gtk.StateFlags.NORMAL)),
|
||||
)
|
||||
cr.clip()
|
||||
Image.do_draw(self, cr)
|
||||
|
||||
@@ -113,7 +113,7 @@ class SlideRevealer(Gtk.Overlay):
|
||||
x, y = self._get_position_at_progress_cached(progress)
|
||||
|
||||
# Round to nearest pixel for actual positioning
|
||||
pixel_x, pixel_y = int(round(x)), int(round(y))
|
||||
pixel_x, pixel_y = round(x), round(y)
|
||||
self._fixed.move(self.child, pixel_x, pixel_y)
|
||||
self.queue_draw()
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ from typing import Callable, Iterable, Literal, TypedDict
|
||||
from fabric.utils import Gdk, GObject, Gtk, cairo
|
||||
from fabric.utils.helpers import clamp
|
||||
from fabric.widgets.widget import Widget
|
||||
from gi.repository import Pango, PangoCairo # noqa: E402
|
||||
from gi.repository import Pango, PangoCairo
|
||||
|
||||
from shared.widgets.animator import Animator, ease_in, ease_in_out, ease_out
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ class AnimatedScrollable(ScrolledWindow):
|
||||
def animate_size(self, height: int = -1):
|
||||
if not self.animate:
|
||||
idle_add(lambda: self.snap_to_size(height))
|
||||
return
|
||||
return None
|
||||
self._last_req = height
|
||||
current_val = self.height_animator.value
|
||||
return self.do_animate(current_val, height)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
from fabric.utils import logger
|
||||
from fabric.utils import GLib
|
||||
from fabric.widgets.eventbox import EventBox # noqa: E402
|
||||
from fabric.widgets.wayland import WaylandWindow as Window # noqa: E402
|
||||
from fabric.utils import GLib, logger
|
||||
from fabric.widgets.eventbox import EventBox
|
||||
from fabric.widgets.wayland import WaylandWindow as Window
|
||||
|
||||
from shared.window.popup_win import PopupWindow # noqa: E402
|
||||
from shared.window.popup_win import PopupWindow
|
||||
|
||||
|
||||
class DismissLayer(Window):
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
from fabric.utils import logger
|
||||
from fabric.utils import GLib
|
||||
from fabric.utils import GLib, logger
|
||||
from fabric.widgets.box import Box
|
||||
from fabric.widgets.button import Button
|
||||
from fabric.widgets.centerbox import CenterBox
|
||||
from fabric.widgets.image import Image
|
||||
from fabric.widgets.label import Label
|
||||
from fabric.widgets.separator import Separator
|
||||
from services.gamemode import check_gamemode, toggle_gamemode
|
||||
|
||||
from services.battery import Battery
|
||||
from services.gamemode import check_gamemode, toggle_gamemode
|
||||
from utils.functions import clear_children, format_duration
|
||||
from utils.utils import svg_file
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ class PopupWindow(WaylandWindow):
|
||||
|
||||
def do_handle_size_allocate(self, *_):
|
||||
if not self.get_visible():
|
||||
return
|
||||
return None
|
||||
return self.do_reposition(self.do_calculate_edges())
|
||||
|
||||
def do_calculate_edges(self):
|
||||
@@ -142,7 +142,7 @@ class PopupWindow(WaylandWindow):
|
||||
height = self.get_allocated_height()
|
||||
width = self.get_allocated_width()
|
||||
|
||||
monitor_x, monitor_width = _get_monitor_geometry(parent_window)
|
||||
_monitor_x, monitor_width = _get_monitor_geometry(parent_window)
|
||||
|
||||
if self._pointing_widget:
|
||||
coords = self.get_coords_for_widget(self._pointing_widget)
|
||||
@@ -176,7 +176,8 @@ class PopupWindow(WaylandWindow):
|
||||
position_margins = (clamped, 0, 0, 0)
|
||||
|
||||
new_margin = tuple(
|
||||
a + b for a, b in zip(position_margins, self._base_margin.values())
|
||||
a + b
|
||||
for a, b in zip(position_margins, self._base_margin.values(), strict=False)
|
||||
)
|
||||
new_margin = (
|
||||
max(0, new_margin[0]),
|
||||
|
||||
Reference in new issue
Block a user