refactor about window
This commit is contained in:
1 parent
7bf7ed5771
commit
ef4458c99e
1 file changed
+69
-13
+69
-13
@@ -1,6 +1,7 @@
|
||||
import subprocess
|
||||
import time
|
||||
import gi # type: ignore
|
||||
import re
|
||||
|
||||
from fabric.widgets.label import Label
|
||||
from fabric.widgets.button import Button
|
||||
@@ -9,7 +10,45 @@ from utils.wayland import WaylandWindow as Window
|
||||
from fabric.utils.helpers import exec_shell_command_async, get_relative_path
|
||||
from gi.repository import Gtk, GdkPixbuf # type: ignore
|
||||
|
||||
# from config.c import c
|
||||
|
||||
def read_dmi(field):
|
||||
try:
|
||||
with open(f"/sys/class/dmi/id/{field}") as f:
|
||||
return f.read().strip()
|
||||
except Exception:
|
||||
return "Unknown"
|
||||
|
||||
|
||||
def get_gpu_name():
|
||||
try:
|
||||
output = (
|
||||
subprocess.check_output(
|
||||
"lspci -nn | grep -i 'VGA compatible controller'", shell=True, text=True
|
||||
)
|
||||
.strip()
|
||||
.split("\n")
|
||||
)
|
||||
|
||||
def clean(line):
|
||||
matches = re.findall(r"\[(.*?)\]", line)
|
||||
if len(matches) >= 2:
|
||||
return matches[1].strip()
|
||||
desc = line.split(":", 2)[-1]
|
||||
return desc.replace("Corporation", "").strip()
|
||||
|
||||
# Prefer dGPU
|
||||
for line in output:
|
||||
if any(vendor in line.lower() for vendor in ["nvidia", "amd", "radeon"]):
|
||||
return clean(line)
|
||||
|
||||
# Fallback to iGPU
|
||||
if output:
|
||||
return clean(output[0])
|
||||
|
||||
return "Unknown GPU"
|
||||
|
||||
except Exception:
|
||||
return "Unknown GPU"
|
||||
|
||||
|
||||
class About(Gtk.Window):
|
||||
@@ -43,8 +82,8 @@ class About(Gtk.Window):
|
||||
logo_box.pack_start(logo, False, False, 0)
|
||||
|
||||
# Labels
|
||||
name_label = Gtk.Label(label="Modus")
|
||||
date_label = Gtk.Label(label="Modus, 2025")
|
||||
name_label = Gtk.Label(label=read_dmi("product_name"))
|
||||
date_label = Gtk.Label(label=read_dmi("sys_vendor"))
|
||||
|
||||
# Info Section
|
||||
info_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10)
|
||||
@@ -57,28 +96,32 @@ class About(Gtk.Window):
|
||||
|
||||
# Titles
|
||||
info_title_box.pack_start(
|
||||
Gtk.Label(label="SO", halign=Gtk.Align.END), False, False, 0
|
||||
Gtk.Label(label="Kernel", halign=Gtk.Align.END), False, False, 0
|
||||
)
|
||||
info_title_box.pack_start(
|
||||
Gtk.Label(label="Chip", halign=Gtk.Align.END), False, False, 0
|
||||
Gtk.Label(label="CPU", halign=Gtk.Align.END), False, False, 0
|
||||
)
|
||||
info_title_box.pack_start(
|
||||
Gtk.Label(label="Memory", halign=Gtk.Align.END), False, False, 0
|
||||
)
|
||||
info_title_box.pack_start(
|
||||
Gtk.Label(label="GPU", halign=Gtk.Align.END), False, False, 0
|
||||
)
|
||||
info_title_box.pack_start(
|
||||
Gtk.Label(label="Uptime", halign=Gtk.Align.END), False, False, 0
|
||||
)
|
||||
|
||||
# Values
|
||||
so_label = Gtk.Label(
|
||||
|
||||
kernel_label = Gtk.Label(
|
||||
label=subprocess.run(
|
||||
"cat /etc/*-release | grep '^PRETTY_NAME=' | cut -d '\"' -f 2",
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
"uname -r", shell=True, capture_output=True, text=True
|
||||
).stdout.strip(),
|
||||
halign=Gtk.Align.START,
|
||||
)
|
||||
chip_label = Gtk.Label(
|
||||
label=subprocess.run(
|
||||
"lscpu | grep 'Model name:' | awk '{print $5}'",
|
||||
"lscpu | grep 'Model name:' | cut -d ':' -f2-",
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
@@ -94,16 +137,29 @@ class About(Gtk.Window):
|
||||
).stdout.strip(),
|
||||
halign=Gtk.Align.START,
|
||||
)
|
||||
uptime_label = Gtk.Label(
|
||||
label=subprocess.run(
|
||||
"uptime -p",
|
||||
shell=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
).stdout.strip(),
|
||||
halign=Gtk.Align.START,
|
||||
)
|
||||
gpu_label = Gtk.Label(label=get_gpu_name(), halign=Gtk.Align.START)
|
||||
|
||||
info_box_labels.pack_start(so_label, False, False, 0)
|
||||
info_box_labels.pack_start(kernel_label, False, False, 0)
|
||||
info_box_labels.pack_start(chip_label, False, False, 0)
|
||||
info_box_labels.pack_start(mem_label, False, False, 0)
|
||||
info_box_labels.pack_start(gpu_label, False, False, 0)
|
||||
info_box_labels.pack_start(uptime_label, False, False, 0)
|
||||
|
||||
info_box.pack_start(info_title_box, False, False, 10)
|
||||
info_box.pack_start(info_box_labels, False, False, 10)
|
||||
|
||||
# More Info Button
|
||||
button_box = Gtk.Box(halign=Gtk.Align.CENTER)
|
||||
button_box.set_margin_top(20) # Add 20 pixels of vertical spacing
|
||||
more_info_button = Gtk.Button(label="More Info...", name="more-info-button")
|
||||
more_info_button.connect("clicked", self.open_more_info)
|
||||
button_box.pack_start(more_info_button, False, False, 0)
|
||||
@@ -119,7 +175,7 @@ class About(Gtk.Window):
|
||||
self.add(main_box)
|
||||
|
||||
def open_more_info(self, button):
|
||||
# exec_shell_command_async(f"xdg-open {c.get_shell_rule('about-more-info')}")
|
||||
# TODO: Implement the logic to open more info
|
||||
pass
|
||||
|
||||
def toggle(self, b):
|
||||
|
||||
Reference in new issue
Block a user