2014-11-12 20:41:29 -06:00
# -*- coding: utf-8 -*-
2015-04-03 16:57:08 -06:00
import platform
if platform . system ( ) == " Windows " :
import wx
from wxUI import buffers , dialogs , commonMessageDialogs
import user
elif platform . system ( ) == " Linux " :
from gi . repository import Gtk
from gtkUI import buffers , dialogs , commonMessageDialogs
import messages
2014-11-12 20:41:29 -06:00
import widgetUtils
2015-01-05 06:05:31 -06:00
import arrow
2014-11-12 20:41:29 -06:00
import webbrowser
import output
import config
import sound
2015-01-05 06:05:31 -06:00
import languageHandler
2015-01-18 17:19:39 -06:00
import logging
2015-01-05 06:05:31 -06:00
from twitter import compose , utils
2015-01-02 09:38:44 -06:00
from mysc . thread_utils import call_threaded
2015-01-05 05:33:09 -06:00
from twython import TwythonError
2015-02-26 15:21:26 -06:00
from pubsub import pub
2015-06-01 17:52:23 -05:00
from long_tweets import twishort , tweets
2014-11-12 20:41:29 -06:00
2015-01-18 17:19:39 -06:00
log = logging . getLogger ( " controller.buffers " )
2015-02-07 10:43:37 -06:00
def _tweets_exist ( function ) :
""" A decorator to execute a function only if the selected buffer contains at least one item. """
def function_ ( self , * args , * * kwargs ) :
if self . buffer . list . get_count ( ) > 0 :
function ( self , * args , * * kwargs )
return function_
2014-11-12 20:41:29 -06:00
class bufferController ( object ) :
def __init__ ( self , parent = None , function = None , session = None , * args , * * kwargs ) :
super ( bufferController , self ) . __init__ ( )
self . function = function
self . compose_function = None
self . args = args
self . kwargs = kwargs
self . buffer = None
self . account = " "
2014-12-31 00:07:27 -06:00
self . needs_init = True
2015-01-19 12:15:57 -06:00
self . invisible = False # False if the buffer will be ignored on the invisible interface.
2014-11-12 20:41:29 -06:00
2015-02-07 10:23:23 -06:00
def clear_list ( self ) : pass
2015-05-13 20:59:46 -05:00
2014-11-12 20:41:29 -06:00
def get_event ( self , ev ) :
2015-07-03 17:23:25 -05:00
if ev . GetKeyCode ( ) == wx . WXK_RETURN and ev . ControlDown ( ) : event = " audio "
2015-06-12 12:26:14 -05:00
elif ev . GetKeyCode ( ) == wx . WXK_RETURN : event = " url "
2014-11-12 20:41:29 -06:00
elif ev . GetKeyCode ( ) == wx . WXK_F5 : event = " volume_down "
elif ev . GetKeyCode ( ) == wx . WXK_F6 : event = " volume_up "
elif ev . GetKeyCode ( ) == wx . WXK_DELETE and ev . ShiftDown ( ) : event = " clear_list "
2015-01-05 05:33:09 -06:00
elif ev . GetKeyCode ( ) == wx . WXK_DELETE : event = " destroy_status "
2014-11-12 20:41:29 -06:00
else :
event = None
ev . Skip ( )
if event != None :
2015-03-17 12:24:29 -06:00
try :
getattr ( self , event ) ( )
except AttributeError :
pass
2014-11-12 20:41:29 -06:00
def volume_down ( self ) :
2015-01-20 15:40:33 -06:00
if self . session . settings [ " sound " ] [ " volume " ] > 0.0 :
if self . session . settings [ " sound " ] [ " volume " ] < = 0.05 :
self . session . settings [ " sound " ] [ " volume " ] = 0.0
2014-11-12 20:41:29 -06:00
else :
2015-01-20 15:40:33 -06:00
self . session . settings [ " sound " ] [ " volume " ] - = 0.05
2015-01-20 22:07:13 -06:00
if hasattr ( sound . URLPlayer , " stream " ) :
sound . URLPlayer . stream . volume = self . session . settings [ " sound " ] [ " volume " ]
2015-01-20 15:40:33 -06:00
self . session . sound . play ( " volume_changed.ogg " )
2014-11-12 20:41:29 -06:00
def volume_up ( self ) :
2015-01-20 15:40:33 -06:00
if self . session . settings [ " sound " ] [ " volume " ] < 1.0 :
if self . session . settings [ " sound " ] [ " volume " ] > = 0.95 :
self . session . settings [ " sound " ] [ " volume " ] = 1.0
2014-11-12 20:41:29 -06:00
else :
2015-01-20 15:40:33 -06:00
self . session . settings [ " sound " ] [ " volume " ] + = 0.05
2015-01-20 22:07:13 -06:00
if hasattr ( sound . URLPlayer , " stream " ) :
sound . URLPlayer . stream . volume = self . session . settings [ " sound " ] [ " volume " ]
2015-01-22 08:54:41 -06:00
self . session . sound . play ( " volume_changed.ogg " )
2014-11-12 20:41:29 -06:00
def start_stream ( self ) :
pass
2015-02-03 09:59:18 -06:00
def get_more_items ( self ) :
2015-04-10 09:34:24 -05:00
output . speak ( _ ( u " This action is not supported for this buffer " ) , True )
2015-02-03 09:59:18 -06:00
2014-11-12 20:41:29 -06:00
def put_items_on_list ( self , items ) :
pass
def remove_buffer ( self ) :
2015-02-25 08:39:06 -06:00
return False
2014-11-12 20:41:29 -06:00
def remove_item ( self , item ) :
self . buffer . list . remove_item ( item )
def bind_events ( self ) :
pass
def get_object ( self ) :
return self . buffer
2015-01-05 05:33:09 -06:00
def get_message ( self ) :
pass
2014-11-12 20:41:29 -06:00
def set_list_position ( self , reversed = False ) :
if reversed == False :
self . buffer . list . select_item ( - 1 )
else :
self . buffer . list . select_item ( 0 )
2015-01-02 09:38:44 -06:00
def reply ( self ) :
pass
def direct_message ( self ) :
pass
2015-01-02 10:53:33 -06:00
def retweet ( self ) :
pass
2015-01-05 05:33:09 -06:00
def destroy_status ( self ) :
pass
2015-01-05 06:05:31 -06:00
def post_tweet ( self , * args , * * kwargs ) :
title = _ ( u " Tweet " )
caption = _ ( u " Write the tweet here " )
tweet = messages . tweet ( self . session , title , caption , " " )
if tweet . message . get_response ( ) == widgetUtils . OK :
text = tweet . message . get_text ( )
if tweet . image == None :
2015-01-08 08:01:45 -06:00
call_threaded ( self . session . api_call , call_name = " update_status " , status = text )
2015-01-05 06:05:31 -06:00
else :
2015-01-08 08:01:45 -06:00
call_threaded ( self . session . api_call , call_name = " update_status_with_media " , status = text , media = tweet . image )
2015-04-03 16:57:08 -06:00
if hasattr ( tweet . message , " destroy " ) : tweet . message . destroy ( )
2015-01-05 06:05:31 -06:00
2014-11-12 20:41:29 -06:00
class accountPanel ( bufferController ) :
2015-02-26 15:21:26 -06:00
def __init__ ( self , parent , name , account , account_id ) :
2014-11-12 20:41:29 -06:00
super ( accountPanel , self ) . __init__ ( parent , None , name )
2015-01-18 17:19:39 -06:00
log . debug ( " Initializing buffer %s , account %s " % ( name , account , ) )
2014-11-12 20:41:29 -06:00
self . buffer = buffers . accountPanel ( parent , name )
self . type = self . buffer . type
self . compose_function = None
2014-12-31 00:07:27 -06:00
self . session = None
self . needs_init = False
2014-11-12 20:41:29 -06:00
self . account = account
self . buffer . account = account
self . name = name
2015-02-26 15:21:26 -06:00
self . account_id = account_id
def setup_account ( self ) :
widgetUtils . connect_event ( self . buffer , widgetUtils . CHECKBOX , self . autostart , menuitem = self . buffer . autostart_account )
2015-04-08 13:34:50 -05:00
if self . account_id in config . app [ " sessions " ] [ " ignored_sessions " ] :
2015-02-26 15:21:26 -06:00
self . buffer . change_autostart ( False )
2015-04-08 13:34:50 -05:00
else :
self . buffer . change_autostart ( True )
2015-02-26 15:21:26 -06:00
if not hasattr ( self , " logged " ) :
self . buffer . change_login ( login = False )
widgetUtils . connect_event ( self . buffer . login , widgetUtils . BUTTON_PRESSED , self . logout )
else :
2015-03-12 17:55:54 -06:00
self . buffer . change_login ( login = True )
2015-02-26 15:21:26 -06:00
widgetUtils . connect_event ( self . buffer . login , widgetUtils . BUTTON_PRESSED , self . login )
2015-04-03 16:57:08 -06:00
2015-02-26 15:21:26 -06:00
def login ( self , * args , * * kwargs ) :
del self . logged
self . setup_account ( )
pub . sendMessage ( " login " , session_id = self . account_id )
def logout ( self , * args , * * kwargs ) :
self . logged = False
self . setup_account ( )
pub . sendMessage ( " logout " , session_id = self . account_id )
def autostart ( self , * args , * * kwargs ) :
if self . account_id in config . app [ " sessions " ] [ " ignored_sessions " ] :
self . buffer . change_autostart ( True )
config . app [ " sessions " ] [ " ignored_sessions " ] . remove ( self . account_id )
else :
self . buffer . change_autostart ( False )
config . app [ " sessions " ] [ " ignored_sessions " ] . append ( self . account_id )
2014-11-12 20:41:29 -06:00
class emptyPanel ( bufferController ) :
def __init__ ( self , parent , name , account ) :
super ( emptyPanel , self ) . __init__ ( parent , None , name )
2015-01-18 17:19:39 -06:00
log . debug ( " Initializing buffer %s , account %s " % ( name , account , ) )
2014-11-12 20:41:29 -06:00
self . buffer = buffers . emptyPanel ( parent , name )
self . type = self . buffer . type
self . compose_function = None
self . account = account
self . buffer . account = account
self . name = name
2014-12-31 00:07:27 -06:00
self . session = None
self . needs_init = True
2015-01-02 09:38:44 -06:00
2014-11-12 20:41:29 -06:00
class baseBufferController ( bufferController ) :
2015-01-27 17:09:28 -06:00
def __init__ ( self , parent , function , name , sessionObject , account , sound = None , bufferType = None , * args , * * kwargs ) :
2014-11-12 20:41:29 -06:00
super ( baseBufferController , self ) . __init__ ( parent , function , * args , * * kwargs )
2015-01-18 17:19:39 -06:00
log . debug ( " Initializing buffer %s , account %s " % ( name , account , ) )
2014-11-12 20:41:29 -06:00
if bufferType != None :
self . buffer = getattr ( buffers , bufferType ) ( parent , name )
else :
self . buffer = buffers . basePanel ( parent , name )
2015-01-19 12:15:57 -06:00
self . invisible = True
2014-11-12 20:41:29 -06:00
self . name = name
self . type = self . buffer . type
self . session = sessionObject
self . compose_function = compose . compose_tweet
2015-01-18 17:19:39 -06:00
log . debug ( " Compose_function: %s " % ( self . compose_function , ) )
2014-11-12 20:41:29 -06:00
self . account = account
self . buffer . account = account
self . bind_events ( )
2015-01-27 17:09:28 -06:00
self . sound = sound
2014-11-12 20:41:29 -06:00
2015-01-25 02:38:17 -06:00
def get_formatted_message ( self ) :
if self . type == " dm " or self . name == " sent_tweets " or self . name == " sent_direct_messages " : return self . compose_function ( self . get_right_tweet ( ) , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] ) [ 1 ]
return self . get_message ( )
2015-01-05 05:33:09 -06:00
def get_message ( self ) :
2015-01-19 12:15:57 -06:00
return " " . join ( self . compose_function ( self . get_right_tweet ( ) , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] ) )
2015-01-05 05:33:09 -06:00
2015-06-01 17:52:23 -05:00
def get_full_tweet ( self ) :
tweet = self . get_right_tweet ( )
tweetsList = [ ]
tweet_id = tweet [ " id " ]
uri = None
if tweet . has_key ( " long_uri " ) :
uri = tweet [ " long_uri " ]
2015-06-13 07:35:04 -05:00
try :
tweet = self . session . twitter . twitter . show_status ( id = tweet_id )
except TwythonError as e :
utils . twitter_error ( e )
return
2015-06-01 17:52:23 -05:00
if uri != None :
tweet [ " text " ] = twishort . get_full_text ( uri )
l = tweets . is_long ( tweet )
while l != False :
tweetsList . append ( tweet )
id = tweets . get_id ( l )
2015-06-13 07:35:04 -05:00
try :
tweet = self . session . twitter . twitter . show_status ( id = id )
except TwythonError as e :
utils . twitter_error ( e )
2015-06-15 04:59:23 -05:00
return
2015-06-01 17:52:23 -05:00
l = tweets . is_long ( tweet )
if l == False :
tweetsList . append ( tweet )
return ( tweet , tweetsList )
2014-11-12 20:41:29 -06:00
def start_stream ( self ) :
2015-01-18 17:19:39 -06:00
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 ) )
2014-11-12 20:41:29 -06:00
val = self . session . call_paged ( self . function , * self . args , * * self . kwargs )
number_of_items = self . session . order_buffer ( self . name , val )
2015-01-18 17:19:39 -06:00
log . debug ( " Number of items retrieved: %d " % ( number_of_items , ) )
2014-11-12 20:41:29 -06:00
self . put_items_on_list ( number_of_items )
2015-01-27 17:09:28 -06:00
if self . sound == None : return
if number_of_items > 0 and self . name != " sent_tweets " and self . name != " sent_direct_messages " :
self . session . sound . play ( self . sound )
2014-11-12 20:41:29 -06:00
2015-02-03 09:59:18 -06:00
def get_more_items ( self ) :
2015-04-10 09:34:24 -05:00
elements = [ ]
2015-02-03 09:59:18 -06:00
if self . session . settings [ " general " ] [ " reverse_timelines " ] == False :
last_id = self . session . db [ self . name ] [ 0 ] [ " id " ]
else :
2015-03-20 17:04:39 -06:00
last_id = self . session . db [ self . name ] [ - 1 ] [ " id " ]
2015-02-03 09:59:18 -06:00
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 )
except TwythonError as e :
2015-04-10 09:34:24 -05:00
output . speak ( e . message , True )
2015-02-03 09:59:18 -06:00
for i in items :
if utils . is_allowed ( i , self . session . settings [ " twitter " ] [ " ignored_clients " ] ) == True :
2015-04-10 09:34:24 -05:00
elements . append ( i )
2015-02-03 09:59:18 -06:00
if self . session . settings [ " general " ] [ " reverse_timelines " ] == False :
self . session . db [ self . name ] . insert ( 0 , i )
else :
self . session . db [ self . name ] . append ( i )
selection = self . buffer . list . get_selected ( )
2015-04-10 09:34:24 -05:00
if self . session . settings [ " general " ] [ " reverse_timelines " ] == False :
for i in elements :
tweet = self . compose_function ( i , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] )
self . buffer . list . insert_item ( True , * tweet )
else :
for i in items :
tweet = self . compose_function ( i , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] )
self . buffer . list . insert_item ( False , * tweet )
2015-03-24 03:47:16 -06:00
# self.buffer.list.select_item(selection+elements)
# else:
self . buffer . list . select_item ( selection )
2015-04-10 09:34:24 -05:00
output . speak ( _ ( u " %s items retrieved " ) % ( str ( len ( elements ) ) ) , True )
2015-02-03 09:59:18 -06:00
2015-02-11 16:14:25 -06:00
def remove_buffer ( self ) :
2015-03-19 05:34:18 -06:00
if " -timeline " in self . name :
2015-02-11 16:14:25 -06:00
dlg = commonMessageDialogs . remove_buffer ( )
if dlg == widgetUtils . YES :
2015-02-12 13:18:24 -06:00
if self . name [ : - 9 ] in self . session . settings [ " other_buffers " ] [ " timelines " ] :
self . session . settings [ " other_buffers " ] [ " timelines " ] . remove ( self . name [ : - 9 ] )
2015-02-12 10:35:13 -06:00
return True
elif dlg == widgetUtils . NO :
return False
2015-03-17 05:12:29 -06:00
elif " favorite " in self . name :
dlg = commonMessageDialogs . remove_buffer ( )
if dlg == widgetUtils . YES :
if self . name [ : - 9 ] in self . session . settings [ " other_buffers " ] [ " favourites_timelines " ] :
self . session . settings [ " other_buffers " ] [ " favourites_timelines " ] . remove ( self . name [ : - 9 ] )
return True
elif dlg == widgetUtils . NO :
return False
2015-02-11 16:14:25 -06:00
else :
2015-04-10 09:34:24 -05:00
output . speak ( _ ( u " This buffer is not a timeline; it can ' t be deleted. " ) , True )
2015-02-12 10:35:13 -06:00
return False
2015-02-11 16:14:25 -06:00
2014-11-12 20:41:29 -06:00
def put_items_on_list ( self , number_of_items ) :
2015-01-18 17:19:39 -06:00
log . debug ( " The list contains %d items " % ( self . buffer . list . get_count ( ) , ) )
log . debug ( " Putting %d items on the list " % ( number_of_items , ) )
2014-11-12 20:41:29 -06:00
if self . buffer . list . get_count ( ) == 0 :
for i in self . session . db [ self . name ] :
tweet = self . compose_function ( i , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] )
2015-03-28 05:02:17 -06:00
self . buffer . list . insert_item ( False , * tweet )
2015-01-22 08:54:41 -06:00
self . buffer . set_position ( self . session . settings [ " general " ] [ " reverse_timelines " ] )
2014-11-12 20:41:29 -06:00
elif self . buffer . list . get_count ( ) > 0 :
if self . session . settings [ " general " ] [ " reverse_timelines " ] == False :
for i in self . session . db [ self . name ] [ : number_of_items ] :
tweet = self . compose_function ( i , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] )
self . buffer . list . insert_item ( False , * tweet )
else :
for i in self . session . db [ self . name ] [ 0 : number_of_items ] :
tweet = self . compose_function ( i , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] )
self . buffer . list . insert_item ( True , * tweet )
2015-01-18 17:19:39 -06:00
log . debug ( " Now the list contains %d items " % ( self . buffer . list . get_count ( ) , ) )
2014-11-12 20:41:29 -06:00
def add_new_item ( self , item ) :
tweet = self . compose_function ( item , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] )
if self . session . settings [ " general " ] [ " reverse_timelines " ] == False :
self . buffer . list . insert_item ( False , * tweet )
else :
self . buffer . list . insert_item ( True , * tweet )
2015-03-11 17:17:29 -06:00
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 :
2015-02-07 10:23:23 -06:00
output . speak ( " " . join ( tweet [ : 2 ] ) )
2015-05-12 13:53:23 -05:00
#Improve performance on Windows
if platform . system ( ) == " Windows " :
call_threaded ( utils . is_audio , item )
2014-11-12 20:41:29 -06:00
def bind_events ( self ) :
2015-01-18 17:19:39 -06:00
log . debug ( " Binding events... " )
2015-04-04 21:25:52 -06:00
self . buffer . set_focus_function ( self . onFocus )
2015-04-10 09:34:24 -05:00
widgetUtils . connect_event ( self . buffer . list . list , widgetUtils . KEYPRESS , self . get_event )
2015-01-05 06:05:31 -06:00
widgetUtils . connect_event ( self . buffer , widgetUtils . BUTTON_PRESSED , self . post_tweet , self . buffer . tweet )
# if self.type == "baseBuffer":
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 )
2014-11-12 20:41:29 -06:00
def get_tweet ( self ) :
if self . session . db [ self . name ] [ self . buffer . list . get_selected ( ) ] . has_key ( " retweeted_status " ) :
tweet = self . session . db [ self . name ] [ self . buffer . list . get_selected ( ) ] [ " retweeted_status " ]
else :
tweet = self . session . db [ self . name ] [ self . buffer . list . get_selected ( ) ]
return tweet
2015-01-02 09:38:44 -06:00
def get_right_tweet ( self ) :
tweet = self . session . db [ self . name ] [ self . buffer . list . get_selected ( ) ]
return tweet
2015-02-07 10:43:37 -06:00
@_tweets_exist
2015-01-05 06:05:31 -06:00
def reply ( self , * args , * * kwargs ) :
2015-01-02 09:38:44 -06:00
tweet = self . get_right_tweet ( )
screen_name = tweet [ " user " ] [ " screen_name " ]
id = tweet [ " id " ]
users = utils . get_all_mentioned ( tweet , self . session . db )
2015-01-20 15:40:33 -06:00
message = messages . reply ( self . session , _ ( u " Reply " ) , _ ( u " Reply to %s " ) % ( screen_name , ) , " @ %s " % ( screen_name , ) , users )
2015-01-02 09:38:44 -06:00
if message . message . get_response ( ) == widgetUtils . OK :
if message . image == None :
2015-01-13 12:31:37 -06:00
call_threaded ( self . session . api_call , call_name = " update_status " , _sound = " reply_send.ogg " , in_reply_to_status_id = id , status = message . message . get_text ( ) )
2015-01-02 09:38:44 -06:00
else :
2015-01-13 12:31:37 -06:00
call_threaded ( self . session . api_call , call_name = " update_status_with_media " , _sound = " reply_send.ogg " , in_reply_to_status_id = id , status = message . message . get_text ( ) , media = message . file )
2015-04-03 16:57:08 -06:00
if hasattr ( message . message , " destroy " ) : message . message . destroy ( )
2015-01-02 09:38:44 -06:00
2015-02-07 10:43:37 -06:00
@_tweets_exist
2015-01-05 06:05:31 -06:00
def direct_message ( self , * args , * * kwargs ) :
2015-03-11 16:36:22 -06:00
tweet = self . get_right_tweet ( )
2015-01-02 09:38:44 -06:00
if self . type == " dm " :
screen_name = tweet [ " sender " ] [ " screen_name " ]
users = utils . get_all_users ( tweet , self . session . db )
elif self . type == " people " :
screen_name = tweet [ " screen_name " ]
users = [ screen_name ]
else :
screen_name = tweet [ " user " ] [ " screen_name " ]
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 :
2015-01-08 08:01:45 -06:00
call_threaded ( self . session . api_call , call_name = " send_direct_message " , text = dm . message . get_text ( ) , screen_name = dm . message . get ( " cb " ) )
2015-04-03 16:57:08 -06:00
if hasattr ( dm . message , " destroy " ) : dm . message . destroy ( )
2015-01-02 09:38:44 -06:00
2015-02-07 10:43:37 -06:00
@_tweets_exist
2015-01-05 06:05:31 -06:00
def retweet ( self , * args , * * kwargs ) :
2015-01-02 10:53:33 -06:00
tweet = self . get_right_tweet ( )
id = tweet [ " id " ]
2015-04-15 11:09:36 -05:00
if self . session . settings [ " general " ] [ " retweet_mode " ] == " ask " :
answer = commonMessageDialogs . retweet_question ( self . buffer )
if answer == widgetUtils . YES :
self . _retweet_with_comment ( tweet , id )
2015-04-27 16:08:02 -05:00
elif answer == widgetUtils . NO :
2015-04-15 11:09:36 -05:00
self . _direct_retweet ( id )
elif self . session . settings [ " general " ] [ " retweet_mode " ] == " direct " :
self . _direct_retweet ( id )
else :
self . _retweet_with_comment ( tweet , id )
2015-05-04 10:42:28 -05:00
def _retweet_with_comment ( self , tweet , id , comment = ' ' ) :
2015-04-15 11:09:36 -05:00
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 " )
2015-05-04 10:42:28 -05:00
if comment != ' ' :
retweet . message . set_text ( comment )
2015-04-15 11:09:36 -05:00
if retweet . message . get_response ( ) == widgetUtils . OK :
text = retweet . message . get_text ( )
2015-05-04 10:42:28 -05:00
comments = text
2015-04-15 11:09:36 -05:00
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 :
2015-05-04 10:42:28 -05:00
answer = commonMessageDialogs . retweet_as_link ( self . buffer )
if answer == widgetUtils . YES :
text = text + " @ {2} https://twitter.com/ {0} /status/ {1} " . format ( tweet [ " user " ] [ " screen_name " ] , id , tweet [ " user " ] [ " screen_name " ] )
else :
return self . _retweet_with_comment ( tweet , id , comment = comments )
2015-04-15 11:09:36 -05:00
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 )
2015-01-02 10:53:33 -06:00
2015-04-04 21:25:52 -06:00
def onFocus ( self , * args , * * kwargs ) :
2014-11-12 20:41:29 -06:00
tweet = self . get_tweet ( )
2015-04-04 21:25:52 -06:00
if platform . system ( ) == " Windows " and self . session . settings [ " general " ] [ " relative_times " ] == True :
2015-01-05 06:05:31 -06:00
# fix this:
2015-01-19 12:15:57 -06:00
original_date = arrow . get ( self . session . db [ self . name ] [ self . buffer . list . get_selected ( ) ] [ " created_at " ] , " ddd MMM D H:m:s Z YYYY " , locale = " en " )
2015-01-05 06:05:31 -06:00
ts = original_date . humanize ( locale = languageHandler . getLanguage ( ) )
2014-11-12 20:41:29 -06:00
self . buffer . list . list . SetStringItem ( self . buffer . list . get_selected ( ) , 2 , ts )
if utils . is_audio ( tweet ) :
2015-01-20 15:40:33 -06:00
self . session . sound . play ( " audio.ogg " )
2015-02-03 05:10:01 -06:00
if utils . is_geocoded ( tweet ) :
self . session . sound . play ( " geo.ogg " )
2015-05-11 19:25:35 -05:00
self . session . db [ str ( self . name + " _pos " ) ] = self . buffer . list . get_selected ( )
2015-06-01 11:18:39 -05:00
2015-02-07 10:43:37 -06:00
@_tweets_exist
2015-05-12 10:30:56 -05:00
def audio ( self , url = ' ' ) :
2015-05-16 13:25:38 -05:00
if hasattr ( sound . URLPlayer , ' stream ' ) :
return sound . URLPlayer . stop_audio ( delete = True )
2014-11-12 20:41:29 -06:00
tweet = self . get_tweet ( )
2015-02-07 10:43:37 -06:00
if tweet == None : return
2014-11-12 20:41:29 -06:00
urls = utils . find_urls ( tweet )
if len ( urls ) == 1 :
2015-05-12 10:30:56 -05:00
url = urls [ 0 ]
2015-03-11 16:36:22 -06:00
elif len ( urls ) > 1 :
2014-11-12 20:41:29 -06:00
urls_list = dialogs . urlList . urlList ( )
urls_list . populate_list ( urls )
if urls_list . get_response ( ) == widgetUtils . OK :
2015-05-12 10:30:56 -05:00
url = urls_list . get_string ( )
2015-04-03 16:57:08 -06:00
if hasattr ( urls_list , " destroy " ) : urls_list . destroy ( )
2015-05-12 10:30:56 -05:00
if url != ' ' :
2015-05-12 10:46:08 -05:00
try :
sound . URLPlayer . play ( url , self . session . settings [ " sound " ] [ " volume " ] )
except :
2015-05-26 20:23:02 -05:00
log . error ( " Exception while executing audio method. " )
2015-02-07 10:43:37 -06:00
@_tweets_exist
2015-05-13 16:29:58 -05:00
def url ( self , url = ' ' , announce = True ) :
2015-05-12 10:20:50 -05:00
if url == ' ' :
tweet = self . get_tweet ( )
urls = utils . find_urls ( tweet )
if len ( urls ) == 1 :
url = urls [ 0 ]
elif len ( urls ) > 1 :
urls_list = dialogs . urlList . urlList ( )
urls_list . populate_list ( urls )
if urls_list . get_response ( ) == widgetUtils . OK :
url = urls_list . get_string ( )
if hasattr ( urls_list , " destroy " ) : urls_list . destroy ( )
if url != ' ' :
2015-05-13 16:29:58 -05:00
if announce :
output . speak ( _ ( u " Opening URL... " ) , True )
2015-05-12 10:20:50 -05:00
webbrowser . open_new_tab ( url )
2014-11-12 20:41:29 -06:00
def clear_list ( self ) :
2015-02-07 10:23:23 -06:00
dlg = commonMessageDialogs . clear_list ( )
if dlg == widgetUtils . YES :
2014-11-12 20:41:29 -06:00
self . session . db [ self . name ] = [ ]
self . buffer . list . clear ( )
2015-02-07 10:43:37 -06:00
@_tweets_exist
2015-01-05 05:33:09 -06:00
def destroy_status ( self , * args , * * kwargs ) :
index = self . buffer . list . get_selected ( )
if self . type == " events " or self . type == " people " or self . type == " empty " or self . type == " account " : return
answer = commonMessageDialogs . delete_tweet_dialog ( None )
if answer == widgetUtils . YES :
2015-02-07 10:23:23 -06:00
try :
2015-03-26 16:20:21 -06:00
if self . name == " direct_messages " or self . name == " sent_direct_messages " :
2015-02-07 10:23:23 -06:00
self . session . twitter . twitter . destroy_direct_message ( id = self . get_right_tweet ( ) [ " id " ] )
else :
self . session . twitter . twitter . destroy_status ( id = self . get_right_tweet ( ) [ " id " ] )
self . session . db [ self . name ] . pop ( index )
self . buffer . list . remove_item ( index )
# if index > 0:
except TwythonError :
2015-05-14 09:09:31 -05:00
self . session . sound . play ( " error " )
2014-11-12 20:41:29 -06:00
2015-03-08 14:18:29 -06:00
@_tweets_exist
def user_details ( self ) :
2015-03-17 03:50:49 -06:00
tweet = self . get_right_tweet ( )
2015-03-08 14:18:29 -06:00
if self . type == " dm " :
users = utils . get_all_users ( tweet , self . session . db )
elif self . type == " people " :
users = [ tweet [ " screen_name " ] ]
else :
users = utils . get_all_users ( tweet , self . session . db )
dlg = dialogs . utils . selectUserDialog ( title = _ ( u " User details " ) , users = users )
if dlg . get_response ( ) == widgetUtils . OK :
user . profileController ( session = self . session , user = dlg . get_user ( ) )
2015-04-03 16:57:08 -06:00
if hasattr ( dlg , " destroy " ) : dlg . destroy ( )
2015-03-08 14:18:29 -06:00
2015-04-27 16:08:02 -05:00
class listBufferController ( baseBufferController ) :
def __init__ ( self , parent , function , name , sessionObject , account , sound = None , bufferType = None , list_id = None , * args , * * kwargs ) :
super ( listBufferController , self ) . __init__ ( parent , function , name , sessionObject , account , sound = None , bufferType = None , * args , * * kwargs )
self . users = [ ]
self . list_id = list_id
self . kwargs [ " list_id " ] = list_id
def start_stream ( self ) :
self . get_user_ids ( )
super ( listBufferController , self ) . start_stream ( )
def get_user_ids ( self ) :
self . users = [ ]
next_cursor = - 1
while ( next_cursor ) :
users = self . session . twitter . twitter . get_list_members ( list_id = self . list_id , cursor = next_cursor , include_entities = False , skip_status = True )
for i in users [ ' users ' ] :
self . users . append ( i [ " id " ] )
next_cursor = users [ " next_cursor " ]
2015-06-11 16:09:46 -05:00
def remove_buffer ( self ) :
dlg = commonMessageDialogs . remove_buffer ( )
if dlg == widgetUtils . YES :
if self . name [ : - 5 ] in self . session . settings [ " other_buffers " ] [ " lists " ] :
self . session . settings [ " other_buffers " ] [ " lists " ] . remove ( self . name [ : - 5 ] )
return True
elif dlg == widgetUtils . NO :
return False
2014-11-12 20:41:29 -06:00
class eventsBufferController ( bufferController ) :
def __init__ ( self , parent , name , session , account , * args , * * kwargs ) :
super ( eventsBufferController , self ) . __init__ ( parent , * args , * * kwargs )
2015-01-18 17:19:39 -06:00
log . debug ( " Initializing buffer %s , account %s " % ( name , account , ) )
2015-01-19 12:15:57 -06:00
self . invisible = True
2014-11-12 20:41:29 -06:00
self . buffer = buffers . eventsPanel ( parent , name )
self . name = name
self . account = account
2015-01-02 09:38:44 -06:00
self . buffer . account = self . account
2014-11-12 20:41:29 -06:00
self . compose_function = compose . compose_event
self . session = session
2015-01-05 05:33:09 -06:00
self . type = self . buffer . type
2015-01-25 02:38:17 -06:00
self . get_formatted_message = self . get_message
2015-01-05 05:33:09 -06:00
def get_message ( self ) :
2015-01-19 12:15:57 -06:00
if self . buffer . list . get_count ( ) == 0 : return _ ( u " Empty " )
2015-01-05 05:33:09 -06:00
# fix this:
2015-01-19 12:15:57 -06:00
return " %s . %s " % ( self . buffer . list . list . GetItemText ( self . buffer . list . get_selected ( ) ) , self . buffer . list . list . GetItemText ( self . buffer . list . get_selected ( ) , 1 ) )
2014-11-12 20:41:29 -06:00
def add_new_item ( self , item ) :
tweet = self . compose_function ( item , self . session . db [ " user_name " ] )
if self . session . settings [ " general " ] [ " reverse_timelines " ] == False :
self . buffer . list . insert_item ( False , * tweet )
else :
self . buffer . list . insert_item ( True , * tweet )
2015-03-11 17:17:29 -06:00
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 :
2015-02-07 10:23:23 -06:00
output . speak ( " " . join ( tweet ) )
2015-04-15 11:09:36 -05:00
if self . buffer . list . get_count ( ) == 1 :
self . buffer . list . select_item ( 0 )
2015-02-07 10:23:23 -06:00
def clear_list ( self ) :
dlg = commonMessageDialogs . clear_list ( )
if dlg == widgetUtils . YES :
self . buffer . list . clear ( )
2014-11-12 20:41:29 -06:00
class peopleBufferController ( baseBufferController ) :
def __init__ ( self , parent , function , name , sessionObject , account , bufferType = None , * args , * * kwargs ) :
super ( peopleBufferController , self ) . __init__ ( parent , function , name , sessionObject , account , bufferType = " peoplePanel " )
2015-01-18 17:19:39 -06:00
log . debug ( " Initializing buffer %s , account %s " % ( name , account , ) )
2014-11-12 20:41:29 -06:00
self . compose_function = compose . compose_followers_list
2015-01-19 12:15:57 -06:00
log . debug ( " Compose_function: %s " % ( self . compose_function , ) )
2015-01-02 09:38:44 -06:00
self . get_tweet = self . get_right_tweet
2015-06-01 11:18:39 -05:00
self . url = self . interact
2014-11-12 20:41:29 -06:00
2015-02-12 12:59:56 -06:00
def remove_buffer ( self ) :
return False
2014-11-12 20:41:29 -06:00
def onFocus ( self , ev ) :
pass
2015-01-05 05:33:09 -06:00
def get_message ( self ) :
return " " . join ( self . compose_function ( self . get_tweet ( ) , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] ) )
2014-11-12 20:41:29 -06:00
def delete_item ( self ) : pass
2015-02-12 12:59:56 -06:00
@_tweets_exist
def reply ( self , * args , * * kwargs ) :
tweet = self . get_right_tweet ( )
screen_name = tweet [ " screen_name " ]
message = messages . reply ( self . session , _ ( u " Mention " ) , _ ( u " Mention to %s " ) % ( screen_name , ) , " @ %s " % ( screen_name , ) , [ screen_name , ] )
if message . message . get_response ( ) == widgetUtils . OK :
if message . image == None :
call_threaded ( self . session . api_call , call_name = " update_status " , _sound = " reply_send.ogg " , status = message . message . get_text ( ) )
else :
call_threaded ( self . session . api_call , call_name = " update_status_with_media " , _sound = " reply_send.ogg " , status = message . message . get_text ( ) , media = message . file )
2015-04-03 16:57:08 -06:00
if hasattr ( message . message , " destroy " ) : message . message . destroy ( )
2015-02-12 12:59:56 -06:00
2014-11-12 20:41:29 -06:00
def start_stream ( self ) :
2015-01-18 17:19:39 -06:00
log . debug ( " Starting stream for %s buffer, %s account " % ( self . name , self . account , ) )
log . debug ( " args: %s , kwargs: %s " % ( self . args , self . kwargs ) )
2014-11-12 20:41:29 -06:00
val = self . session . get_cursored_stream ( self . name , self . function , * self . args , * * self . kwargs )
# self.session.order_cursored_buffer(self.name, self.session.db[self.name])
2015-01-19 12:15:57 -06:00
# log.debug("Number of items retrieved: %d" % (val,))
2014-11-12 20:41:29 -06:00
self . put_items_on_list ( val )
2015-02-03 09:59:18 -06:00
def get_more_items ( self ) :
try :
items = self . session . get_more_items ( self . function , users = True , name = self . name , count = self . session . settings [ " general " ] [ " max_tweets_per_call " ] , cursor = self . session . db [ self . name ] [ " cursor " ] )
except TwythonError as e :
2015-04-10 09:34:24 -05:00
output . speak ( e . message , True )
2015-02-03 09:59:18 -06:00
return
for i in items :
if self . session . settings [ " general " ] [ " reverse_timelines " ] == False :
self . session . db [ self . name ] [ " items " ] . insert ( 0 , i )
else :
self . session . db [ self . name ] [ " items " ] . append ( i )
selected = self . buffer . list . get_selected ( )
2015-04-10 09:34:24 -05:00
# self.put_items_on_list(len(items))
2015-03-24 03:47:16 -06:00
if self . session . settings [ " general " ] [ " reverse_timelines " ] == True :
2015-04-10 09:34:24 -05:00
for i in items :
tweet = self . compose_function ( i , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] )
self . buffer . list . insert_item ( True , * tweet )
self . buffer . list . select_item ( selected )
else :
for i in items :
tweet = self . compose_function ( i , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] )
self . buffer . list . insert_item ( True , * tweet )
# self.buffer.list.select_item(selection)
2015-03-24 03:47:16 -06:00
# else:
# self.buffer.list.select_item(selection-elements)
2015-04-10 09:34:24 -05:00
output . speak ( _ ( u " %s items retrieved " ) % ( len ( items ) ) , True )
2015-02-03 09:59:18 -06:00
2014-11-12 20:41:29 -06:00
def put_items_on_list ( self , number_of_items ) :
2015-01-18 17:19:39 -06:00
log . debug ( " The list contains %d items " % ( self . buffer . list . get_count ( ) , ) )
2015-01-19 12:15:57 -06:00
# log.debug("Putting %d items on the list..." % (number_of_items,))
2014-11-12 20:41:29 -06:00
if self . buffer . list . get_count ( ) == 0 :
for i in self . session . db [ self . name ] [ " items " ] :
tweet = self . compose_function ( i , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] )
self . buffer . list . insert_item ( False , * tweet )
2015-01-22 08:54:41 -06:00
self . buffer . set_position ( self . session . settings [ " general " ] [ " reverse_timelines " ] )
2014-11-12 20:41:29 -06:00
# self.buffer.set_list_position()
elif self . buffer . list . get_count ( ) > 0 :
if self . session . settings [ " general " ] [ " reverse_timelines " ] == False :
for i in self . session . db [ self . name ] [ " items " ] [ : number_of_items ] :
tweet = self . compose_function ( i , self . session . db )
2015-02-03 09:59:18 -06:00
self . buffer . list . insert_item ( False , * tweet )
2014-11-12 20:41:29 -06:00
else :
for i in self . session . db [ self . name ] [ " items " ] [ 0 : number_of_items ] :
tweet = self . compose_function ( i , self . session . db )
self . buffer . list . insert_item ( True , * tweet )
2015-01-18 17:19:39 -06:00
log . debug ( " now the list contains %d items " % ( self . buffer . list . get_count ( ) , ) )
2014-11-12 20:41:29 -06:00
2015-01-02 09:38:44 -06:00
def get_right_tweet ( self ) :
tweet = self . session . db [ self . name ] [ " items " ] [ self . buffer . list . get_selected ( ) ]
return tweet
2015-01-20 15:40:33 -06:00
def add_new_item ( self , item ) :
tweet = self . compose_function ( item , self . session . db , self . session . settings [ " general " ] [ " relative_times " ] )
if self . session . settings [ " general " ] [ " reverse_timelines " ] == False :
self . buffer . list . insert_item ( False , * tweet )
else :
self . buffer . list . insert_item ( True , * tweet )
2015-03-11 17:17:29 -06:00
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 :
2015-02-07 10:23:23 -06:00
output . speak ( " " . join ( tweet ) )
def clear_list ( self ) :
dlg = commonMessageDialogs . clear_list ( )
if dlg == widgetUtils . YES :
self . session . db [ self . name ] [ " items " ] = [ ]
self . session . db [ self . name ] [ " cursor " ] = - 1
self . buffer . list . clear ( )
2015-01-20 15:40:33 -06:00
2015-05-12 09:47:24 -05:00
def interact ( self ) :
2015-03-08 14:18:29 -06:00
user . profileController ( self . session , user = self . get_right_tweet ( ) [ " screen_name " ] )
2015-03-06 21:37:08 -06:00
2014-11-12 20:41:29 -06:00
class searchBufferController ( baseBufferController ) :
def start_stream ( self ) :
2015-01-18 17:19:39 -06:00
log . debug ( " Starting stream for %s buffer, %s account and %s type " % ( self . name , self . account , self . type ) )
log . debug ( " args: %s , kwargs: %s " % ( self . args , self . kwargs ) )
log . debug ( " Function: %s " % ( self . function , ) )
2015-03-24 17:07:14 -06:00
# try:
val = self . session . search ( self . name , * self . args , * * self . kwargs )
# except:
# return None
num = self . session . order_buffer ( self . name , val )
self . put_items_on_list ( num )
if num > 0 :
2015-01-20 15:40:33 -06:00
self . session . sound . play ( " search_updated.ogg " )
2014-11-12 20:41:29 -06:00
2015-02-16 16:37:56 -06:00
def remove_buffer ( self ) :
dlg = commonMessageDialogs . remove_buffer ( )
if dlg == widgetUtils . YES :
if self . name [ : - 11 ] in self . session . settings [ " other_buffers " ] [ " tweet_searches " ] :
self . session . settings [ " other_buffers " ] [ " tweet_searches " ] . remove ( self . name [ : - 11 ] )
2015-03-12 11:45:53 -06:00
self . timer . cancel ( )
2015-02-16 16:37:56 -06:00
return True
elif dlg == widgetUtils . NO :
return False
2015-03-17 03:50:49 -06:00
class searchPeopleBufferController ( peopleBufferController ) :
2014-11-12 20:41:29 -06:00
def __init__ ( self , parent , function , name , sessionObject , account , bufferType = " peoplePanel " , * args , * * kwargs ) :
super ( searchPeopleBufferController , self ) . __init__ ( parent , function , name , sessionObject , account , bufferType = " peoplePanel " , * args , * * kwargs )
2015-01-18 17:19:39 -06:00
log . debug ( " Initializing buffer %s , account %s " % ( name , account , ) )
2015-03-17 03:50:49 -06:00
# self.compose_function = compose.compose_followers_list
2015-01-18 17:19:39 -06:00
log . debug ( " Compose_function: %s " % ( self . compose_function , ) )
2015-03-17 03:50:49 -06:00
self . args = args
self . kwargs = kwargs
self . function = function
2015-01-18 17:19:39 -06:00
2014-11-12 20:41:29 -06:00
def start_stream ( self ) :
2015-01-18 17:19:39 -06:00
log . debug ( " starting stream for %s buffer, %s account and %s type " % ( self . name , self . account , self . type ) )
log . debug ( " args: %s , kwargs: %s " % ( self . args , self . kwargs ) )
log . debug ( " Function: %s " % ( self . function , ) )
2015-03-28 05:58:57 -06:00
# try:
val = self . session . call_paged ( self . function , * self . args , * * self . kwargs )
# except:
# return
2015-03-17 03:50:49 -06:00
number_of_items = self . session . order_cursored_buffer ( self . name , val )
2015-01-18 17:19:39 -06:00
log . debug ( " Number of items retrieved: %d " % ( number_of_items , ) )
2014-11-12 20:41:29 -06:00
self . put_items_on_list ( number_of_items )
if number_of_items > 0 :
2015-01-20 15:40:33 -06:00
self . session . sound . play ( " search_updated.ogg " )
2015-02-01 21:13:18 -06:00
2015-03-17 03:50:49 -06:00
def remove_buffer ( self ) :
dlg = commonMessageDialogs . remove_buffer ( )
if dlg == widgetUtils . YES :
if self . name [ : - 11 ] in self . session . settings [ " other_buffers " ] [ " tweet_searches " ] :
self . session . settings [ " other_buffers " ] [ " tweet_searches " ] . remove ( self . name [ : - 11 ] )
self . timer . cancel ( )
return True
elif dlg == widgetUtils . NO :
return False
2015-02-01 21:13:18 -06:00
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 ) :
2015-02-07 13:55:52 -06:00
try :
2015-03-24 17:07:14 -06:00
data = self . session . call_paged ( " get_place_trends " , id = self . trendsFor )
2015-02-07 13:55:52 -06:00
except :
return
2015-02-03 04:39:46 -06:00
if not hasattr ( self , " name_ " ) :
self . name_ = data [ 0 ] [ " locations " ] [ 0 ] [ " name " ]
2015-02-01 21:13:18 -06:00
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 )
2015-02-03 04:39:46 -06:00
self . buffer . set_position ( self . session . settings [ " general " ] [ " reverse_timelines " ] )
2015-02-01 21:13:18 -06:00
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 ]
2015-02-12 12:59:56 -06:00
def remove_buffer ( self ) :
dlg = commonMessageDialogs . remove_buffer ( )
if dlg == widgetUtils . YES :
2015-02-12 13:18:24 -06:00
if self . name [ : - 3 ] in self . session . settings [ " other_buffers " ] [ " trending_topic_buffers " ] :
self . session . settings [ " other_buffers " ] [ " trending_topic_buffers " ] . remove ( self . name [ : - 3 ] )
2015-03-12 11:45:53 -06:00
self . timer . cancel ( )
2015-02-12 12:59:56 -06:00
return True
elif dlg == widgetUtils . NO :
2015-03-17 12:24:29 -06:00
return False
2015-05-12 09:47:24 -05:00
def interact ( self , * args , * * kwargs ) :
2015-03-18 11:45:39 -06:00
self . searchfunction ( value = self . get_message ( ) )
class conversationBufferController ( searchBufferController ) :
def start_stream ( self , start = False ) :
if start == True :
self . statuses = [ ]
self . ids = [ ]
self . statuses . append ( self . tweet )
self . ids . append ( self . tweet [ " id " ] )
tweet = self . tweet
while tweet [ " in_reply_to_status_id " ] != None :
tweet = self . session . twitter . twitter . show_status ( id = tweet [ " in_reply_to_status_id " ] )
self . statuses . insert ( 0 , tweet )
self . ids . append ( tweet [ " id " ] )
if tweet [ " in_reply_to_status_id " ] == None :
self . kwargs [ " since_id " ] = tweet [ " id " ]
self . ids . append ( tweet [ " id " ] )
2015-03-28 05:58:57 -06:00
val2 = self . session . search ( self . name , * self . args , * * self . kwargs )
for i in val2 :
2015-03-18 11:45:39 -06:00
if i [ " in_reply_to_status_id " ] in self . ids :
self . statuses . append ( i )
self . ids . append ( i [ " id " ] )
tweet = i
number_of_items = self . session . order_buffer ( self . name , self . statuses )
log . debug ( " Number of items retrieved: %d " % ( number_of_items , ) )
self . put_items_on_list ( number_of_items )
if number_of_items > 0 :
self . session . sound . play ( " search_updated.ogg " )
2015-04-27 16:08:02 -05:00
2015-06-21 21:20:53 -05:00
class pocketBufferController ( baseBufferController ) :
def __init__ ( self , parent , name , sessionObject , account , sound = None , function = None , bufferType = None , * args , * * kwargs ) :
super ( pocketBufferController , self ) . __init__ ( parent , name , sessionObject , account , sound , function , bufferType , * args , * * kwargs )
self . type = " pocket "
def start_stream ( self ) :
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 ) )