本文整理汇总了Python中siriObjects.uiObjects.UIAddViews类的典型用法代码示例。如果您正苦于以下问题:Python UIAddViews类的具体用法?Python UIAddViews怎么用?Python UIAddViews使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UIAddViews类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list_music
def list_music(self, speech, langauge, matchedRegex):
found, lst = 0, UIDisambiguationList()
lst.items = []
anchor = UIAddViews(self.refId)
anchor.dialogPhase = anchor.DialogPhaseCompletionValue
stripped_artistname = ''.join(ch for ch in matchedRegex.group('artistname') if ch.isalnum()).lower()
if stripped_artistname == 'latest':
result = json.AudioLibrary.GetRecentlyAddedAlbums(properties=['artist'], limits={'end': 10})
for album in result['albums']:
lst.items.append(CreateListItem(album['albumid'], 'album'))
anchor.views = [lst]
self.say("", "Last 10 albums added...")
self.sendRequestWithoutAnswer(anchor)
else:
result = json.AudioLibrary.GetAlbums(properties=['artist'])
for album in result['albums']:
if stripped_artistname in ''.join(ch for ch in album['artist'] if ch.isalnum()).lower():
lst.items.append(CreateListItem(album['albumid'], 'album'))
found = 1
if found == 0:
self.say("Sorry, I couldn't find the artist you're looking for")
else:
anchor.views = [lst]
self.say("", "Albums for '%s'" %(string.capwords(matchedRegex.group('artistname'))))
self.sendRequestWithoutAnswer(anchor)
self.complete_request()
示例2: CreateAnswerObject
def CreateAnswerObject(self, id, mtype):
if mtype == 'movie':
y = json.VideoLibrary.GetMovieDetails(movieid=id, properties=['thumbnail', 'plot'])['moviedetails']
print 'http://%s:%s/vfs/%s' %(GetLogin()[0], GetLogin()[1], urllib.urlencode({'': y['thumbnail']})[1:])
m = ['http://%s:%s/vfs/%s' %(GetLogin()[0], GetLogin()[1], urllib.urlencode({'': y['thumbnail']})[1:]), y['label'], y['plot']]
AnswerTitle, AnswerThumb, AnswerPlot = AnswerObject(title='Title',lines=[AnswerObjectLine(text=m[1])]), AnswerObject(title='Thumbnail',lines=[AnswerObjectLine(image=m[0])]), AnswerObject(title='Plot',lines=[AnswerObjectLine(text="'%s'" %(m[2]))])
view1 = AnswerSnippet(answers=[AnswerTitle, AnswerThumb, AnswerPlot])
if mtype == 'tvshow':
y = json.VideoLibrary.GetEpisodeDetails(episodeid=id, properties=['thumbnail', 'plot', 'showtitle', 'season', 'episode'])['episodedetails']
m = ['http://%s:%s/vfs/%s' %(GetLogin()[0], GetLogin()[1], urllib.urlencode({'': y['thumbnail']})[1:]), y['label'], y['plot'], y['showtitle'], y['season'], y['episode']]
AnswerShowtitle, AnswerEpisode, AnswerThumb, AnswerPlot = AnswerObject(title='Show',lines=[AnswerObjectLine(text=m[3])]), AnswerObject(title='Episode',lines=[AnswerObjectLine(text="%ix%i. %s" %(m[4], m[5], m[1]))]), AnswerObject(title='Thumbnail',lines=[AnswerObjectLine(image="%s"%(m[0]))]), AnswerObject(title='Plot', lines=[AnswerObjectLine(text="'%s'" %(m[2]))])
view1 = AnswerSnippet(answers=[AnswerShowtitle, AnswerEpisode, AnswerThumb, AnswerPlot])
if mtype == 'album':
y = json.AudioLibrary.GetAlbumDetails(albumid=id, properties=['thumbnail', 'year', 'artist', 'title', 'description'])['albumdetails']
m = ['http://%s:%s/vfs/%s' %(GetLogin()[0], GetLogin()[1], urllib.urlencode({'': y['thumbnail']})[1:]), y['title'], y['artist'], y['year'], y['description']]
print m[0]
AnswerTitle, AnswerThumb, AnswerInfo, AnswerArtist = AnswerObject(title='Album',lines=[AnswerObjectLine(text="%s (%s)" %(m[1], m[3]))]), AnswerObject(title='Art',lines=[AnswerObjectLine(image=m[0])]), AnswerObject(title='Description',lines=[AnswerObjectLine(text=m[4])]), AnswerObject(title='Artist', lines=[AnswerObjectLine(text=m[2])])
view1 = AnswerSnippet(answers=[AnswerTitle, AnswerArtist, AnswerThumb, AnswerInfo])
view = UIAddViews(self.refId)
view.views = [view1]
return view
示例3: play
def play(self, results, language):
collection = MPTitleCollection()
collection.items = []
for result in results:
if not hasattr(result, "genre"):
result.genre = ""
if not hasattr(result, "trackNumber"):
result.trackNumber = ""
if not hasattr(result, "artist"):
result.artist = ""
if not hasattr(result, "title"):
result.title = ""
if not hasattr(result, "sortTitle"):
result.sortTitle = ""
if not hasattr(result, "playCount"):
result.playCount = ""
if not hasattr(result, "rating"):
result.rating = ""
if not hasattr(result, "album"):
result.album = ""
if not hasattr(result, "identifier"):
result.identifier = ""
song = MPSong()
song.album = result.album
song.artist = result.artist
song.genre = result.genre
song.playCount = result.playCount
song.rating = result.rating
song.sortTitle = result.sortTitle
song.title = result.title
song.trackNumber = result.trackNumber
song.identifier = result.identifier
collection.items.append(song)
collection.sortTitle = result.title
collection.title = result.sortTitle
collection.identifier = result.identifier
complete = MPSetQueue(self.refId)
complete.mediaItems = collection
self.getResponseForRequest(complete)
commands = MPSetState(self.refId)
commands.state = "Playing"
commands2 = MPEnableShuffle(self.refId)
commands2.enable = False
code = 0
root = UIAddViews(self.refId)
root.dialogPhase = "Summary"
assistant = UIAssistantUtteranceView()
assistant.dialogIdentifier = "PlayMedia#nowPlayingMediaItemByTitle"
assistant.speakableText = assistant.text = res["play"][language]
root.views = [(assistant)]
root.callbacks = [ResultCallback([commands, commands2], code)]
callback = [ResultCallback([root], code)]
self.send_object(RequestCompleted(self.refId, callback))
self.complete_request()
示例4: process_recognized_speech
def process_recognized_speech(self, googleJson, requestId, dictation):
possible_matches = googleJson['hypotheses']
if len(possible_matches) > 0:
best_match = possible_matches[0]['utterance']
if len(best_match) == 1:
best_match = best_match.upper()
else:
best_match = best_match[0].upper() + best_match[1:]
best_match_confidence = possible_matches[0]['confidence']
self.logger.info(u"Best matching result: \"{0}\" with a confidence of {1}%".format(best_match, round(float(best_match_confidence) * 100, 2)))
# construct a SpeechRecognized
token = Token(best_match, 0, 0, 1000.0, True, True)
interpretation = Interpretation([token])
phrase = Phrase(lowConfidence=False, interpretations=[interpretation])
recognition = Recognition([phrase])
recognized = SpeechRecognized(requestId, recognition)
if not dictation:
if self.current_running_plugin == None:
plugin = PluginManager.getPluginForImmediateExecution(self.assistant.assistantId, best_match, self.assistant.language, (self.send_object, self.send_plist, self.assistant, self.current_location))
if plugin != None:
plugin.refId = requestId
plugin.connection = self
self.current_running_plugin = plugin
self.send_object(recognized)
self.current_running_plugin.start()
else:
self.send_object(recognized)
view = UIAddViews(requestId)
errorText = SiriProtocolHandler.__not_recognized[self.assistant.language] if self.assistant.language in SiriProtocolHandler.__not_recognized else SiriProtocolHandler.__not_recognized["en-US"]
errorView = UIAssistantUtteranceView()
errorView.text = errorText.format(best_match)
errorView.speakableText = errorText.format(best_match)
view.views = [errorView]
websearchText = SiriProtocolHandler.__websearch[self.assistant.language] if self.assistant.language in SiriProtocolHandler.__websearch else SiriProtocolHandler.__websearch["en-US"]
button = UIButton()
button.text = websearchText
cmd = SendCommands()
cmd.commands = [StartRequest(utterance=u"^webSearchQuery^=^{0}^^webSearchConfirmation^=^Yes^".format(best_match))]
button.commands = [cmd]
view.views.append(button)
self.send_object(view)
self.send_object(RequestCompleted(requestId))
elif self.current_running_plugin.waitForResponse != None:
# do we need to send a speech recognized here? i.d.k
self.current_running_plugin.response = best_match
self.current_running_plugin.refId = requestId
self.current_running_plugin.waitForResponse.set()
else:
self.send_object(recognized)
self.send_object(RequestCompleted(requestId))
else:
self.send_object(recognized)
self.send_object(RequestCompleted(requestId))
示例5: listlatestmovies
def listlatestmovies(self, speech, langauge):
lst = UIDisambiguationList()
lst.items = []
x = UIAddViews(self.refId)
x.dialogPhase = x.DialogPhaseCompletionValue
result = json.VideoLibrary.GetRecentlyAddedMovies(limits={'end': 10})
for movie in result['movies']:
lst.items.append(CreateListItem(movie['movieid'], 'movie'))
x.views = [lst]
self.say("", "Last 10 movies added...")
self.sendRequestWithoutAnswer(x)
self.complete_request()
示例6: pause
def pause(self, language):
commands = MPSetState(self.refId)
commands.state = "Paused"
code = 0
root = UIAddViews(self.refId)
root.dialogPhase = "Summary"
assistant = UIAssistantUtteranceView()
assistant.dialogIdentifier = "PlayMedia#Paused"
assistant.speakableText = assistant.text = res["pause"][language]
root.views = [(assistant)]
root.callbacks = [ResultCallback([commands], code)]
callback = [ResultCallback([root], code)]
self.send_object(RequestCompleted(self.refId, callback))
self.complete_request()
示例7: beginning
def beginning(self, language):
commands = MPSetState(self.refId)
commands.state = "Playing"
commands2 = MPSetPlaybackPosition(self.refId)
commands2.position = "Beginning"
code = 0
root = UIAddViews(self.refId)
root.dialogPhase = "Summary"
assistant = UIAssistantUtteranceView()
assistant.dialogIdentifier = "PlayMedia#SkipToBeginning"
assistant.speakableText = assistant.text = res["beginning"][language]
root.views = [(assistant)]
root.callbacks = [ResultCallback([commands, commands2], code)]
callback = [ResultCallback([root], code)]
self.send_object(RequestCompleted(self.refId, callback))
self.complete_request()
示例8: CreateUIView
def CreateUIView(self):
dialog = UIAddViews(self.refId)
dialog.dialogPhase = dialog.DialogPhaseCompletionValue
return dialog