Multiline in tweets, searches improvements and visual changes

This commit is contained in:
Manuel Cortez 2015-03-20 17:04:39 -06:00
parent ee006eeb66
commit a63d6eceb1
11 changed files with 98 additions and 58 deletions

View File

@ -231,7 +231,7 @@ class baseBufferController(bufferController):
if self.session.settings["general"]["reverse_timelines"] == False: if self.session.settings["general"]["reverse_timelines"] == False:
last_id = self.session.db[self.name][0]["id"] last_id = self.session.db[self.name][0]["id"]
else: else:
last_id = self.session.db[self.name_buffer][-1]["id"] last_id = self.session.db[self.name][-1]["id"]
try: try:
items = self.session.get_more_items(self.function, count=self.session.settings["general"]["max_tweets_per_call"], max_id=last_id, *self.args, **self.kwargs) items = self.session.get_more_items(self.function, count=self.session.settings["general"]["max_tweets_per_call"], max_id=last_id, *self.args, **self.kwargs)
except TwythonError as e: except TwythonError as e:

View File

@ -30,6 +30,7 @@ import userActionsController
import trendingTopics import trendingTopics
import user import user
import webbrowser import webbrowser
from long_tweets import twishort
log = logging.getLogger("mainController") log = logging.getLogger("mainController")
@ -375,12 +376,12 @@ class Controller(object):
if dlg.get("tweets") == True: if dlg.get("tweets") == True:
if term not in buffer.session.settings["other_buffers"]["tweet_searches"]: if term not in buffer.session.settings["other_buffers"]["tweet_searches"]:
buffer.session.settings["other_buffers"]["tweet_searches"].append(term) buffer.session.settings["other_buffers"]["tweet_searches"].append(term)
search = buffersController.searchBufferController(self.view.nb, "search", "%s-searchterm" % (term,), buffer.session, buffer.session.db["user_name"], bufferType="searchPanel", q=term, count=buffer.settings["general"]["max_tweets_per_call"]) search = buffersController.searchBufferController(self.view.nb, "search", "%s-searchterm" % (term,), buffer.session, buffer.session.db["user_name"], bufferType="searchPanel", q=term, count=buffer.session.settings["general"]["max_tweets_per_call"])
else: else:
log.error("A buffer for the %s search term is already created. You can't create a duplicate buffer." % (term,)) log.error("A buffer for the %s search term is already created. You can't create a duplicate buffer." % (term,))
return return
elif dlg.get("users") == True: elif dlg.get("users") == True:
search = buffersController.searchPeopleBufferController(self.view.nb, "search_users", "%s-searchUser" % (term,), buffer.session, buffer.session.db["user_name"], bufferType=None, q=term, count=buffer.settings["general"]["max_tweets_per_call"]) search = buffersController.searchPeopleBufferController(self.view.nb, "search_users", "%s-searchUser" % (term,), buffer.session, buffer.session.db["user_name"], bufferType=None, q=term, count=buffer.session.settings["general"]["max_tweets_per_call"])
self.buffers.append(search) self.buffers.append(search)
search.start_stream() search.start_stream()
self.view.insert_buffer(search.buffer, name=_(u"Search for {}".format(term)), pos=self.view.search("searches", buffer.session.db["user_name"])) self.view.insert_buffer(search.buffer, name=_(u"Search for {}".format(term)), pos=self.view.search("searches", buffer.session.db["user_name"]))
@ -597,8 +598,14 @@ class Controller(object):
buffer = self.get_current_buffer() buffer = self.get_current_buffer()
if buffer.type == "baseBuffer" or buffer.type == "favourites_timeline" or buffer.type == "list" or buffer.type == "search": if buffer.type == "baseBuffer" or buffer.type == "favourites_timeline" or buffer.type == "list" or buffer.type == "search":
try: try:
tweet_id = buffer.get_right_tweet()["id"] tweet = buffer.get_right_tweet()
tweet_id = tweet["id"]
uri = None
if tweet.has_key("long_uri"):
uri = tweet["long_uri"]
tweet = buffer.session.twitter.twitter.show_status(id=tweet_id) tweet = buffer.session.twitter.twitter.show_status(id=tweet_id)
if uri != None:
tweet["text"] = twishort.get_full_text(uri)
msg = messages.viewTweet(tweet, ) msg = messages.viewTweet(tweet, )
except TwythonError: except TwythonError:
non_tweet = buffer.get_formatted_message() non_tweet = buffer.get_formatted_message()

