TWBlue allows ask for comment or not in a retweet. Check account settings

This commit is contained in:
Manuel Cortez 2015-04-15 11:09:36 -05:00
parent 7565d2ea57
commit c2521f28fc
7 changed files with 132 additions and 25 deletions

View File

@ -11,6 +11,7 @@ max_tweets_per_call = integer(default=100)
reverse_timelines = boolean(default=False)
time_to_check_streams = integer(default=30)
announce_stream_status = boolean(default=True)
retweet_mode = string(default="ask")
[sound]
volume = float(default=1.0)

View File

@ -365,22 +365,33 @@ class baseBufferController(bufferController):
def retweet(self, *args, **kwargs):
tweet = self.get_right_tweet()
id = tweet["id"]
answer = commonMessageDialogs.retweet_question(self.buffer)
if answer == widgetUtils.YES:
retweet = messages.tweet(self.session, _(u"Retweet"), _(u"Add your comment to the tweet"), u"“@%s: %s" % (tweet["user"]["screen_name"], tweet["text"]), max=116-len("@%s " % (tweet["user"]["screen_name"],)), messageType="retweet")
if retweet.message.get_response() == widgetUtils.OK:
text = retweet.message.get_text()
if len(text+ u"“@%s: %s" % (tweet["user"]["screen_name"], tweet["text"])) < 140:
text = text+u"“@%s: %s" % (tweet["user"]["screen_name"], tweet["text"])
else:
text = text+" @{2} https://twitter.com/{0}/status/{1}".format(tweet["user"]["screen_name"], id, tweet["user"]["screen_name"])
if retweet.image == None:
call_threaded(self.session.api_call, call_name="update_status", _sound="retweet_send.ogg", status=text, in_reply_to_status_id=id)
else:
call_threaded(self.session.api_call, call_name="update_status", _sound="retweet_send.ogg", status=text, media=retweet.image)
if hasattr(retweet.message, "destroy"): retweet.message.destroy()
elif answer == widgetUtils.NO:
call_threaded(self.session.api_call, call_name="retweet", _sound="retweet_send.ogg", id=id)
if self.session.settings["general"]["retweet_mode"] == "ask":
answer = commonMessageDialogs.retweet_question(self.buffer)
if answer == widgetUtils.YES:
self._retweet_with_comment(tweet, id)
else:
self._direct_retweet(id)
elif self.session.settings["general"]["retweet_mode"] == "direct":
self._direct_retweet(id)
else:
self._retweet_with_comment(tweet, id)
def _retweet_with_comment(self, tweet, id):
retweet = messages.tweet(self.session, _(u"Retweet"), _(u"Add your comment to the tweet"), u"“@%s: %s" % (tweet["user"]["screen_name"], tweet["text"]), max=116-len("@%s " % (tweet["user"]["screen_name"],)), messageType="retweet")
if retweet.message.get_response() == widgetUtils.OK:
text = retweet.message.get_text()
if len(text+ u"“@%s: %s" % (tweet["user"]["screen_name"], tweet["text"])) < 140:
text = text+u"“@%s: %s" % (tweet["user"]["screen_name"], tweet["text"])
else:
text = text+" @{2} https://twitter.com/{0}/status/{1}".format(tweet["user"]["screen_name"], id, tweet["user"]["screen_name"])
if retweet.image == None:
call_threaded(self.session.api_call, call_name="update_status", _sound="retweet_send.ogg", status=text, in_reply_to_status_id=id)
else:
call_threaded(self.session.api_call, call_name="update_status", _sound="retweet_send.ogg", status=text, media=retweet.image)
if hasattr(retweet.message, "destroy"): retweet.message.destroy()
def _direct_retweet(self, id):
call_threaded(self.session.api_call, call_name="retweet", _sound="retweet_send.ogg", id=id)
def onFocus(self, *args, **kwargs):
tweet = self.get_tweet()
@ -487,6 +498,8 @@ class eventsBufferController(bufferController):
self.buffer.list.insert_item(True, *tweet)
if self.name in self.session.settings["other_buffers"]["autoread_buffers"] and self.name not in self.session.settings["other_buffers"]["muted_buffers"] and self.session.settings["sound"]["session_mute"] == False:
output.speak(" ".join(tweet))
if self.buffer.list.get_count() == 1:
self.buffer.list.select_item(0)
def clear_list(self):
dlg = commonMessageDialogs.clear_list()

