From a6dd5d602ff94b1bcf2d484990106f9d34f76c5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Wed, 31 Dec 2014 00:07:27 -0600 Subject: [PATCH] Uploading photos is now supported for tweets --- src/controller/buffersController.py | 6 +++++- src/controller/mainController.py | 28 +++++++++++++--------------- src/controller/messages.py | 21 +++++++++++++++++++-- src/wxUI/dialogs/message.py | 13 +++++++++++-- 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/controller/buffersController.py b/src/controller/buffersController.py index 9bde81e6..a94e868e 100644 --- a/src/controller/buffersController.py +++ b/src/controller/buffersController.py @@ -18,6 +18,7 @@ class bufferController(object): self.kwargs = kwargs self.buffer = None self.account = "" + self.needs_init = True def get_event(self, ev): if ev.GetKeyCode() == wx.WXK_RETURN and ev.ControlDown(): event = "audio" @@ -85,6 +86,8 @@ class accountPanel(bufferController): self.buffer = buffers.accountPanel(parent, name) self.type = self.buffer.type self.compose_function = None + self.session = None + self.needs_init = False self.id = self.buffer.GetId() self.account = account self.buffer.account = account @@ -100,7 +103,8 @@ class emptyPanel(bufferController): self.account = account self.buffer.account = account self.name = name - + self.session = None + self.needs_init = True class baseBufferController(bufferController): def __init__(self, parent, function, name, sessionObject, account, bufferType=None, *args, **kwargs): super(baseBufferController, self).__init__(parent, function, *args, **kwargs) diff --git a/src/controller/mainController.py b/src/controller/mainController.py index bfb90a2e..61443d55 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -67,10 +67,11 @@ class Controller(object): self.bind_stream_events() self.bind_other_events() self.do_work() - + def do_work(self): for i in session.sessions: self.create_buffers(session.sessions[i]) + call_threaded(self.start_buffers, session.sessions[i]) sound.player.play("tweet_timeline.ogg") def create_buffers(self, session): @@ -80,50 +81,41 @@ class Controller(object): self.view.add_buffer(account.buffer , name=session.db["user_name"]) home = buffersController.baseBufferController(self.view.nb, "get_home_timeline", "home_timeline", session, session.db["user_name"]) self.buffers.append(home) - home.start_stream() self.view.insert_buffer(home.buffer, name=_(u"Home"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) mentions = buffersController.baseBufferController(self.view.nb, "get_mentions_timeline", "mentions", session, session.db["user_name"]) self.buffers.append(mentions) - mentions.start_stream() self.view.insert_buffer(mentions.buffer, name=_(u"Mentions"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) sound.player.play("mention_received.ogg") dm = buffersController.baseBufferController(self.view.nb, "get_direct_messages", "direct_messages", session, session.db["user_name"], bufferType="dmPanel") self.buffers.append(dm) - dm.start_stream() self.view.insert_buffer(dm.buffer, name=_(u"Direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) sound.player.play("dm_received.ogg") sent_dm = buffersController.baseBufferController(self.view.nb, "get_sent_messages", "sent_direct_messages", session, session.db["user_name"], bufferType="dmPanel") self.buffers.append(sent_dm) - sent_dm.start_stream() self.view.insert_buffer(sent_dm.buffer, name=_(u"Sent direct messages"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) sent_tweets = buffersController.baseBufferController(self.view.nb, "get_user_timeline", "sent_tweets", session, session.db["user_name"], bufferType="dmPanel", screen_name=session.db["user_name"]) self.buffers.append(sent_tweets) - sent_tweets.start_stream() self.view.insert_buffer(sent_tweets.buffer, name=_(u"Sent tweets"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) if session.settings["other_buffers"]["show_favourites"] == True: favourites = buffersController.baseBufferController(self.view.nb, "get_favorites", "favourites", session, session.db["user_name"]) self.buffers.append(favourites) - favourites.start_stream() + self.view.insert_buffer(favourites.buffer, name=_(u"Favourites"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) if session.settings["other_buffers"]["show_followers"] == True: followers = buffersController.peopleBufferController(self.view.nb, "get_followers_list", "followers", session, session.db["user_name"], screen_name=session.db["user_name"]) self.buffers.append(followers) - followers.start_stream() self.view.insert_buffer(followers.buffer, name=_(u"Followers"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) if session.settings["other_buffers"]["show_friends"] == True: friends = buffersController.peopleBufferController(self.view.nb, "get_friends_list", "friends", session, session.db["user_name"], screen_name=session.db["user_name"]) self.buffers.append(friends) - friends.start_stream() self.view.insert_buffer(friends.buffer, name=_(u"Friends"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) if session.settings["other_buffers"]["show_blocks"] == True: blocks = buffersController.peopleBufferController(self.view.nb, "list_blocks", "blocked", session, session.db["user_name"]) self.buffers.append(blocks) - blocks.start_stream() self.view.insert_buffer(blocks.buffer, name=_(u"Blocked users"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) if session.settings["other_buffers"]["show_muted_users"] == True: muted = buffersController.peopleBufferController(self.view.nb, "get_muted_users_list", "muted", session, session.db["user_name"]) self.buffers.append(muted) - muted.start_stream() self.view.insert_buffer(muted.buffer, name=_(u"Muted users"), pos=self.view.search(session.db["user_name"], session.db["user_name"])) if session.settings["other_buffers"]["show_events"] == True: events = buffersController.eventsBufferController(self.view.nb, "events", session, session.db["user_name"], bufferType="dmPanel", screen_name=session.db["user_name"]) @@ -135,7 +127,6 @@ class Controller(object): for i in session.settings["other_buffers"]["timelines"]: tl = buffersController.baseBufferController(self.view.nb, "get_user_timeline", "%s-timeline" % (i,), session, session.db["user_name"], bufferType=None, screen_name=i) self.buffers.append(tl) - tl.start_stream() self.view.insert_buffer(tl.buffer, name=_(u"Timeline for {}".format(i)), pos=self.view.search("timelines", session.db["user_name"])) searches = buffersController.emptyPanel(self.view.nb, "searches", session.db["user_name"]) self.buffers.append(searches) @@ -143,11 +134,9 @@ class Controller(object): for i in session.settings["other_buffers"]["tweet_searches"]: tl = buffersController.searchBufferController(self.view.nb, "search", "%s-searchterm" % (i,), session, session.db["user_name"], bufferType="searchPanel", q=i) self.buffers.append(tl) - tl.start_stream() self.view.insert_buffer(tl.buffer, name=_(u"Search for {}".format(i)), pos=self.view.search("searches", session.db["user_name"])) tl.timer = RepeatingTimer(180, tl.start_stream) tl.timer.start() - session.start_streaming() def search(self, event=None): dlg = dialogs.search.searchDialog() @@ -227,7 +216,10 @@ class Controller(object): tweet = messages.tweet(buffer.session) if tweet.message.get_response() == widgetUtils.OK: text = tweet.message.get_text() - call_threaded(buffer.session.api_call, call_name="update_status", _sound="tweet_send.ogg", status=text) + if tweet.image == None: + call_threaded(buffer.session.api_call, call_name="update_status", _sound="tweet_send.ogg", status=text) + else: + call_threaded(buffer.session.api_call, call_name="update_status_with_media", _sound="tweet_send.ogg", status=text, media=tweet.image) def post_reply(self): pass @@ -354,5 +346,11 @@ class Controller(object): def editing_keystroke(self, action, parentDialog): print "i've pressed" + def start_buffers(self, session): + for i in self.buffers: + if i.session == session and i.needs_init == True: + i.start_stream() + session.start_streaming() + def __del__(self): config.app.write() \ No newline at end of file diff --git a/src/controller/messages.py b/src/controller/messages.py index dfef1aef..48561d9d 100644 --- a/src/controller/messages.py +++ b/src/controller/messages.py @@ -9,9 +9,10 @@ from extra import translator, SpellChecker from extra.AudioUploader import audioUploader from twitter import utils -class tweet(object): +class basicTweet(object): + """ This class handles the tweet main features. Other classes should derive from this class.""" def __init__(self, session): - super(tweet, self).__init__() + super(basicTweet, self).__init__() self.session = session self.message = message.tweet(_(u"Write the tweet here"), _(u"tweet - 0 characters"), "") widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck) @@ -92,3 +93,19 @@ class tweet(object): output.speak(_(u"Unable to upload the audio")) dlg.cleanup() dlg = audioUploader.audioUploader(self.session.settings, completed_callback) + +class tweet(basicTweet): + def __init__(self, session): + super(tweet, self).__init__(session) + self.image = None + widgetUtils.connect_event(self.message.upload_image, widgetUtils.BUTTON_PRESSED, self.upload_image) + + 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() + self.message.set("upload_image", _(u"Discard image")) \ No newline at end of file diff --git a/src/wxUI/dialogs/message.py b/src/wxUI/dialogs/message.py index 9a1448d3..e8d3db15 100644 --- a/src/wxUI/dialogs/message.py +++ b/src/wxUI/dialogs/message.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- import wx -import baseDialog +import widgetUtils -class textLimited(baseDialog.BaseWXDialog): +class textLimited(widgetUtils.BaseDialog): def __init__(self, *args, **kwargs): super(textLimited, self).__init__(parent=None, *args, **kwargs) @@ -21,6 +21,9 @@ class textLimited(baseDialog.BaseWXDialog): self.textBox.Add(self.label, 0, wx.ALL, 5) self.textBox.Add(self.text, 0, wx.ALL, 5) + def text_focus(self): + self.text.SetFocus() + def get_text(self): return self.text.GetValue() @@ -85,6 +88,12 @@ class tweet(textLimited): # self.onTimer(wx.EVT_CHAR_HOOK) self.SetClientSize(self.mainBox.CalcMin()) + def get_image(self): + openFileDialog = wx.FileDialog(self, _(u"Select the picture to be uploaded"), "", "", _("Image files (*.png, *.jpg, *.gif)|*.png; *.jpg; *.gif"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) + if openFileDialog.ShowModal() == wx.ID_CANCEL: + return None + return open(openFileDialog.GetPath(), "rb") + class dm(textLimited): def createControls(self, message, title, users): self.panel = wx.Panel(self)