Trending topics support has been added

This commit is contained in:
Manuel Cortez 2015-02-01 21:13:18 -06:00
parent e93f0f4980
commit 103b62719e
10 changed files with 203 additions and 1 deletions

View File

@ -439,3 +439,52 @@ class searchPeopleBufferController(searchBufferController):
self.put_items_on_list(number_of_items) self.put_items_on_list(number_of_items)
if number_of_items > 0: if number_of_items > 0:
self.session.sound.play("search_updated.ogg") self.session.sound.play("search_updated.ogg")
class trendsBufferController(bufferController):
def __init__(self, parent, name, session, account, trendsFor, *args, **kwargs):
super(trendsBufferController, self).__init__(parent=parent, session=session)
self.trendsFor = trendsFor
self.session = session
self.account = account
self.invisible = True
self.buffer = buffers.trendsPanel(parent, name)
self.buffer.account = account
self.type = self.buffer.type
self.bind_events()
self.sound = "trends_updated.ogg"
self.trends = []
self.name = name
self.buffer.name = name
self.compose_function = self.compose_function_
self.get_formatted_message = self.get_message
def start_stream(self):
data = self.session.twitter.twitter.get_place_trends(id=self.trendsFor)
if not hasattr(self, "name"):
self.name = data[0]["locations"][0]["name"]
self.trends = data[0]["trends"]
self.put_items_on_the_list()
self.session.sound.play(self.sound)
def put_items_on_the_list(self):
selected_item = self.buffer.list.get_selected()
self.buffer.list.clear()
for i in self.trends:
tweet = self.compose_function(i)
self.buffer.list.insert_item(False, *tweet)
self.buffer.list.select_item(selected_item)
def compose_function_(self, trend):
return [trend["name"]]
def bind_events(self):
log.debug("Binding events...")
self.buffer.list.list.Bind(wx.EVT_CHAR_HOOK, self.get_event)
# widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.post_tweet, self.buffer.tweet)
# widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.retweet, self.buffer.retweet)
# widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.direct_message, self.buffer.dm)
# widgetUtils.connect_event(self.buffer, widgetUtils.BUTTON_PRESSED, self.reply, self.buffer.reply)
def get_message(self):
return self.compose_function(self.trends[self.buffer.list.get_selected()])[0]

View File

@ -24,6 +24,7 @@ if platform.system() == "Windows":
import keystrokeEditor import keystrokeEditor
from keyboard_handler.wx_handler import WXKeyboardHandler from keyboard_handler.wx_handler import WXKeyboardHandler
import userActionsController import userActionsController
import trendingTopics
log = logging.getLogger("mainController") log = logging.getLogger("mainController")
@ -96,6 +97,7 @@ class Controller(object):
pub.subscribe(self.create_new_buffer, "create-new-buffer") pub.subscribe(self.create_new_buffer, "create-new-buffer")
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.show_hide, menuitem=self.view.show_hide) 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.search, menuitem=self.view.menuitem_search)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.get_trending_topics, menuitem=self.view.trends)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.learn_sounds, menuitem=self.view.sounds_tutorial) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.learn_sounds, menuitem=self.view.sounds_tutorial)
widgetUtils.connect_event(self.view, widgetUtils.MENU, self.accountConfiguration, menuitem=self.view.account_settings) 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) widgetUtils.connect_event(self.view, widgetUtils.MENU, self.configuration, menuitem=self.view.prefs)
@ -473,6 +475,19 @@ class Controller(object):
def toggle_autoread(self): def toggle_autoread(self):
pass pass
def get_trending_topics(self, *args, **kwargs):
buff = self.get_best_buffer()
trends = trendingTopics.trendingTopicsController(buff.session)
if trends.dialog.get_response() == widgetUtils.OK:
woeid = trends.get_woeid()
buffer = buffersController.trendsBufferController(self.view.nb, "%s_tt" % (woeid,), buff.session, buff.account, woeid)
self.buffers.append(buffer)
self.view.insert_buffer(buffer.buffer, name=_(u"Trending topics for %s") % (trends.get_string()), pos=self.view.search(buff.session.db["user_name"], buff.session.db["user_name"]))
buffer.start_stream()
timer = RepeatingTimer(300, buffer.start_stream)
timer.start()
buffer.session.settings["other_buffers"]["trending_topic_buffers"].append(woeid)
def skip_buffer(self, forward=True): def skip_buffer(self, forward=True):
buff = self.get_current_buffer() buff = self.get_current_buffer()
if buff.invisible == False: if buff.invisible == False:
@ -626,6 +641,7 @@ class Controller(object):
def audio(self, *args, **kwargs): def audio(self, *args, **kwargs):
self.get_current_buffer().audio() self.get_current_buffer().audio()
def volume_down(self, *args, **kwargs): def volume_down(self, *args, **kwargs):
self.get_current_buffer().volume_down() self.get_current_buffer().volume_down()

