-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabletShortcuts.py
executable file
·76 lines (51 loc) · 1.84 KB
/
tabletShortcuts.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtCore import QUrl, Qt
from PyQt5.QtDBus import QDBusConnection
from PyQt5.QtGui import QGuiApplication, QColor
from PyQt5.QtQuick import QQuickView
from subprocess import Popen, PIPE
import re
import shlex
from utils import MyDBUSServer
class TabletShortcuts(QGuiApplication):
def __init__(self, argv):
QGuiApplication.__init__(self, argv)
self.view = QQuickView()
self.bus = QDBusConnection.sessionBus()
self.server = MyDBUSServer(self)
self.bus.registerObject("/app", self.server)
self.bus.registerService("sevanteri.TabletShortcuts")
self.view.setTitle("TabletShortcuts")
self.view.setResizeMode(QQuickView.SizeRootObjectToView)
self.view.setSource(QUrl('main.qml'))
self.root = self.view.rootObject()
self.showView()
self.root.runCommand.connect(self.run)
self.root.hideView.connect(self.view.hide)
self.view.engine().quit.connect(self.quit)
def run(self, cmd):
return Popen(shlex.split(cmd))
def quit(self):
self.exit()
def showView(self):
if self.view.isVisible():
self.view.hide()
else:
# width, height = TabletShortcuts.getScreenGeometry()
# self.view.setGeometry(1, 1, width, height)
self.view.show()
def getScreenGeometry():
output = Popen("xrandr | grep 'current'", shell=True, stdout=PIPE)\
.communicate()[0].decode('UTF-8')
m = re.search('current.([0-9]+).x.([0-9]+)', output)
width = int(m.group(1))
height = int(m.group(2))
return (width, height)
def main():
# root.setAttribute(Qt.WA_ShowWithoutActivating)
app = TabletShortcuts(sys.argv)
sys.exit(app.exec_())
if __name__ == '__main__':
main()