Image description is shown in the view tweets dialogue if is possible

This commit is contained in:
Manuel Cortez 2016-03-29 15:12:16 -06:00
parent f24d5fec4e
commit edd45a1adf
3 changed files with 30 additions and 2 deletions

View File

@ -246,7 +246,7 @@ class baseBufferController(bufferController):
if tweet.has_key("long_uri"): if tweet.has_key("long_uri"):
uri = tweet["long_uri"] uri = tweet["long_uri"]
try: 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"]) urls = utils.find_urls_in_text(tweet["text"])
for url in range(0, len(urls)): for url in range(0, len(urls)):
try: tweet["text"] = tweet["text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"]) try: tweet["text"] = tweet["text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"])
@ -261,7 +261,7 @@ class baseBufferController(bufferController):
tweetsList.append(tweet) tweetsList.append(tweet)
id = tweets.get_id(l) id = tweets.get_id(l)
try: 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"]) urls = utils.find_urls_in_text(tweet["text"])
for url in range(0, len(urls)): for url in range(0, len(urls)):
try: tweet["text"] = tweet["text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"]) try: tweet["text"] = tweet["text"].replace(urls[url], tweet["entities"]["urls"][url]["expanded_url"])

View File

@ -166,12 +166,17 @@ class dm(basicTweet):
class viewTweet(basicTweet): class viewTweet(basicTweet):
def __init__(self, tweet, tweetList, is_tweet=True): def __init__(self, tweet, tweetList, is_tweet=True):
if is_tweet == True: if is_tweet == True:
image_description = []
text = "" text = ""
for i in xrange(0, len(tweetList)): for i in xrange(0, len(tweetList)):
if tweetList[i].has_key("retweeted_status"): 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"]) text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i]["retweeted_status"]["text"])
else: else:
text = text + "@%s: %s\n" % (tweetList[i]["user"]["screen_name"], tweetList[i]["text"]) 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"]) rt_count = str(tweet["retweet_count"])
favs_count = str(tweet["favorite_count"]) favs_count = str(tweet["favorite_count"])
source = str(re.sub(r"(?s)<.*?>", "", tweet["source"].encode("utf-8"))) source = str(re.sub(r"(?s)<.*?>", "", tweet["source"].encode("utf-8")))
@ -181,8 +186,13 @@ class viewTweet(basicTweet):
else: else:
text = tweet["text"] text = tweet["text"]
text = self.clear_text(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 = message.viewTweet(text, rt_count, favs_count, source.decode("utf-8"))
self.message.set_title(len(text)) self.message.set_title(len(text))
[self.message.set_image_description(i) for i in image_description]
else: else:
text = tweet text = tweet
self.message = message.viewNonTweet(text) self.message = message.viewNonTweet(text)

View File

@ -260,6 +260,17 @@ class viewTweet(widgetUtils.BaseDialog):
textBox.Add(self.text, 1, wx.EXPAND, 5) textBox.Add(self.text, 1, wx.EXPAND, 5)
mainBox = wx.BoxSizer(wx.VERTICAL) mainBox = wx.BoxSizer(wx.VERTICAL)
mainBox.Add(textBox, 0, wx.ALL, 5) 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: ")) rtCountLabel = wx.StaticText(panel, -1, _(u"Retweets: "))
rtCount = wx.TextCtrl(panel, -1, rt_count, size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE) rtCount = wx.TextCtrl(panel, -1, rt_count, size=wx.DefaultSize, style=wx.TE_READONLY|wx.TE_MULTILINE)
rtBox = wx.BoxSizer(wx.HORIZONTAL) rtBox = wx.BoxSizer(wx.HORIZONTAL)
@ -307,6 +318,13 @@ class viewTweet(widgetUtils.BaseDialog):
def get_text(self): def get_text(self):
return self.text.GetValue() 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): def text_focus(self):
self.text.SetFocus() self.text.SetFocus()