View File

@ -95,7 +95,7 @@ class audioUploader(object):
self.file = tempfile.mktemp(suffix='.wav') self.file = tempfile.mktemp(suffix='.wav')
self.recording = sound.recording(self.file) self.recording = sound.recording(self.file)
self.recording.play() self.recording.play()
self.dialog.set("record", _(u"Stop recording")) self.dialog.set("record", _(u"Stop"))
output.speak(_(u"Recording")) output.speak(_(u"Recording"))
def stop_recording(self): def stop_recording(self):

View File

@ -28,6 +28,9 @@ class audioDialog(widgetUtils.BaseDialog):
super(audioDialog, self).__init__(None, -1, _(u"Attach audio")) super(audioDialog, self).__init__(None, -1, _(u"Attach audio"))
panel = wx.Panel(self) panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
btnSizer2 = wx.BoxSizer(wx.HORIZONTAL)
self.play = wx.Button(panel, -1, _(u"Play")) self.play = wx.Button(panel, -1, _(u"Play"))
self.play.Disable() self.play.Disable()
self.pause = wx.Button(panel, -1, _(u"Pause")) self.pause = wx.Button(panel, -1, _(u"Pause"))
@ -40,17 +43,23 @@ class audioDialog(widgetUtils.BaseDialog):
label = wx.StaticText(panel, -1, _(u"Upload to")) label = wx.StaticText(panel, -1, _(u"Upload to"))
self.services = wx.ComboBox(panel, -1, choices=services, value=services[0], style=wx.CB_READONLY) self.services = wx.ComboBox(panel, -1, choices=services, value=services[0], style=wx.CB_READONLY)
servicesBox = wx.BoxSizer(wx.HORIZONTAL) servicesBox = wx.BoxSizer(wx.HORIZONTAL)
servicesBox.Add(label) servicesBox.Add(label, 0, wx.ALL, 5)
servicesBox.Add(self.services) servicesBox.Add(self.services, 0, wx.ALL, 5)
self.attach = wx.Button(panel, wx.ID_OK, _(u"Attach")) self.attach = wx.Button(panel, wx.ID_OK, _(u"Attach"))
self.attach.Disable() self.attach.Disable()
cancel = wx.Button(panel, wx.ID_CANCEL, _(u"Cancel")) cancel = wx.Button(panel, wx.ID_CANCEL, _(u"Cancel"))
sizer.Add(self.play) btnSizer.Add(self.play, 0, wx.ALL, 5)
sizer.Add(self.pause) btnSizer.Add(self.pause, 0, wx.ALL, 5)
sizer.Add(self.record) btnSizer.Add(self.record, 0, wx.ALL, 5)
sizer.Add(self.attach_exists) btnSizer2.Add(self.attach_exists, 0, wx.ALL, 5)
sizer.Add(self.discard) btnSizer2.Add(self.discard, 0, wx.ALL, 5)
sizer.Add(self.attach) btnSizer2.Add(self.attach, 0, wx.ALL, 5)
btnSizer2.Add(cancel, 0, wx.ALL, 5)
sizer.Add(servicesBox, 0, wx.ALL, 5)
sizer.Add(btnSizer, 0, wx.ALL, 5)
sizer.Add(btnSizer2, 0, wx.ALL, 5)
panel.SetSizer(sizer)
self.SetClientSize(sizer.CalcMin())
def enable_control(self, control): def enable_control(self, control):
log.debug("Enabling control %s" % (control,)) log.debug("Enabling control %s" % (control,))

View File

