mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-07-18 06:06:06 -04:00
Image uploader has been rewritten. Images can have description when uploading
This commit is contained in:
38
src/controller/attach.py
Normal file
38
src/controller/attach.py
Normal file
@@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import os
|
||||
import widgetUtils
|
||||
import logging
|
||||
from wxUI.dialogs import attach as gui
|
||||
log = logging.getLogger("controller.attach")
|
||||
|
||||
class attach(object):
|
||||
def __init__(self):
|
||||
self.attachments = list()
|
||||
self.dialog = gui.attachDialog()
|
||||
widgetUtils.connect_event(self.dialog.photo, widgetUtils.BUTTON_PRESSED, self.upload_image)
|
||||
widgetUtils.connect_event(self.dialog.remove, widgetUtils.BUTTON_PRESSED, self.remove_attachment)
|
||||
self.dialog.get_response()
|
||||
log.debug("Attachments controller started.")
|
||||
|
||||
def upload_image(self, *args, **kwargs):
|
||||
image, description = self.dialog.get_image()
|
||||
if image != None:
|
||||
imageInfo = {"type": "photo", "file": image, "description": description}
|
||||
log.debug("Image data to upload: %r" % (imageInfo,))
|
||||
self.attachments.append(imageInfo)
|
||||
info = [_(u"Photo"), description]
|
||||
self.dialog.attachments.insert_item(False, *info)
|
||||
self.dialog.remove.Enable(True)
|
||||
|
||||
def remove_attachment(self, *args, **kwargs):
|
||||
current_item = self.dialog.attachments.get_selected()
|
||||
log.debug("Removing item %d" % (current_item,))
|
||||
if current_item == -1: current_item = 0
|
||||
self.attachments.pop(current_item)
|
||||
self.dialog.attachments.remove_item(current_item)
|
||||
self.check_remove_status()
|
||||
log.debug("Removed")
|
||||
|
||||
def check_remove_status(self):
|
||||
if len(self.attachments) == 0 and self.dialog.attachments.get_count() == 0:
|
||||
self.dialog.remove.Enable(False)
|
@@ -137,22 +137,24 @@ class bufferController(object):
|
||||
self.session.settings["mysc"]["twishort_enabled"] = tweet.message.long_tweet.GetValue()
|
||||
text = tweet.message.get_text()
|
||||
if len(text) > 140 and tweet.message.get("long_tweet") == True:
|
||||
if tweet.image == None:
|
||||
if not hasattr(tweet, "attachments"):
|
||||
text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text)
|
||||
else:
|
||||
text = twishort.create_tweet(self.session.settings["twitter"]["user_key"], self.session.settings["twitter"]["user_secret"], text, 1)
|
||||
if tweet.image == None:
|
||||
if not hasattr(tweet, "attachments"):
|
||||
call_threaded(self.session.api_call, call_name="update_status", status=text)
|
||||
else:
|
||||
call_threaded(self.post_with_media, text=text, image=tweet.image, description="test")
|
||||
call_threaded(self.post_with_media, text=text, attachments=tweet.attachments)
|
||||
if hasattr(tweet.message, "destroy"): tweet.message.destroy()
|
||||
|
||||
def post_with_media(self, text="", image=None, description=None):
|
||||
if image != None:
|
||||
img = self.session.twitter.twitter.upload_media(media=image)
|
||||
if description != None:
|
||||
self.session.twitter.twitter.set_description(media_id=img["media_id"], alt_text=dict(text=description))
|
||||
self.session.api_call(call_name="update_status", status=text, media_ids=img["media_id"])
|
||||
def post_with_media(self, text, attachments):
|
||||
media_ids = []
|
||||
for i in attachments:
|
||||
photo = open(i["file"], "rb")
|
||||
img = self.session.twitter.twitter.upload_media(media=photo)
|
||||
self.session.twitter.twitter.set_description(media_id=img["media_id"], alt_text=dict(text=i["description"]))
|
||||
media_ids.append(img["media_id"])
|
||||
self.session.twitter.twitter.update_status(status=text, media_ids=media_ids)
|
||||
|
||||
def save_positions(self):
|
||||
try:
|
||||
|
@@ -1,6 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import platform
|
||||
import attach
|
||||
system = platform.system()
|
||||
import widgetUtils
|
||||
import output
|
||||
@@ -32,6 +33,7 @@ class basicTweet(object):
|
||||
widgetUtils.connect_event(self.message.shortenButton, widgetUtils.BUTTON_PRESSED, self.shorten)
|
||||
widgetUtils.connect_event(self.message.unshortenButton, widgetUtils.BUTTON_PRESSED, self.unshorten)
|
||||
widgetUtils.connect_event(self.message.translateButton, widgetUtils.BUTTON_PRESSED, self.translate)
|
||||
self.attachments = []
|
||||
|
||||
def translate(self, event=None):
|
||||
dlg = translator.gui.translateDialog()
|
||||
@@ -125,16 +127,9 @@ class tweet(basicTweet):
|
||||
except AttributeError: pass
|
||||
|
||||
def upload_image(self, *args, **kwargs):
|
||||
if self.message.get("upload_image") == _(u"Discard image"):
|
||||
del self.image
|
||||
self.image = None
|
||||
output.speak(_(u"Discarded"))
|
||||
self.message.set("upload_image", _(u"Upload a picture"))
|
||||
else:
|
||||
self.image = self.message.get_image()
|
||||
if self.image != None:
|
||||
self.message.set("upload_image", _(u"Discard image"))
|
||||
self.message.text_focus()
|
||||
a = attach.attach()
|
||||
if len(a.attachments) != 0:
|
||||
self.attachments = a.attachments
|
||||
|
||||
def autocomplete_users(self, *args, **kwargs):
|
||||
c = autocompletionUsers.completion.autocompletionUsers(self.message, self.session.session_id)
|
||||
@@ -184,7 +179,7 @@ class viewTweet(basicTweet):
|
||||
else:
|
||||
text = text + "rt @%s: %s\n" % (tweetList[i]["retweeted_status"]["user"]["screen_name"], tweetList[i][value])
|
||||
else:
|
||||
text = text + "@%s: %s\n" % (tweetList[i]["user"]["screen_name"], tweetList[i][value])
|
||||
text = text + " @%s: %s\n" % (tweetList[i]["user"]["screen_name"], tweetList[i][value])
|
||||
# tweets with extended_entities could include image descriptions.
|
||||
if tweetList[i].has_key("extended_entities") and tweetList[i]["extended_entities"].has_key("media"):
|
||||
for z in tweetList[i]["extended_entities"]["media"]:
|
||||
@@ -234,5 +229,5 @@ class viewTweet(basicTweet):
|
||||
urls = utils.find_urls_in_text(text)
|
||||
for i in urls:
|
||||
if "https://twitter.com/" in i:
|
||||
text = text.replace(i, "")
|
||||
text = text.replace(i, "\n")
|
||||
return text
|
||||
|
Reference in New Issue
Block a user