-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-powermenu
executable file
·233 lines (192 loc) · 6.78 KB
/
simple-powermenu
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/usr/bin/env -S python
import os
import sys
import subprocess as sp
from ansible.parsing.utils.addresses import label
from qtpy.QtGui import *
from qtpy.QtWidgets import *
from qtpy.QtCore import *
import qdarkstyle
from pynput import keyboard
# Depends
# python-qdarkstyle python-pyqt5 python-pyinput i3lock-color
# Current version
current_version='0.1.5'
class QLabelClickable(QLabel):
clicked = Signal(str)
def __init__(self, parent=None):
super(QLabelClickable, self).__init__(parent)
def mousePressEvent(self, event):
self.ultimo = "Clic"
def mouseReleaseEvent(self, event):
if self.ultimo == "Clic":
QTimer.singleShot(QApplication.instance().doubleClickInterval(),
self.performSingleClickAction)
else:
# Realizar acción de doble clic.
self.clicked.emit(self.ultimo)
def mouseDoubleClickEvent(self, event):
self.ultimo = "Doble Clic"
def performSingleClickAction(self):
if self.ultimo == "Clic":
self.clicked.emit(self.ultimo)
# Listen for keyboard events
class keyboardWatch(QObject):
signal = Signal(str, name='keyPressed')
def __init__(self, parent=None):
super().__init__(parent)
listener = keyboard.Listener(on_press=self.on_press)
listener.start()
def on_press(self, key):
self.signal.emit(str(key))
class Version:
@staticmethod
def getAppName():
return 'Duckchannel Powermenu'
@staticmethod
def getVersion():
return current_version
class mainWindow(QMainWindow):
app = QApplication(sys.argv)
shutdownLabel = QLabelClickable()
rebootLabel = QLabelClickable()
screenlockLabel = QLabelClickable()
currentButtonIndex = 0
buttons = [
shutdownLabel,
rebootLabel,
screenlockLabel
]
defaultStyleSheet = """
QPushButton { background: transparent; }
"""
# keyboardthread
kbdWatch = keyboardWatch()
def __init__(self):
super().__init__(parent=None)
self.setWindowTitle(f'Xerolinux Rollback Utility v. {Version.getVersion()}')
# self.setFixedSize(QSize(640, 480))
############
# Hide Title Bar
self.setWindowFlag(Qt.FramelessWindowHint)
###################################################
# Horizontal Default Layout ###
horizontalLayout = QHBoxLayout()
horizontalLayout.setAlignment(Qt.AlignTop)
###
# Default Sizes and Styles
iconDefaultSize = QSize(96, 96)
#####
# Shutdown button
self.preparelabel('/usr/share/simple-powermenu-git/images/shutdown.png', self.shutdownLabel, horizontalLayout)
###
# Reboot button
self.preparelabel('/usr/share/simple-powermenu-git/images/reboot.png', self.rebootLabel, horizontalLayout)
###
# Screenlock button
self.preparelabel('/usr/share/simple-powermenu-git/images/lock.png', self.screenlockLabel, horizontalLayout)
#####
# Set the central widget of the Window.
centralWidget = QWidget()
centralWidget.setLayout(horizontalLayout)
self.setCentralWidget(centralWidget)
####
# Connecting signals
self.kbdWatch.signal.connect(self.keyPressed)
####
# Connecting events
self.shutdownLabel.enterEvent = self.shutdownMouseEnter
self.shutdownLabel.clicked.connect(self.shutdown)
self.rebootLabel.enterEvent = self.rebootMouseEnter
self.rebootLabel.clicked.connect(self.reboot)
self.screenlockLabel.enterEvent = self.screenlockMouseEnter
self.screenlockLabel.clicked.connect(self.screenlock)
# Hover the First button index
self.hoverButton()
############
# setup stylesheet
# the default system in qdarkstyle uses qtpy environment variable
self.app.setStyleSheet(qdarkstyle.load_stylesheet())
self.show()
self.centerMe()
###
sys.exit(self.app.exec())
def centerMe(self):
qtRectangle = self.frameGeometry()
centerPoint = QDesktopWidget().availableGeometry().center()
qtRectangle.moveCenter(centerPoint)
self.move(qtRectangle.topLeft())
def shutdownMouseEnter(self, event):
self.currentButtonIndex = 0
self.updateButtons()
def rebootMouseEnter(self, event):
self.currentButtonIndex = 1
self.updateButtons()
def screenlockMouseEnter(self, event):
self.currentButtonIndex = 2
self.updateButtons()
@staticmethod
def preparelabel(imageStr, qlabel, qhlayout):
tempPixmap = QPixmap(imageStr)
qlabel.setPixmap(tempPixmap.scaled(96, 96, Qt.KeepAspectRatio))
qlabel.setFixedSize(QSize(110, 110))
qlabel.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
qhlayout.addWidget(qlabel)
def keyPressed(self, keyCode):
if keyCode == 'Key.esc':
self.exitApp()
elif keyCode == 'Key.enter':
if self.currentButtonIndex == 0:
self.shutdown()
elif self.currentButtonIndex == 1:
self.reboot()
else:
self.screenlock()
elif keyCode == 'Key.tab':
if self.currentButtonIndex == 2:
self.currentButtonIndex = 0
else:
self.currentButtonIndex += 1
self.updateButtons()
elif keyCode == 'Key.right':
if self.currentButtonIndex == 2:
self.currentButtonIndex = 0
else:
self.currentButtonIndex += 1
self.updateButtons()
elif keyCode == 'Key.left':
if self.currentButtonIndex == 0:
self.currentButtonIndex = 2
else:
self.currentButtonIndex -= 1
self.updateButtons()
def hoverButton(self):
currentStyleSheet = """
border-radius: 5px;
border: 2px solid #00d7f0;
"""
self.buttons[self.currentButtonIndex].setFocus()
self.buttons[self.currentButtonIndex].setStyleSheet(currentStyleSheet)
def updateButtons(self):
for button in self.buttons:
button.setStyleSheet(self.defaultStyleSheet)
self.hoverButton()
@staticmethod
def shutdown():
print('shutdown')
sp.getoutput('poweroff')
@staticmethod
def reboot():
print('Reboot')
sp.getoutput('reboot')
def screenlock(self):
print('screenlock')
sp.getoutput('/usr/bin/simple-screenlock')
self.exitApp()
def exitApp(self):
self.app.quit()
sys.exit(0)
if __name__ == '__main__':
os.environ['QT_LOGGING_RULES'] = "qt5ct.debug=false"
os.environ['QT_API'] = 'pyqt5'
window = mainWindow()