View File

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
from wxUI.dialogs import trends
import widgetUtils
class trendingTopicsController(object):
def __init__(self, session):
super(trendingTopicsController, self).__init__()
self.countries = {}
self.cities = {}
self.dialog = trends.trendingTopicsDialog()
self.information = session.twitter.twitter.get_available_trends()
self.split_information()
widgetUtils.connect_event(self.dialog.country, widgetUtils.RADIOBUTTON, self.get_places)
widgetUtils.connect_event(self.dialog.city, widgetUtils.RADIOBUTTON, self.get_places)
self.get_places()
def split_information(self):
for i in self.information:
if i["placeType"]["name"] == "Country":
self.countries[i["name"]] = i["woeid"]
else:
self.cities[i["name"]] = i["woeid"]
def get_places(self, event=None):
values = []
if self.dialog.get_active() == "country":
for i in self.information:
if i["placeType"]["name"] == "Country":
values.append(i["name"])
elif self.dialog.get_active() == "city":
for i in self.information:
if i["placeType"]["name"] != "Country":
values.append(i["name"])
self.dialog.set(values)
def get_woeid(self):
selected = self.dialog.get_item()
if self.dialog.get_active() == "country":
woeid = self.countries[selected]
else:
woeid = self.cities[selected]
return woeid
def get_string(self):
return self.dialog.get_item()

View File

@ -13,6 +13,7 @@ from twitter import utils
from twython import TwythonError, TwythonRateLimitError, TwythonAuthError from twython import TwythonError, TwythonRateLimitError, TwythonAuthError
from config_utils import Configuration, ConfigurationResetException from config_utils import Configuration, ConfigurationResetException
from mysc.thread_utils import stream_threaded from mysc.thread_utils import stream_threaded
from pubsub import pub
log = logging.getLogger("sessionmanager.session") log = logging.getLogger("sessionmanager.session")
sessions = {} sessions = {}

View File

@ -24,6 +24,7 @@ MENU = wx.EVT_MENU
KEYPRESS = wx.EVT_CHAR_HOOK KEYPRESS = wx.EVT_CHAR_HOOK
KEYUP = wx.EVT_KEY_UP KEYUP = wx.EVT_KEY_UP
NOTEBOOK_PAGE_CHANGED = wx.EVT_TREEBOOK_PAGE_CHANGED NOTEBOOK_PAGE_CHANGED = wx.EVT_TREEBOOK_PAGE_CHANGED
RADIOBUTTON = wx.EVT_RADIOBUTTON
def exit_application(): def exit_application():
""" Closes the current window cleanly. """ """ Closes the current window cleanly. """
wx.GetApp().ExitMainLoop() wx.GetApp().ExitMainLoop()

View File

@ -6,5 +6,6 @@ from favourites import favsPanel
from lists import listPanel from lists import listPanel
from panels import accountPanel, emptyPanel from panels import accountPanel, emptyPanel
from people import peoplePanel from people import peoplePanel
from trends import trendsPanel
from tweet_searches import searchPanel from tweet_searches import searchPanel
from user_searches import searchUsersPanel from user_searches import searchUsersPanel

