From f4ecf1088543147d9ac00783982e35c37163a0e5 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Wed, 25 Aug 2021 16:30:37 -0500 Subject: [PATCH] Allow to copy tweet URLS from tweet displayer dialog --- doc/changelog.md | 1 + src/controller/buffers/twitter/base.py | 8 ++++++-- src/controller/buffers/twitter/people.py | 5 ++--- src/controller/mainController.py | 7 +++++-- src/controller/messages.py | 11 ++++++++++- src/wxUI/dialogs/message.py | 8 ++++++-- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/doc/changelog.md b/doc/changelog.md index 4f9951ec..6e7ca628 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -3,6 +3,7 @@ ## changes in this version * When reading a tweet, if the tweet contains more than 2 consecutive mentions, TWBlue will announce how many more users the tweet includes, as opposed to read every user in the conversation. You still can display the tweet to read all users. +* In the tweet displayer, It is possible to copy a link to the current tweet or person by pressing a button called "copy link to clipboard". * Added a keymap capable to work under Windows 11. ([#391](https://github.com/manuelcortez/TWBlue/pull/391)) * Added user aliases to TWBlue. This feature allows you to rename user's display names on Twitter, so the next time you'll read an user it will be announced as you configured. For adding an alias to an user, select the "add alias" option in the user menu, located in the menu bar. This feature works only if you have set display screen names unchecked. Users are displayed with their display name in people buffers only. This action is supported in all keymaps, although it is undefined by default. ([#389](https://github.com/manuelcortez/TWBlue/pull/389)) * There are some changes to the autocomplete users feature: diff --git a/src/controller/buffers/twitter/base.py b/src/controller/buffers/twitter/base.py index b7b535e1..fa872844 100644 --- a/src/controller/buffers/twitter/base.py +++ b/src/controller/buffers/twitter/base.py @@ -644,8 +644,12 @@ class BaseBuffer(base.Buffer): original_tweet.text = utils.find_urls_in_text(original_tweet.text, original_tweet.entities) 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): + def get_item_url(self): tweet = self.get_tweet() - output.speak(_(u"Opening item in web browser...")) url = "https://twitter.com/{screen_name}/status/{tweet_id}".format(screen_name=self.session.get_user(tweet.user).screen_name, tweet_id=tweet.id) + return url + + def open_in_browser(self, *args, **kwargs): + url = self.get_item_url() + output.speak(_(u"Opening item in web browser...")) webbrowser.open(url) \ No newline at end of file diff --git a/src/controller/buffers/twitter/people.py b/src/controller/buffers/twitter/people.py index 09d89c5d..eae6c718 100644 --- a/src/controller/buffers/twitter/people.py +++ b/src/controller/buffers/twitter/people.py @@ -252,8 +252,7 @@ class PeopleBuffer(base.BaseBuffer): 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): + def get_item_url(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) \ No newline at end of file + return url \ No newline at end of file diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 0db1a6ca..30fd3f1a 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -831,7 +831,7 @@ class Controller(object): return elif buffer.type == "baseBuffer" or buffer.type == "favourites_timeline" or buffer.type == "list" or buffer.type == "search": tweet, tweetsList = buffer.get_full_tweet() - msg = messages.viewTweet(tweet, tweetsList, utc_offset=buffer.session.db["utc_offset"]) + msg = messages.viewTweet(tweet, tweetsList, utc_offset=buffer.session.db["utc_offset"], item_url=buffer.get_item_url()) elif buffer.type == "dm": non_tweet = buffer.get_formatted_message() item = buffer.get_right_tweet() @@ -839,8 +839,11 @@ class Controller(object): date = original_date.shift(seconds=buffer.session.db["utc_offset"]).format(_(u"MMM D, YYYY. H:m"), locale=languageHandler.getLanguage()) msg = messages.viewTweet(non_tweet, [], False, date=date) else: + item_url = "" + if hasattr(buffer, "get_item_url"): + item_url = buffer.get_item_url() non_tweet = buffer.get_formatted_message() - msg = messages.viewTweet(non_tweet, [], False) + msg = messages.viewTweet(non_tweet, [], False, item_url=item_url) def open_in_browser(self, *args, **kwargs): buffer = self.get_current_buffer() diff --git a/src/controller/messages.py b/src/controller/messages.py index e4a7747c..38082427 100644 --- a/src/controller/messages.py +++ b/src/controller/messages.py @@ -205,7 +205,7 @@ class dm(basicTweet): c.show_menu("dm") class viewTweet(basicTweet): - def __init__(self, tweet, tweetList, is_tweet=True, utc_offset=0, date=""): + def __init__(self, tweet, tweetList, is_tweet=True, utc_offset=0, date="", item_url=""): """ This represents a tweet displayer. However it could be used for showing something wich is not a tweet, like a direct message or an event. param tweet: A dictionary that represents a full tweet or a string for non-tweets. param tweetList: If is_tweet is set to True, this could be a list of quoted tweets. @@ -273,6 +273,10 @@ class viewTweet(basicTweet): text = tweet self.message = message.viewNonTweet(text, date) widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck) + if item_url != "": + self.message.enable_button("share") + widgetUtils.connect_event(self.message.share, widgetUtils.BUTTON_PRESSED, self.share) + self.item_url = item_url widgetUtils.connect_event(self.message.translateButton, widgetUtils.BUTTON_PRESSED, self.translate) if self.contain_urls() == True: self.message.enable_button("unshortenButton") @@ -290,3 +294,8 @@ class viewTweet(basicTweet): if "https://twitter.com/" in i: text = text.replace(i, "\n") return text + + def share(self, *args, **kwargs): + if hasattr(self, "item_url"): + output.copy(self.item_url) + output.speak(_("Link copied to clipboard.")) \ No newline at end of file diff --git a/src/wxUI/dialogs/message.py b/src/wxUI/dialogs/message.py index 6a74b32e..093934f5 100644 --- a/src/wxUI/dialogs/message.py +++ b/src/wxUI/dialogs/message.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals -from builtins import str import wx import widgetUtils @@ -356,6 +354,8 @@ class viewTweet(widgetUtils.BaseDialog): infoBox.Add(sourceBox, 0, wx.ALL, 5) mainBox.Add(infoBox, 0, wx.ALL, 5) mainBox.Add(dateBox, 0, wx.ALL, 5) + self.share = wx.Button(panel, wx.ID_ANY, _("Copy link to clipboard")) + self.share.Enable(False) self.spellcheck = wx.Button(panel, -1, _("Check &spelling..."), size=wx.DefaultSize) self.unshortenButton = wx.Button(panel, -1, _(u"&Expand URL"), size=wx.DefaultSize) self.unshortenButton.Disable() @@ -363,6 +363,7 @@ class viewTweet(widgetUtils.BaseDialog): cancelButton = wx.Button(panel, wx.ID_CANCEL, _(u"C&lose"), size=wx.DefaultSize) cancelButton.SetDefault() buttonsBox = wx.BoxSizer(wx.HORIZONTAL) + buttonsBox.Add(self.share, 0, wx.ALL, 5) buttonsBox.Add(self.spellcheck, 0, wx.ALL, 5) buttonsBox.Add(self.unshortenButton, 0, wx.ALL, 5) buttonsBox.Add(self.translateButton, 0, wx.ALL, 5) @@ -429,6 +430,8 @@ class viewNonTweet(widgetUtils.BaseDialog): dateBox.Add(dateLabel, 0, wx.ALL, 5) dateBox.Add(date, 0, wx.ALL, 5) mainBox.Add(dateBox, 0, wx.ALL, 5) + self.share = wx.Button(panel, wx.ID_ANY, _("Copy link to clipboard")) + self.share.Enable(False) self.spellcheck = wx.Button(panel, -1, _("Check &spelling..."), size=wx.DefaultSize) self.unshortenButton = wx.Button(panel, -1, _(u"&Expand URL"), size=wx.DefaultSize) self.unshortenButton.Disable() @@ -436,6 +439,7 @@ class viewNonTweet(widgetUtils.BaseDialog): cancelButton = wx.Button(panel, wx.ID_CANCEL, _(u"C&lose"), size=wx.DefaultSize) cancelButton.SetDefault() buttonsBox = wx.BoxSizer(wx.HORIZONTAL) + buttonsBox.Add(self.share, 0, wx.ALL, 5) buttonsBox.Add(self.spellcheck, 0, wx.ALL, 5) buttonsBox.Add(self.unshortenButton, 0, wx.ALL, 5) buttonsBox.Add(self.translateButton, 0, wx.ALL, 5)