diff --git a/config/fabric/modules/bar/widgets/__init__.py b/config/fabric/modules/bar/widgets/__init__.py index d6901760..9f55d865 100644 --- a/config/fabric/modules/bar/widgets/__init__.py +++ b/config/fabric/modules/bar/widgets/__init__.py @@ -21,5 +21,5 @@ __all__ = [ "TaskBar", "VolumeIndicator", "workspace", - "Weather", + # "Weather", ] diff --git a/config/fabric/modules/bar/widgets/battery.py b/config/fabric/modules/bar/widgets/battery.py index fa4a3b87..39ed5549 100644 --- a/config/fabric/modules/bar/widgets/battery.py +++ b/config/fabric/modules/bar/widgets/battery.py @@ -1,6 +1,5 @@ import psutil - -from fabric.utils import invoke_repeater +from fabric import Fabricator from fabric.widgets.box import Box from fabric.widgets.label import Label from snippets import MaterialIcon @@ -36,9 +35,9 @@ class BatteryLabel(Box): def __init__(self, **kwargs): super().__init__(**kwargs) - invoke_repeater(1000, self.update_battery_status, initial_call=True) + Fabricator(interval=1000, poll_from=self.update_battery_status) - def update_battery_status(self): + def update_battery_status(self, *_): battery = psutil.sensors_battery() if battery is None: self.hide() diff --git a/config/fabric/modules/bar/widgets/bluetooth.py b/config/fabric/modules/bar/widgets/bluetooth.py index 6d83d054..a91dd160 100644 --- a/config/fabric/modules/bar/widgets/bluetooth.py +++ b/config/fabric/modules/bar/widgets/bluetooth.py @@ -1,11 +1,11 @@ from fabric.bluetooth import BluetoothClient from fabric.widgets.box import Box -from snippets import MaterialIcon # Import your MaterialIcon function +from snippets import MaterialIcon class Bluetooth(Box): - ICON_ENABLED = "bluetooth" # Use the appropriate Material icon name - ICON_DISABLED = "bluetooth_disabled" # Use the appropriate Material icon name + ICON_ENABLED = "bluetooth" + ICON_DISABLED = "bluetooth_disabled" def __init__(self, **kwargs): super().__init__(**kwargs) @@ -31,5 +31,4 @@ class Bluetooth(Box): self.add(self.bluetooth_icon) def on_destroy(self): - """Disconnect the Bluetooth client when the widget is destroyed.""" self.bluetooth_client.disconnect("changed", self.update_bluetooth_status) diff --git a/config/fabric/modules/bar/widgets/idle_indicator.py b/config/fabric/modules/bar/widgets/idle_indicator.py index 7a747fbd..4f641801 100644 --- a/config/fabric/modules/bar/widgets/idle_indicator.py +++ b/config/fabric/modules/bar/widgets/idle_indicator.py @@ -1,6 +1,5 @@ -from fabric.utils import exec_shell_command +from fabric.utils import exec_shell_command, invoke_repeater from fabric.widgets.box import Box -from gi.repository import GLib from snippets import MaterialIcon @@ -13,7 +12,7 @@ class IdleIndicator(Box): self.check_idle_status() - GLib.timeout_add(1000, self.check_idle_status) + invoke_repeater(1000, self.check_idle_status) self.children = (self.idle_icon,) diff --git a/config/fabric/modules/bar/widgets/info.py b/config/fabric/modules/bar/widgets/info.py index 7c0ad615..c8661dc8 100644 --- a/config/fabric/modules/bar/widgets/info.py +++ b/config/fabric/modules/bar/widgets/info.py @@ -1,5 +1,5 @@ import psutil -from fabric.utils import invoke_repeater +from fabric import Fabricator from fabric.widgets.box import Box from fabric.widgets.button import Button from fabric.widgets.circularprogressbar import CircularProgressBar @@ -13,52 +13,79 @@ class HardwareUsage(Button): ("CPU", "settings_motion_mode"), ("Swap", "swap_horiz"), ("RAM", "memory_alt"), + ("Temp", "thermometer"), ] def __init__(self): - super().__init__(child=self._create_content()) - invoke_repeater(1000, self._update_labels) + super().__init__(child=self._initialize_content()) + Fabricator(poll_from=self._refresh_hardware_usage, interval=1000) - def _create_content(self): + def _initialize_content(self): self.box = Box(orientation="h", name="tray") self.progress_bars = {} self.labels = {} self.icons = {} for hardware, icon_name in self.HARDWARE_ITEMS: - self.progress_bars[hardware] = self._create_progress_bar() - self.labels[hardware] = Label(style="font-size:14px; margin: 4px;") - self.icons[hardware] = MaterialIcon(icon_name, size="16px") - self._pack_items(hardware) + self._create_hardware_item(hardware, icon_name) return self.box - def _create_progress_bar(self): - return CircularProgressBar( - name="progress", line_style="round", line_width=1, size=30 - ) + def _create_hardware_item(self, hardware, icon_name): + self.progress_bars[hardware] = self._create_progress_bar() + self.labels[hardware] = self._create_label() + self.icons[hardware] = self._create_icon(icon_name) - def _pack_items(self, hardware): overlay = Overlay( child=self.progress_bars[hardware], overlays=self.icons[hardware] ) self.box.pack_start(overlay, False, False, 0) self.box.pack_start(self.labels[hardware], False, False, 0) - def _update_labels(self): - usages = self._get_hardware_usages() - self._update_progress_bars(usages) + def _create_progress_bar(self): + return CircularProgressBar( + name="progress", line_style="round", line_width=1, size=30 + ) + + def _create_label(self): + return Label(style="font-size:14px; margin: 4px;") + + def _create_icon(self, icon_name): + return MaterialIcon(icon_name, size="16px") + + def _refresh_hardware_usage(self, *_): + usages = self._retrieve_hardware_data() + self._update_hardware_display(usages) return True - def _get_hardware_usages(self): + @staticmethod + def _get_device_temperature(): + try: + temps = psutil.sensors_temperatures() + if "coretemp" in temps: + return temps["coretemp"][0].current + elif "cpu_thermal" in temps: + return temps["cpu_thermal"][0].current + return None + except Exception: + return None + + def _retrieve_hardware_data(self): return { "CPU": round(psutil.cpu_percent()), "RAM": round(psutil.virtual_memory().percent), "Swap": round(psutil.swap_memory().percent), + "Temp": self._get_device_temperature(), } - def _update_progress_bars(self, usages): + def _update_hardware_display(self, usages): for hardware, usage in usages.items(): + if usage is None: + usage = 0 + self.labels[hardware].set_label("N/A") + else: + usage = int(usage) + self.progress_bars[hardware].value = usage / 100 - self.labels[hardware].set_label(f"{usage}%") + self.labels[hardware].set_label(f"{usage}") self.progress_bars[hardware].set_tooltip_text(f"{hardware} Usage: {usage}%") diff --git a/config/fabric/modules/bar/widgets/network.py b/config/fabric/modules/bar/widgets/network.py index 8a39d1c7..565ec884 100644 --- a/config/fabric/modules/bar/widgets/network.py +++ b/config/fabric/modules/bar/widgets/network.py @@ -1,7 +1,7 @@ import subprocess import psutil -from fabric.utils import invoke_repeater +from fabric import Fabricator from fabric.widgets.box import Box from snippets import MaterialIcon @@ -9,13 +9,14 @@ from snippets import MaterialIcon class Network(Box): def __init__(self, **kwargs): super().__init__(**kwargs) - self.update_interval = 5000 + self.update_interval = 1000 self.last_status = None - invoke_repeater( - self.update_interval, self.update_network_status, initial_call=True + Fabricator( + interval=self.update_interval, + poll_from=self.update_network_status, ) - def update_network_status(self): + def update_network_status(self, *_): current_status = self.get_network_status() if current_status != self.last_status: self.update_icon(current_status) @@ -68,7 +69,7 @@ class Network(Box): def is_ethernet_connected(self): return any( - self._is_interface_up(interface, ["eth"]) + self._is_interface_up(interface, ["enp", "eth"]) for interface in psutil.net_if_addrs() )