@ -26,34 +26,35 @@ class spellCheckerDialog(wx.Dialog):
word = wx.StaticText(panel, -1, _(u"Mis-spelled word")) word = wx.StaticText(panel, -1, _(u"Mis-spelled word"))
self.word = wx.TextCtrl(panel, -1) self.word = wx.TextCtrl(panel, -1)
wordBox = wx.BoxSizer(wx.HORIZONTAL) wordBox = wx.BoxSizer(wx.HORIZONTAL)
wordBox.Add(word) wordBox.Add(word, 0, wx.ALL, 5)
wordBox.Add(self.word) wordBox.Add(self.word, 0, wx.ALL, 5)
context = wx.StaticText(panel, -1, _(u"Context")) context = wx.StaticText(panel, -1, _(u"Context"))
self.context = wx.TextCtrl(panel, -1) self.context = wx.TextCtrl(panel, -1)
contextBox = wx.BoxSizer(wx.HORIZONTAL) contextBox = wx.BoxSizer(wx.HORIZONTAL)
contextBox.Add(context) contextBox.Add(context, 0, wx.ALL, 5)
contextBox.Add(self.context) contextBox.Add(self.context, 0, wx.ALL, 5)
suggest = wx.StaticText(panel, -1, _(u"Suggestions")) suggest = wx.StaticText(panel, -1, _(u"Suggestions"))
self.suggestions = wx.ListBox(panel, -1, choices=[], style=wx.LB_SINGLE) self.suggestions = wx.ListBox(panel, -1, choices=[], style=wx.LB_SINGLE)
suggestionsBox = wx.BoxSizer(wx.HORIZONTAL) suggestionsBox = wx.BoxSizer(wx.HORIZONTAL)
suggestionsBox.Add(suggest) suggestionsBox.Add(suggest, 0, wx.ALL, 5)
suggestionsBox.Add(self.suggestions) suggestionsBox.Add(self.suggestions, 0, wx.ALL, 5)
self.ignore = wx.Button(panel, -1, _(u"Ignore")) self.ignore = wx.Button(panel, -1, _(u"Ignore"))
self.ignoreAll = wx.Button(panel, -1, _(u"Ignore all")) self.ignoreAll = wx.Button(panel, -1, _(u"Ignore all"))
self.replace = wx.Button(panel, -1, _(u"Replace")) self.replace = wx.Button(panel, -1, _(u"Replace"))
self.replaceAll = wx.Button(panel, -1, _(u"Replace all")) self.replaceAll = wx.Button(panel, -1, _(u"Replace all"))
close = wx.Button(panel, wx.ID_CANCEL) close = wx.Button(panel, wx.ID_CANCEL)
btnBox = wx.BoxSizer(wx.HORIZONTAL) btnBox = wx.BoxSizer(wx.HORIZONTAL)
btnBox.Add(self.ignore) btnBox.Add(self.ignore, 0, wx.ALL, 5)
btnBox.Add(self.ignoreAll) btnBox.Add(self.ignoreAll, 0, wx.ALL, 5)
btnBox.Add(self.replace) btnBox.Add(self.replace, 0, wx.ALL, 5)
btnBox.Add(self.replaceAll) btnBox.Add(self.replaceAll, 0, wx.ALL, 5)
btnBox.Add(close) btnBox.Add(close, 0, wx.ALL, 5)
sizer.Add(wordBox) sizer.Add(wordBox, 0, wx.ALL, 5)
sizer.Add(contextBox) sizer.Add(contextBox, 0, wx.ALL, 5)
sizer.Add(suggestionsBox) sizer.Add(suggestionsBox, 0, wx.ALL, 5)
sizer.Add(btnBox) sizer.Add(btnBox, 0, wx.ALL, 5)
panel.SetSizerAndFit(sizer) panel.SetSizer(sizer)
self.SetClientSize(sizer.CalcMin())
def get_response(self): def get_response(self):

View File

