Huge Updates

This commit is contained in:
sankalp committed 2025-02-25 05:21:53 +05:45
1 parent 06064b0d94
commit f580786643
30 files changed
+1421 -1260

No files matched your search

+149 -42
View File
@@ -9,6 +9,12 @@ from fabric.widgets.scrolledwindow import ScrolledWindow
from gi.repository import GLib, Gdk
from snippets import read_config
from fabric.widgets.image import Image
import json
import os
import re
import math
import subprocess
import webbrowser
class AppLauncher(Box):
@@ -22,11 +28,18 @@ class AppLauncher(Box):
self.launcher = kwargs["launcher"]
self.selected_index = -1
self._arranger_handler: int = 0
self._all_apps = get_desktop_applications()
self.config = read_config()
# Calculator history initialization
self.calc_history_path = os.path.expanduser("~/.cache/modus/calc.json")
if os.path.exists(self.calc_history_path):
with open(self.calc_history_path, "r") as f:
self.calc_history = json.load(f)
else:
self.calc_history = []
self.viewport = Box(name="viewport", spacing=4, orientation="v")
self.search_entry = Entry(
name="search-entry",
@@ -35,18 +48,13 @@ class AppLauncher(Box):
on_activate=lambda entry, *_: self.on_search_entry_activate(
entry.get_text()
),
on_key_press_event=self.on_search_entry_key_press, # Handle key presses
)
self.scrolled_window = ScrolledWindow(
name="scrolled-window",
spacing=10,
h_scrollbar_policy="never",
v_scrollbar_policy="never",
child=self.viewport,
on_key_press_event=self.on_search_entry_key_press,
)
self.scrolled_window = None
self.header_box = Box(
name="header_box",
name="header-box",
orientation="h",
children=[self.search_entry],
)
@@ -55,41 +63,46 @@ class AppLauncher(Box):
name="launcher-box",
h_expand=True,
orientation="v",
children=[
self.header_box,
self.scrolled_window,
],
children=[self.header_box],
)
self.resize_viewport()
self.add(self.launcher_box)
self.show_all()
def close_launcher(self, *_):
self.viewport.children = []
self.selected_index = -1 # Reset selection
self.selected_index = -1
self.launcher.close()
def open_launcher(self):
self._all_apps = get_desktop_applications()
self.arrange_viewport()
self.show_all()
self.arrange_viewport("")
def arrange_viewport(self, query: str = ""):
if query.startswith(":"): # Don't show ScrolledWindow for web search
self.destroy_scrolled_window()
self.launcher.dashboard.hide()
return
if query.startswith("="):
self.show_scrolled_window()
# In calculator mode, update history view once (not per keystroke)
self.update_calculator_viewport()
self.launcher.dashboard.hide()
return
remove_handler(self._arranger_handler) if self._arranger_handler else None
self.viewport.children = []
self.selected_index = -1
if query.strip():
self.launcher.dashboard.hide()
self.show_scrolled_window()
else:
self.launcher.dashboard.show()
if not query.strip():
self.destroy_scrolled_window()
return False
filtered_apps = iter(
filtered_apps_iter = iter(
sorted(
[
app
@@ -100,19 +113,41 @@ class AppLauncher(Box):
+ (" " + app.name + " ")
+ (app.generic_name or "")
).casefold()
][:6],
],
key=lambda app: (app.display_name or "").casefold(),
)
)
should_resize = operator.length_hint(filtered_apps) == len(self._all_apps)
should_resize = operator.length_hint(filtered_apps_iter) == len(self._all_apps)
self._arranger_handler = idle_add(
lambda apps_iter: self.add_next_application(apps_iter)
or self.handle_arrange_complete(should_resize, query),
filtered_apps,
filtered_apps_iter,
pin=True,
)
def show_scrolled_window(self):
if self.scrolled_window is None:
self.scrolled_window = ScrolledWindow(
name="scrolled-window",
spacing=10,
min_content_size=(-1, -1),
h_scrollbar_policy="never",
child=self.viewport,
v_expand=True,
)
self.launcher_box.add(self.scrolled_window)
self.scrolled_window.show_all()
self.get_style_context().add_class("applauncher")
def destroy_scrolled_window(self):
if hasattr(self, "scrolled_window") and self.scrolled_window:
# self.scrolled_window.destroy()
self.launcher_box.remove(self.scrolled_window)
self.scrolled_window = None
self.get_style_context().remove_class("applauncher")
def handle_arrange_complete(self, should_resize, query):
if should_resize:
self.resize_viewport()
@@ -128,12 +163,6 @@ class AppLauncher(Box):
self.viewport.add(self.bake_application_slot(app))
return True
def resize_viewport(self):
self.scrolled_window.set_min_content_width(
self.viewport.get_allocation().width # type: ignore
)
return False
def bake_application_slot(self, app: DesktopApp, **kwargs) -> Button:
button = Button(
name="launcher-app",
@@ -160,13 +189,12 @@ class AppLauncher(Box):
return button
def update_selection(self, new_index: int):
# Unselect current
if self.selected_index != -1 and self.selected_index < len(
self.viewport.get_children()
):
current_button = self.viewport.get_children()[self.selected_index]
current_button.get_style_context().remove_class("selected")
# Select new
if new_index != -1 and new_index < len(self.viewport.get_children()):
new_button = self.viewport.get_children()[new_index]
new_button.get_style_context().add_class("selected")
@@ -180,41 +208,49 @@ class AppLauncher(Box):
adj = self.scrolled_window.get_vadjustment()
alloc = button.get_allocation()
if alloc.height == 0:
return False # Retry if allocation isn't ready
return False
y = alloc.y
height = alloc.height
page_size = adj.get_page_size()
current_value = adj.get_value()
# Calculate visible boundaries
visible_top = current_value
visible_bottom = current_value + page_size
if y < visible_top:
# Item above viewport - align to top
adj.set_value(y)
elif y + height > visible_bottom:
# Item below viewport - align to bottom
new_value = y + height - page_size
adj.set_value(new_value)
# No action if already fully visible
return False
GLib.idle_add(scroll)
def on_search_entry_activate(self, text):
commands = self.config.get("commands", {})
if text.startswith(":i "): # Detecting ':i' search
search_query = text[3:].strip() # Extract query after ':i '
if search_query:
url = f"https://www.google.com/search?q={search_query}"
webbrowser.open(url)
self.close_launcher()
return
if text.startswith("="):
# If in calculator mode and no history item is selected, evaluate new expression.
if self.selected_index == -1:
self.evaluate_calculator_expression(text)
return
if text in commands:
command = commands[text]
eval(command, {"launcher": self.launcher}) # Dynamically execute command
exec(command, {"launcher": self.launcher})
else:
children = self.viewport.get_children()
if children:
# Only activate if we have selection or non-empty query
if text.strip() == "" and self.selected_index == -1:
return # Prevent accidental activation when empty
return
selected_index = self.selected_index if self.selected_index != -1 else 0
if 0 <= selected_index < len(children):
children[selected_index].clicked()
@@ -236,10 +272,81 @@ class AppLauncher(Box):
children = self.viewport.get_children()
if not children:
return
# Allow starting selection from nothing when empty
if self.selected_index == -1 and delta == 1:
new_index = 0
else:
new_index = self.selected_index + delta
new_index = max(0, min(new_index, len(children) - 1))
self.update_selection(new_index)
def save_calc_history(self):
with open(self.calc_history_path, "w") as f:
json.dump(self.calc_history, f)
def evaluate_calculator_expression(self, text: str):
# Remove the '=' prefix and extra spaces
expr = text.lstrip("=").strip()
if not expr:
return
# Replace operators: '^' -> '**', and '×' -> '*'
expr = expr.replace("^", "**").replace("×", "*")
# Replace factorial: e.g. 5! -> math.factorial(5)
expr = re.sub(r"(\d+)!", r"math.factorial(\1)", expr)
# Replace brackets: allow [] and {} as ()
for old, new in [("[", "("), ("]", ")"), ("{", "("), ("}", ")")]:
expr = expr.replace(old, new)
try:
result = eval(expr, {"__builtins__": None, "math": math})
except Exception as e:
result = f"Error: {e}"
# Prepend to history (newest first)
self.calc_history.insert(0, f"{text} => {result}")
self.save_calc_history()
self.update_calculator_viewport()
def update_calculator_viewport(self):
self.viewport.children = []
for item in self.calc_history:
btn = self.create_calc_history_button(item)
self.viewport.add(btn)
# Remove resetting selected_index unconditionally so that a highlighted result isn't lost.
# Optionally, only reset if the input is not more than "=".
# if self.search_entry.get_text().strip() != "=":
# self.selected_index = -1
def create_calc_history_button(self, text: str) -> Button:
btn = Button(
name="app-slot-button", # reuse existing CSS styling
child=Box(
name="calc-slot-box",
orientation="h",
spacing=10,
children=[
Label(
name="calc-label",
label=text,
ellipsization="end",
v_align="center",
h_align="center",
),
],
),
tooltip_text=text,
on_clicked=lambda *_: self.copy_text_to_clipboard(text),
)
return btn
def copy_text_to_clipboard(self, text: str):
# Split the text on "=>" and copy only the result part if available
parts = text.split("=>", 1)
copy_text = parts[1].strip() if len(parts) > 1 else text
try:
subprocess.run(["wl-copy"], input=copy_text.encode(), check=True)
except subprocess.CalledProcessError as e:
print(f"Clipboard copy failed: {e}")
def delete_selected_calc_history(self):
if self.selected_index != -1 and self.selected_index < len(self.calc_history):
del self.calc_history[self.selected_index]
self.save_calc_history()
self.update_calculator_viewport()
+38 -34
View File
@@ -5,8 +5,7 @@ from fabric.widgets.button import Button
from fabric.widgets.centerbox import CenterBox
from fabric.widgets.scrolledwindow import ScrolledWindow
from fabric.bluetooth import BluetoothClient, BluetoothDevice
from snippets import MaterialIcon
# from .buttons import
import snippets.iconss as icons
class BluetoothDeviceSlot(CenterBox):
@@ -18,7 +17,9 @@ class BluetoothDeviceSlot(CenterBox):
"notify::closed", lambda *_: self.device.closed and self.destroy()
)
self.connection_icon = MaterialIcon("bluetooth_disabled", 12)
self.connection_label = Label(
name="bluetooth-connection", markup=icons.bluetooth_disconnected
)
self.connect_button = Button(
name="bluetooth-connect",
label="Connect",
@@ -29,9 +30,9 @@ class BluetoothDeviceSlot(CenterBox):
Box(
spacing=8,
children=[
Image(icon_name=device.icon_name + "-symbolic", size=32),
Image(icon_name=f"{device.icon_name}-symbolic", size=32),
Label(label=device.name),
self.connection_icon,
self.connection_label,
],
)
]
@@ -40,10 +41,11 @@ class BluetoothDeviceSlot(CenterBox):
self.device.emit("changed") # to update display status
def on_changed(self, *_):
self.connection_icon.set_label(
"bluetooth" if self.device.connected else "bluetooth_disabled"
self.connection_label.set_markup(
icons.bluetooth_connected
if self.device.connected
else icons.bluetooth_disconnected
)
if self.device.connecting:
self.connect_button.set_label(
"Connecting..." if not self.device.connecting else "Disconnecting..."
@@ -63,38 +65,37 @@ class BluetoothConnections(Box):
orientation="vertical",
**kwargs,
)
self.launcher = kwargs["launcher"]
self.bluetooth_button = self.launcher.dashboard.bluetooth_button
self.bt_status_text = self.bluetooth_button.bluetooth_status_text
self.bt_status_button = self.bluetooth_button.bluetooth_status_button
self.bt_icon = self.bluetooth_button.bluetooth_icon
self.bt_label = self.bluetooth_button.bluetooth_label
self.bt_menu_button = self.bluetooth_button.bluetooth_menu_button
self.bt_menu_label = self.bluetooth_button.bluetooth_menu_label
self.buttons = self.launcher.dashboard.bluetooth_button
self.bt_status_text = self.buttons.bluetooth_status_text
self.bt_status_button = self.buttons.bluetooth_status_button
self.bt_icon = self.buttons.bluetooth_icon
self.bt_label = self.buttons.bluetooth_label
self.bt_menu_button = self.buttons.bluetooth_menu_button
self.bt_menu_label = self.buttons.bluetooth_menu_label
self.client = BluetoothClient(on_device_added=self.on_device_added)
self.toggle_icon = MaterialIcon("bluetooth_disabled")
self.scan_icon = MaterialIcon("stop")
self.scan_button = Button(
name="bluetooth-scan",
child=self.scan_icon,
tooltip_text="scan",
child=Label(name="bluetooth-scan-icon", markup=icons.scan_stop),
on_clicked=lambda *_: self.client.toggle_scan(),
)
self.toggle_button = Button(
name="bluetooth-toggle",
tooltip_text="bluetooth-toggle",
child=self.toggle_icon,
child=Label(name="bluetooth-toggle-icon", markup=icons.bluetooth_off),
on_clicked=lambda *_: self.client.toggle_power(),
)
self.client.connect("notify::enabled", lambda *_: self.status_label())
self.client.connect(
"notify::enabled",
lambda *_: self.status_label(),
)
self.client.connect(
"notify::scanning",
lambda *_: self.scan_icon.set_label(
"stop" if self.client.scanning else "bluetooth_searching"
lambda *_: self.scan_button.get_child().set_markup(
icons.scan_stop if self.client.scanning else icons.scan
),
)
@@ -111,14 +112,16 @@ class BluetoothConnections(Box):
Label(name="bluetooth-section", label="Paired"),
ScrolledWindow(
name="bluetooth-paired",
v_expand=True,
min_content_size=(-1, -1),
child=self.paired_box,
v_expand=True,
),
Label(name="bluetooth-section", label="Available"),
ScrolledWindow(
name="bluetooth-paired",
v_expand=True,
name="bluetooth-available",
min_content_size=(-1, -1),
child=self.available_box,
v_expand=True,
),
]
@@ -130,7 +133,7 @@ class BluetoothConnections(Box):
def status_label(self):
print(self.client.enabled)
if self.client.enabled:
self.toggle_icon.set_label("bluetooth")
self.toggle_button.get_child().set_markup(icons.bluetooth)
self.bt_status_text.set_label("Enabled")
for i in [
self.bt_status_button,
@@ -141,9 +144,9 @@ class BluetoothConnections(Box):
self.bt_menu_label,
]:
i.remove_style_class("disabled")
self.bt_icon.set_label("bluetooth")
self.bt_icon.set_markup(icons.bluetooth)
else:
self.toggle_icon.set_label("bluetooth_disabled")
self.toggle_button.get_child().set_markup(icons.bluetooth_off)
self.bt_status_text.set_label("Disabled")
for i in [
self.bt_status_button,
@@ -154,7 +157,7 @@ class BluetoothConnections(Box):
self.bt_menu_label,
]:
i.add_style_class("disabled")
self.bt_icon.set_label("bluetooth_disabled")
self.bt_icon.set_markup(icons.bluetooth_off)
def on_device_added(self, client: BluetoothClient, address: str):
if not (device := client.get_device(address)):
@@ -162,5 +165,6 @@ class BluetoothConnections(Box):
slot = BluetoothDeviceSlot(device)
if device.paired:
return self.paired_box.add(slot)
return self.available_box.add(slot)
self.paired_box.add(slot)
else:
self.available_box.add(slot)
-396
View File
@@ -1,396 +0,0 @@
import subprocess
from fabric.widgets.box import Box
from fabric.widgets.centerbox import CenterBox
from fabric.widgets.label import Label
from fabric.widgets.button import Button
from fabric.utils.helpers import exec_shell_command_async, exec_shell_command
import gi
from gi.repository import Gtk, Gdk, GLib # Added Gdk import
from fabric.utils import get_relative_path
gi.require_version("Gtk", "3.0")
from snippets import MaterialIcon
def add_hover_cursor(widget):
# Add enter/leave events to change the cursor
widget.add_events(Gdk.EventMask.ENTER_NOTIFY_MASK | Gdk.EventMask.LEAVE_NOTIFY_MASK)
widget.connect(
"enter-notify-event",
lambda w, e: w.get_window().set_cursor(
Gdk.Cursor.new_from_name(w.get_display(), "pointer")
)
if w.get_window()
else None,
)
widget.connect(
"leave-notify-event",
lambda w, e: w.get_window().set_cursor(None) if w.get_window() else None,
)
class NetworkButton(Box):
def __init__(self):
self.network_icon = MaterialIcon(
"wifi",
)
self.network_icon.add_style_class("network-icon")
self.network_label = Label(
name="network-label",
label="Wi-Fi",
justification="left",
)
self.network_label_box = Box(children=[self.network_label, Box(h_expand=True)])
self.network_ssid = Label(
name="network-ssid",
label="Hello_World!!",
justification="left",
)
self.network_ssid_box = Box(children=[self.network_ssid, Box(h_expand=True)])
self.network_text = Box(
name="network-text",
orientation="v",
h_align="start",
v_align="center",
children=[self.network_label_box, self.network_ssid_box],
)
self.network_status_box = Box(
h_align="start",
v_align="center",
spacing=10,
children=[self.network_icon, self.network_text],
)
self.network_status_button = Button(
name="network-status-button",
h_expand=True,
child=self.network_status_box,
)
add_hover_cursor(self.network_status_button) # <-- Added hover
self.network_menu_label = MaterialIcon("chevron_right")
self.network_menu_button = Button(
name="network-menu-button",
child=self.network_menu_label,
)
add_hover_cursor(self.network_menu_button) # <-- Added hover
super().__init__(
name="network-button",
orientation="h",
h_align="fill",
v_align="fill",
h_expand=True,
v_expand=True,
spacing=0,
children=[self.network_status_button, self.network_menu_button],
)
class BluetoothButton(Box):
def __init__(self, launcher):
super().__init__(
name="bluetooth-button",
orientation="h",
h_align="fill",
v_align="fill",
h_expand=True,
v_expand=True,
)
self.launcher = launcher
self.bluetooth_icon = MaterialIcon("bluetooth")
self.bluetooth_label = Label(
name="bluetooth-label",
label="Bluetooth",
justification="left",
)
self.bluetooth_label_box = Box(
children=[self.bluetooth_label, Box(h_expand=True)]
)
self.bluetooth_status_text = Label(
name="bluetooth-status",
label="Disabled",
justification="left",
)
self.bluetooth_status_box = Box(
children=[self.bluetooth_status_text, Box(h_expand=True)]
)
self.bluetooth_text = Box(
orientation="v",
h_align="start",
v_align="center",
children=[self.bluetooth_label_box, self.bluetooth_status_box],
)
self.bluetooth_status_container = Box(
h_align="start",
v_align="center",
spacing=10,
children=[self.bluetooth_icon, self.bluetooth_text],
)
self.bluetooth_status_button = Button(
name="bluetooth-status-button",
h_expand=True,
child=self.bluetooth_status_container,
on_clicked=lambda *_: self.launcher.bluetooth.client.toggle_power(),
)
add_hover_cursor(self.bluetooth_status_button) # <-- Added hover
self.bluetooth_menu_label = MaterialIcon("chevron_right")
self.bluetooth_menu_button = Button(
name="bluetooth-menu-button",
on_clicked=lambda *_: self.launcher.open("bluetooth"),
child=self.bluetooth_menu_label,
)
add_hover_cursor(self.bluetooth_menu_button) # <-- Added hover
self.add(self.bluetooth_status_button)
self.add(self.bluetooth_menu_button)
class NightModeButton(Button):
def __init__(self):
self.night_mode_icon = MaterialIcon("mode_night")
self.night_mode_label = Label(
name="night-mode-label",
label="Night Mode",
justification="left",
)
self.night_mode_label_box = Box(
children=[self.night_mode_label, Box(h_expand=True)]
)
self.night_mode_status = Label(
name="night-mode-status",
label="Enabled",
justification="left",
)
self.night_mode_status_box = Box(
children=[self.night_mode_status, Box(h_expand=True)]
)
self.night_mode_text = Box(
name="night-mode-text",
orientation="v",
h_align="start",
v_align="center",
children=[self.night_mode_label_box, self.night_mode_status_box],
)
self.night_mode_box = Box(
h_align="start",
v_align="center",
spacing=10,
children=[self.night_mode_icon, self.night_mode_text],
)
super().__init__(
name="night-mode-button",
h_expand=True,
child=self.night_mode_box,
on_clicked=self.toggle_hyprsunset,
)
add_hover_cursor(self) # <-- Added hover
self.widgets = [
self,
self.night_mode_label,
self.night_mode_status,
self.night_mode_icon,
]
self.check_hyprsunset()
def toggle_hyprsunset(self, *args):
"""
Toggle the 'hyprsunset' process:
- If running, kill it and mark as 'Disabled'.
- If not running, start it and mark as 'Enabled'.
"""
try:
subprocess.check_output(["pgrep", "hyprsunset"])
exec_shell_command_async("pkill hyprsunset")
self.night_mode_status.set_label("Disabled")
for widget in self.widgets:
widget.add_style_class("disabled")
except subprocess.CalledProcessError:
exec_shell_command_async("hyprsunset -t 3500")
self.night_mode_status.set_label("Enabled")
for widget in self.widgets:
widget.remove_style_class("disabled")
def check_hyprsunset(self, *args):
"""
Update the button state based on whether hyprsunset is running.
"""
try:
subprocess.check_output(["pgrep", "hyprsunset"])
self.night_mode_status.set_label("Enabled")
for widget in self.widgets:
widget.remove_style_class("disabled")
except subprocess.CalledProcessError:
self.night_mode_status.set_label("Disabled")
for widget in self.widgets:
widget.add_style_class("disabled")
class CaffeineButton(Button):
def __init__(self):
self.caffeine_icon = MaterialIcon("coffee")
self.caffeine_label = Label(
name="caffeine-label",
label="Caffeine",
justification="left",
)
self.caffeine_label_box = Box(
children=[self.caffeine_label, Box(h_expand=True)]
)
self.caffeine_status = Label(
name="caffeine-status",
label="Enabled",
justification="left",
)
self.caffeine_status_box = Box(
children=[self.caffeine_status, Box(h_expand=True)]
)
self.caffeine_text = Box(
name="caffeine-text",
orientation="v",
h_align="start",
v_align="center",
children=[self.caffeine_label_box, self.caffeine_status_box],
)
self.caffeine_box = Box(
h_align="start",
v_align="center",
spacing=10,
children=[self.caffeine_icon, self.caffeine_text],
)
super().__init__(
name="caffeine-button",
h_expand=True,
child=self.caffeine_box,
on_clicked=self.toggle_wlinhibit,
)
add_hover_cursor(self) # <-- Added hover
self.widgets = [
self,
self.caffeine_label,
self.caffeine_status,
self.caffeine_icon,
]
self.check_wlinhibit()
def toggle_wlinhibit(self, *args):
"""
Toggle the 'wlinhibit' process:
- If running, kill it and mark as 'Disabled' (add 'disabled' class).
- If not running, start it and mark as 'Enabled' (remove 'disabled' class).
"""
try:
subprocess.check_output(["pgrep", "wlinhibit"])
exec_shell_command_async("pkill wlinhibit")
self.caffeine_status.set_label("Disabled")
for i in self.widgets:
i.add_style_class("disabled")
except subprocess.CalledProcessError:
exec_shell_command_async("wlinhibit")
self.caffeine_status.set_label("Enabled")
for i in self.widgets:
i.remove_style_class("disabled")
def check_wlinhibit(self, *args):
try:
subprocess.check_output(["pgrep", "wlinhibit"])
self.caffeine_status.set_label("Enabled")
for i in self.widgets:
i.remove_style_class("disabled")
except subprocess.CalledProcessError:
self.caffeine_status.set_label("Disabled")
for i in self.widgets:
i.add_style_class("disabled")
class DarkModeButton(Button):
def __init__(self):
self.dark_mode_icon = MaterialIcon("contrast")
self.dark_mode_icon.add_style_class("iconss")
self.dark_mode_label = Label(
name="dark-mode-label", label="Dark Mode", justification="left"
)
self.dark_mode_label_box = Box(
children=[self.dark_mode_label, Box(h_expand=True)]
)
self.dark_mode_status = Label(
name="dark-mode-status", label="Enabled", justification="left"
)
self.dark_mode_status_box = Box(
children=[self.dark_mode_status, Box(h_expand=True)]
)
self.dark_mode_text = Box(
name="dark-mode-text",
orientation="v",
h_align="start",
v_align="center",
children=[self.dark_mode_label_box, self.dark_mode_status_box],
)
self.dark_mode_box = Box(
h_align="start",
v_align="center",
spacing=10,
children=[self.dark_mode_icon, self.dark_mode_text],
)
super().__init__(
name="dark-mode-button",
h_expand=True,
child=self.dark_mode_box,
on_clicked=self.toggle_darkmode,
)
add_hover_cursor(self)
self.widgets = [
self,
self.dark_mode_label,
self.dark_mode_status,
self.dark_mode_icon,
]
self.check_darkmode()
def toggle_darkmode(self, *_):
current_state = self.check_darkmode()
new_mode = "dark" if not current_state else "light"
command = f"bash {get_relative_path('../../../config/scripts/dark-theme.sh')} --set {new_mode}"
GLib.spawn_command_line_async(command)
self.dark_mode_status.set_label("Enabled" if new_mode == "dark" else "Disabled")
def check_darkmode(self):
result = exec_shell_command(
"gsettings get org.gnome.desktop.interface color-scheme"
)
return result.strip().replace("'", "") == "prefer-dark"
class Buttons(Gtk.Grid):
def __init__(self, **kwargs):
super().__init__(name="buttons-grid")
self.set_row_homogeneous(True)
self.set_column_homogeneous(True)
self.set_row_spacing(8)
self.set_column_spacing(8)
self.set_vexpand(True) # Prevent vertical expansion
self.launcher = kwargs["launcher"]
# Instantiate each button
self.network_button = NetworkButton()
self.bluetooth_button = BluetoothButton(self.launcher)
self.night_mode_button = NightModeButton()
self.caffeine_button = CaffeineButton()
self.dark_mode_button = DarkModeButton()
# Attach buttons into the grid (one row, four columns)
self.attach(self.network_button, 0, 0, 1, 1)
self.attach(self.bluetooth_button, 1, 0, 1, 1)
self.attach(self.dark_mode_button, 2, 0, 1, 1)
self.attach(self.night_mode_button, 0, 1, 1, 1)
self.attach(self.caffeine_button, 1, 1, 1, 1)
self.show_all()
+3 -3
View File
@@ -1,11 +1,11 @@
import calendar
from datetime import datetime
import gi
from snippets import MaterialIcon
from fabric.widgets.label import Label
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk, GLib
import snippets.iconss as icons
class Calendar(Gtk.Box):
@@ -27,7 +27,7 @@ class Calendar(Gtk.Box):
self.prev_month_button = Gtk.Button(
name="prev-month-button",
child=MaterialIcon("chevron_left"),
child=Label(name="month-button-label", markup=icons.chevron_left)
)
self.prev_month_button.connect("clicked", self.on_prev_month_clicked)
self.header.pack_start(self.prev_month_button, False, False, 0)
@@ -37,7 +37,7 @@ class Calendar(Gtk.Box):
self.next_month_button = Gtk.Button(
name="next-month-button",
child=MaterialIcon("chevron_right"),
child=Label(name="month-button-label", markup=icons.chevron_right)
)
self.next_month_button.connect("clicked", self.on_next_month_clicked)
self.header.pack_start(self.next_month_button, False, False, 0)
+33 -43
View File
@@ -1,16 +1,14 @@
import os
import subprocess
from typing import List
from fabric import Fabricator
from fabric.utils import remove_handler
from fabric.widgets.box import Box
from fabric.widgets.button import Button
from fabric.widgets.entry import Entry
from fabric.widgets.label import Label
from fabric.widgets.scrolledwindow import ScrolledWindow
from gi.repository import GLib
from snippets import MaterialIcon
import snippets.iconss as icons
class Cliphist(Box):
@@ -25,30 +23,30 @@ class Cliphist(Box):
self._arranger_handler = 0
self.cliphist_manager = CliphistManager(self)
self.viewport = None
self.launcher = kwargs["launcher"]
self.search_entry = Entry(
name="search-entry",
h_expand=True,
notify_text=lambda entry, *_: self.handle_search_input(entry.get_text()),
on_activate=lambda entry, *_: self.handle_search_input(entry.get_text()),
)
self.toggle_button = Button(
child=MaterialIcon("delete_forever"),
name="clear-launcher-button",
on_clicked=self.on_button_clicked,
on_activate=lambda entry, *_: self.handle_search(entry.get_text()),
)
self.header_box = Box(
name="header-box",
spacing=10,
orientation="h",
children=[self.search_entry, self.toggle_button],
children=[
self.search_entry,
Button(
name="clear-button",
child=Label(name="cliphist-clear-button", markup=icons.clear),
tooltip_text="Clear Clipboard History",
on_clicked=self.handle_clear_history,
),
],
)
self.launcher_box = Box(
name="cliphist-history",
name="cliphist-launcher-box",
spacing=10,
orientation="v",
h_expand=True,
@@ -57,32 +55,31 @@ class Cliphist(Box):
self.add(self.launcher_box)
def on_button_clicked(self, *_):
GLib.spawn_command_line_async("cliphist wipe")
self.cliphist_manager.update_cliphist_history()
def open_launcher(self):
if not self.viewport:
self.viewport = Box(name="viewport", spacing=4, orientation="v")
self.scrolled_window = ScrolledWindow(
name="scrolled-window",
spacing=10,
min_content_size=(-1, -1),
h_scrollbar_policy="never",
# v_scrollbar_policy="never",
child=self.viewport,
)
self.launcher_box.add(self.scrolled_window)
self.viewport.children = []
self.cliphist_manager.arrange_viewport()
self.cliphist_manager.update_cliphist_history()
self.viewport.show()
self.search_entry.grab_focus()
def close_launcher(self):
self.launcher.close()
def handle_search(self, text: str):
self.cliphist_manager.arrange_viewport(query=text)
def handle_search_input(self, text: str):
self.cliphist_manager.arrange_viewport(text)
def handle_clear_history(self, *_):
GLib.spawn_command_line_async("cliphist wipe")
self.cliphist_manager.update_cliphist_history()
class CliphistManager:
@@ -121,7 +118,7 @@ class CliphistManager:
["cliphist", "decode", clip_id], capture_output=True, check=True
)
subprocess.run(["wl-copy"], input=decode_result.stdout, check=True)
self.launcher.close_launcher()
self.launcher.open_launcher()
except subprocess.CalledProcessError as e:
print(f"Error copying clip {clip_id}: {e}")
@@ -133,22 +130,25 @@ class CliphistManager:
decode_result = subprocess.run(
["cliphist", "decode", clip_id], capture_output=True, check=True
)
with open(output_file, "wb") as f:
f.write(decode_result.stdout)
return output_file
except (subprocess.CalledProcessError, IOError) as e:
print(f"Error saving image file for clip {clip_id}: {e}")
return ""
def update_cliphist_history(self):
self.cliphist_history = self.get_clip_history()
self.arrange_viewport()
def query_clips(self, query: str = "") -> List[dict]:
history = self.get_clip_history()
if not query.strip():
return history
return [item for item in history if query.lower() in item["content"].lower()]
return self.cliphist_history
return [
clip
for clip in self.cliphist_history
if query.lower() in clip["content"].lower()
]
def bake_clip_slot(self, item: dict) -> Button:
if "[[ binary data" in item["content"].lower():
@@ -163,19 +163,17 @@ class CliphistManager:
name="clip-img-item",
on_clicked=lambda _, clip_id=item["id"]: self.copy_clip(clip_id),
)
button.set_style(
f"background-image: url('{output_file}'); background-size: cover; background-position: center;"
)
return button
return None
def _create_text_button(self, item: dict) -> Button:
return Button(
child=Label(
label=item["content"][:55]
+ ("..." if len(item["content"]) > 55 else ""),
label=item["content"][:35]
+ ("..." if len(item["content"]) > 35 else ""),
h_expand=True,
v_align="center",
h_align="start",
@@ -184,18 +182,10 @@ class CliphistManager:
name="clip-item",
)
def update_cliphist_history(self):
self.cliphist_history = self.get_clip_history()
if self.launcher.viewport:
GLib.idle_add(self.arrange_viewport)
def arrange_viewport(self, query: str = ""):
if not self.launcher.viewport:
return
if self.launcher._arranger_handler:
remove_handler(self.launcher._arranger_handler)
self.launcher.viewport.children = []
filtered_clips = self.query_clips(query)
+28 -102
View File
@@ -9,7 +9,7 @@ from gi.repository import Gtk, Gdk, GLib # Added Gdk import
from fabric.utils import get_relative_path
gi.require_version("Gtk", "3.0")
from snippets import MaterialIcon
import snippets.iconss as icons
def add_hover_cursor(widget):
@@ -31,8 +31,9 @@ def add_hover_cursor(widget):
class NetworkButton(Box):
def __init__(self):
self.network_icon = MaterialIcon(
"wifi",
self.network_icon = Label(
name="network-icon",
markup=icons.wifi,
)
self.network_label = Label(
name="network-label",
@@ -66,7 +67,10 @@ class NetworkButton(Box):
)
add_hover_cursor(self.network_status_button) # <-- Added hover
self.network_menu_label = MaterialIcon("chevron_right")
self.network_menu_label = Label(
name="network-menu-label",
markup=icons.chevron_right,
)
self.network_menu_button = Button(
name="network-menu-button",
child=self.network_menu_label,
@@ -97,7 +101,10 @@ class BluetoothButton(Box):
)
self.launcher = launcher
self.bluetooth_icon = MaterialIcon("bluetooth")
self.bluetooth_icon = Label(
name="bluetooth-icon",
markup=icons.bluetooth,
)
self.bluetooth_label = Label(
name="bluetooth-label",
label="Bluetooth",
@@ -133,8 +140,10 @@ class BluetoothButton(Box):
on_clicked=lambda *_: self.launcher.bluetooth.client.toggle_power(),
)
add_hover_cursor(self.bluetooth_status_button) # <-- Added hover
self.bluetooth_menu_label = MaterialIcon("chevron_right")
self.bluetooth_menu_label = Label(
name="bluetooth-menu-label",
markup=icons.chevron_right,
)
self.bluetooth_menu_button = Button(
name="bluetooth-menu-button",
on_clicked=lambda *_: self.launcher.open("bluetooth"),
@@ -148,7 +157,10 @@ class BluetoothButton(Box):
class NightModeButton(Button):
def __init__(self):
self.night_mode_icon = MaterialIcon("mode_night")
self.night_mode_icon = Label(
name="night-mode-icon",
markup=icons.night,
)
self.night_mode_label = Label(
name="night-mode-label",
label="Night Mode",
@@ -230,7 +242,10 @@ class NightModeButton(Button):
class CaffeineButton(Button):
def __init__(self):
self.caffeine_icon = MaterialIcon("coffee")
self.caffeine_icon = Label(
name="caffeine-icon",
markup=icons.coffee,
)
self.caffeine_label = Label(
name="caffeine-label",
label="Caffeine",
@@ -308,7 +323,10 @@ class CaffeineButton(Button):
class DarkModeButton(Button):
def __init__(self):
self.dark_mode_icon = MaterialIcon("contrast")
self.dark_mode_icon = Label(
name="dark-mode-icon",
markup=icons.darkmode,
)
self.dark_mode_label = Label(
name="dark-mode-label", label="Dark Mode", justification="left"
)
@@ -384,96 +402,6 @@ class DarkModeButton(Button):
return is_dark_mode
#
# class PowerProfileButton(Button):
# def __init__(self):
# self.power_profile_icon = MaterialIcon("local_fire_department")
# self.power_profile_label = Label(
# name="power-profile-label", label="Power Profile", justification="left"
# )
# self.power_profile_label_box = Box(
# children=[self.power_profile_label, Box(h_expand=True)]
# )
# self.power_profile_status = Label(
# name="power-profile-status", label="Loading...", justification="left"
# )
# self.power_profile_status_box = Box(
# children=[self.power_profile_status, Box(h_expand=True)]
# )
# self.power_profile_text = Box(
# name="power-profile-text",
# orientation="v",
# h_align="start",
# v_align="center",
# children=[self.power_profile_label_box, self.power_profile_status_box],
# )
# self.power_profile_box = Box(
# h_align="start",
# v_align="center",
# spacing=10,
# children=[self.power_profile_icon, self.power_profile_text],
# )
#
# super().__init__(
# name="power-profile-button",
# h_expand=True,
# child=self.power_profile_box,
# on_clicked=self.toggle_power_profile,
# )
# add_hover_cursor(self)
#
# self.widgets = [
# self,
# self.power_profile_label,
# self.power_profile_status,
# self.power_profile_icon,
# ]
#
# # **Delay the profile check to allow system services to start**
# GLib.timeout_add(1000, self.check_power_profile)
#
# def toggle_power_profile(self, *_):
# current_profile = self.check_power_profile()
# if current_profile == "balanced":
# self.set_power_profile("performance")
# elif current_profile == "performance":
# self.set_power_profile("power-saver")
# else:
# self.set_power_profile("balanced")
#
# def check_power_profile(self):
# try:
# result = exec_shell_command("powerprofilesctl get")
# if isinstance(result, str):
# current_profile = result.strip().lower()
# self.power_profile_status.set_label(current_profile.capitalize())
# self.update_button_style(current_profile)
# return current_profile
# except Exception as e:
# print(f"Error checking power profile: {e}")
# self.power_profile_status.set_label("Balanced") # Fallback
# return "balanced"
#
# def set_power_profile(self, profile):
# exec_shell_command_async(f"powerprofilesctl set {profile}")
# self.power_profile_status.set_label(profile.capitalize())
# self.update_button_style(profile)
#
# def update_button_style(self, profile):
# if profile == "balanced":
# self.power_profile_icon.set_label("balance")
# self.add_style_class("balanced-profile")
# self.power_profile_label.add_style_class("disabled")
# else:
# self.remove_style_class("balanced-profile")
#
# if profile == "performance":
# self.power_profile_icon.set_label("local_fire_department")
# elif profile == "power-saver":
# self.power_profile_icon.set_label("data_saver_on")
#
class Dashboard(Gtk.Grid):
def __init__(self, **kwargs):
super().__init__(name="buttons-grid")
@@ -491,7 +419,6 @@ class Dashboard(Gtk.Grid):
self.night_mode_button = NightModeButton()
self.caffeine_button = CaffeineButton()
self.dark_mode_button = DarkModeButton()
# self.power_profile_button = PowerProfileButton()
# Attach buttons into the grid (one row, four columns)
self.attach(self.network_button, 0, 0, 1, 1)
@@ -499,6 +426,5 @@ class Dashboard(Gtk.Grid):
self.attach(self.dark_mode_button, 2, 0, 1, 1)
self.attach(self.night_mode_button, 0, 1, 1, 1)
self.attach(self.caffeine_button, 1, 1, 1, 1)
# self.attach(self.power_profile_button, 2, 1, 1, 1)
self.show_all()
+25 -24
View File
@@ -1,14 +1,14 @@
from fabric.widgets.box import Box
from fabric.widgets.label import Label
from fabric.widgets.button import Button
from gi.repository import GLib
from snippets import MaterialIcon
from fabric.utils.helpers import exec_shell_command_async
import snippets.iconss as icons
class PowerMenu(Box):
def __init__(self, **kwargs):
super().__init__(
name="powermenu",
name="power-menu",
orientation="h",
spacing=10,
v_align="center",
@@ -22,32 +22,32 @@ class PowerMenu(Box):
self.launcher = kwargs["launcher"]
self.btn_lock = Button(
name="powermenu-button",
child=MaterialIcon("lock", 45),
name="power-menu-button",
child=Label(name="button-label", markup=icons.lock),
on_clicked=self.lock,
)
self.btn_suspend = Button(
name="powermenu-button",
child=MaterialIcon("sleep", 45),
name="power-menu-button",
child=Label(name="button-label", markup=icons.suspend),
on_clicked=self.suspend,
)
self.btn_logout = Button(
name="powermenu-button",
child=MaterialIcon("logout", 45),
name="power-menu-button",
child=Label(name="button-label", markup=icons.logout),
on_clicked=self.logout,
)
self.btn_reboot = Button(
name="powermenu-button",
child=MaterialIcon("restart_alt", 45),
name="power-menu-button",
child=Label(name="button-label", markup=icons.reboot),
on_clicked=self.reboot,
)
self.btn_shutdown = Button(
name="powermenu-button",
child=MaterialIcon("power_settings_new", 45),
name="power-menu-button",
child=Label(name="button-label", markup=icons.shutdown),
on_clicked=self.poweroff,
)
@@ -67,22 +67,23 @@ class PowerMenu(Box):
def close_menu(self):
self.launcher.close()
def lock(self, *_):
GLib.spawn_command_line_async("hyprlock --immediate")
def lock(self, *args):
exec_shell_command_async("hyprlock --immediate")
self.close_menu()
def suspend(self, *_):
GLib.spawn_command_line_async("systemctl suspend")
def suspend(self, *args):
exec_shell_command_async("systemctl suspend")
self.close_menu()
def logout(self, *_):
GLib.spawn_command_line_async("hyprctl dispatch exit")
def logout(self, *args):
exec_shell_command_async("hyprctl dispatch exit")
self.close_menu()
def reboot(self, *_):
GLib.spawn_command_line_async("systemctl reboot")
def reboot(self, *args):
exec_shell_command_async("systemctl reboot")
self.close_menu()
def poweroff(self, *_):
GLib.spawn_command_line_async("systemctl poweroff")
def poweroff(self, *args):
exec_shell_command_async("systemctl poweroff")
self.close_menu()
+4 -2
View File
@@ -6,7 +6,7 @@ from fabric.widgets.button import Button
from fabric.widgets.entry import Entry
from fabric.widgets.label import Label
from fabric.widgets.scrolledwindow import ScrolledWindow
from snippets import MaterialIcon
CACHE_DIR = os.getenv(
"XDG_CACHE_HOME", os.path.join(os.path.expanduser("~"), ".cache", "fabric")
@@ -37,7 +37,7 @@ class Sh(Box):
self.header_box = Box(
spacing=10,
orientation="h",
children=[self.search_entry, MaterialIcon("terminal")],
children=[self.search_entry],
)
self.launcher_box = Box(
@@ -53,9 +53,11 @@ class Sh(Box):
if not self.viewport:
self.viewport = Box(name="viewport", spacing=10, orientation="v")
self.scrolled_window = ScrolledWindow(
name="scrolled-window",
spacing=10,
h_scrollbar_policy="never",
v_scrollbar_policy="never",
# min_content_size=(-1, -1),
child=self.viewport,
)
self.launcher_box.add(self.scrolled_window)
+10 -8
View File
@@ -6,7 +6,7 @@ from fabric.widgets.button import Button
from fabric.widgets.entry import Entry
from fabric.widgets.label import Label
from fabric.widgets.scrolledwindow import ScrolledWindow
from snippets import MaterialIcon
import snippets.iconss as icons
class TodoManager(Box):
@@ -36,7 +36,7 @@ class TodoManager(Box):
self.todo_entry,
Button(
name="add-button",
child=MaterialIcon("add"),
child=Label(name="todo-add-button", markup=icons.add),
tooltip_text="Add Todo",
on_clicked=lambda *_: self.handle_add_todo(
self.todo_entry.get_text()
@@ -59,8 +59,9 @@ class TodoManager(Box):
if not self.viewport:
self.viewport = Box(name="viewport", spacing=4, orientation="v")
self.scrolled_window = ScrolledWindow(
name="todo-content",
name="scrolled-window",
spacing=10,
min_content_size=(-1, -1),
h_scrollbar_policy="never",
child=self.viewport,
)
@@ -82,7 +83,7 @@ class TodoListManager:
def __init__(self, launcher):
self.launcher = launcher
self.todos = []
self.todo_file = os.path.expanduser("~/.local/share/fabric/todos.json")
self.todo_file = os.path.expanduser("~/.local/share/modus/todos.json")
self.load_todos()
def load_todos(self):
@@ -130,9 +131,10 @@ class TodoListManager:
)
checkbox = Button(
name="todo-checkbox",
child=MaterialIcon(
"check_box" if todo["completed"] else "check_box_outline_blank"
name="checkbox",
child=Label(
name="todo-checkbox",
markup=icons.check_box if todo["completed"] else icons.box,
),
on_clicked=lambda _, todo_id=todo["id"]: self.toggle_todo(todo_id),
)
@@ -147,7 +149,7 @@ class TodoListManager:
delete_button = Button(
name="delete-button",
child=MaterialIcon("delete"),
child=Label(name="todo-delete-button", markup=icons.trash),
on_clicked=lambda _, todo_id=todo["id"]: self.delete_todo(todo_id),
)
+10 -12
View File
@@ -4,8 +4,8 @@ from fabric.widgets.image import Image
from fabric.widgets.button import Button
from fabric.widgets.centerbox import CenterBox
from fabric.widgets.scrolledwindow import ScrolledWindow
from snippets import MaterialIcon
from services import NetworkClient
import snippets.iconss as icons
class WifiNetworkSlot(CenterBox):
@@ -15,7 +15,7 @@ class WifiNetworkSlot(CenterBox):
self.client = client
self.connecting = False # Tracks if we are connecting/disconnecting
self.connection_icon = MaterialIcon("signal_wifi_off", 12)
self.connection_icon = Label(name="wifi-connection", markup=icons.wifi_off)
self.connect_button = Button(
name="wifi-connect",
label="Connect",
@@ -68,9 +68,7 @@ class WifiNetworkSlot(CenterBox):
self.connect_button.sensitive = True
if not self.connecting:
self.connection_icon.set_label(
"signal_wifi_4_bar" if connected else "signal_wifi_off"
)
self.connection_icon.set_markup(icons.wifi if connected else icons.wifi_off)
self.connect_button.set_label("Disconnect" if connected else "Connect")
@@ -84,8 +82,8 @@ class WifiManager(Box):
)
self.client = NetworkClient()
self.scan_icon = MaterialIcon("wifi_find")
self.toggle_icon = MaterialIcon("signal_wifi_off")
self.scan_icon = Label(name="wifi-scan-icon", markup=icons.scan)
self.toggle_icon = Label(name="wifi-toggle-icon", markup=icons.wifi_off)
self.scan_button = Button(
name="wifi-scan",
@@ -113,8 +111,10 @@ class WifiManager(Box):
end_children=self.toggle_button,
),
ScrolledWindow(
name="scrolled-window",
name="wifi-available",
v_expand=True,
h_scrollbar_policy="never",
min_content_size=(-1, -1),
child=self.available_box,
),
]
@@ -135,10 +135,8 @@ class WifiManager(Box):
self.build_wifi_options()
def update_toggle_icon(self):
self.toggle_icon.set_label(
"signal_wifi_4_bar"
if self.client.wifi_device.enabled
else "signal_wifi_off"
self.toggle_icon.set_markup(
icons.wifi if self.client.wifi_device.enabled else icons.wifi_off
)
def build_wifi_options(self):