View File

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
import wx
from multiplatform_widgets import widgets
class trendsPanel(wx.Panel):
def create_list(self):
""" Returns the list for put the tweets here."""
self.list = widgets.list(self, _(u"Trending topic"), style=wx.LC_REPORT|wx.LC_SINGLE_SEL|wx.LC_VRULES)
self.list.set_windows_size(0, 30)
self.list.set_size()
def __init__(self, parent, name):
super(trendsPanel, self).__init__(parent)
self.type = "trends"
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.create_list()
self.tweet = wx.Button(self, -1, _(u"Tweet"))
self.tweetTrendBtn = wx.Button(self, -1, _(u"Tweet about this trend"))
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
btnSizer.Add(self.tweet, 0, wx.ALL, 5)
btnSizer.Add(self.tweetTrendBtn, 0, wx.ALL, 5)
self.sizer.Add(btnSizer, 0, wx.ALL, 5)
self.sizer.Add(self.list.list, 0, wx.ALL, 5)
self.SetSizer(self.sizer)

View File

@ -1 +1 @@
import baseDialog, configuration, lists, message, search, show_user, update_profile, urlList import baseDialog, trends, configuration, lists, message, search, show_user, update_profile, urlList

View File

@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
import baseDialog
import wx
class trendingTopicsDialog(baseDialog.BaseWXDialog):
def __init__(self):
super(trendingTopicsDialog, self).__init__(None, -1)
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
self.SetTitle(_(u"View trending topics"))
label = wx.StaticText(panel, -1, _(u"Trending topics by"))
sizer.Add(label, 0, wx.ALL, 5)
self.country = wx.RadioButton(panel, -1, _(u"Country"), style=wx.RB_GROUP)
self.city = wx.RadioButton(panel, -1, _(u"City"))
radioSizer = wx.BoxSizer(wx.HORIZONTAL)
radioSizer.Add(label, 0, wx.ALL, 5)
radioSizer.Add(self.country, 0, wx.ALL, 5)
radioSizer.Add(self.city, 0, wx.ALL, 5)
sizer.Add(radioSizer, 0, wx.ALL, 5)
label = wx.StaticText(panel, -1, _(u"Location"))
self.location = wx.ListBox(panel, -1, choices=[], style=wx.CB_READONLY)
locationBox = wx.BoxSizer(wx.HORIZONTAL)
locationBox.Add(label, 0, wx.ALL, 5)
locationBox.Add(self.location, 0, wx.ALL, 5)
sizer.Add(locationBox, 0, wx.ALL, 5)
ok = wx.Button(panel, wx.ID_OK, _(u"OK"))
ok.SetDefault()
cancel = wx.Button(panel, wx.ID_CANCEL, _(u"Close"))
btnsizer = wx.BoxSizer()
btnsizer.Add(ok, 0, wx.ALL, 5)
btnsizer.Add(cancel, 0, wx.ALL, 5)
sizer.Add(btnsizer, 0, wx.ALL, 5)
panel.SetSizer(sizer)
self.SetClientSize(sizer.CalcMin())
def get_active(self):
if self.country.GetValue() == True:
return "country"
else:
return "city"
def get_item(self):
return self.location.GetStringSelection()
def set(self, values):
self.location.Set(values)

View File