@ -17,4 +17,22 @@
# #
############################################################ ############################################################
import requests import requests
import keys
from twitter import utils
def get_twishort_uri(url):
return url.split("twishort.com/")[1]
def is_long(tweet):
long = False
for url in range(0, len(tweet["entities"]["urls"])):
if "twishort.com" in tweet["entities"]["urls"][url]["expanded_url"]:
long = get_twishort_uri(tweet["entities"]["urls"][url]["expanded_url"])
return long
def get_full_text(uri):
# try:
r = requests.get("http://api.twishort.com/1.1/get.json", params={"uri": uri, "api_key": keys.keyring.get("twishort_api_key")})
return r.json()["text"]
# except:
# return False

View File

@ -14,16 +14,15 @@ class list(object):
# self.set_size() # self.set_size()
def set_windows_size(self, column, characters_max): def set_windows_size(self, column, characters_max):
it = wx.ListItem() # it = wx.ListItem()
dc = wx.WindowDC(self.list) # dc = wx.WindowDC(self.list)
dc.SetFont(it.GetFont()) # dc.SetFont(it.GetFont())
(x, y) = dc.GetTextExtent("r"*characters_max) # (x, y) = dc.GetTextExtent("r"*characters_max)
self.list.SetColumnWidth(column, x) self.list.SetColumnWidth(column, characters_max*2)
def set_size(self): def set_size(self):
# self.list.SetSize(self.list.GetBestSize()) self.list.SetSize((self.list.GetBestSize()[0], 728))
# print self.list.GetBestSize() # self.list.SetSize((1439, 1000))
self.list.SetSize((1439, 1000))
def create_list(self, parent): def create_list(self, parent):
if self.system == "Windows": if self.system == "Windows":

View File

@ -7,6 +7,7 @@ import output
import languageHandler import languageHandler
import arrow import arrow
import logging import logging
from long_tweets import twishort
log = logging.getLogger("compose") log = logging.getLogger("compose")
def StripChars(s): def StripChars(s):
@ -26,6 +27,9 @@ chars = "abcdefghijklmnopqrstuvwxyz"
def compose_tweet(tweet, db, relative_times): def compose_tweet(tweet, db, relative_times):
""" It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is.""" """ It receives a tweet and returns a list with the user, text for the tweet or message, date and the client where user is."""
long = twishort.is_long(tweet)
if long != False:
tweet["long_uri"] = long
original_date = arrow.get(tweet["created_at"], "ddd MMM D H:m:s Z YYYY", locale="en") original_date = arrow.get(tweet["created_at"], "ddd MMM D H:m:s Z YYYY", locale="en")
if relative_times == True: if relative_times == True:
ts = original_date.humanize(locale=languageHandler.getLanguage()) ts = original_date.humanize(locale=languageHandler.getLanguage())

View File

@ -6,10 +6,10 @@ class basePanel(wx.Panel):
def create_list(self): def create_list(self):
self.list = widgets.list(self, _(u"User"), _(u"Text"), _(u"Date"), _(u"Client"), style=wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_VRULES) self.list = widgets.list(self, _(u"User"), _(u"Text"), _(u"Date"), _(u"Client"), style=wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_VRULES)
self.list.set_windows_size(0, 30) self.list.set_windows_size(0, 60)
self.list.set_windows_size(1, 160) self.list.set_windows_size(1, 320)
self.list.set_windows_size(2, 55) self.list.set_windows_size(2, 110)
self.list.set_windows_size(3, 42) self.list.set_windows_size(3, 84)
self.list.set_size() self.list.set_size()
def __init__(self, parent, name): def __init__(self, parent, name):

View File

