-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path__init__.py
201 lines (183 loc) · 6.99 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
"""
Plasma Activities Mycroft Skill.
"""
import sys
import dbus
import re
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 ActivitiesPlasmaDesktopSkill(MycroftSkill):
"""
Activities Skill Class.
"""
def __init__(self):
"""
Initialization
"""
super(
ActivitiesPlasmaDesktopSkill,
self).__init__(
name="ActivitiesPlasmaDesktopSkill")
@intent_handler(IntentBuilder("ActivitiesKeywordIntent").require("ActivitiesCreateKeyword").build())
def handle_activities_create_plasma_skill_intent(self, message):
"""
Create Activities
"""
utterance = message.data.get('utterance').lower()
utterance = utterance.replace(
message.data.get('ActivitiesCreateKeyword'), '')
searchString = utterance
speakword = searchString.lstrip(' ')
bus = dbus.SessionBus()
remote_object = bus.get_object(
"org.kde.ActivityManager",
"/ActivityManager/Activities")
remote_object.AddActivity(
speakword,
dbus_interface="org.kde.ActivityManager.Activities")
remote_object2 = bus.get_object("org.kde.plasmashell", "/PlasmaShell")
remote_object2.toggleActivityManager(
dbus_interface="org.kde.PlasmaShell")
speakdlg = "New Activity {0} Has Been Created".format(speakword)
self.speak(speakdlg)
@intent_handler(IntentBuilder("ShowActivitiesIntent").require("ActivitiesShowKeyword").build())
def handle_activities_show_plasma_skill_intent(self, message):
"""
Show Activities
"""
bus = dbus.SessionBus()
remote_object2 = bus.get_object("org.kde.plasmashell", "/PlasmaShell")
remote_object2.toggleActivityManager(dbus_interface="org.kde.PlasmaShell")
@intent_handler(IntentBuilder("RemoveActivitiesIntent").require("ActivitiesRemoveKeyword").build())
def handle_activities_remove_plasma_skill_intent(self, message):
"""
Remove Activities
"""
utterance = message.data.get('utterance').lower()
utterance = utterance.replace(
message.data.get('ActivitiesRemoveKeyword'), '')
searchString = utterance.lower()
speakword = searchString.lstrip(' ')
actinfo = []
bus = dbus.SessionBus()
remote_object = bus.get_object(
"org.kde.ActivityManager",
"/ActivityManager/Activities")
callback = remote_object.ListActivitiesWithInformation(
dbus_interface="org.kde.ActivityManager.Activities")
spkdlg = "Activity {0} has been removed".format(speakword)
self.speak(spkdlg)
for i in range(len(callback)):
temp_callback = list(map(str, callback[i]))
actinfo.append(temp_callback)
actenum = actinfo[i][1]
actgetid = actenum.lower()
if(actgetid == speakword):
actid = actinfo[i][0]
self.removeactivity(actid)
def removeactivity(self, activitieslist):
"""
Remove Activities SubFunc
"""
activityaddr = activitieslist
bus = dbus.SessionBus()
remote_object = bus.get_object(
"org.kde.ActivityManager",
"/ActivityManager/Activities")
remote_object.RemoveActivity(
activityaddr,
dbus_interface="org.kde.ActivityManager.Activities")
@intent_handler(IntentBuilder("StopActivitiesIntent").require("ActivitiesStopKeyword").build())
def handle_activities_stop_plasma_skill_intent(self, message):
"""
Stop Activities
"""
utterance = message.data.get('utterance').lower()
utterance = utterance.replace(
message.data.get('ActivitiesStopKeyword'), '')
searchString = utterance.lower()
speakword = searchString.lstrip(' ')
actinfo = []
bus = dbus.SessionBus()
remote_object = bus.get_object(
"org.kde.ActivityManager",
"/ActivityManager/Activities")
callback = remote_object.ListActivitiesWithInformation(
dbus_interface="org.kde.ActivityManager.Activities")
spkdlg = "Activity {0} has been stopped".format(speakword)
self.speak(spkdlg)
for i in range(len(callback)):
temp_callback = list(map(str, callback[i]))
actinfo.append(temp_callback)
actenum = actinfo[i][1]
actgetid = actenum.lower()
if(actgetid == speakword):
actid = actinfo[i][0]
self.stopactivity(actid)
def stopactivity(self, activitieslist):
"""
Stop Activities SubFunc
"""
activityaddr = activitieslist
bus = dbus.SessionBus()
remote_object = bus.get_object(
"org.kde.ActivityManager",
"/ActivityManager/Activities")
remote_object.StopActivity(
activityaddr,
dbus_interface="org.kde.ActivityManager.Activities")
@intent_handler(IntentBuilder("SwitchActivitiesIntent").require("ActivitiesSwitchKeyword").build())
def handle_activities_switch_plasma_skill_intent(self, message):
"""
Switch Activities
"""
utterance = message.data.get('utterance').lower()
utterance = utterance.replace(
message.data.get('ActivitiesSwitchKeyword'), '')
searchString = utterance.lower()
speakword = searchString.lstrip(' ')
actinfo = []
bus = dbus.SessionBus()
remote_object = bus.get_object(
"org.kde.ActivityManager",
"/ActivityManager/Activities")
callback = remote_object.ListActivitiesWithInformation(
dbus_interface="org.kde.ActivityManager.Activities")
self.speak_dialog(
"activities.switch",
data={'SwitchActivityName': speakword})
for i in range(len(callback)):
temp_callback = list(map(str, callback[i]))
actinfo.append(temp_callback)
actenum = actinfo[i][1]
actgetid = actenum.lower()
if(actgetid == speakword):
actid = actinfo[i][0]
self.switchtoactivity(actid)
def switchtoactivity(self, activitieslist):
"""
Switch Activities SubFunc
"""
activityaddr = activitieslist
bus = dbus.SessionBus()
remote_object = bus.get_object(
"org.kde.ActivityManager",
"/ActivityManager/Activities")
remote_object.SetCurrentActivity(
activityaddr,
dbus_interface="org.kde.ActivityManager.Activities")
def stop(self):
"""
Mycroft Stop Function
"""
pass
def create_skill():
"""
Mycroft Create Skill Function
"""
return ActivitiesPlasmaDesktopSkill()