-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanel.py
156 lines (127 loc) · 6.16 KB
/
panel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import subprocess
import sys
from datetime import datetime
import os
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Pango', '1.0')
from gi.repository import Pango
from gi.repository import Gtk, Gdk, GLib, GdkPixbuf
class Panel(Gtk.Window):
def __init__(self):
super().__init__(title="Panel")
self.load_css()
# Get screen size using the new algorithm
display = Gdk.Display.get_default()
monitor = display.get_primary_monitor()
scale_factor = monitor.get_scale_factor()
geometry = monitor.get_geometry()
self.width = geometry.width * scale_factor
self.height = 50
self.set_default_size(self.width, self.height)
# Calculate y-position based on screen height
y_position = geometry.height * scale_factor - self.height
self.move(0, y_position)
# Necessary settings for the panel to function correctly
self.set_type_hint(Gdk.WindowTypeHint.DOCK)
self.set_decorated(False)
self.set_app_paintable(True)
self.set_accept_focus(False)
self.set_keep_above(True) # Ensure panel stays on top
self.fixed = Gtk.Fixed()
self.add(self.fixed)
#self.image = Gtk.Image.new_from_pixbuf(GdkPixbuf.Pixbuf.new_from_file("assets/taskbar9x.png"))
self.image = Gtk.Image.new_from_pixbuf(GdkPixbuf.Pixbuf.new_from_file("/home/anon/.comfy/panel.png"))
self.fixed.put(self.image, 0, 0)
# Create a button with an icon
self.start_menu_button = Gtk.Button()
self.start_menu_button.connect("clicked", self.on_start_menu_clicked)
self.fixed.put(self.start_menu_button, 2, 1) # Button location
self.start_menu_button.set_size_request(0, 40) # Fixed height for the button
# Load the clover icon
clover_icon = Gtk.Image.new_from_file("assets/clover.png")
self.start_menu_button.set_image(clover_icon)
self.clock_button = Gtk.Button(label="")
self.clock_button.set_size_request(100, 40) # Fixed height for the button
self.clock_button.connect("clicked", self.on_clock_clicked)
self.fixed.put(self.clock_button, self.width - 103, 1)
GLib.timeout_add_seconds(1, self.update_clock)
# Task List
self.tasklist_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
self.fixed.put(self.tasklist_box, 72, 1)
self.update_tasklist()
GLib.timeout_add_seconds(1, self.update_tasklist) # Refresh every second
self.menu_process = None
self.show_all()
self.update_clock()
# Run blur.sh when the panel is shown
subprocess.Popen(["./blur.sh"], shell=True) # Replace with the actual path to blur.sh
def load_css(self):
style_provider = Gtk.CssProvider()
style_provider.load_from_path("style.css")
Gtk.StyleContext.add_provider_for_screen(Gdk.Screen.get_default(), style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
def on_start_menu_clicked(self, widget):
if self.menu_process is None:
self.menu_process = subprocess.Popen(["sh", "build.sh"])
self.menu_process = subprocess.Popen(["build/menu"])
#self.menu_process = subprocess.Popen([sys.executable, "menu.py"])
else:
self.menu_process.terminate()
self.menu_process.wait()
self.menu_process = None
def on_clock_clicked(self, widget):
print(f"Current time is: {self.clock_button.get_label()}")
def update_clock(self):
now = datetime.now()
formatted_time = now.strftime("%H:%M")
self.clock_button.set_label(formatted_time)
return True
def update_tasklist(self):
# Clear the current task list
for child in self.tasklist_box.get_children():
self.tasklist_box.remove(child)
# Get the list of running processes
try:
# Sample command that lists running GUI applications
proc = subprocess.Popen(['wmctrl', '-l'], stdout=subprocess.PIPE)
output = proc.communicate()[0].decode('utf-8')
for line in output.splitlines():
parts = line.split()
if len(parts) > 3:
title = " ".join(parts[3:])
# Skip "Panel" and "Desktop" titles
if "Panel" in title or "Desktop" in title or "Whisker Menu" in title or "Find" in title or "Open" in title or "xfce4-panel" in title:
continue
# Create a button with left-aligned text
button_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
button_box.set_halign(Gtk.Align.START) # Align to the left
# Create an icon image
icon_image = Gtk.Image.new_from_file("assets/clover.png")
button_box.pack_start(icon_image, False, False, 0)
# Create a label for the button
label = Gtk.Label(label=title)
label.set_ellipsize(Pango.EllipsizeMode.END) # Ellipsize long titles
# Set a fixed width of 150px for the button
label.set_size_request(100, -1)
button_box.pack_start(label, True, True, 0)
# Create the button with the label
button = Gtk.Button()
button.add(button_box)
button.connect("clicked", self.on_task_clicked, parts[0]) # Pass window ID
button.set_size_request(100, 40) # Set max width to 100px and fixed height
# Add the button to the task list box
self.tasklist_box.pack_start(button, True, True, 0)
except Exception as e:
print("Error retrieving tasklist:", e)
self.show_all()
return True
def on_task_clicked(self, widget, window_id):
# Use wmctrl to activate a window using its ID
subprocess.call(['wmctrl', '-ia', window_id])
def main():
window = Panel()
window.connect("destroy", Gtk.main_quit)
window.show_all()
Gtk.main()
if __name__ == "__main__":
main()