@ -12,9 +12,12 @@ class mainFrame(wx.Frame):
# Application menu # Application menu
app = wx.Menu() app = wx.Menu()
self.updateProfile = app.Append(wx.NewId(), _(u"&Update profile")) self.updateProfile = app.Append(wx.NewId(), _(u"&Update profile"))
self.updateProfile.Enable(False)
self.show_hide = app.Append(wx.NewId(), _(u"&Hide window")) self.show_hide = app.Append(wx.NewId(), _(u"&Hide window"))
self.menuitem_search = app.Append(wx.NewId(), _(u"&Search")) self.menuitem_search = app.Append(wx.NewId(), _(u"&Search"))
self.trends = app.Append(wx.NewId(), _(u"View &trending topics"))
self.lists = app.Append(wx.NewId(), _(u"&Lists manager")) self.lists = app.Append(wx.NewId(), _(u"&Lists manager"))
self.lists.Enable(True)
self.sounds_tutorial = app.Append(wx.NewId(), _(u"Sounds &tutorial")) self.sounds_tutorial = app.Append(wx.NewId(), _(u"Sounds &tutorial"))
self.keystroke_editor = app.Append(wx.NewId(), _(u"&Edit keystrokes")) self.keystroke_editor = app.Append(wx.NewId(), _(u"&Edit keystrokes"))
self.account_settings = app.Append(wx.NewId(), _(u"Account se&ttings")) self.account_settings = app.Append(wx.NewId(), _(u"Account se&ttings"))
@ -42,27 +45,43 @@ class mainFrame(wx.Frame):
self.unblock = user.Append(wx.NewId(), _(u"Unb&lock")) self.unblock = user.Append(wx.NewId(), _(u"Unb&lock"))
self.dm = user.Append(wx.NewId(), _(u"Direct me&ssage")) self.dm = user.Append(wx.NewId(), _(u"Direct me&ssage"))
self.addToList = user.Append(wx.NewId(), _(u"&Add to list")) self.addToList = user.Append(wx.NewId(), _(u"&Add to list"))
self.addToList.Enable(False)
self.removeFromList = user.Append(wx.NewId(), _(u"R&emove from list")) self.removeFromList = user.Append(wx.NewId(), _(u"R&emove from list"))
self.removeFromList.Enable(False)
self.viewLists = user.Append(wx.NewId(), _(u"&View lists")) self.viewLists = user.Append(wx.NewId(), _(u"&View lists"))
self.viewLists.Enable(False)
self.details = user.Append(wx.NewId(), _(u"Show user &profile")) self.details = user.Append(wx.NewId(), _(u"Show user &profile"))
self.details.Enable(False)
self.timeline = user.Append(wx.NewId(), _(u"&Timeline")) self.timeline = user.Append(wx.NewId(), _(u"&Timeline"))
self.timeline.Enable(False)
self.favs = user.Append(wx.NewId(), _(u"V&iew favourites")) self.favs = user.Append(wx.NewId(), _(u"V&iew favourites"))
self.favs.Enable(False)
# buffer menu # buffer menu
buffer = wx.Menu() buffer = wx.Menu()
self.mute = buffer.Append(wx.NewId(), _(u"&Mute")) self.mute = buffer.Append(wx.NewId(), _(u"&Mute"))
self.mute.Enable(False)
self.autoread = buffer.Append(wx.NewId(), _(u"&Autoread tweets for this buffer")) self.autoread = buffer.Append(wx.NewId(), _(u"&Autoread tweets for this buffer"))
self.autoread.Enable(False)
self.clear = buffer.Append(wx.NewId(), _(u"&Clear buffer")) self.clear = buffer.Append(wx.NewId(), _(u"&Clear buffer"))
self.clear.Enable(False)
self.deleteTl = buffer.Append(wx.NewId(), _(u"&Remove buffer")) self.deleteTl = buffer.Append(wx.NewId(), _(u"&Remove buffer"))
self.deleteTl.Enable(False)
# Help Menu # Help Menu
help = wx.Menu() help = wx.Menu()
self.doc = help.Append(-1, _(u"&Documentation")) self.doc = help.Append(-1, _(u"&Documentation"))
self.doc.Enable(False)
self.changelog = help.Append(wx.NewId(), _(u"&What's new in this version?")) self.changelog = help.Append(wx.NewId(), _(u"&What's new in this version?"))
self.changelog.Enable(False)
self.check_for_updates = help.Append(wx.NewId(), _(u"&Check for updates")) self.check_for_updates = help.Append(wx.NewId(), _(u"&Check for updates"))
self.check_for_updates.Enable(False)
self.reportError = help.Append(wx.NewId(), _(u"&Report an error")) self.reportError = help.Append(wx.NewId(), _(u"&Report an error"))
self.reportError.Enable(False)
self.visit_website = help.Append(-1, _(u"TW Blue &website")) self.visit_website = help.Append(-1, _(u"TW Blue &website"))
self.visit_website.Enable(False)
self.about = help.Append(-1, _(u"About &TW Blue")) self.about = help.Append(-1, _(u"About &TW Blue"))
self.about.Enable(False)
# Add all to the menu Bar # Add all to the menu Bar
menuBar.Append(app, _(u"&Application")) menuBar.Append(app, _(u"&Application"))