diff --git a/src/controller/buffersController.py b/src/controller/buffersController.py index 1d500a87..e7475c2d 100644 --- a/src/controller/buffersController.py +++ b/src/controller/buffersController.py @@ -246,7 +246,7 @@ class baseBufferController(bufferController): if tweet.has_key("long_uri"): uri = tweet["long_uri"] try: - tweet = self.session.twitter.twitter.show_status(id=tweet_id) + tweet = self.session.twitter.twitter.show_status(id=tweet_id, include_ext_alt_text=True) urls = utils.find_urls_in_text(tweet["text"]) for url in range(0, len(urls)): try: tweet["text"] = tweet["text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"]) @@ -261,7 +261,7 @@ class baseBufferController(bufferController): tweetsList.append(tweet) id = tweets.get_id(l) try: - tweet = self.session.twitter.twitter.show_status(id=id) + tweet = self.session.twitter.twitter.show_status(id=id, include_ext_alt_text=True) urls = utils.find_urls_in_text(tweet["text"]) for url in range(0, len(urls)): try: tweet["text"] = tweet["text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"]) diff --git a/src/controller/messages.py b/src/controller/messages.py index 7c8854ea..01b27c5c 100644 --- a/src/controller/messages.py +++ b/src/controller/messages.py @@ -166,12 +166,17 @@ class dm(basicTweet): class viewTweet(basicTweet): def __init__(self, tweet, tweetList, is_tweet=True): if is_tweet == True: + image_description = [] text = "" for i in xrange(0, len(tweetList)): if tweetList[i].has_key("retweeted_status"): text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i]["retweeted_status"]["text"]) else: text = text + "@%s: %s\n" % (tweetList[i]["user"]["screen_name"], tweetList[i]["text"]) + if tweetList[i].has_key("extended_entities") and tweetList[i]["extended_entities"].has_key("media"): + for z in tweetList[i]["extended_entities"]["media"]: + if z.has_key("ext_alt_text") and z["ext_alt_text"] != None: + image_description.append(z["ext_alt_text"]) rt_count = str(tweet["retweet_count"]) favs_count = str(tweet["favorite_count"]) source = str(re.sub(r"(?s)<.*?>", "", tweet["source"].encode("utf-8"))) @@ -181,8 +186,13 @@ class viewTweet(basicTweet): else: text = tweet["text"] text = self.clear_text(text) + if tweet.has_key("extended_entities") and tweet["extended_entities"].has_key("media"): + for z in tweet["extended_entities"]["media"]: + if z.has_key("ext_alt_text") and z["ext_alt_text"] != None: + image_description.append(z["ext_alt_text"]) self.message = message.viewTweet(text, rt_count, favs_count, source.decode("utf-8")) self.message.set_title(len(text)) + [self.message.set_image_description(i) for i in image_description] else: text = tweet self.message = message.viewNonTweet(text) diff --git a/src/wxUI/dialogs/message.py b/src/wxUI/dialogs/message.py index bcc6340e..084a853f 100644 --- a/src/wxUI/dialogs/message.py +++ b/src/wxUI/dialogs/message.py @@ -260,6 +260,17 @@ class viewTweet(widgetUtils.BaseDialog): textBox.Add(self.text, 1, wx.EXPAND, 5) mainBox = wx.BoxSizer(wx.VERTICAL) mainBox.Add(textBox, 0, wx.ALL, 5) + label2 = wx.StaticText(panel, -1, _(u"Image description")) + self.image_description = wx.TextCtrl(panel, -1, style=wx.TE_READONLY|wx.TE_MULTILINE, size=(250, 180)) + dc = wx.WindowDC(self.image_description) + dc.SetFont(self.image_description.GetFont()) + (x, y, z) = dc.GetMultiLineTextExtent("0"*450) + self.image_description.SetSize((x, y)) + self.image_description.Enable(False) + iBox = wx.BoxSizer(wx.HORIZONTAL) + iBox.Add(label2, 0, wx.ALL, 5) + iBox.Add(self.image_description, 1, wx.EXPAND, 5) + mainBox.Add(iBox, 0, wx.ALL, 5) rtCountLabel = wx.StaticText(panel, -1, _(u"Retweets: ")) rtCount = wx.TextCtrl(panel, -1, rt_count, size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE) rtBox = wx.BoxSizer(wx.HORIZONTAL) @@ -307,6 +318,13 @@ class viewTweet(widgetUtils.BaseDialog): def get_text(self): return self.text.GetValue() + def set_image_description(self, desc): + self.image_description.Enable(True) + if len(self.image_description.GetValue()) == 0: + self.image_description.SetValue(desc) + else: + self.image_description.SetValue(self.image_description.GetValue()+"\n"+desc) + def text_focus(self): self.text.SetFocus()