View File

@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
import widgetUtils
import output
from wxUI.dialogs import lists
from twython import TwythonError
from twitter import compose, utils
class listsController(object):
def __init__(self, session, user=None):
super(listsController, self).__init__()
self.session = session
if user == None:
self.dialog = lists.listViewer()
self.dialog.populate_list(self.get_all_lists())
widgetUtils.connect_event(self.dialog.createBtn, widgetUtils.BUTTON_PRESSED, self.create_list)
widgetUtils.connect_event(self.dialog.editBtn, widgetUtils.BUTTON_PRESSED, self.edit_list)
self.dialog.get_response()
def get_all_lists(self):
return [compose.compose_list(item) for item in self.session.db["lists"]]
def create_list(self, *args, **kwargs):
dialog = lists.createListDialog()
if dialog.get_response() == widgetUtils.OK:
name = dialog.get("name")
description = dialog.get("description")
p = dialog.get("public")
if public == True:
mode = "public"
else:
mode = "private"
try:
new_list = self.session.twitter.twitter.create_list(name=name, description=description, mode=mode)
self.session.db["lists"].append(new_list)
self.dialog.lista.insert_item(False, *compose.compose_list(new_list))
except TwythonError as e:
output.speak("error %s: %s" % (e.status_code, e.msg))
dialog.destroy()
def edit_list(self, *args, **kwargs):
if self.dialog.lista.get_count() == 0: return
list = self.session.db["lists"][self.dialog.get_item()]
dialog = lists.editListDialog(list)
if dialog.get_response() == widgetUtils.OK:
name = dialog.get("name")
description = dialog.get("description")
p = dialog.get("public")
if p == True:
mode = "public"
else:
mode = "private"
try:
self.session.twitter.twitter.update_list(list_id=list["id"], name=name, description=description, mode=mode)
except TwythonError as e:
output.speak("error %s: %s" % (e.error_code, e.msg))
dialog.destroy()
def remove_list(self, *args, **kwargs):
if self.dialog.lista.get_count() == 0: return
list = self.session.db["lists"][self.dialog.get_item()]["id"]
if lists.remove_list() == widgetUtils.YES:
try:
self.session.twitter.twitter.delete_list(list_id=list)
self.session.db["lists"].pop(self.dialog.get_item())
self.dialog.lista.remove_item(self.dialog.get_item())
except TwythonError as e:
output.speak("error %s: %s" % (e.error_code, e.msg))

View File

@ -12,6 +12,7 @@ if system == "Windows":
import userActionsController
import trendingTopics
import user
import listsController
from issueReporter import issueReporter
elif system == "Linux":
from gtkUI import (view, commonMessageDialogs)
@ -124,6 +125,7 @@ class Controller(object):
pub.subscribe(self.invisible_shorcuts_changed, "invisible-shorcuts-changed")
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.show_hide, menuitem=self.view.show_hide)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.search, menuitem=self.view.menuitem_search)
# widgetUtils.connect_event(self.view, widgetUtils.MENU, self.list_manager, menuitem=self.view.lists)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.get_trending_topics, menuitem=self.view.trends)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.accountConfiguration, menuitem=self.view.account_settings)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.configuration, menuitem=self.view.prefs)
@ -432,8 +434,10 @@ class Controller(object):
def remove_from_list(self, user):
pass
def lists_manager(self):
pass
def list_manager(self, *args, **kwargs):
s = self.get_best_buffer().session
l = listsController.listsController(s)
def configuration(self, *args, **kwargs):
""" Opens the global settings dialogue."""

View File

