This commit is contained in:
sankalp committed 2025-02-07 12:49:51 +05:45
1 parent 755ac6584d
commit 4b21fa5d53
6 files changed
+103 -66

No files matched your search

+1
View File
@@ -109,6 +109,7 @@ class Bar(Window):
super().__init__(
layer="top",
anchor="left bottom right",
# anchor="left top right",
exclusivity="auto",
visible=True,
child=self.bar,
@@ -43,7 +43,7 @@ class BatteryLabel(Box):
self.hide()
return
battery_percent = round(battery.percent) if battery else 0.0
battery_percent = round(battery.percent)
battery_label = Label(label=f"{battery_percent}%")
is_charging = battery.power_plugged if battery else False
+22 -17
View File
@@ -1,3 +1,4 @@
from time import sleep
import psutil
from fabric import Fabricator
from fabric.widgets.box import Box
@@ -18,7 +19,12 @@ class SystemInfo(Button):
def __init__(self):
super().__init__(child=self._initialize_content())
self.fabricator = Fabricator(poll_from=self._refresh_system_info, interval=1000)
Fabricator(
poll_from=self._refresh_system_info,
stream=True,
on_changed=lambda fab, data: self._update_ui(data),
)
def _initialize_content(self):
self.box = Box(orientation="h", name="tray")
@@ -36,7 +42,9 @@ class SystemInfo(Button):
self.labels[system] = self._create_label()
self.icons[system] = self._create_icon(icon_name)
overlay = Overlay(child=self.progress_bars[system], overlays=self.icons[system])
overlay = Overlay(
child=self.progress_bars[system], overlays=[self.icons[system]]
)
self.box.pack_start(overlay, False, False, 0)
self.box.pack_start(self.labels[system], False, False, 0)
@@ -51,32 +59,29 @@ class SystemInfo(Button):
def _create_icon(self, icon_name):
return MaterialIcon(icon_name, size=16)
def _refresh_system_info(self, *_):
usages = self._retrieve_system_data()
self._update_tooltip(usages)
return True
def _refresh_system_info(self, fab: Fabricator):
while True:
yield {
"CPU": round(psutil.cpu_percent()),
"RAM": round(psutil.virtual_memory().percent),
"Swap": round(psutil.swap_memory().percent),
"Temp": self._get_device_temperature(),
}
sleep(1)
@staticmethod
def _get_device_temperature():
try:
temps = psutil.sensors_temperatures()
if "coretemp" in temps:
return temps["coretemp"][0].current
return round(temps["coretemp"][0].current, 1)
elif "cpu_thermal" in temps:
return temps["cpu_thermal"][0].current
return round(temps["cpu_thermal"][0].current, 1)
return None
except Exception:
return None
def _retrieve_system_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_tooltip(self, usages):
def _update_ui(self, usages):
for system, usage in usages.items():
if usage is None:
usage = 0
+12 -1
View File
@@ -1,4 +1,15 @@
from .animator import *
from .custom_image import *
from .config import *
from .icon import *
import json
from gi.repository import GLib
def read_config():
home_dir = GLib.get_home_dir()
config_path = f"{home_dir}/dotfiles/modus/assets/config.json"
with open(config_path, "r") as file:
# Load JSON data into a Python dictionary
data = json.load(file)
return data
-43
View File
@@ -1,43 +0,0 @@
import json
import os
import time
import psutil
from gi.repository import GLib
from loguru import logger
def read_config():
home_dir = GLib.get_home_dir()
config_path = f"{home_dir}/dotfiles/modus/assets/config.json"
with open(config_path, "r") as file:
# Load JSON data into a Python dictionary
data = json.load(file)
return data
def get_current_uptime():
uptime = time.time() - psutil.boot_time()
uptime_hours, remainder = divmod(uptime, 3600)
uptime_minutes, _ = divmod(remainder, 60)
return (
f"Up: {int(uptime_hours)} {'hours' if uptime_hours != 1 else 'hour'}, "
f"{int(uptime_minutes)} {'minutes' if uptime_minutes != 1 else 'minute'}"
)
def get_profile_picture_path() -> str | None:
path = os.path.expanduser("~/Pictures/Other/face.jpg")
if not os.path.exists(path):
path = os.path.expanduser("~/.face")
if not os.path.exists(path):
logger.warning(
"can't fetch a user profile picture, add a profile picture image at ~/.face or at ~/Pictures/Other/profile.jpg"
)
path = None
return path
def username():
return os.getlogin().title()
+67 -4
View File
@@ -1,3 +1,42 @@
#switcher {
background-color: @background;
border: solid 1px @surfaceVariant;
padding: 12px;
border-radius: 16px;
}
.switcher-button {
border-radius: 16px;
border: 1px solid @surfaceVariant;
padding: 4px;
margin: 4px;
}
.switcher-button button:active {
background-color: @primaryContainer;
border-radius: 11px;
box-shadow: inset 0 0 0 1px rgba(158, 142, 130, 0.04);
}
.switcher-button:hover,
.switcher-button:focus {
background-color: mix(@onSurface, @surface, 0.85);
}
.switcher-button:hover image,
.switcher-button:focus image {
-gtk-icon-shadow: 2px 2px @primary;
}
.switcher-button:hover #title,
.switcher-button:focus #title {
color: @primary;
}
/*
* ── launcher ──────────────────────────────────────────────────────────
*/
#launcher {
margin: 18px;
border: 1px solid @outlineVariant;
@@ -21,10 +60,18 @@
min-width: 620px;
}
#launcher-content.bluetooth {
#launcer-content.cliphist {
min-height: 420px;
}
#launcher-content.bluetooth {
min-height: 464px;
}
#launcher-content.power {
min-height: 52px;
}
#launcher-content {
min-width: 420px;
}
@@ -163,6 +210,9 @@
/*
* ── cliphist ──────────────────────────────────────────────────────────
*/
#cliphist-history {
min-height: 420px;
}
#launcher button#clip-img-item {
background-size: cover;
@@ -183,11 +233,11 @@
background-color: transparent;
background-image: none;
box-shadow: none;
padding: 0px;
padding: 6px;
}
#launcher button#clip-item {
font-size: 24px;
font-size: 30px;
}
#launcher button#clip-item:hover,
@@ -198,6 +248,9 @@
/*
* ── todo ──────────────────────────────────────────────────────────────
*/
#todo-content {
min-height: 250px;
}
#todo-launcher {
background-color: @surface;
@@ -256,6 +309,10 @@
margin-bottom: 4px;
}
#bluetooth-header {
padding: 4px;
}
#bluetooth-scan,
#bluetooth-toggle {
background-color: @secondaryContainer;
@@ -277,7 +334,8 @@
font-weight: bold;
}
#bluetooth-text {
#bluetooth-text,
#bluetooth-section {
font-weight: bold;
}
@@ -294,3 +352,8 @@
#bluetooth-connect:hover {
background-color: @surfaceBright;
}
#bluetooth-paired,
#bluetooth-available {
padding: 4px;
}