From 0afba81c7197bae0cd98bfa11579775a844aa744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Sat, 26 Dec 2015 09:02:08 -0600 Subject: [PATCH] Update buffers by pressing ctrl+win+shift+u; workaround for dm issues --- src/application.py | 2 +- src/controller/buffersController.py | 32 ++++++++++++++++++++--------- src/controller/mainController.py | 19 ++++++++++++++++- src/keymaps/Chicken Nugget.keymap | 3 ++- src/keymaps/Qwitter.keymap | 3 ++- src/keymaps/Windows 10.keymap | 3 ++- src/keymaps/base.template | 3 ++- src/keymaps/default.keymap | 3 ++- src/keystrokeEditor/constants.py | 1 + src/sessionmanager/session.py | 3 ++- 10 files changed, 54 insertions(+), 18 deletions(-) diff --git a/src/application.py b/src/application.py index 17328fd1..a9e60f2e 100644 --- a/src/application.py +++ b/src/application.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- name = 'TWBlue' -snapshot = False +snapshot = True if snapshot == False: version = "0.80" update_url = 'http://twblue.es/updates/twblue_ngen.json' diff --git a/src/controller/buffersController.py b/src/controller/buffersController.py index 2aedef2b..048741ba 100644 --- a/src/controller/buffersController.py +++ b/src/controller/buffersController.py @@ -84,7 +84,9 @@ class bufferController(object): sound.URLPlayer.stream.volume = self.session.settings["sound"]["volume"] self.session.sound.play("volume_changed.ogg") - def start_stream(self): + def start_stream(self, mandatory=False): + if mandatory == True: + output.speak(_(u"Unable to update this buffer.")) pass def get_more_items(self): @@ -272,10 +274,10 @@ class baseBufferController(bufferController): tweetsList.append(tweet) return (tweet, tweetsList) - def start_stream(self): + def start_stream(self, mandatory=False): # starts stream every 3 minutes. current_time = time.time() - if self.execution_time == 0 or current_time-self.execution_time >= 180: + if self.execution_time == 0 or current_time-self.execution_time >= 180 or mandatory==True: self.execution_time = current_time log.debug("Starting stream for buffer %s, account %s and type %s" % (self.name, self.account, self.type)) log.debug("args: %s, kwargs: %s" % (self.args, self.kwargs)) @@ -283,9 +285,9 @@ class baseBufferController(bufferController): number_of_items = self.session.order_buffer(self.name, val) log.debug("Number of items retrieved: %d" % (number_of_items,)) self.put_items_on_list(number_of_items) - if self.sound == None: return - if number_of_items > 0 and self.name != "sent_tweets" and self.name != "sent_direct_messages": + if number_of_items > 0 and self.name != "sent_tweets" and self.name != "sent_direct_messages" and self.sound != None: self.session.sound.play(self.sound) + return number_of_items def get_more_items(self): elements = [] @@ -481,7 +483,13 @@ class baseBufferController(bufferController): users = utils.get_all_users(tweet, self.session.db) dm = messages.dm(self.session, _(u"Direct message to %s") % (screen_name,), _(u"New direct message"), users) if dm.message.get_response() == widgetUtils.OK: - call_threaded(self.session.api_call, call_name="send_direct_message", text=dm.message.get_text(), screen_name=dm.message.get("cb")) + val = self.session.api_call(call_name="send_direct_message", text=dm.message.get_text(), screen_name=dm.message.get("cb")) + if val != None: + if self.session.settings["general"]["reverse_timelines"] == False: + self.session.db["sent_direct_messages"].append(val) + else: + self.session.db["sent_direct_messages"].insert(0, val) + pub.sendMessage("sent-dm", data=val, user=self.session.db["user_name"]) if hasattr(dm.message, "destroy"): dm.message.destroy() @_tweets_exist @@ -638,9 +646,9 @@ class listBufferController(baseBufferController): self.list_id = list_id self.kwargs["list_id"] = list_id - def start_stream(self): + def start_stream(self, mandatory=False): self.get_user_ids() - super(listBufferController, self).start_stream() + super(listBufferController, self).start_stream(mandatory) def get_user_ids(self): self.users = [] @@ -762,15 +770,16 @@ class peopleBufferController(baseBufferController): call_threaded(self.session.api_call, call_name="update_status_with_media", _sound="reply_send.ogg", status=message.message.get_text(), media=message.file) if hasattr(message.message, "destroy"): message.message.destroy() - def start_stream(self): + def start_stream(self, mandatory=False): # starts stream every 3 minutes. current_time = time.time() - if self.execution_time == 0 or current_time-self.execution_time >= 180: + if self.execution_time == 0 or current_time-self.execution_time >= 180 or mandatory==True: self.execution_time = current_time log.debug("Starting stream for %s buffer, %s account" % (self.name, self.account,)) log.debug("args: %s, kwargs: %s" % (self.args, self.kwargs)) val = self.session.get_cursored_stream(self.name, self.function, *self.args, **self.kwargs) self.put_items_on_list(val) + return val def get_more_items(self): try: @@ -875,6 +884,7 @@ class searchBufferController(baseBufferController): self.put_items_on_list(num) if num > 0: self.session.sound.play("search_updated.ogg") + return num def remove_buffer(self): dlg = commonMessageDialogs.remove_buffer() @@ -914,6 +924,7 @@ class searchPeopleBufferController(peopleBufferController): self.put_items_on_list(number_of_items) if number_of_items > 0: self.session.sound.play("search_updated.ogg") + return number_of_items def remove_buffer(self): dlg = commonMessageDialogs.remove_buffer() @@ -1070,6 +1081,7 @@ class conversationBufferController(searchBufferController): self.put_items_on_list(number_of_items) if number_of_items > 0: self.session.sound.play("search_updated.ogg") + return number_of_items def remove_buffer(self): dlg = commonMessageDialogs.remove_buffer() diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 8df5b1b9..4be9fff7 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -118,6 +118,7 @@ class Controller(object): pub.subscribe(self.manage_unblocked_user, "unblocked-user") pub.subscribe(self.manage_item_in_timeline, "item-in-timeline") pub.subscribe(self.manage_item_in_list, "item-in-list") + pub.subscribe(self.restart_streams, "restart_streams") widgetUtils.connect_event(self.view, widgetUtils.CLOSE_EVENT, self.exit_) def bind_other_events(self): @@ -1459,5 +1460,21 @@ class Controller(object): if hasattr(self, action): getattr(self, action)() + def restart_streams(self, session): + for i in self.buffers: + if i.session != None and i.session.session_id == session: + i.start_stream() + def __del__(self): - config.app.write() \ No newline at end of file + config.app.write() + + def update_buffer(self, *args, **kwargs): + bf = self.get_current_buffer() + if not hasattr(bf, "start_stream"): + output.speak(_(u"Unable to update this buffer.")) + return + else: + output.speak(_(u"Updating buffer...")) + n = bf.start_stream(mandatory=True) + if n != None: + output.speak(_(u"{0} items retrieved").format(n,)) \ No newline at end of file diff --git a/src/keymaps/Chicken Nugget.keymap b/src/keymaps/Chicken Nugget.keymap index bf0a1cc6..607d55f7 100644 --- a/src/keymaps/Chicken Nugget.keymap +++ b/src/keymaps/Chicken Nugget.keymap @@ -31,4 +31,5 @@ find = string(default="control+win+shift+/") check_for_updates = string(default="alt+win+u) list_manager = string(default="control+win+shift+l") configuration = string(default="control+win+o") -accountConfiguration = string(default="control+win+shift+o") \ No newline at end of file +accountConfiguration = string(default="control+win+shift+o") +update_buffer = string(default="control+win+shift+u") \ No newline at end of file diff --git a/src/keymaps/Qwitter.keymap b/src/keymaps/Qwitter.keymap index dcab193e..43e22585 100644 --- a/src/keymaps/Qwitter.keymap +++ b/src/keymaps/Qwitter.keymap @@ -50,4 +50,5 @@ get_trending_topics = string(default="control+win+shift+t") check_for_updates = string(default="control+win+u") list_manager = string(default="control+win+shift+l") configuration = string(default="control+win+o") -accountConfiguration = string(default="control+win+shift+o") \ No newline at end of file +accountConfiguration = string(default="control+win+shift+o") +update_buffer = string(default="control+win+shift+u") \ No newline at end of file diff --git a/src/keymaps/Windows 10.keymap b/src/keymaps/Windows 10.keymap index bc4c23f8..33c64d88 100644 --- a/src/keymaps/Windows 10.keymap +++ b/src/keymaps/Windows 10.keymap @@ -52,4 +52,5 @@ get_trending_topics = string(default="alt+win+t") check_for_updates = string(default="alt+win+u") list_manager = string(default="alt+win+shift+l") configuration = string(default="control+win+o") -accountConfiguration = string(default="control+win+shift+o") \ No newline at end of file +accountConfiguration = string(default="control+win+shift+o") +update_buffer = string(default="control+alt+shift+u") \ No newline at end of file diff --git a/src/keymaps/base.template b/src/keymaps/base.template index 7350d282..b053e65f 100644 --- a/src/keymaps/base.template +++ b/src/keymaps/base.template @@ -53,4 +53,5 @@ get_trending_topics = string(default="control+win+t") check_for_updates = string(default="control+win+u") list_manager = string(default="control+win+shift+l") configuration = string(default="control+win+o") -accountConfiguration = string(default="control+win+shift+o") \ No newline at end of file +accountConfiguration = string(default="control+win+shift+o") +update_buffer = string(default="control+win+shift+u") \ No newline at end of file diff --git a/src/keymaps/default.keymap b/src/keymaps/default.keymap index 241db4ed..c32d867d 100644 --- a/src/keymaps/default.keymap +++ b/src/keymaps/default.keymap @@ -53,4 +53,5 @@ find = string(default="control+win+{") check_for_updates = string(default="control+win+u") list_manager = string(default="control+win+shift+l") configuration = string(default="control+win+o") -accountConfiguration = string(default="control+win+shift+o") \ No newline at end of file +accountConfiguration = string(default="control+win+shift+o") +update_buffer = string(default="control+win+shift+u") \ No newline at end of file diff --git a/src/keystrokeEditor/constants.py b/src/keystrokeEditor/constants.py index 8b337180..d06d152c 100644 --- a/src/keystrokeEditor/constants.py +++ b/src/keystrokeEditor/constants.py @@ -51,4 +51,5 @@ actions = { "configuration": _(u"Opens the global settings dialogue"), "accountConfiguration": _(u"Opens the account settings dialogue"), "audio": _(u"Try to play an audio file"), +"update_buffer": _(u"Updates the buffer and retrieves possible lost items there."), } \ No newline at end of file diff --git a/src/sessionmanager/session.py b/src/sessionmanager/session.py index 7e93f593..6b912dc2 100644 --- a/src/sessionmanager/session.py +++ b/src/sessionmanager/session.py @@ -194,6 +194,7 @@ class Session(object): if report_success: output.speak(_("%s succeeded.") % action) if _sound != None: self.sound.play(_sound) + return val def search(self, name, *args, **kwargs): tl = self.twitter.twitter.search(*args, **kwargs) @@ -352,7 +353,7 @@ class Session(object): self.logged = False self.twitter = twitter.twitter.twitter() self.login(False) -# pub.sendMessage("streamError", session=self.session_id) + pub.sendMessage("restart_streams", session=self.session_id) if self.reconnection_function_active == True: return self.reconnection_function_active = True if not hasattr(self, "main_stream"):