-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathpower.py
111 lines (95 loc) · 3.06 KB
/
power.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
from fabric.widgets.box import Box
from fabric.widgets.label import Label
from fabric.widgets.button import Button
from fabric.utils.helpers import exec_shell_command_async
import modules.icons as icons
class PowerMenu(Box):
def __init__(self, **kwargs):
super().__init__(
name="power-menu",
orientation="h",
spacing=4,
v_align="center",
h_align="center",
visible=True,
**kwargs,
)
self.notch = kwargs["notch"]
self.btn_lock = Button(
name="power-menu-button",
child=Label(name="button-label", markup=icons.lock),
on_clicked=self.lock,
h_expand=False,
v_expand=False,
h_align="center",
v_align="center",
)
self.btn_suspend = Button(
name="power-menu-button",
child=Label(name="button-label", markup=icons.suspend),
on_clicked=self.suspend,
h_expand=False,
v_expand=False,
h_align="center",
v_align="center",
)
self.btn_logout = Button(
name="power-menu-button",
child=Label(name="button-label", markup=icons.logout),
on_clicked=self.logout,
h_expand=False,
v_expand=False,
h_align="center",
v_align="center",
)
self.btn_reboot = Button(
name="power-menu-button",
child=Label(name="button-label", markup=icons.reboot),
on_clicked=self.reboot,
h_expand=False,
v_expand=False,
h_align="center",
v_align="center",
)
self.btn_shutdown = Button(
name="power-menu-button",
child=Label(name="button-label", markup=icons.shutdown),
on_clicked=self.poweroff,
h_expand=False,
v_expand=False,
h_align="center",
v_align="center",
)
self.buttons = [
self.btn_lock,
self.btn_suspend,
self.btn_logout,
self.btn_reboot,
self.btn_shutdown,
]
for button in self.buttons:
self.add(button)
self.show_all()
def close_menu(self):
self.notch.close_notch()
# Métodos de acción
def lock(self, *args):
print("Locking screen...")
exec_shell_command_async("loginctl lock-session")
self.close_menu()
def suspend(self, *args):
print("Suspending system...")
exec_shell_command_async("systemctl suspend")
self.close_menu()
def logout(self, *args):
print("Logging out...")
exec_shell_command_async("hyprctl dispatch exit")
self.close_menu()
def reboot(self, *args):
print("Rebooting system...")
exec_shell_command_async("systemctl reboot")
self.close_menu()
def poweroff(self, *args):
print("Powering off...")
exec_shell_command_async("systemctl poweroff")
self.close_menu()