@ -65,6 +65,13 @@ class accountSettingsController(globalSettingsController):
self.dialog.set_value("general", "apiCalls", self.config["general"]["max_api_calls"])
self.dialog.set_value("general", "itemsPerApiCall", self.config["general"]["max_tweets_per_call"])
self.dialog.set_value("general", "reverse_timelines", self.config["general"]["reverse_timelines"])
rt = self.config["general"]["retweet_mode"]
if rt == "ask":
self.dialog.set_value("general", "retweet_mode", _(u"Ask"))
elif rt == "direct":
self.dialog.set_value("general", "retweet_mode", _(u"Retweet without comments"))
else:
self.dialog.set_value("general", "retweet_mode", _(u"Retweet with comments"))
self.dialog.create_other_buffers()
self.dialog.set_value("buffers", "followers", self.config["other_buffers"]["show_followers"])
self.dialog.set_value("buffers", "friends", self.config["other_buffers"]["show_friends"])
@ -105,6 +112,13 @@ class accountSettingsController(globalSettingsController):
if self.config["general"]["reverse_timelines"] != self.dialog.get_value("general", "reverse_timelines"):
self.needs_restart = True
self.config["general"]["reverse_timelines"] = self.dialog.get_value("general", "reverse_timelines")
rt = self.dialog.get_value("general", "retweet_mode")
if rt == _(u"Ask"):
self.config["general"]["retweet_mode"] = "ask"
elif rt == _(u"Retweet without comments"):
self.config["general"]["retweet_mode"] = "direct"
else:
self.config["general"]["retweet_mode"] = "comment"
if self.config["other_buffers"]["show_followers"] != self.dialog.get_value("buffers", "followers"):
self.config["other_buffers"]["show_followers"] = self.dialog.get_value("buffers", "followers")
pub.sendMessage("create-new-buffer", buffer="followers", account=self.user, create=self.config["other_buffers"]["show_followers"])

View File

@ -48,6 +48,12 @@ class generalAccount(wx.Panel, baseDialog.BaseWXDialog):
sizer.Add(tweetsPerCallBox, 0, wx.ALL, 5)
self.reverse_timelines = wx.CheckBox(self, wx.NewId(), _(u"Inverted buffers: The newest tweets will be shown at the beginning of the lists while the oldest at the end"))
sizer.Add(self.reverse_timelines, 0, wx.ALL, 5)
lbl = wx.StaticText(self, wx.NewId(), _(u"Retweets mode"))
self.retweet_mode = wx.ComboBox(self, wx.NewId(), choices=[_(u"Ask"), _(u"Retweet without comments"), _(u"Retweet with comments")], style=wx.CB_READONLY)
rMode = wx.BoxSizer(wx.HORIZONTAL)
rMode.Add(lbl, 0, wx.ALL, 5)
rMode.Add(self.retweet_mode, 0, wx.ALL, 5)
sizer.Add(rMode, 0, wx.ALL, 5)
self.SetSizer(sizer)
class other_buffers(wx.Panel):

View File

@ -1,8 +1,9 @@
# -*- coding: utf-8 -*-
import wx
import widgetUtils
from multiplatform_widgets import widgets
class listViewer(wx.Dialog):
class listViewer(widgetUtils.BaseDialog):
def __init__(self, *args, **kwargs):
super(listViewer, self).__init__(parent=None, *args, **kwargs)
@ -48,10 +49,10 @@ class userListViewer(listViewer):
self.editBtn.Disable()
self.view.Disable()
class createListDialog(wx.Dialog):
class createListDialog(widgetUtils.BaseDialog):
def __init__(self, *args, **kwargs):
super(createListDialog, self).__init__(*args, **kwargs)
super(createListDialog, self).__init__(parent=None, *args, **kwargs)
self.SetTitle(_(u"Create a new list"))
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
@ -83,9 +84,6 @@ class createListDialog(wx.Dialog):
sizer.Add(modeBox)
sizer.Add(btnBox)
def get(self, field):
return getattr(self, field).GetValue()
class editListDialog(createListDialog):
def __init__(self, list, *args, **kwargs):
@ -120,4 +118,8 @@ class removeUserListDialog(listViewer):
self.view.Disable()
# self.subscriptors.Disable()
# self.members.Disable()
self.deleteBtn.Disable()
self.deleteBtn.Disable()
def remove_list():
return wx.MessageDialog(None, _("Do you really want to delete this list?"), _("Delete"), wx.YES_NO).ShowModal()