From 1fbee07de2fecc67acb1ea81973c2f84a80b7a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Tue, 3 Feb 2015 05:10:01 -0600 Subject: [PATCH] Geo support has been implemented --- src/app-configuration.defaults | 5 +++- src/controller/buffersController.py | 2 ++ src/controller/mainController.py | 40 +++++++++++++++++++++++++++++ src/twitter/utils.py | 4 +++ src/wxUI/view.py | 3 +++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/app-configuration.defaults b/src/app-configuration.defaults index 0808d587..6eea18f4 100644 --- a/src/app-configuration.defaults +++ b/src/app-configuration.defaults @@ -54,4 +54,7 @@ toggle_autoread = string(default="control+win+e") search = string(default="control+win+-") edit_keystrokes = string(default="control+win+k") view_user_lists = string(default="control+win+l") -get_more_items = string(default="alt+win+pageup") \ No newline at end of file +get_more_items = string(default="alt+win+pageup") +reverse_geocode = string(default="control+win+g") +view_reverse_geocode = string(default="control+win+shift+g") +get_trending_topics = string(default="control+win+t") \ No newline at end of file diff --git a/src/controller/buffersController.py b/src/controller/buffersController.py index 07c30aa6..f8ace9d3 100644 --- a/src/controller/buffersController.py +++ b/src/controller/buffersController.py @@ -276,6 +276,8 @@ class baseBufferController(bufferController): self.buffer.list.list.SetStringItem(self.buffer.list.get_selected(), 2, ts) if utils.is_audio(tweet): self.session.sound.play("audio.ogg") + if utils.is_geocoded(tweet): + self.session.sound.play("geo.ogg") def audio(self): tweet = self.get_tweet() diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 60750f07..a4507879 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -111,6 +111,7 @@ class Controller(object): widgetUtils.connect_event(self.view, widgetUtils.MENU, self.add_to_favourites, self.view.fav) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.remove_from_favourites, self.view.unfav) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.view_item, self.view.view) + widgetUtils.connect_event(self.view, widgetUtils.MENU, self.reverse_geocode, menuitem=self.view.view_coordinates) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.delete, self.view.delete) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.follow, menuitem=self.view.follow) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.send_dm, self.view.dm) @@ -501,6 +502,45 @@ class Controller(object): timer.start() buffer.session.settings["other_buffers"]["trending_topic_buffers"].append(woeid) + def reverse_geocode(self, event=None): + try: + tweet = self.get_current_buffer().get_right_tweet() + if tweet["coordinates"] != None: + x = tweet["coordinates"]["coordinates"][0] + y = tweet["coordinates"]["coordinates"][1] + address = geocoder.reverse_geocode(y, x) + if event == None: output.speak(address[0].__str__().decode("utf-8")) + else: self.view.show_address(address[0].__str__().decode("utf-8")) + else: + output.speak(_(u"There are no coordinates in this tweet")) + except GeocoderError: + output.speak(_(u"There are no results for the coordinates in this tweet")) + except ValueError: + output.speak(_(u"Error decoding coordinates. Try again later.")) + except KeyError: + pass + except AttributeError: + pass + + def view_reverse_geocode(self, event=None): + try: + tweet = self.get_current_buffer().get_right_tweet() + if tweet["coordinates"] != None: + x = tweet["coordinates"]["coordinates"][0] + y = tweet["coordinates"]["coordinates"][1] + address = geocoder.reverse_geocode(y, x) + dlg = messages.viewTweet(address[0].__str__(), False) + else: + output.speak(_(u"There are no coordinates in this tweet")) + except GeocoderError: + output.speak(_(u"There are no results for the coordinates in this tweet")) + except ValueError: + output.speak(_(u"Error decoding coordinates. Try again later.")) + except KeyError: + pass + except AttributeError: + pass + def skip_buffer(self, forward=True): buff = self.get_current_buffer() if buff.invisible == False: diff --git a/src/twitter/utils.py b/src/twitter/utils.py index fc44eb6f..28587fb8 100644 --- a/src/twitter/utils.py +++ b/src/twitter/utils.py @@ -46,6 +46,10 @@ def is_audio(tweet): return True return False +def is_geocoded(tweet): + if tweet.has_key("coordinates") and tweet["coordinates"] != None: + return True + def get_all_mentioned(tweet, conf): """ Gets all users that has been mentioned.""" string = [] diff --git a/src/wxUI/view.py b/src/wxUI/view.py index e25859c0..751e8a8e 100644 --- a/src/wxUI/view.py +++ b/src/wxUI/view.py @@ -32,6 +32,7 @@ class mainFrame(wx.Frame): self.fav = tweet.Append(wx.NewId(), _(u"Add to &favourites")) self.unfav = tweet.Append(wx.NewId(), _(u"Remove from favo&urites")) self.view = tweet.Append(wx.NewId(), _(u"&Show tweet")) + self.view_coordinates = tweet.Append(wx.NewId(), _(u"View &address")) self.delete = tweet.Append(wx.NewId(), _(u"&Delete")) # User menu @@ -167,3 +168,5 @@ class mainFrame(wx.Frame): def show(self): self.Show() + def show_address(self, address): + wx.MessageDialog(self, address, _(u"Address"), wx.OK).ShowModal() \ No newline at end of file