-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
98 lines (75 loc) · 2.72 KB
/
Copy pathmain.py
File metadata and controls
98 lines (75 loc) · 2.72 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
import sys
import os
import subprocess
import shlex
from PyQt5.QtCore import QObject, pyqtSlot
from PyQt5.QtGui import QGuiApplication, QIcon
from PyQt5.QtQml import QQmlApplicationEngine
if not os.path.exists("/tmp/azura-desktop-area-icon-previews"):
print('"/tmp/azura-desktop-area-icon-previews" Created ( Required for Icon Previews )')
os.makedirs("/tmp/azura-desktop-area-icon-previews", exist_ok=True)
app = QGuiApplication(sys.argv)
# ~/Desktop
def fetch_desktop():
desktop_path = os.path.expanduser('~/Desktop')
if not os.path.exists(desktop_path):
return []
icons = []
for filename in os.listdir(desktop_path):
file_path = os.path.join(desktop_path, filename)
# filter out .desktop specfically
if filename.endswith('.desktop'):
with open(file_path, 'r') as f:
content = f.readlines()
name = None
icon = None
for line in content:
if line.startswith('Name='):
name = line.strip().split('=')[1]
elif line.startswith('Icon='):
icon = line.strip().split('=')[1]
if name:
# it's time i cook up some dodgy black magic for theme matching icons :sob:
pixmap = QIcon.fromTheme(icon, QIcon("assets/config.svg")).pixmap(64, 64)
pixmap.save("/tmp/azura-desktop-area-icon-previews/" + icon + ".png")
# pixmap.save("/tmp/azura-desktop-area-icon-previews/" + icon + ".jpg")
pixmap.save("/tmp/azura-desktop-area-icon-previews/" + icon + ".svg")
# fallback icon
icon_path = icon if icon else "/usr/share/icons/hicolor/128x128/apps/default-icon.png"
icons.append({
"name": name,
"type": "app",
# "src": "file://" + icon_path,
# "src": QIcon.fromTheme(icon_path, QIcon("assets/config.svg")),
"icon": "/tmp/azura-desktop-area-icon-previews/" + icon_path,
"path": file_path
})
else:
icons.append({
"name": filename,
"type": "unknown",
"icon": "assets/config.svg",
"icon": file_path
})
return icons
print(fetch_desktop())
class Launcher(QObject):
@pyqtSlot(str, str) # (command, type) parametersss yeaaa
def launch_item(self, command, type=""):
# for placeholder in ["%U", "%F", "%i", "%c", "%k"]: # weird stuff in .desktop files, i should probably learn them-
# command = command.replace(placeholder, "")
# print(command)
# args = shlex.split(command)
# subprocess.Popen(args, start_new_session=True)
subprocess.Popen(["dex", command], start_new_session=True)
print(command)
engine = QQmlApplicationEngine()
engine.quit.connect(app.quit)
model = fetch_desktop()
launcher = Launcher()
engine.rootContext().setContextProperty("launcher", launcher)
engine.rootContext().setContextProperty("apps", model)
engine.load('main.qml')
root = engine.rootObjects()[0]
# root.setProperty("launcher", launcher)
sys.exit(app.exec())