This repository has been archived by the owner on May 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
qoverview.py
executable file
·191 lines (145 loc) · 4.72 KB
/
qoverview.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
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
import os
import sys
import subprocess as sp
import dbus
import json
import uuid
from PyQt5.QtCore import QObject, QUrl, pyqtSlot
from PyQt5.QtGui import QGuiApplication, QWindow
from PyQt5.QtQuick import QQuickView
import wm
tmp_dir = os.path.join(os.environ.get('XDG_RUNTIME_DIR', '/tmp'), 'qoverview')
#ifdef KDEPLASMA
KDE_FRAMEWORKS = True
#else
KDE_FRAMEWORKS = False
#endif
class PythonQMLInterface(QObject):
def __init__(self, view):
self.view = view
super(PythonQMLInterface, self).__init__()
self.options = json.loads(config.get_config())
self.apps_list = json.loads(config.get_apps_list())
self.uid = str(uuid.uuid4())
@pyqtSlot(result=str)
def get_uuid(self):
return self.uid
@pyqtSlot(str)
def window_clicked(self, w_id):
print('Switching to window:', w_id)
self.view.hide()
wm.activate(w_id)
sys.exit()
@pyqtSlot(str)
def window_clicked_midbutton(self, w_id):
print('Closing window:', w_id)
wm.close(w_id)
@pyqtSlot(result=bool)
def is_midbutton_enabled(self):
return options.get('middle-mouse-close', True)
@pyqtSlot(str)
def app_clicked(self, app_item):
print('Opening app:', app_item)
self.view.hide()
config.desktop_entry_execute(config.desktop_entry_locate(app_item))
sys.exit()
@pyqtSlot()
def background_clicked(self):
print('Background clicked, exiting')
self.view.hide()
sys.exit()
@pyqtSlot(str, result=list)
def search(self, search_terms):
results = []
done = []
for entry in self.apps_list:
try:
if entry['Name'].lower().startswith(search_terms.lower()) and entry['Name'] not in done:
#ifdef KDEPLASMA
results.append([entry['Name'], entry['EntryName'], entry['Icon']])
#else
results.append([entry['Name'], entry['EntryName'], entry['IconPath']])
#endif
done.append(entry['Name'])
except KeyError:
pass
return sorted(results)
@pyqtSlot(result=list)
def get_background_overlay_color(self):
return self.options.get('background-color-overlay', [0, 0, 0, 0])
@pyqtSlot(result=str)
def get_background(self):
return config.get_background()
@pyqtSlot(result=list)
def get_dock_items(self):
dock_items_list = json.loads(config.get_dock_items())
results = []
for entry in self.apps_list:
if entry['EntryName'] in dock_items_list:
#ifdef KDEPLASMA
results.append([entry['Name'], entry['EntryName'], entry['Icon']])
#else
results.append([entry['Name'], entry['EntryName'], entry['IconPath']])
#endif
return results
@pyqtSlot(str, result=list)
def get_windows(self, workspace):
ids = wm.get_window_ids(int(workspace) - 1)
results = []
for index, w_id in enumerate(ids):
if wm.get_window_name(w_id) not in [self.uid, 'Desktop — Plasma']:
#ifdef KDEPLASMA
results.append([wm.get_window_name(w_id), w_id, int(w_id, 16)])
#else
results.append([wm.get_window_name(w_id), w_id,
wm.get_window_screenshot(str(int(w_id, 16)), str(int(w_id, 16)))])
#endif
return results
@pyqtSlot(result=list)
def get_workspaces(self):
return [str(x + 1) for x in range(wm.get_num_workspaces())]
@pyqtSlot(str)
def workspace_clicked(self, num):
print('Switching to workspace:', num)
wm.switch_workspace(int(num) - 1)
sp.Popen('python3 {}'.format(__file__), shell=True, preexec_fn=os.setpgrp)
sys.exit()
@pyqtSlot(str, str)
def dropped_on_workspace(self, workspace, w_id):
workspace = int(workspace) - 1 # workspaces are 0-indexed
wm.move_to_workspace(workspace, w_id)
print(w_id, 'moved to workspace', workspace)
@pyqtSlot(result=str)
def get_current_workspace(self):
return str(wm.get_current_workspace() + 1)
@pyqtSlot(result=bool)
def is_workspaces_enabled(self):
return self.options.get('workspaces-sidebar', True)
@pyqtSlot(result=bool)
def is_dock_enabled(self):
return bool(json.loads(config.get_dock_items()))
if __name__ == "__main__":
os.makedirs(tmp_dir, exist_ok=True)
try:
bus = dbus.SessionBus()
session = bus.get_object('org.qoverview.config', '/org/qoverview/config')
config = dbus.Interface(session, 'org.qoverview.config.iface')
except:
print('config-server is (probably) not running! (Unable to connect to it via DBUS)')
print('Start it and try again. The command is "qoverview-config-server"')
sys.exit(1)
print('KDE Frameworks:', 'Yes' if KDE_FRAMEWORKS else 'No')
app = QGuiApplication(sys.argv)
if os.path.exists('ui.qml'):
qmlview = QQuickView(QUrl('ui.qml'))
else:
qmlview = QQuickView(QUrl('/usr/lib/qoverview/ui.qml'))
qmlview.setResizeMode(qmlview.SizeRootObjectToView)
root = qmlview.rootObject()
context = qmlview.rootContext()
interface = PythonQMLInterface(view=qmlview)
context.setContextProperty('Python', interface)
qmlview.setTitle(interface.uid)
print(interface.uid)
qmlview.showFullScreen()
app.exec_()