This repository was archived by the owner on May 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
145 lines (114 loc) · 3.88 KB
/
Copy pathmain.py
File metadata and controls
145 lines (114 loc) · 3.88 KB
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
import sys
import signal
import pathlib
from PySide6 import QtCore, QtWidgets
from Xlib import display
from button import Button
from config import Config
from process import Process
# fix ctrl+c
signal.signal(signal.SIGINT, signal.SIG_DFL)
try: # temporary, needs to be fixed to use system themes
import qdarktheme
except ImportError:
qdarktheme = None
try:
config = Config()
except EnvironmentError as err:
print(err)
sys.exit(1)
sys.path.append(pathlib.Path(__file__).parent)
class MyWidget(QtWidgets.QWidget):
hidden = False
def __init__(self):
super().__init__()
self.setWindowFlags(
QtCore.Qt.Tool |
QtCore.Qt.WindowStaysOnTopHint |
QtCore.Qt.FramelessWindowHint |
QtCore.Qt.Window
)
self.menu = QtWidgets.QMenu("Menu", self)
self.setUpMenu()
self.mainLayout = QtWidgets.QVBoxLayout(self)
self.container = QtWidgets.QWidget(self)
self.mainLayout.addWidget(self.container)
self.layout = QtWidgets.QVBoxLayout(self.container)
self.timer = QtCore.QTimer()
self.timer.setSingleShot(True)
self.timer.timeout.connect(self.hide)
self.setupSpacing()
self.setButtons()
self.delayedHide()
self.setNetWMWindowFlags()
def setupSpacing(self):
self.mainLayout.setContentsMargins(
config.layoutSpacing, config.layoutSpacing,
config.layoutSpacing, config.layoutSpacing
)
self.layout.setContentsMargins(0, 0, 0, 0)
self.layout.setSpacing(config.layoutSpacing)
self.setMinimumSize(0, 0)
def setButtons(self):
for button in config.launchers:
self.layout.addWidget(
Button(
config.iconSize,
button.get('icon'),
button.get('cmd'),
button.get('name')
)
)
def delayedHide(self):
self.timer.setInterval(config.hideTimeoutMsec)
self.timer.start()
def leaveEvent(self, event):
self.delayedHide()
super().leaveEvent(event)
def enterEvent(self, event):
self.timer.stop()
super().enterEvent(event)
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.MouseButton.LeftButton:
if self.hidden:
self.restore()
elif event.button() == QtCore.Qt.MouseButton.RightButton:
self.showMenu(event)
super().mousePressEvent(event)
def setUpMenu(self):
self.menu.addAction("Edit config", self.openEditor)
self.menu.addAction("Quit", app.quit)
def openEditor(self):
process = Process()
process.startDetached(f'/usr/bin/xdg-open {config.configLocation}')
def showMenu(self, event):
self.menu.exec(event.globalPosition().toPoint())
def hide(self):
self.container.hide()
self.setFixedSize(config.hiddenWidth, HEIGHT)
self.repaint()
self.hidden = True
def restore(self):
self.container.show()
self.setFixedSize(WIDTH, HEIGHT)
self.hidden = False
def setNetWMWindowFlags(self):
d = display.Display()
win = d.create_resource_object('window', self.window().winId())
_ATOM = d.intern_atom("ATOM")
_TYPE = d.intern_atom("_NET_WM_WINDOW_TYPE")
_DOCK = d.intern_atom("_NET_WM_WINDOW_TYPE_DOCK")
win.change_property(_TYPE, _ATOM, 32, [_DOCK])
d.flush()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
if qdarktheme:
app.setStyleSheet(qdarktheme.load_stylesheet())
screen = app.primaryScreen()
widget = MyWidget()
widget.show()
HEIGHT = widget.height()
WIDTH = widget.width()
pos = (screen.size().height() / 2) - (HEIGHT / 2)
widget.setGeometry(0, pos, WIDTH, HEIGHT)
sys.exit(app.exec())