refactor(modules): Clean up imports and centralize utilities- Enhancements:
- Remove redundant gi.repository imports - Move common utilities (GLib, GObject, logger, os) into fabric.utils - Centralize GLib usage and reduce namespace pollution
This commit is contained in:
12 files changed
+25
-41
No files matched your search
@@ -1,6 +1,5 @@
|
|||||||
# Standard library imports
|
# Standard library imports
|
||||||
import gc
|
import gc
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import tempfile
|
import tempfile
|
||||||
import threading
|
import threading
|
||||||
@@ -9,7 +8,15 @@ import urllib.request
|
|||||||
import weakref
|
import weakref
|
||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
from fabric.utils import bulk_connect, cooldown, invoke_repeater
|
from fabric.utils import (
|
||||||
|
bulk_connect,
|
||||||
|
cooldown,
|
||||||
|
invoke_repeater,
|
||||||
|
GLib,
|
||||||
|
GObject,
|
||||||
|
logger,
|
||||||
|
os,
|
||||||
|
)
|
||||||
from fabric.widgets.box import Box
|
from fabric.widgets.box import Box
|
||||||
from fabric.widgets.button import Button
|
from fabric.widgets.button import Button
|
||||||
from fabric.widgets.image import Image
|
from fabric.widgets.image import Image
|
||||||
@@ -20,8 +27,6 @@ from fabric.widgets.overlay import Overlay
|
|||||||
from fabric.widgets.scale import Scale
|
from fabric.widgets.scale import Scale
|
||||||
from fabric.widgets.stack import Stack
|
from fabric.widgets.stack import Stack
|
||||||
from fabric.widgets.wayland import WaylandWindow as Window
|
from fabric.widgets.wayland import WaylandWindow as Window
|
||||||
from gi.repository import GLib, GObject
|
|
||||||
from loguru import logger
|
|
||||||
|
|
||||||
import config.data as data
|
import config.data as data
|
||||||
|
|
||||||
@@ -908,8 +913,6 @@ class PlayerBox(Box):
|
|||||||
# Cancel seek bar timer
|
# Cancel seek bar timer
|
||||||
if self._seekbar_timer_id:
|
if self._seekbar_timer_id:
|
||||||
try:
|
try:
|
||||||
from gi.repository import GLib
|
|
||||||
|
|
||||||
GLib.source_remove(self._seekbar_timer_id)
|
GLib.source_remove(self._seekbar_timer_id)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
@@ -1038,8 +1041,6 @@ class PlayerBox(Box):
|
|||||||
# Restart timer to ensure it's running with updated metadata
|
# Restart timer to ensure it's running with updated metadata
|
||||||
if self._seekbar_timer_id:
|
if self._seekbar_timer_id:
|
||||||
try:
|
try:
|
||||||
from gi.repository import GLib
|
|
||||||
|
|
||||||
GLib.source_remove(self._seekbar_timer_id)
|
GLib.source_remove(self._seekbar_timer_id)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
import os
|
|
||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
from fabric.utils import (
|
|
||||||
bulk_connect,
|
|
||||||
)
|
|
||||||
from fabric.utils.helpers import get_relative_path
|
|
||||||
from fabric.widgets.box import Box
|
from fabric.widgets.box import Box
|
||||||
from fabric.widgets.button import Button
|
from fabric.widgets.button import Button
|
||||||
from fabric.widgets.centerbox import CenterBox
|
from fabric.widgets.centerbox import CenterBox
|
||||||
@@ -14,8 +9,8 @@ from fabric.widgets.image import Image
|
|||||||
from fabric.widgets.label import Label
|
from fabric.widgets.label import Label
|
||||||
from fabric.widgets.overlay import Overlay
|
from fabric.widgets.overlay import Overlay
|
||||||
from fabric.widgets.stack import Stack
|
from fabric.widgets.stack import Stack
|
||||||
from gi.repository import Gio, GLib, GObject
|
|
||||||
from loguru import logger
|
from fabric.utils import GLib, GObject, Gio, logger, bulk_connect, get_relative_path, os
|
||||||
|
|
||||||
import config.data as data
|
import config.data as data
|
||||||
from services.mpris import MprisPlayer, MprisPlayerManager
|
from services.mpris import MprisPlayer, MprisPlayerManager
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from services.network import NetworkClient
|
|||||||
from utils.functions import get_wifi_connecting_icon, get_wifi_icon_for_strength
|
from utils.functions import get_wifi_connecting_icon, get_wifi_icon_for_strength
|
||||||
from utils.utils import svg_file
|
from utils.utils import svg_file
|
||||||
from widgets.wifi_password_dialog import WiFiPasswordDialog
|
from widgets.wifi_password_dialog import WiFiPasswordDialog
|
||||||
|
from gi.repository import NM
|
||||||
|
|
||||||
|
|
||||||
class WifiNetworkSlot(Box):
|
class WifiNetworkSlot(Box):
|
||||||
@@ -202,7 +203,6 @@ class WifiNetworkSlot(Box):
|
|||||||
if success:
|
if success:
|
||||||
self.is_connected = True
|
self.is_connected = True
|
||||||
# Remove connecting state after a short delay
|
# Remove connecting state after a short delay
|
||||||
from gi.repository import GLib
|
|
||||||
|
|
||||||
GLib.timeout_add(500, lambda: self._reset_connect_state())
|
GLib.timeout_add(500, lambda: self._reset_connect_state())
|
||||||
|
|
||||||
@@ -544,8 +544,6 @@ class WifiConnections(Box):
|
|||||||
# Compare SSIDs
|
# Compare SSIDs
|
||||||
connection_ssid_bytes = wifi_setting.get_ssid()
|
connection_ssid_bytes = wifi_setting.get_ssid()
|
||||||
if connection_ssid_bytes:
|
if connection_ssid_bytes:
|
||||||
from gi.repository import NM
|
|
||||||
|
|
||||||
connection_ssid = NM.utils_ssid_to_utf8(
|
connection_ssid = NM.utils_ssid_to_utf8(
|
||||||
connection_ssid_bytes.get_data()
|
connection_ssid_bytes.get_data()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from fabric.widgets.box import Box
|
|||||||
from fabric.widgets.entry import Entry
|
from fabric.widgets.entry import Entry
|
||||||
from fabric.widgets.scrolledwindow import ScrolledWindow
|
from fabric.widgets.scrolledwindow import ScrolledWindow
|
||||||
from fabric.widgets.wayland import WaylandWindow as Window
|
from fabric.widgets.wayland import WaylandWindow as Window
|
||||||
from gi.repository import Gdk, GLib
|
from fabric.utils import Gdk, GLib
|
||||||
|
|
||||||
from modules.launcher.plugin_manager import PluginManager
|
from modules.launcher.plugin_manager import PluginManager
|
||||||
from modules.launcher.result import Result
|
from modules.launcher.result import Result
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ from pathlib import Path
|
|||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from fabric.utils import GLib
|
||||||
|
from fabric.utils.helpers import get_relative_path
|
||||||
from thefuzz import fuzz
|
from thefuzz import fuzz
|
||||||
|
|
||||||
from fabric.utils.helpers import get_relative_path
|
|
||||||
from modules.launcher.plugin_base import PluginBase
|
from modules.launcher.plugin_base import PluginBase
|
||||||
from modules.launcher.result import Result
|
from modules.launcher.result import Result
|
||||||
|
|
||||||
@@ -739,7 +740,6 @@ class BookmarksPlugin(PluginBase):
|
|||||||
|
|
||||||
# Reset to trigger word with space
|
# Reset to trigger word with space
|
||||||
try:
|
try:
|
||||||
from gi.repository import GLib
|
|
||||||
|
|
||||||
def reset_and_refresh():
|
def reset_and_refresh():
|
||||||
# Set text to trigger word
|
# Set text to trigger word
|
||||||
@@ -772,7 +772,6 @@ class BookmarksPlugin(PluginBase):
|
|||||||
|
|
||||||
# Trigger a search to refresh results
|
# Trigger a search to refresh results
|
||||||
try:
|
try:
|
||||||
from gi.repository import GLib
|
|
||||||
|
|
||||||
def refresh():
|
def refresh():
|
||||||
self._launcher_instance._perform_search(current_text)
|
self._launcher_instance._perform_search(current_text)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import time
|
|||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
from gi.repository import GdkPixbuf, GLib
|
from fabric.utils import GdkPixbuf, GLib
|
||||||
|
|
||||||
from modules.launcher.plugin_base import PluginBase
|
from modules.launcher.plugin_base import PluginBase
|
||||||
from modules.launcher.result import Result
|
from modules.launcher.result import Result
|
||||||
@@ -85,7 +85,6 @@ class ClipboardPlugin(PluginBase):
|
|||||||
def _force_launcher_refresh(self):
|
def _force_launcher_refresh(self):
|
||||||
"""Force the launcher to refresh its results."""
|
"""Force the launcher to refresh its results."""
|
||||||
try:
|
try:
|
||||||
from gi.repository import GLib
|
|
||||||
|
|
||||||
def trigger_refresh():
|
def trigger_refresh():
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import time
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
from fabric.utils import get_relative_path
|
from fabric.utils import GLib, get_relative_path
|
||||||
|
|
||||||
from modules.launcher.plugin_base import PluginBase
|
from modules.launcher.plugin_base import PluginBase
|
||||||
from modules.launcher.result import Result
|
from modules.launcher.result import Result
|
||||||
from services.auth import (
|
from services.auth import (
|
||||||
@@ -99,8 +100,6 @@ class OTPPlugin(PluginBase):
|
|||||||
try:
|
try:
|
||||||
import gc
|
import gc
|
||||||
|
|
||||||
from gi.repository import GLib
|
|
||||||
|
|
||||||
def do_update():
|
def do_update():
|
||||||
try:
|
try:
|
||||||
for obj in gc.get_objects():
|
for obj in gc.get_objects():
|
||||||
@@ -230,8 +229,6 @@ class OTPPlugin(PluginBase):
|
|||||||
def _trigger_refresh(self):
|
def _trigger_refresh(self):
|
||||||
"""Trigger launcher refresh to return to default OTP view."""
|
"""Trigger launcher refresh to return to default OTP view."""
|
||||||
try:
|
try:
|
||||||
from gi.repository import GLib
|
|
||||||
|
|
||||||
# Use a small delay to ensure the action completes first
|
# Use a small delay to ensure the action completes first
|
||||||
def trigger_refresh():
|
def trigger_refresh():
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ from datetime import datetime
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
from fabric.utils import get_relative_path
|
from fabric.utils import GLib, get_relative_path
|
||||||
|
|
||||||
from modules.launcher.plugin_base import PluginBase
|
from modules.launcher.plugin_base import PluginBase
|
||||||
from modules.launcher.result import Result
|
from modules.launcher.result import Result
|
||||||
|
|
||||||
@@ -676,7 +677,6 @@ class PasswordPlugin(PluginBase):
|
|||||||
|
|
||||||
# Trigger a search to refresh results
|
# Trigger a search to refresh results
|
||||||
try:
|
try:
|
||||||
from gi.repository import GLib
|
|
||||||
|
|
||||||
def refresh():
|
def refresh():
|
||||||
self._launcher_instance._perform_search(current_text)
|
self._launcher_instance._perform_search(current_text)
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
import colorsys
|
import colorsys
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from typing import Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
from loguru import logger
|
|
||||||
|
|
||||||
from gi.repository import GdkPixbuf
|
|
||||||
|
|
||||||
import config.data as data
|
import config.data as data
|
||||||
from fabric.utils.helpers import exec_shell_command_async
|
from fabric.utils import exec_shell_command_async, GdkPixbuf, logger, os, GLib
|
||||||
from modules.launcher.plugin_base import PluginBase
|
from modules.launcher.plugin_base import PluginBase
|
||||||
from modules.launcher.result import Result
|
from modules.launcher.result import Result
|
||||||
|
|
||||||
@@ -123,7 +119,6 @@ class WallpaperPlugin(PluginBase):
|
|||||||
"""Clear the launcher search query and reset to trigger."""
|
"""Clear the launcher search query and reset to trigger."""
|
||||||
try:
|
try:
|
||||||
# Try to access the launcher through the fabric Application
|
# Try to access the launcher through the fabric Application
|
||||||
from gi.repository import GLib
|
|
||||||
|
|
||||||
from fabric import Application
|
from fabric import Application
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Any, Callable, Optional
|
from typing import Any, Callable, Optional
|
||||||
|
|
||||||
from gi.repository import GdkPixbuf, Gtk
|
from fabric.utils import GdkPixbuf, Gtk
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
|||||||
+1
-1
@@ -1,12 +1,12 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from fabric.hyprland.widgets import get_hyprland_connection
|
from fabric.hyprland.widgets import get_hyprland_connection
|
||||||
|
from fabric.utils import Gdk
|
||||||
from fabric.widgets.box import Box
|
from fabric.widgets.box import Box
|
||||||
from fabric.widgets.eventbox import EventBox
|
from fabric.widgets.eventbox import EventBox
|
||||||
from fabric.widgets.image import Image
|
from fabric.widgets.image import Image
|
||||||
from fabric.widgets.label import Label
|
from fabric.widgets.label import Label
|
||||||
from fabric.widgets.wayland import WaylandWindow as Window
|
from fabric.widgets.wayland import WaylandWindow as Window
|
||||||
from gi.repository import Gdk
|
|
||||||
|
|
||||||
import config.data as data
|
import config.data as data
|
||||||
from utils.functions import is_special_workspace
|
from utils.functions import is_special_workspace
|
||||||
|
|||||||
@@ -7,13 +7,13 @@ from fabric.widgets.button import Button
|
|||||||
from fabric.widgets.entry import Entry
|
from fabric.widgets.entry import Entry
|
||||||
from fabric.widgets.label import Label
|
from fabric.widgets.label import Label
|
||||||
from fabric.widgets.scrolledwindow import ScrolledWindow
|
from fabric.widgets.scrolledwindow import ScrolledWindow
|
||||||
from gi.repository import GLib
|
from fabric.utils import GLib
|
||||||
|
|
||||||
# Local imports
|
# Local imports
|
||||||
from utils.utils import svg_file
|
from utils.utils import svg_file
|
||||||
from services.todo import get_todo_service
|
from services.todo import get_todo_service
|
||||||
from widgets.mousecapture import MouseCapture
|
from widgets.mousecapture import MouseCapture
|
||||||
from widgets.wayland import WaylandWindow as Window
|
from fabric.widgets.wayland import WaylandWindow as Window
|
||||||
|
|
||||||
|
|
||||||
class TodoItem(Box):
|
class TodoItem(Box):
|
||||||
|
|||||||
Reference in new issue
Block a user