mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-22 11:18:08 -06:00
Support for shorten and unshorten URL's on tweets has been added
This commit is contained in:
parent
05dc8e5a31
commit
cd0aab90ef
@ -1,18 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import widgetUtils
|
||||
import output
|
||||
from wxUI.dialogs import message
|
||||
import url_shortener
|
||||
import sound
|
||||
from wxUI.dialogs import message, urlList
|
||||
from extra import translator
|
||||
from twitter import utils
|
||||
|
||||
class tweet(object):
|
||||
def __init__(self, session):
|
||||
super(tweet, self).__init__()
|
||||
self.message = message.tweet(_(u"Write the tweet here"), _(u"tweet - 0 characters"), "")
|
||||
# widgetUtils.connect_event(self.message.upload_image, widgetUtils.BUTTON_PRESSED, self.upload_image)
|
||||
# widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck)
|
||||
# widgetUtils.connect_event(self.message.attach, widgetUtils.BUTTON_PRESSED, self.attach)
|
||||
# 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.text, widgetUtils.ENTERED_TEXT, self.text_processor)
|
||||
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)
|
||||
|
||||
def translate(self, event=None):
|
||||
@ -29,3 +32,42 @@ class tweet(object):
|
||||
output.speak(_(u"Translated"))
|
||||
else:
|
||||
return
|
||||
|
||||
def shorten(self, event=None):
|
||||
urls = utils.find_urls_in_text(self.message.get_text())
|
||||
if len(urls) == 0:
|
||||
output.speak(_(u"There's no URL to be shortened"))
|
||||
elif len(urls) == 1:
|
||||
self.message.set_text(self.message.get_text().replace(urls[0], url_shortener.shorten(urls[0])))
|
||||
output.speak(_(u"URL shortened"))
|
||||
elif len(urls) > 1:
|
||||
list_urls = urlList.urlList()
|
||||
list_urls.populate_list(urls)
|
||||
if list_urls.get_response() == widgetUtils.OK:
|
||||
self.message.set_text(self.message.get_text().replace(urls[list_urls.get_item()], url_shortener.shorten(list_urls.get_string())))
|
||||
output.speak(_(u"URL shortened"))
|
||||
|
||||
def unshorten(self, event=None):
|
||||
urls = utils.find_urls_in_text(self.message.get_text())
|
||||
if len(urls) == 0:
|
||||
output.speak(_(u"There's no URL to be sexpanded"))
|
||||
elif len(urls) == 1:
|
||||
self.message.set_text(self.message.get_text().replace(urls[0], url_shortener.unshorten(urls[0])))
|
||||
output.speak(_(u"URL expanded"))
|
||||
elif len(urls) > 1:
|
||||
list_urls = urlList.urlList()
|
||||
list_urls.populate_list(urls)
|
||||
if list_urls.get_response() == widgetUtils.OK:
|
||||
self.message.set_text(self.message.get_text().replace(urls[list_urls.get_item()], url_shortener.unshorten(list_urls.get_string())))
|
||||
output.speak(_(u"URL expanded"))
|
||||
|
||||
def text_processor(self, event=None):
|
||||
self.message.set_title("%s of 140 characters" % (len(self.message.get_text())))
|
||||
if len(self.message.get_text()) > 1:
|
||||
self.message.enable_button("shortenButton")
|
||||
self.message.enable_button("unshortenButton")
|
||||
else:
|
||||
self.message.disable_button("shortenButton")
|
||||
self.message.disable_button("unshortenButton")
|
||||
if len(self.message.get_text()) > 140:
|
||||
sound.player.play("max_length.ogg")
|
||||
|
@ -10,6 +10,7 @@ NO = wx.ID_NO
|
||||
#events
|
||||
CLOSE_EVENT = wx.EVT_CLOSE
|
||||
BUTTON_PRESSED = wx.EVT_BUTTON
|
||||
ENTERED_TEXT = wx.EVT_TEXT
|
||||
|
||||
def exit_application():
|
||||
wx.GetApp().ExitMainLoop()
|
||||
|
@ -27,6 +27,17 @@ class textLimited(baseDialog.BaseWXDialog):
|
||||
def set_text(self, text):
|
||||
return self.text.ChangeValue(text)
|
||||
|
||||
def set_title(self, new_title):
|
||||
return self.SetTitle(new_title)
|
||||
|
||||
def enable_button(self, buttonName):
|
||||
if getattr(self, buttonName):
|
||||
return getattr(self, buttonName).Enable()
|
||||
|
||||
def disable_button(self, buttonName):
|
||||
if getattr(self, buttonName):
|
||||
return getattr(self, buttonName).Disable()
|
||||
|
||||
def onSelect(self, ev):
|
||||
self.text.SelectAll()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user