Interact function refactorized

This commit is contained in:
Manuel Cortez 2015-06-01 11:18:39 -05:00
parent 5976caf736
commit 91c5165d12
3 changed files with 28 additions and 23 deletions

View File

@ -81,6 +81,30 @@ class bufferController(object):
sound.URLPlayer.stream.volume = self.session.settings["sound"]["volume"] sound.URLPlayer.stream.volume = self.session.settings["sound"]["volume"]
self.session.sound.play("volume_changed.ogg") self.session.sound.play("volume_changed.ogg")
def interact(self):
if hasattr(sound.URLPlayer,'stream'):
return sound.URLPlayer.stop_audio(delete=True)
tweet = self.get_tweet()
url=None
urls = utils.find_urls(tweet)
if len(urls) == 1:
url=urls[0]
elif len(urls) > 1:
urls_list = dialogs.urlList.urlList()
urls_list.populate_list(urls)
if urls_list.get_response() == widgetUtils.OK:
url=urls_list.get_string()
if hasattr(urls_list, "destroy"): urls_list.destroy()
if url != None:
output.speak(_(u"Opening media..."), True)
if sound.URLPlayer.is_playable(url=url, play=True, volume=self.session.settings["sound"]["volume"]) == False:
return webbrowser.open_new_tab(url)
elif utils.is_geocoded(tweet):
return output.speak("Not implemented",True)
else:
output.speak(_(u"Not actionable."), True)
self.session.sound.play("error.ogg")
def start_stream(self): def start_stream(self):
pass pass
@ -416,6 +440,7 @@ class baseBufferController(bufferController):
if utils.is_geocoded(tweet): if utils.is_geocoded(tweet):
self.session.sound.play("geo.ogg") self.session.sound.play("geo.ogg")
self.session.db[str(self.name+"_pos")]=self.buffer.list.get_selected() self.session.db[str(self.name+"_pos")]=self.buffer.list.get_selected()
@_tweets_exist @_tweets_exist
def audio(self,url=''): def audio(self,url=''):
if hasattr(sound.URLPlayer,'stream'): if hasattr(sound.URLPlayer,'stream'):
@ -554,6 +579,7 @@ class peopleBufferController(baseBufferController):
self.compose_function = compose.compose_followers_list self.compose_function = compose.compose_followers_list
log.debug("Compose_function: %s" % (self.compose_function,)) log.debug("Compose_function: %s" % (self.compose_function,))
self.get_tweet = self.get_right_tweet self.get_tweet = self.get_right_tweet
self.url = self.interact
def remove_buffer(self): def remove_buffer(self):
return False return False

View File

@ -1013,28 +1013,7 @@ class Controller(object):
def interact(self): def interact(self):
"Select the best action for the currently focused tweet (audio, geocode, URL, etc)." "Select the best action for the currently focused tweet (audio, geocode, URL, etc)."
buffer = self.get_current_buffer() buffer = self.get_current_buffer()
if hasattr(sound.URLPlayer,'stream'): buffer.interact()
return sound.URLPlayer.stop_audio(delete=True)
tweet = buffer.get_tweet()
url=None
urls = utils.find_urls(tweet)
if len(urls) == 1:
url=urls[0]
elif len(urls) > 1:
urls_list = dialogs.urlList.urlList()
urls_list.populate_list(urls)
if urls_list.get_response() == widgetUtils.OK:
url=urls_list.get_string()
if hasattr(urls_list, "destroy"): urls_list.destroy()
if url != None:
output.speak(_(u"Opening media..."), True)
if sound.URLPlayer.is_playable(url=url,play=True,volume=buffer.session.settings["sound"]["volume"]) == False:
return webbrowser.open_new_tab(url)
elif utils.is_geocoded(tweet):
return output.speak("Not implemented",True)
else:
output.speak(_(u"Not actionable."), True)
buffer.session.sound.play("error.ogg")
def url(self, *args, **kwargs): def url(self, *args, **kwargs):
buffer = self.get_current_buffer() buffer = self.get_current_buffer()

View File

@ -151,7 +151,7 @@ class URLStream(object):
def stop_audio(self,delete=False): def stop_audio(self,delete=False):
if hasattr(self, "stream"): if hasattr(self, "stream"):
output.speak("Stopped.",True) output.speak(_(u"Stopped."), True)
try: try:
self.stream.stop() self.stream.stop()
log.debug("Stopped audio stream.") log.debug("Stopped audio stream.")