update
This commit is contained in:
1 parent
013a55f2c4
commit
f8f1816aa3
14 files changed
+148
-164
No files matched your search
@@ -16,6 +16,7 @@ from modules.bar.widgets import (
|
||||
PowerProfile,
|
||||
TaskBar,
|
||||
VolumeIndicator,
|
||||
Weather,
|
||||
workspace,
|
||||
)
|
||||
|
||||
@@ -42,9 +43,10 @@ class Bar(Window):
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
self.date_time = DateTime(formatters=["%-I:%M %a %d %b"], name="datetime")
|
||||
self.system_tray = SystemTray(name="tray", spacing=4, icon_size=18)
|
||||
self.taskbar = TaskBar(icon_size=18)
|
||||
self.taskbar = TaskBar()
|
||||
self.volume = VolumeIndicator()
|
||||
self.network = Network()
|
||||
self.bluetooth = Bluetooth()
|
||||
@@ -54,6 +56,7 @@ class Bar(Window):
|
||||
self.workspaces = Button(child=workspace, name="workspaces")
|
||||
self.info = HardwareUsage()
|
||||
self.idle = IdleIndicator()
|
||||
self.weather = Weather("Kohalpur")
|
||||
self.applets = Box(
|
||||
name="applets",
|
||||
spacing=4,
|
||||
@@ -67,6 +70,7 @@ class Bar(Window):
|
||||
self.idle,
|
||||
],
|
||||
)
|
||||
|
||||
self.children = CenterBox(
|
||||
name="bar",
|
||||
start_children=Box(
|
||||
@@ -76,6 +80,7 @@ class Bar(Window):
|
||||
children=[
|
||||
self.workspaces,
|
||||
self.info,
|
||||
self.weather,
|
||||
],
|
||||
),
|
||||
center_children=Box(
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
from .battery import BatteryLabel
|
||||
from .bluetooth import Bluetooth
|
||||
from .glace import TaskBar
|
||||
from .idle_indicator import IdleIndicator
|
||||
from .info import HardwareUsage
|
||||
from .microphone import MicrophoneIndicator
|
||||
from .network import Network
|
||||
from .powerprofile import PowerProfile
|
||||
from .taskbar import TaskBar
|
||||
from .volume import VolumeIndicator
|
||||
from .weather import Weather
|
||||
from .workspace import workspace
|
||||
|
||||
__all__ = [
|
||||
@@ -20,4 +21,5 @@ __all__ = [
|
||||
"TaskBar",
|
||||
"VolumeIndicator",
|
||||
"workspace",
|
||||
"Weather",
|
||||
]
|
||||
@@ -3,7 +3,7 @@ import psutil
|
||||
from fabric.utils import invoke_repeater
|
||||
from fabric.widgets.box import Box
|
||||
from fabric.widgets.label import Label
|
||||
from services import MaterialIcon
|
||||
from snippets import MaterialIcon
|
||||
|
||||
|
||||
class BatteryLabel(Box):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from fabric.bluetooth import BluetoothClient
|
||||
from fabric.widgets.box import Box
|
||||
from services import MaterialIcon # Import your MaterialIcon function
|
||||
from snippets import MaterialIcon # Import your MaterialIcon function
|
||||
|
||||
|
||||
class Bluetooth(Box):
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import gi
|
||||
from fabric.widgets.box import Box
|
||||
from fabric.widgets.button import Button
|
||||
from fabric.widgets.image import Image
|
||||
from fabric.widgets.wayland import WaylandWindow as Window
|
||||
from snippets import IconResolver
|
||||
|
||||
gi.require_version("Glace", "0.1")
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Glace, Gtk
|
||||
|
||||
|
||||
class TaskBar(Box):
|
||||
def __init__(self):
|
||||
self.client_buttons = {}
|
||||
super().__init__(spacing=10, name="taskbar")
|
||||
self.icon_resolver = IconResolver()
|
||||
self._manager = Glace.Manager()
|
||||
self._manager.connect("client-added", self.on_client_added)
|
||||
self._manager.connect(
|
||||
"client-removed", self.on_client_removed
|
||||
) # Listen for client removal
|
||||
|
||||
def on_client_added(self, _, client: Glace.Client):
|
||||
client_image = Image()
|
||||
client_button = Button(
|
||||
image=client_image,
|
||||
on_button_press_event=lambda *_: client.activate(),
|
||||
)
|
||||
self.client_buttons[client.get_id()] = client_button
|
||||
|
||||
client.connect(
|
||||
"notify::app-id",
|
||||
lambda *_: client_image.set_from_pixbuf(
|
||||
self.icon_resolver.get_icon_pixbuf(client.get_app_id(), 24)
|
||||
),
|
||||
)
|
||||
|
||||
client.connect(
|
||||
"notify::activated",
|
||||
lambda *_: (
|
||||
client_button.add_style_class("activated")
|
||||
if client.get_activated()
|
||||
else client_button.remove_style_class("activated")
|
||||
),
|
||||
)
|
||||
tooltip_image = Image(style="padding-bottom: 50px;")
|
||||
|
||||
popover = Window(type="popup", anchor="bottom", child=tooltip_image)
|
||||
|
||||
client_button.connect(
|
||||
"enter-notify-event", self.on_enter, client, tooltip_image, popover
|
||||
)
|
||||
client_button.connect("leave-notify-event", self.on_leave, popover)
|
||||
|
||||
# client.bind_property("title", client_button, "tooltip-text", 0)
|
||||
client.connect("close", lambda *_: self.remove(client_button))
|
||||
self.add(client_button)
|
||||
|
||||
# After adding a new client, ensure the taskbar is visible
|
||||
self._update_visibility()
|
||||
|
||||
def on_client_removed(self, _, client: Glace.Client):
|
||||
# Remove the button associated with the client
|
||||
client_button = self.client_buttons.pop(client.get_id(), None)
|
||||
if client_button:
|
||||
self.remove(client_button)
|
||||
|
||||
# After removing a client, ensure the taskbar visibility is updated
|
||||
self._update_visibility()
|
||||
|
||||
def on_enter(self, button: Button, event, client, tooltip_image, popover):
|
||||
x = event.x_root
|
||||
|
||||
def capture_callback(pbuf, user_data):
|
||||
tooltip_image.set_from_pixbuf(
|
||||
pbuf.scale_simple(pbuf.get_width() * 0.15, pbuf.get_height() * 0.15, 2)
|
||||
)
|
||||
tooltip_image.set_style(f"padding-bottom: 10px;")
|
||||
popover.show() if button.is_hovered() else None
|
||||
|
||||
self._manager.capture_client(
|
||||
client=client,
|
||||
overlay_cursor=False,
|
||||
callback=capture_callback,
|
||||
user_data=None,
|
||||
)
|
||||
|
||||
def on_leave(self, button, event, popover: Gtk.Popover):
|
||||
popover.hide()
|
||||
|
||||
def _update_visibility(self):
|
||||
# Check if there are any client buttons; if not, hide the taskbar
|
||||
if len(self.client_buttons) == 0:
|
||||
self.set_visible(False)
|
||||
else:
|
||||
self.set_visible(True)
|
||||
@@ -1,8 +1,7 @@
|
||||
from gi.repository import GLib
|
||||
|
||||
from fabric.utils import exec_shell_command
|
||||
from fabric.widgets.box import Box
|
||||
from services import MaterialIcon
|
||||
from gi.repository import GLib
|
||||
from snippets import MaterialIcon
|
||||
|
||||
|
||||
class IdleIndicator(Box):
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import psutil
|
||||
|
||||
from fabric.utils import invoke_repeater
|
||||
from fabric.widgets.box import Box
|
||||
from fabric.widgets.button import Button
|
||||
from fabric.widgets.circularprogressbar import CircularProgressBar
|
||||
from fabric.widgets.label import Label
|
||||
from fabric.widgets.overlay import Overlay
|
||||
from services import MaterialIcon
|
||||
from snippets import MaterialIcon
|
||||
|
||||
|
||||
class HardwareUsage(Button):
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from fabric.audio.service import Audio
|
||||
from fabric.widgets.box import Box
|
||||
from services import MaterialIcon
|
||||
from snippets import MaterialIcon
|
||||
|
||||
|
||||
class MicrophoneIndicator(Box):
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import subprocess
|
||||
|
||||
import psutil
|
||||
|
||||
from fabric.utils import invoke_repeater
|
||||
from fabric.widgets.box import Box
|
||||
from services import MaterialIcon
|
||||
from snippets import MaterialIcon
|
||||
|
||||
|
||||
class Network(Box):
|
||||
|
||||
@@ -1,149 +0,0 @@
|
||||
from fabric.utils import bulk_connect, exec_shell_command_async
|
||||
from fabric.widgets.box import Box
|
||||
from fabric.widgets.button import Button
|
||||
from fabric.widgets.eventbox import EventBox
|
||||
from fabric.widgets.label import Label
|
||||
from fabric.widgets.revealer import Revealer
|
||||
|
||||
|
||||
class PowerMenu(EventBox):
|
||||
def __init__(self):
|
||||
super().__init__(name="power-event")
|
||||
|
||||
icons_map = {
|
||||
"power-lock": "",
|
||||
"power-suspend": "",
|
||||
"power-logout": "",
|
||||
"power-reboot": "",
|
||||
"power-shutdown": "",
|
||||
}
|
||||
|
||||
self.buttons = {
|
||||
name: Button(name=name, child=Label(label=f"{icon}"))
|
||||
for name, icon in icons_map.items()
|
||||
}
|
||||
|
||||
self.power_box = Box(
|
||||
name="power-box",
|
||||
orientation="h",
|
||||
children=[
|
||||
self.buttons[name]
|
||||
for name in [
|
||||
"power-lock",
|
||||
"power-suspend",
|
||||
"power-logout",
|
||||
"power-reboot",
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
self.accept_button = Button(name="accept", child=Label(label="✔"))
|
||||
self.cancel_button = Button(name="cancel", child=Label(label="✘"))
|
||||
|
||||
self.revealer_buttons_box = Box(
|
||||
name="confirm-box",
|
||||
orientation="h",
|
||||
children=[self.accept_button, self.cancel_button],
|
||||
)
|
||||
|
||||
self.revealer = Revealer(
|
||||
name="power-revealer",
|
||||
transition_type="slide-right",
|
||||
transition_duration=300,
|
||||
child=self.power_box,
|
||||
reveal_child=False,
|
||||
)
|
||||
|
||||
self.shutdown_box = Box(
|
||||
name="shutdown-box",
|
||||
orientation="h",
|
||||
children=[self.buttons["power-shutdown"]],
|
||||
)
|
||||
|
||||
self.super_box = Box(
|
||||
name="super-box",
|
||||
orientation="h",
|
||||
children=[self.revealer, self.shutdown_box],
|
||||
)
|
||||
|
||||
self.confirm_revealer = Revealer(
|
||||
name="confirm-revealer",
|
||||
transition_type="slide-right",
|
||||
transition_duration=300,
|
||||
child=self.revealer_buttons_box,
|
||||
reveal_child=False,
|
||||
)
|
||||
|
||||
self.full_power = Box(
|
||||
name="full-power",
|
||||
orientation="h",
|
||||
children=[self.super_box, self.confirm_revealer],
|
||||
)
|
||||
|
||||
self.add(self.full_power)
|
||||
self.buttons["self"] = self
|
||||
self.current_command = None
|
||||
self.confirmation_active = False
|
||||
|
||||
for btn in self.buttons.values():
|
||||
bulk_connect(
|
||||
btn,
|
||||
{
|
||||
"button-press-event": self.on_button_press,
|
||||
"enter-notify-event": self.on_button_hover,
|
||||
"leave-notify-event": self.on_button_unhover,
|
||||
},
|
||||
)
|
||||
|
||||
self.accept_button.connect("button-press-event", self.on_accept_press)
|
||||
self.cancel_button.connect("button-press-event", self.on_cancel_press)
|
||||
|
||||
def on_button_hover(self, button, event):
|
||||
if button == self and not self.confirmation_active:
|
||||
self.revealer.set_reveal_child(True)
|
||||
|
||||
def on_button_unhover(self, button, event):
|
||||
if button == self and not self.confirmation_active:
|
||||
self.revealer.set_reveal_child(False)
|
||||
|
||||
def on_button_press(self, button, event):
|
||||
commands = {
|
||||
self.buttons["power-lock"]: "hyprlock",
|
||||
self.buttons[
|
||||
"power-suspend"
|
||||
]: "hyprctl dispatch exec hyprlock && systemctl suspend",
|
||||
self.buttons["power-logout"]: "hyprctl dispatch exit",
|
||||
self.buttons["power-reboot"]: "systemctl reboot",
|
||||
self.buttons["power-shutdown"]: "systemctl poweroff",
|
||||
}
|
||||
if button in commands:
|
||||
if button != self.buttons["power-lock"]:
|
||||
self.current_command = commands[button]
|
||||
self.revealer.set_reveal_child(False)
|
||||
self.confirm_revealer.set_reveal_child(True)
|
||||
self.shutdown_box.hide()
|
||||
self.confirmation_active = True
|
||||
|
||||
else:
|
||||
exec_shell_command_async(commands[button], lambda *_: None)
|
||||
return True
|
||||
|
||||
def on_accept_press(self, button, event):
|
||||
if self.current_command:
|
||||
exec_shell_command_async(self.current_command, lambda *_: None)
|
||||
self.current_command = None
|
||||
self.confirm_revealer.set_reveal_child(False)
|
||||
self.revealer.set_reveal_child(True)
|
||||
self.shutdown_box.show()
|
||||
self.confirmation_active = False
|
||||
|
||||
return True
|
||||
|
||||
def on_cancel_press(self, button, event):
|
||||
self.current_command = None
|
||||
self.confirm_revealer.set_reveal_child(False)
|
||||
self.revealer.set_reveal_child(True)
|
||||
self.shutdown_box.show()
|
||||
self.confirmation_active = False
|
||||
|
||||
return True
|
||||
@@ -1,6 +1,6 @@
|
||||
from fabric.utils import exec_shell_command, invoke_repeater
|
||||
from fabric.widgets.box import Box
|
||||
from services import MaterialIcon
|
||||
from snippets import MaterialIcon
|
||||
|
||||
PROFILE_ICONS = {
|
||||
"power-saver": "data_saver_on",
|
||||
|
||||
@@ -68,7 +68,7 @@ class TaskBar(Box):
|
||||
button = Button(image=icon, tooltip_text=client["title"])
|
||||
if client["address"] == active_window_address:
|
||||
button.set_style(
|
||||
"background-color: @surfaceVariant; border-radius:101px;"
|
||||
"background-color: @surfaceVariant; border-radius:100px;"
|
||||
)
|
||||
button.connect(
|
||||
"button-press-event", self.on_icon_click, client["address"]
|
||||
|
||||
@@ -2,7 +2,7 @@ from fabric.audio.service import Audio
|
||||
from fabric.utils import exec_shell_command, invoke_repeater
|
||||
from fabric.widgets.box import Box
|
||||
from fabric.widgets.button import Button
|
||||
from services import MaterialIcon
|
||||
from snippets import MaterialIcon
|
||||
|
||||
VOLUME_ICONS = {
|
||||
"muted": "volume_off",
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
from services import WeatherInfo
|
||||
|
||||
from fabric.utils import invoke_repeater
|
||||
from fabric.widgets.box import Box
|
||||
from fabric.widgets.label import Label
|
||||
|
||||
|
||||
class Weather(Box):
|
||||
def __init__(
|
||||
self,
|
||||
city: str,
|
||||
interval: int = 60000,
|
||||
enable_tooltip=True,
|
||||
):
|
||||
super().__init__(name="tray")
|
||||
self.enable_tooltip = enable_tooltip
|
||||
self.city = city
|
||||
|
||||
self.weather_service = WeatherInfo()
|
||||
|
||||
self.weather_label = Label(label="weather")
|
||||
self.children = self.weather_label
|
||||
|
||||
invoke_repeater(interval, self.update_label, initial_call=True)
|
||||
|
||||
def update_label(self):
|
||||
res = self.weather_service.simple_weather_info(city=self.city)
|
||||
self.weather_label.set_label(f"{res["icon"]} {res["temperature"]}")
|
||||
|
||||
if self.enable_tooltip:
|
||||
self.set_tooltip_text(f"{res["city"]}, {res["condition"]}".strip("'"))
|
||||
return True
|
||||
Reference in new issue
Block a user