From d7132ecaf629129af888e00ebd4e39deeef571a8 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Tue, 19 Feb 2019 17:41:34 -0600 Subject: [PATCH] Added 'open in Twitter' for tweets and users --- doc/changelog.md | 1 + src/controller/buffers/twitterBuffers.py | 22 ++++++++++++++++++++++ src/controller/mainController.py | 5 +++++ src/keymaps/Chicken Nugget.keymap | 3 ++- src/keymaps/Qwitter.keymap | 3 ++- src/keymaps/Windows 10.keymap | 3 ++- src/keymaps/base.template | 3 ++- src/keymaps/default.keymap | 3 ++- src/wxUI/menus.py | 6 ++++++ 9 files changed, 44 insertions(+), 5 deletions(-) diff --git a/doc/changelog.md b/doc/changelog.md index 3413afed..7af4c2d0 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -2,6 +2,7 @@ ## changes in this version +* TWBlue can open a Tweet or user directly in Twitter. There is a new option in the context menu for people and tweet buffers, and also, the shortcut control+win+alt+Enter will open the focused item in Twitter. * Fixed an error that was preventing TWBlue to load the direct messages buffer if an user who sent a message has been deleted. * Added support for playing audios posted in [AnyAudio.net](http://anyaudio.net) directly from TWBlue. Thanks to [Sam Tupy](http://www.samtupy.com/) * Custom buffer ordering will not be reset every time the application restarts after an account setting has been modified. diff --git a/src/controller/buffers/twitterBuffers.py b/src/controller/buffers/twitterBuffers.py index 4450d996..1cce2ce1 100644 --- a/src/controller/buffers/twitterBuffers.py +++ b/src/controller/buffers/twitterBuffers.py @@ -344,6 +344,8 @@ class baseBufferController(baseBuffers.buffer): widgetUtils.connect_event(menu, widgetUtils.MENU, self.view, menuitem=menu.view) widgetUtils.connect_event(menu, widgetUtils.MENU, self.copy, menuitem=menu.copy) widgetUtils.connect_event(menu, widgetUtils.MENU, self.destroy_status, menuitem=menu.remove) + if hasattr(menu, "openInBrowser"): + widgetUtils.connect_event(menu, widgetUtils.MENU, self.open_in_browser, menuitem=menu.openInBrowser) if pos != 0: self.buffer.PopupMenu(menu, pos) else: @@ -627,6 +629,12 @@ class baseBufferController(baseBuffers.buffer): except IndexError: pass return compose.compose_quoted_tweet(quoted_tweet, original_tweet, self.session.db, self.session.settings["general"]["relative_times"]) + def open_in_browser(self, *args, **kwargs): + tweet = self.get_tweet() + output.speak(_(u"Opening item in web browser...")) + url = "https://twitter.com/{screen_name}/status/{tweet_id}".format(screen_name=tweet["user"]["screen_name"], tweet_id=tweet["id"]) + webbrowser.open(url) + class directMessagesController(baseBufferController): def get_more_items(self): @@ -719,6 +727,9 @@ class directMessagesController(baseBufferController): elif number_of_items > 1 and self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False: output.speak(_(u"{0} new direct messages.").format(number_of_items,)) + def open_in_browser(self, *args, **kwargs): + output.speak(_(u"This action is not supported in the buffer yet.")) + class sentDirectMessagesController(directMessagesController): def __init__(self, *args, **kwargs): @@ -951,6 +962,8 @@ class peopleBufferController(baseBufferController): # widgetUtils.connect_event(menu, widgetUtils.MENU, self.lists, menuitem=menu.lists) widgetUtils.connect_event(menu, widgetUtils.MENU, self.view, menuitem=menu.view) widgetUtils.connect_event(menu, widgetUtils.MENU, self.copy, menuitem=menu.copy) + if hasattr(menu, "openInBrowser"): + widgetUtils.connect_event(menu, widgetUtils.MENU, self.open_in_browser, menuitem=menu.openInBrowser) if pos != 0: self.buffer.PopupMenu(menu, pos) else: @@ -969,6 +982,12 @@ class peopleBufferController(baseBufferController): elif number_of_items > 1 and self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False: output.speak(_(u"{0} new followers.").format(number_of_items)) + def open_in_browser(self, *args, **kwargs): + tweet = self.get_tweet() + output.speak(_(u"Opening item in web browser...")) + url = "https://twitter.com/{screen_name}".format(screen_name=tweet["screen_name"]) + webbrowser.open(url) + class searchBufferController(baseBufferController): def start_stream(self, mandatory=False, play_sound=True, avoid_autoreading=False): # starts stream every 3 minutes. @@ -1243,6 +1262,9 @@ class trendsBufferController(baseBuffers.buffer): if ev.GetKeyCode() == wx.WXK_WINDOWS_MENU: self.show_menu(widgetUtils.MENU, pos=self.buffer.list.list.GetPosition()) + def open_in_browser(self, *args, **kwargs): + output.speak(_(u"This action is not supported in the buffer, yet.")) + class conversationBufferController(searchBufferController): def start_stream(self, start=False, mandatory=False, play_sound=True, avoid_autoreading=False): diff --git a/src/controller/mainController.py b/src/controller/mainController.py index eba10b7d..d0303bac 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -812,6 +812,11 @@ class Controller(object): non_tweet = buffer.get_formatted_message() msg = messages.viewTweet(non_tweet, [], False) + def view_in_browser(self, *args, **kwargs): + buffer = self.get_current_buffer() + if hasattr(buffer, "open_in_browser"): + buffer.open_in_browser() + def open_favs_timeline(self, *args, **kwargs): self.open_timeline(default="favourites") diff --git a/src/keymaps/Chicken Nugget.keymap b/src/keymaps/Chicken Nugget.keymap index 1d0651e0..c741ba5a 100644 --- a/src/keymaps/Chicken Nugget.keymap +++ b/src/keymaps/Chicken Nugget.keymap @@ -33,4 +33,5 @@ list_manager = string(default="control+win+shift+l") configuration = string(default="control+win+o") accountConfiguration = string(default="control+win+shift+o") update_buffer = string(default="control+win+shift+u") -ocr_image = string(default="win+alt+o") \ No newline at end of file +ocr_image = string(default="win+alt+o") +open_in_browser = string(default="alt+control+win+return") \ No newline at end of file diff --git a/src/keymaps/Qwitter.keymap b/src/keymaps/Qwitter.keymap index 86c9dc21..21ae6160 100644 --- a/src/keymaps/Qwitter.keymap +++ b/src/keymaps/Qwitter.keymap @@ -52,4 +52,5 @@ list_manager = string(default="control+win+shift+l") configuration = string(default="control+win+o") accountConfiguration = string(default="control+win+shift+o") update_buffer = string(default="control+win+shift+u") -ocr_image = string(default="win+alt+o") \ No newline at end of file +ocr_image = string(default="win+alt+o") +open_in_browser = string(default="alt+control+win+return") \ No newline at end of file diff --git a/src/keymaps/Windows 10.keymap b/src/keymaps/Windows 10.keymap index 5b936bf4..a76a8e73 100644 --- a/src/keymaps/Windows 10.keymap +++ b/src/keymaps/Windows 10.keymap @@ -53,4 +53,5 @@ list_manager = string(default="alt+win+shift+l") configuration = string(default="control+win+alt+o") accountConfiguration = string(default="control+win+shift+o") update_buffer = string(default="control+alt+shift+u") -ocr_image = string(default="win+alt+o") \ No newline at end of file +ocr_image = string(default="win+alt+o") +open_in_browser = string(default="alt+control+win+return") \ No newline at end of file diff --git a/src/keymaps/base.template b/src/keymaps/base.template index b053e65f..31784e42 100644 --- a/src/keymaps/base.template +++ b/src/keymaps/base.template @@ -54,4 +54,5 @@ check_for_updates = string(default="control+win+u") list_manager = string(default="control+win+shift+l") configuration = string(default="control+win+o") accountConfiguration = string(default="control+win+shift+o") -update_buffer = string(default="control+win+shift+u") \ No newline at end of file +update_buffer = string(default="control+win+shift+u") +open_in_browser = string(default="alt+control+win+return") \ No newline at end of file diff --git a/src/keymaps/default.keymap b/src/keymaps/default.keymap index 642d3809..f4dbb190 100644 --- a/src/keymaps/default.keymap +++ b/src/keymaps/default.keymap @@ -55,4 +55,5 @@ list_manager = string(default="control+win+shift+l") configuration = string(default="control+win+o") accountConfiguration = string(default="control+win+shift+o") update_buffer = string(default="control+win+shift+u") -ocr_image = string(default="win+alt+o") \ No newline at end of file +ocr_image = string(default="win+alt+o") +open_in_browser = string(default="alt+control+win+return") \ No newline at end of file diff --git a/src/wxUI/menus.py b/src/wxUI/menus.py index 8d1f2602..164035bd 100644 --- a/src/wxUI/menus.py +++ b/src/wxUI/menus.py @@ -14,6 +14,8 @@ class basePanelMenu(wx.Menu): self.Append(self.unfav) self.openUrl = wx.MenuItem(self, wx.ID_ANY, _(u"&Open URL")) self.Append(self.openUrl) + self.openInBrowser = wx.MenuItem(self, wx.ID_ANY, _(u"&Open in Twitter")) + self.Append(self.openInBrowser) self.play = wx.MenuItem(self, wx.ID_ANY, _(u"&Play audio")) self.Append(self.play) self.view = wx.MenuItem(self, wx.ID_ANY, _(u"&Show tweet")) @@ -48,6 +50,8 @@ class sentPanelMenu(wx.Menu): super(sentPanelMenu, self).__init__() self.openUrl = wx.MenuItem(self, wx.ID_ANY, _(u"&Open URL")) self.Append(self.openUrl) + self.openInBrowser = wx.MenuItem(self, wx.ID_ANY, _(u"&Open in Twitter")) + self.Append(self.openInBrowser) self.play = wx.MenuItem(self, wx.ID_ANY, _(u"&Play audio")) self.Append(self.play) self.view = wx.MenuItem(self, wx.ID_ANY, _(u"&Show tweet")) @@ -79,6 +83,8 @@ class peoplePanelMenu(wx.Menu): self.Append(self.details) self.view = wx.MenuItem(self, wx.ID_ANY, _(u"&Show user")) self.Append(self.view) + self.openInBrowser = wx.MenuItem(self, wx.ID_ANY, _(u"&Open in Twitter")) + self.Append(self.openInBrowser) self.copy = wx.MenuItem(self, wx.ID_ANY, _(u"&Copy to clipboard")) self.Append(self.copy) self.userActions = wx.MenuItem(self, wx.ID_ANY, _(u"&User actions..."))