@ -10,12 +10,12 @@ class textLimited(widgetUtils.BaseDialog):
self.panel = wx.Panel(self) self.panel = wx.Panel(self)
self.label = wx.StaticText(self.panel, -1, message) self.label = wx.StaticText(self.panel, -1, message)
self.SetTitle(str(len(text))) self.SetTitle(str(len(text)))
self.text = wx.TextCtrl(self.panel, -1, text) self.text = wx.TextCtrl(self.panel, -1, text, size=(439, -1), style=wx.TE_MULTILINE)
font = self.text.GetFont() # font = self.text.GetFont()
dc = wx.WindowDC(self.text) # dc = wx.WindowDC(self.text)
dc.SetFont(font) # dc.SetFont(font)
x, y = dc.GetTextExtent("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") # x, y = dc.GetTextExtent("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
self.text.SetSize((x, y)) # self.text.SetSize((x, y))
self.text.SetFocus() self.text.SetFocus()
self.textBox = wx.BoxSizer(wx.HORIZONTAL) self.textBox = wx.BoxSizer(wx.HORIZONTAL)
self.textBox.Add(self.label, 0, wx.ALL, 5) self.textBox.Add(self.label, 0, wx.ALL, 5)
@ -74,19 +74,19 @@ class tweet(textLimited):
self.okButton.SetDefault() self.okButton.SetDefault()
cancelButton = wx.Button(self.panel, wx.ID_CANCEL, _(u"Close"), size=wx.DefaultSize) cancelButton = wx.Button(self.panel, wx.ID_CANCEL, _(u"Close"), size=wx.DefaultSize)
self.buttonsBox1 = wx.BoxSizer(wx.HORIZONTAL) self.buttonsBox1 = wx.BoxSizer(wx.HORIZONTAL)
self.buttonsBox1.Add(self.upload_image, 0, wx.ALL, 5) self.buttonsBox1.Add(self.upload_image, 0, wx.ALL, 10)
self.buttonsBox1.Add(self.spellcheck, 0, wx.ALL, 5) self.buttonsBox1.Add(self.spellcheck, 0, wx.ALL, 10)
self.buttonsBox1.Add(self.attach, 0, wx.ALL, 5) self.buttonsBox1.Add(self.attach, 0, wx.ALL, 10)
self.mainBox.Add(self.buttonsBox1, 0, wx.ALL, 5) self.mainBox.Add(self.buttonsBox1, 0, wx.ALL, 10)
self.buttonsBox2 = wx.BoxSizer(wx.HORIZONTAL) self.buttonsBox2 = wx.BoxSizer(wx.HORIZONTAL)
self.buttonsBox2.Add(self.shortenButton, 0, wx.ALL, 5) self.buttonsBox2.Add(self.shortenButton, 0, wx.ALL, 10)
self.buttonsBox2.Add(self.unshortenButton, 0, wx.ALL, 5) self.buttonsBox2.Add(self.unshortenButton, 0, wx.ALL, 10)
self.buttonsBox2.Add(self.translateButton, 0, wx.ALL, 5) self.buttonsBox2.Add(self.translateButton, 0, wx.ALL, 10)
self.mainBox.Add(self.buttonsBox2, 0, wx.ALL, 5) self.mainBox.Add(self.buttonsBox2, 0, wx.ALL, 10)
self.ok_cancelSizer = wx.BoxSizer(wx.HORIZONTAL) self.ok_cancelSizer = wx.BoxSizer(wx.HORIZONTAL)
self.ok_cancelSizer.Add(self.autocompletionButton, 0, wx.ALL, 5) self.ok_cancelSizer.Add(self.autocompletionButton, 0, wx.ALL, 10)
self.ok_cancelSizer.Add(self.okButton, 0, wx.ALL, 5) self.ok_cancelSizer.Add(self.okButton, 0, wx.ALL, 10)
self.ok_cancelSizer.Add(cancelButton, 0, wx.ALL, 5) self.ok_cancelSizer.Add(cancelButton, 0, wx.ALL, 10)
self.mainBox.Add(self.ok_cancelSizer) self.mainBox.Add(self.ok_cancelSizer)
selectId = wx.NewId() selectId = wx.NewId()
self.Bind(wx.EVT_MENU, self.onSelect, id=selectId) self.Bind(wx.EVT_MENU, self.onSelect, id=selectId)

View File

@ -136,6 +136,8 @@ class mainFrame(wx.Frame):
# self.Maximize() # self.Maximize()
self.sizer.Layout() self.sizer.Layout()
self.SetClientSize(self.sizer.CalcMin()) self.SetClientSize(self.sizer.CalcMin())
# print self.GetSize()
def search(self, name_, account): def search(self, name_, account):
for i in range(0, self.nb.GetPageCount()): for i in range(0, self.nb.GetPageCount()):