-
Notifications
You must be signed in to change notification settings - Fork 5
/
__init__.py
374 lines (333 loc) · 18.1 KB
/
__init__.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
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
"""
Plasma User Control Mycroft Skill.
"""
import sys
import dbus
import psutil
import platform
import datetime
import subprocess
import argparse
from traceback import print_exc
from os.path import dirname
from adapt.intent import IntentBuilder
from mycroft.skills.core import MycroftSkill, intent_handler
from mycroft.util.log import getLogger
__author__ = 'aix'
LOGGER = getLogger(__name__)
class InternalsPlasmaDesktopSkill(MycroftSkill):
"""
Plasma User Control Skill Class.
"""
def __init__(self):
"""
Initialization
"""
super(InternalsPlasmaDesktopSkill, self).__init__(
name="InternalsPlasmaDesktopSkill")
@intent_handler(IntentBuilder("LockScreenIntent").
require("LockScreenKeyword").build())
def handle_internals_lock_plasma_skill_intent(self, message):
"""
Lock Screen
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.ksmserver","/ScreenSaver")
remote_object.Lock(dbus_interface = "org.freedesktop.ScreenSaver")
self.speak_dialog("internals.lock")
@intent_handler(IntentBuilder("SwitchUserKeywordIntent").
require("InternalSwitchUserKeyword").build())
def handle_internals_switchuser_plasma_skill_intent(self, message):
"""
Switch User
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.ksmserver","/KSMServer")
remote_object.openSwitchUserDialog(dbus_interface = "org.kde.KSMServerInterface")
self.speak_dialog("internals.switchuser")
@intent_handler(IntentBuilder("LogoutKeywordIntent").
require("InternalLogoutDesktopKeyword").build())
def handle_internals_logout_plasma_skill_intent(self, message):
"""
Log Out
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.ksmserver","/KSMServer")
remote_object.logout(1, 0, 0, dbus_interface = "org.kde.KSMServerInterface")
self.speak_dialog("internals.logout")
@intent_handler(IntentBuilder("IncreaseBrightnessKeywordIntent").
require("InternalIncreaseBrightnessDesktopKeyword").build())
def handle_internals_increasebrightness_plasma_skill_intent(self, message):
"""
Increase Brightness
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.freedesktop.PowerManagement","/org/kde/Solid/PowerManagement/Actions/BrightnessControl")
currentbrightness = remote_object.brightness(dbus_interface = "org.kde.Solid.PowerManagement.Actions.BrightnessControl")
if currentbrightness >=25 and currentbrightness < 1500:
currentbrightness += 50
remote_object.setBrightness(currentbrightness, dbus_interface = "org.kde.Solid.PowerManagement.Actions.BrightnessControl")
self.speak_dialog("internals.increasebrightness")
@intent_handler(IntentBuilder("DecreaseBrightnessKeywordIntent").
require("InternalDecreaseBrightnessDesktopKeyword").build())
def handle_internals_decreasebrightness_plasma_skill_intent(self, message):
"""
Decrease Brightness
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.freedesktop.PowerManagement","/org/kde/Solid/PowerManagement/Actions/BrightnessControl")
currentbrightness = remote_object.brightness(dbus_interface = "org.kde.Solid.PowerManagement.Actions.BrightnessControl")
if currentbrightness <=1500 and currentbrightness > 25:
currentbrightness -= 50
remote_object.setBrightness(currentbrightness, dbus_interface = "org.kde.Solid.PowerManagement.Actions.BrightnessControl")
self.speak_dialog("internals.decreasebrightness")
@intent_handler(IntentBuilder("MaximumBrightnessKeywordIntent").
require("InternalMaximumBrightnessDesktopKeyword").build())
def handle_internals_maximumbrightness_plasma_skill_intent(self, message):
"""
Maximum Brightness
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.freedesktop.PowerManagement","/org/kde/Solid/PowerManagement/Actions/BrightnessControl")
remote_object.setBrightness(1500, dbus_interface = "org.kde.Solid.PowerManagement.Actions.BrightnessControl")
self.speak_dialog("internals.maximumbrightness")
@intent_handler(IntentBuilder("MinimumBrightnessKeywordIntent").
require("InternalMinimumBrightnessDesktopKeyword").build())
def handle_internals_minimumbrightness_plasma_skill_intent(self, message):
"""
Minimum Brightness
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.freedesktop.PowerManagement","/org/kde/Solid/PowerManagement/Actions/BrightnessControl")
remote_object.setBrightness(25, dbus_interface = "org.kde.Solid.PowerManagement.Actions.BrightnessControl")
self.speak_dialog("internals.minimumbrightness")
@intent_handler(IntentBuilder("MoveMainPanelKeywordIntent").
require("InternalMoveMainPanelDesktopKeyword").build())
def handle_internals_movemainpanel_plasma_skill_intent(self, message):
"""
Move Main Panel
"""
utterance = message.data.get('utterance').lower()
utterance = utterance.replace(message.data.get('InternalMoveMainPanelDesktopKeyword'), '')
getloc = utterance.replace(" ", "")
location = getloc
if location == "bottom":
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmashell","/PlasmaShell")
remote_object.evaluateScript("var v = panelIds; panelById(v[0]).location = 'bottom';")
self.speak_dialog("internals.changeloc")
elif location == "top":
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmashell","/PlasmaShell")
remote_object.evaluateScript("var v = panelIds; panelById(v[0]).location = 'top';")
self.speak_dialog("internals.changeloc")
elif location == "left":
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmashell","/PlasmaShell")
remote_object.evaluateScript("var v = panelIds; panelById(v[0]).location = 'left';")
self.speak_dialog("internals.changeloc")
elif location == "right":
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmashell","/PlasmaShell")
remote_object.evaluateScript("var v = panelIds; panelById(v[0]).location = 'right';")
self.speak_dialog("internals.changeloc")
else:
self.speak_dialog("internals.badlocation")
@intent_handler(IntentBuilder("AddWigetToPanelKeywordIntent").
require("InternalAddWidgetToPanelDesktopKeyword").build())
def handle_internals_addwidget_plasmapanel_skill_intent(self, message):
"""
Add Widget To Panel
"""
utterance = message.data.get('utterance').lower()
utterance = utterance.replace(message.data.get('InternalAddWidgetToPanelDesktopKeyword'), '')
getwidname = utterance.replace(" ", "")
getwidname.encode('utf-8')
genJsc = 'var utter = "{0}"; var r = knownWidgetTypes; var wr = knownWidgetTypes; var readablelist = []; for(var ir = 0; ir < r.length; ir++){{ var n = r[ir].split(".").pop(); readablelist.push(n); }}; if (readablelist.indexOf(utter) !== -1){{ var utterancematch = utter; for (var lr=0; lr < r.length; lr++){{ if (wr[lr].match(utterancematch)) {{ var widgtName = (wr[lr]); var v = panelIds; panelById(v[0]).addWidget(widgtName); }}; }}; }} else {{ print ("Keyword not Found"); }}'.format(getwidname)
sendJsc = genJsc
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmashell","/PlasmaShell")
remote_object.evaluateScript(sendJsc)
self.speak_dialog("internals.widadded")
@intent_handler(IntentBuilder("AddWigetToDesktopKeywordIntent").
require("InternalAddWidgetToDesktopKeyword").build())
def handle_internals_addwidget_plasmadesktop_skill_intent(self, message):
"""
Add Wiget To Desktop
"""
utterance = message.data.get('utterance').lower()
utterance = utterance.replace(message.data.get('InternalAddWidgetToDesktopKeyword'), '')
getwidname = utterance.replace(" ", "")
getwidname.encode('utf-8')
genJsc = 'var utter = "{0}"; var r = knownWidgetTypes; var wr = knownWidgetTypes; var readablelist = []; for(var ir = 0; ir < r.length; ir++){{ var n = r[ir].split(".").pop(); readablelist.push(n); }}; if (readablelist.indexOf(utter) !== -1){{ var utterancematch = utter; for (var lr=0; lr < r.length; lr++){{ if (wr[lr].match(utterancematch)) {{ var widgtName = (wr[lr]); var mainDesktop = desktops(); var d = mainDesktop[0]; d.addWidget(widgtName); }}; }}; }} else {{ print ("Keyword not Found"); }}'.format(getwidname)
sendJsc = genJsc
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmashell","/PlasmaShell")
remote_object.evaluateScript(sendJsc)
self.speak_dialog("internals.widadded")
@intent_handler(IntentBuilder("ToogleTouchPadKeywordIntent").
require("InternalToogleTouchPadKeyword").build())
def handle_internals_toogletouchpad_plasmadesktop_skill_intent(self, message):
"""
Handle Touchpad
"""
utterance = message.data.get('utterance').lower()
utterance = utterance.replace(message.data.get('InternalToogleTouchPadKeyword'), '')
gettogglequery = utterance.replace(" ", "")
gettogglequery.encode('utf-8')
if (gettogglequery == "enable") or ( gettogglequery == "enabled"):
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmanetworkmanagement","/modules/touchpad")
remote_object.enable(dbus_interface = "org.kde.touchpad")
self.speak("Touchpad Enabled")
elif (gettogglequery == "disable") or (gettogglequery == "disabled"):
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmanetworkmanagement","/modules/touchpad")
remote_object.disable(dbus_interface = "org.kde.touchpad")
self.speak("Touchpad Disable")
else:
self.speak("Touchpad toggle not found, valid toggle's are: touchpad enable, touchpad disable")
@intent_handler(IntentBuilder("ShowKlipperKeywordIntent").
require("InternalToogleKlipperKeyword").build())
def handle_internals_toogleklipper_plasmadesktop_skill_intent(self, message):
"""
Show Klipper
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.klipper","/klipper")
remote_object.showKlipperPopupMenu(dbus_interface = "org.kde.klipper.klipper")
@intent_handler(IntentBuilder("ClearKlipperKeywordIntent").
require("InternalClearKlipperKeyword").build())
def handle_internals_clearklipper_plasmadesktop_skill_intent(self, message):
"""
Clear Klipper
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.klipper","/klipper")
remote_object.clearClipboardHistory(dbus_interface = "org.kde.klipper.klipper")
@intent_handler(IntentBuilder("NextDesktopKeywordIntent").
require("InternalNextDesktopKeyword").build())
def handle_internals_nextdesktop_plasmadesktop_skill_intent(self, message):
"""
Go To Next Virtual Desktop
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.KWin","/KWin")
remote_object.nextDesktop(dbus_interface = "org.kde.KWin")
@intent_handler(IntentBuilder("PreviousDesktopKeywordIntent").
require("InternalPreviousDesktopKeyword").build())
def handle_internals_previousdesktop_plasmadesktop_skill_intent(self, message):
"""
Go To Previous Virtual Desktop
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.KWin","/KWin")
remote_object.previousDesktop(dbus_interface = "org.kde.KWin")
@intent_handler(IntentBuilder("SuspendCompositingKeywordIntent").
require("InternalSuspendCompositingKeyword").build())
def handle_internals_suspendcompositing_plasmadesktop_skill_intent(self, message):
"""
Suspend Compositing
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.KWin","/Compositor")
remote_object.suspend(dbus_interface = "org.kde.kwin.Compositing")
@intent_handler(IntentBuilder("ResumeCompositingKeywordIntent").
require("InternalResumeCompositingKeyword").build())
def handle_internals_resumecompositing_plasmadesktop_skill_intent(self, message):
"""
Resume Compositing
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.KWin","/Compositor")
remote_object.resume(dbus_interface = "org.kde.kwin.Compositing")
@intent_handler(IntentBuilder("SystemSummaryKeywordIntent").
require("InternalSystemSummaryKeyword").build())
def handle_internals_systemsummary_plasmadesktop_skill_intent(self, message):
"""
Speak System Summary
"""
uname_info = platform.uname()
uname_os = uname_info[0]
uname_systemversion = uname_info[1]
uname_kernelversion = uname_info[2]
cores = psutil.cpu_count()
cpu_usage = psutil.cpu_percent()
memory_usage = psutil.virtual_memory()[2]
disk_usage = psutil.disk_usage('/')[3]
online_time = datetime.datetime.fromtimestamp(psutil.boot_time())
online_since = online_time.strftime("%A %d. %B %Y")
reply = "I am currently running on {0} version {1}. This system is named {2} and has {3} CPU cores. Current Disk utilization is {4} percent. Current CPU utilization is {5} percent. Current Memory utilization is {6} percent. System is online since {7}.".format(uname_os, uname_kernelversion, uname_systemversion, cores, disk_usage, cpu_usage, memory_usage, online_since)
self.speak(reply)
@intent_handler(IntentBuilder("AddPanelDesktopIntent").
require("InternalAddPanelKeyword").build())
def handle_addpaneldesktop_intent(self, message):
"""
Add New Panel
"""
utterance = message.data.get('utterance').lower()
utterance = utterance.replace(message.data.get('InternalAddPanelKeyword'), '')
getloc = utterance.replace(" ", "")
location = getloc
if location == "bottom":
bottomJsc = 'var plasma = getApiVersion(1); var bottompanel = new plasma.Panel; bottompanel.location = "bottom"; bottompanel.height = gridUnit * 2;'
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmashell","/PlasmaShell")
remote_object.evaluateScript(bottomJsc)
elif location == "top":
topJsc = 'var plasma = getApiVersion(1); var toppanel = new plasma.Panel; toppanel.location = "top"; toppanel.height = gridUnit * 2;'
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmashell","/PlasmaShell")
remote_object.evaluateScript(topJsc)
elif location == "left":
leftJsc = 'var plasma = getApiVersion(1); var leftpanel = new plasma.Panel; leftpanel.location = "left"; leftpanel.height = gridUnit * 2;'
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmashell","/PlasmaShell")
remote_object.evaluateScript(leftJsc)
elif location == "right":
rightJsc = 'var plasma = getApiVersion(1); var rightpanel = new plasma.Panel; rightpanel.location = "right"; rightpanel.height = gridUnit * 2;'
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.plasmashell","/PlasmaShell")
remote_object.evaluateScript(rightJsc)
else:
self.speak_dialog("internals.badlocation")
@intent_handler(IntentBuilder("InteractiveScreenshot").require("InternalScreenShotKeyword").build())
def handle_interactive_screenshot_intent(self, message):
"""
Interactive Screenshot
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.KWin","/Screenshot")
imgpath = remote_object.screenshotArea(0,0,1920,1080, dbus_interface = "org.kde.kwin.Screenshot")
@intent_handler(IntentBuilder("ImgRecogScreenshot").require("ImgRecogScreenShotKeyword").build())
def handle_imgrecogscreenshot_intent(self, message):
"""
Interactive Screenshot + Image Recoginition
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.KWin","/Screenshot")
imgpath = remote_object.screenshotArea(0,0,1920,1080, dbus_interface = "org.kde.kwin.Screenshot")
filepath = "file:\\\{0}".format(imgpath)
imageRecogCmd = "mycroft:\search image url {0}".format(filepath)
res = subprocess.call(("kioclient5", "cat", imageRecogCmd))
@intent_handler(IntentBuilder("ImgExtractScreenshot").require("ImgExtractScreenShotKeyword").build())
def handle_imgextractscreenshot_intent(self, message):
"""
Interactive Screenshot + Image Recoginition
"""
bus = dbus.SessionBus()
remote_object = bus.get_object("org.kde.KWin","/Screenshot")
imgpath = remote_object.screenshotArea(0,0,1920,1080, dbus_interface = "org.kde.kwin.Screenshot")
filepath = "file:\\\{0}".format(imgpath)
imageExtractCmd = "mycroft:\ocr image url {0}".format(filepath)
res = subprocess.call(("kioclient5", "cat", imageExtractCmd))
def stop(self):
"""
Mycroft Stop Function
"""
pass
def create_skill():
"""
Mycroft Create Skill Function
"""
return InternalsPlasmaDesktopSkill()