2014-11-12 20:41:29 -06:00
# -*- coding: utf-8 -*-
2015-04-03 16:57:08 -06:00
import platform
system = platform . system ( )
2015-02-26 16:09:26 -06:00
import application
2015-04-03 16:57:08 -06:00
if system == " Windows " :
from update import updater
from wxUI import ( view , dialogs , commonMessageDialogs , sysTrayIcon )
import settings
from extra import SoundsTutorial
import keystrokeEditor
from keyboard_handler . wx_handler import WXKeyboardHandler
import userActionsController
import trendingTopics
import user
2015-04-15 11:09:36 -05:00
import listsController
2015-04-03 16:57:08 -06:00
from issueReporter import issueReporter
elif system == " Linux " :
2015-04-04 21:25:52 -06:00
from gtkUI import ( view , commonMessageDialogs )
2015-04-27 16:08:02 -05:00
from twitter import utils , compose
2015-03-04 17:52:27 -06:00
from sessionmanager import manager , sessionManager
2014-11-12 20:41:29 -06:00
import buffersController
2014-11-12 22:37:52 -06:00
import messages
2015-01-13 12:31:37 -06:00
from sessionmanager import session as session_
2014-11-12 20:41:29 -06:00
from pubsub import pub
import sound
import output
2015-01-05 05:33:09 -06:00
from twython import TwythonError
2014-11-12 20:41:29 -06:00
from mysc . thread_utils import call_threaded
from mysc . repeating_timer import RepeatingTimer
2015-01-25 02:38:17 -06:00
from mysc import restart
2014-11-12 20:41:29 -06:00
import config
import widgetUtils
2015-01-19 12:15:57 -06:00
import pygeocoder
from pygeolib import GeocoderError
2015-01-13 12:31:37 -06:00
import logging
2015-02-26 16:09:26 -06:00
import webbrowser
2015-07-06 12:05:03 -05:00
from mysc import localization
import os
2014-11-12 20:41:29 -06:00
2015-01-13 12:31:37 -06:00
log = logging . getLogger ( " mainController " )
2015-01-19 12:15:57 -06:00
geocoder = pygeocoder . Geocoder ( )
2014-11-12 20:41:29 -06:00
class Controller ( object ) :
""" Main Controller for TWBlue. It manages the main window and sessions. """
def search_buffer ( self , name_ , user ) :
""" Searches a buffer.
name_ str : The name for the buffer
user str : The account for the buffer .
for example you may want to search the home_timeline buffer for the tw_blue2 user .
returns buffersController . buffer object with the result if there is one . """
for i in self . buffers :
if i . name == name_ and i . account == user : return i
2015-01-05 05:33:09 -06:00
def get_current_buffer ( self ) :
2015-02-25 08:39:06 -06:00
""" Get the current bufferObject """
2015-01-05 05:33:09 -06:00
buffer = self . view . get_current_buffer ( )
if hasattr ( buffer , " account " ) :
buffer = self . search_buffer ( buffer . name , buffer . account )
return buffer
2014-11-12 20:41:29 -06:00
def get_best_buffer ( self ) :
2015-02-25 08:39:06 -06:00
""" Gets the best buffer for doing something using the session object.
This function is useful when you need to open a timeline or post a tweet , and the user is in a buffer without a session , for example the events buffer .
This returns a bufferObject . """
2014-11-12 20:41:29 -06:00
# Gets the parent buffer to know what account is doing an action
view_buffer = self . view . get_current_buffer ( )
# If the account has no session attached, we will need to search the home_timeline for that account to use its session.
if view_buffer . type == " account " or view_buffer . type == " empty " :
buffer = self . search_buffer ( " home_timeline " , view_buffer . account )
else :
buffer = self . search_buffer ( view_buffer . name , view_buffer . account )
2015-03-30 10:55:56 -06:00
if buffer != None : return buffer
2014-11-12 20:41:29 -06:00
2015-01-19 12:15:57 -06:00
def get_first_buffer ( self , account ) :
2015-02-25 08:39:06 -06:00
""" Gets the first valid buffer for an account.
account str : A twitter username .
The first valid buffer is the home timeline . """
2015-01-19 12:15:57 -06:00
for i in self . buffers :
2015-01-20 15:40:33 -06:00
if i . account == account and i . invisible == True :
2015-01-19 12:15:57 -06:00
buff = i
break
return self . view . search ( buff . name , buff . account )
def get_last_buffer ( self , account ) :
2015-02-25 08:39:06 -06:00
""" Gets the last valid buffer for an account.
account str : A twitter username .
The last valid buffer is the last buffer that contains a session object assigned . """
2015-08-08 09:42:55 -05:00
# results = self.get_buffers_for_account(account)
2015-08-06 12:03:40 -05:00
results = self . get_buffers_for_account ( account )
2015-07-13 05:43:40 -05:00
return self . view . search ( results [ - 1 ] . name , results [ - 1 ] . account )
def get_buffers_for_account ( self , account ) :
2015-01-19 12:15:57 -06:00
results = [ ]
2015-08-08 09:42:55 -05:00
buffers = self . view . get_buffers ( )
2015-08-11 08:58:11 -05:00
[ results . append ( self . search_buffer ( i . name , i . account ) ) for i in buffers if i . account == account and ( i . type != " account " ) ]
2015-07-13 05:43:40 -05:00
return results
2015-01-19 12:15:57 -06:00
2014-11-12 20:41:29 -06:00
def bind_stream_events ( self ) :
2015-02-25 08:39:06 -06:00
""" Binds all the streaming events with their functions. """
2015-01-18 17:19:39 -06:00
log . debug ( " Binding events for the Twitter stream API... " )
2014-11-12 20:41:29 -06:00
pub . subscribe ( self . manage_home_timelines , " item-in-home " )
pub . subscribe ( self . manage_mentions , " mention " )
pub . subscribe ( self . manage_direct_messages , " direct-message " )
pub . subscribe ( self . manage_sent_dm , " sent-dm " )
pub . subscribe ( self . manage_sent_tweets , " sent-tweet " )
pub . subscribe ( self . manage_events , " event " )
pub . subscribe ( self . manage_followers , " follower " )
pub . subscribe ( self . manage_friend , " friend " )
pub . subscribe ( self . manage_unfollowing , " unfollowing " )
pub . subscribe ( self . manage_favourite , " favourite " )
pub . subscribe ( self . manage_unfavourite , " unfavourite " )
pub . subscribe ( self . manage_blocked_user , " blocked-user " )
pub . subscribe ( self . manage_unblocked_user , " unblocked-user " )
pub . subscribe ( self . manage_item_in_timeline , " item-in-timeline " )
2015-04-27 16:08:02 -05:00
pub . subscribe ( self . manage_item_in_list , " item-in-list " )
2015-12-28 09:05:09 -06:00
pub . subscribe ( self . restart_streams_ , " restart_streams " )
2016-04-16 13:31:37 -05:00
pub . subscribe ( self . on_tweet_deleted , " tweet-deleted " )
2015-02-04 17:00:03 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . CLOSE_EVENT , self . exit_ )
2014-11-12 20:41:29 -06:00
def bind_other_events ( self ) :
2015-02-25 08:39:06 -06:00
""" Binds the local application events with their functions. """
2015-01-18 17:19:39 -06:00
log . debug ( " Binding other application events... " )
2015-02-26 15:21:26 -06:00
pub . subscribe ( self . logout_account , " logout " )
pub . subscribe ( self . login_account , " login " )
2015-10-14 17:30:41 -05:00
pub . subscribe ( self . manage_stream_errors , " stream-error " )
2015-01-27 17:09:28 -06:00
pub . subscribe ( self . create_new_buffer , " create-new-buffer " )
2015-02-12 10:29:51 -06:00
pub . subscribe ( self . restart_streams , " restart-streams " )
2015-08-21 09:51:01 -05:00
pub . subscribe ( self . execute_action , " execute-action " )
2015-10-03 04:34:43 -05:00
pub . subscribe ( self . search_topic , " search " )
2015-04-04 21:25:52 -06:00
if system == " Windows " :
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 )
2015-04-27 16:08:02 -05:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . list_manager , menuitem = self . view . lists )
2015-04-04 21:25:52 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . get_trending_topics , menuitem = self . view . trends )
2015-06-24 15:10:21 -05:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . find , menuitem = self . view . find )
2015-04-04 21:25:52 -06:00
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 )
2015-01-01 21:40:57 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . learn_sounds , menuitem = self . view . sounds_tutorial )
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . exit , menuitem = self . view . close )
2015-02-07 13:55:52 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . CLOSE_EVENT , self . exit )
2015-01-20 22:07:13 -06:00
if widgetUtils . toolkit == " wx " :
2015-01-25 02:38:17 -06:00
log . debug ( " Binding the exit function... " )
2015-02-04 17:00:03 -06:00
widgetUtils . connectExitFunction ( self . exit_ )
2015-04-04 21:25:52 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . edit_keystrokes , menuitem = self . view . keystroke_editor )
2015-01-01 21:40:57 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . post_tweet , self . view . compose )
2015-01-02 09:38:44 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . post_reply , self . view . reply )
2015-01-02 10:53:33 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . post_retweet , self . view . retweet )
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . add_to_favourites , self . view . fav )
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . remove_from_favourites , self . view . unfav )
2015-01-05 05:33:09 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . view_item , self . view . view )
2015-02-03 05:10:01 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . reverse_geocode , menuitem = self . view . view_coordinates )
2015-01-05 05:33:09 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . delete , self . view . delete )
2015-02-01 00:49:03 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . follow , menuitem = self . view . follow )
2015-01-02 09:38:44 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . send_dm , self . view . dm )
2015-09-29 09:22:19 -05:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . view_user_lists , menuitem = self . view . viewLists )
2015-02-03 09:59:18 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . get_more_items , menuitem = self . view . load_previous_items )
2015-10-03 04:34:43 -05:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . view_user_lists , menuitem = self . view . viewLists )
2015-02-07 10:23:23 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . clear_buffer , menuitem = self . view . clear )
2015-02-11 16:14:25 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . remove_buffer , self . view . deleteTl )
2015-02-26 10:26:46 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . check_for_updates , self . view . check_for_updates )
2015-02-26 16:09:26 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . about , menuitem = self . view . about )
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . visit_website , menuitem = self . view . visit_website )
2015-03-04 17:52:27 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . manage_accounts , self . view . manage_accounts )
2015-03-06 21:37:08 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . update_profile , menuitem = self . view . updateProfile )
2015-03-08 14:18:29 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . user_details , menuitem = self . view . details )
2015-03-11 16:36:22 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . toggle_autoread , menuitem = self . view . autoread )
2015-03-12 08:31:39 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . toggle_buffer_mute , self . view . mute_buffer )
2015-05-08 08:59:52 -05:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . open_timeline , self . view . timeline )
2015-03-17 11:20:04 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . open_favs_timeline , self . view . favs )
2015-03-19 04:50:24 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . open_conversation , menuitem = self . view . view_conversation )
2015-04-04 21:25:52 -06:00
if widgetUtils . toolkit == " wx " :
widgetUtils . connect_event ( self . view . nb , widgetUtils . NOTEBOOK_PAGE_CHANGED , self . buffer_changed )
2015-03-29 23:27:18 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . report_error , self . view . reportError )
2015-07-06 12:05:03 -05:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . view_documentation , self . view . doc )
2016-02-02 09:30:13 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . view_changelog , self . view . changelog )
2015-08-31 10:08:34 -05:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . add_to_list , self . view . addToList )
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . remove_from_list , self . view . removeFromList )
2015-12-26 23:34:19 -06:00
widgetUtils . connect_event ( self . view , widgetUtils . MENU , self . update_buffer , self . view . update_buffer )
2014-11-12 20:41:29 -06:00
2015-03-12 05:17:59 -06:00
def set_systray_icon ( self ) :
self . systrayIcon = sysTrayIcon . SysTrayIcon ( )
widgetUtils . connect_event ( self . systrayIcon , widgetUtils . MENU , self . post_tweet , menuitem = self . systrayIcon . tweet )
widgetUtils . connect_event ( self . systrayIcon , widgetUtils . MENU , self . configuration , menuitem = self . systrayIcon . global_settings )
widgetUtils . connect_event ( self . systrayIcon , widgetUtils . MENU , self . accountConfiguration , menuitem = self . systrayIcon . account_settings )
widgetUtils . connect_event ( self . systrayIcon , widgetUtils . MENU , self . update_profile , menuitem = self . systrayIcon . update_profile )
widgetUtils . connect_event ( self . systrayIcon , widgetUtils . MENU , self . show_hide , menuitem = self . systrayIcon . show_hide )
widgetUtils . connect_event ( self . systrayIcon , widgetUtils . MENU , self . check_for_updates , menuitem = self . systrayIcon . check_for_updates )
2016-07-23 15:43:38 -05:00
widgetUtils . connect_event ( self . systrayIcon , widgetUtils . MENU , self . view_documentation , menuitem = self . systrayIcon . doc )
2015-03-12 05:17:59 -06:00
widgetUtils . connect_event ( self . systrayIcon , widgetUtils . MENU , self . exit , menuitem = self . systrayIcon . exit )
widgetUtils . connect_event ( self . systrayIcon , widgetUtils . TASKBAR_LEFT_CLICK , self . taskbar_left_click )
widgetUtils . connect_event ( self . systrayIcon , widgetUtils . TASKBAR_RIGHT_CLICK , self . taskbar_right_click )
def taskbar_left_click ( self , * args , * * kwargs ) :
if self . showing == True :
self . view . set_focus ( )
else :
self . show_hide ( )
def taskbar_right_click ( self , * args , * * kwargs ) :
self . systrayIcon . show_menu ( )
2014-11-12 20:41:29 -06:00
def __init__ ( self ) :
super ( Controller , self ) . __init__ ( )
2015-02-25 08:39:06 -06:00
# Visibility state.
2015-01-19 12:15:57 -06:00
self . showing = True
2015-02-25 08:39:06 -06:00
# main window
2015-01-01 21:40:57 -06:00
self . view = view . mainFrame ( )
2015-02-25 08:39:06 -06:00
# buffers list.
2014-11-12 20:41:29 -06:00
self . buffers = [ ]
2015-02-25 08:39:06 -06:00
# accounts list.
2015-01-19 12:15:57 -06:00
self . accounts = [ ]
2015-02-25 08:39:06 -06:00
# This saves the current account (important in invisible mode)
2015-01-19 12:15:57 -06:00
self . current_account = " "
2014-11-12 20:41:29 -06:00
self . view . prepare ( )
self . bind_stream_events ( )
2015-04-04 21:25:52 -06:00
self . bind_other_events ( )
2015-04-03 16:57:08 -06:00
if system == " Windows " :
self . set_systray_icon ( )
2015-03-09 15:55:34 -06:00
def check_invisible_at_startup ( self ) :
2015-04-03 16:57:08 -06:00
# Visibility check. It does only work for windows.
if system != " Windows " : return
2015-01-20 15:40:33 -06:00
if config . app [ " app-settings " ] [ " hide_gui " ] == True :
self . show_hide ( )
self . view . Show ( )
self . view . Hide ( )
2015-02-25 08:39:06 -06:00
# Invisible keyboard Shorcuts check.
2015-01-20 15:40:33 -06:00
if config . app [ " app-settings " ] [ " use_invisible_keyboard_shorcuts " ] == True :
km = self . create_invisible_keyboard_shorcuts ( )
self . register_invisible_keyboard_shorcuts ( km )
2014-12-31 00:07:27 -06:00
2014-11-12 20:41:29 -06:00
def do_work ( self ) :
2015-02-25 08:39:06 -06:00
""" Creates the buffer objects for all accounts. This does not starts the buffer streams, only creates the objects. """
2015-01-13 12:31:37 -06:00
log . debug ( " Creating buffers for all sessions... " )
for i in session_ . sessions :
log . debug ( " Working on session %s " % ( i , ) )
2015-02-26 15:21:26 -06:00
if session_ . sessions [ i ] . is_logged == False :
self . create_ignored_session_buffer ( session_ . sessions [ i ] )
continue
2015-01-13 12:31:37 -06:00
self . create_buffers ( session_ . sessions [ i ] )
2015-05-11 18:41:19 -05:00
2015-02-25 08:39:06 -06:00
# Connection checker executed each minute.
2015-01-13 12:31:37 -06:00
self . checker_function = RepeatingTimer ( 60 , self . check_connection )
self . checker_function . start ( )
2015-02-25 08:39:06 -06:00
2015-01-27 17:09:28 -06:00
def start ( self ) :
2015-02-25 08:39:06 -06:00
""" Starts all buffer objects. Loads their items. """
2015-01-27 17:09:28 -06:00
for i in session_ . sessions :
2015-02-26 15:21:26 -06:00
if session_ . sessions [ i ] . is_logged == False : continue
2015-01-27 17:09:28 -06:00
self . start_buffers ( session_ . sessions [ i ] )
2015-08-25 13:37:31 -05:00
self . set_buffer_positions ( session_ . sessions [ i ] )
2015-04-17 14:32:12 -05:00
if config . app [ " app-settings " ] [ " play_ready_sound " ] == True :
session_ . sessions [ session_ . sessions . keys ( ) [ 0 ] ] . sound . play ( " ready.ogg " )
if config . app [ " app-settings " ] [ " speak_ready_msg " ] == True :
output . speak ( _ ( u " Ready " ) )
2014-11-12 20:41:29 -06:00
2015-02-26 15:21:26 -06:00
def create_ignored_session_buffer ( self , session ) :
self . accounts . append ( session . settings [ " twitter " ] [ " user_name " ] )
account = buffersController . accountPanel ( self . view . nb , session . settings [ " twitter " ] [ " user_name " ] , session . settings [ " twitter " ] [ " user_name " ] , session . session_id )
account . logged = False
account . setup_account ( )
self . buffers . append ( account )
self . view . add_buffer ( account . buffer , name = session . settings [ " twitter " ] [ " user_name " ] )
def login_account ( self , session_id ) :
for i in session_ . sessions :
if session_ . sessions [ i ] . session_id == session_id : session = session_ . sessions [ i ]
session . login ( )
2015-08-19 05:28:56 -05:00
session . db = dict ( )
2015-02-26 15:21:26 -06:00
self . create_buffers ( session , False )
self . start_buffers ( session )
def create_buffers ( self , session , createAccounts = True ) :
2015-02-25 08:39:06 -06:00
""" Generates buffer objects for an user account.
session SessionObject : a sessionmanager . session . Session Object """
2014-11-12 20:41:29 -06:00
session . get_user_info ( )
2015-02-26 15:21:26 -06:00
if createAccounts == True :
self . accounts . append ( session . db [ " user_name " ] )
account = buffersController . accountPanel ( self . view . nb , session . db [ " user_name " ] , session . db [ " user_name " ] , session . session_id )
account . setup_account ( )
self . buffers . append ( account )
self . view . add_buffer ( account . buffer , name = session . db [ " user_name " ] )
2015-05-04 11:51:47 -05:00
for i in session . settings [ ' general ' ] [ ' buffer_order ' ] :
if i == ' home ' :
home = buffersController . baseBufferController ( self . view . nb , " get_home_timeline " , " home_timeline " , session , session . db [ " user_name " ] )
self . buffers . append ( home )
self . view . insert_buffer ( home . buffer , name = _ ( u " Home " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-05-05 08:39:03 -05:00
elif i == ' mentions ' :
2015-05-04 11:51:47 -05:00
mentions = buffersController . baseBufferController ( self . view . nb , " get_mentions_timeline " , " mentions " , session , session . db [ " user_name " ] , sound = " mention_received.ogg " )
self . buffers . append ( mentions )
self . view . insert_buffer ( mentions . buffer , name = _ ( u " Mentions " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-05-05 08:39:03 -05:00
elif i == ' dm ' :
2015-08-12 17:21:00 -05:00
dm = buffersController . baseBufferController ( self . view . nb , " get_direct_messages " , " direct_messages " , session , session . db [ " user_name " ] , bufferType = " dmPanel " , sound = " dm_received.ogg " , full_text = True )
2015-05-04 11:51:47 -05:00
self . buffers . append ( dm )
self . view . insert_buffer ( dm . buffer , name = _ ( u " Direct messages " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-05-05 08:39:03 -05:00
elif i == ' sent_dm ' :
2015-08-12 17:21:00 -05:00
sent_dm = buffersController . baseBufferController ( self . view . nb , " get_sent_messages " , " sent_direct_messages " , session , session . db [ " user_name " ] , bufferType = " dmPanel " , full_text = True )
2015-05-04 11:51:47 -05:00
self . buffers . append ( sent_dm )
self . view . insert_buffer ( sent_dm . buffer , name = _ ( u " Sent direct messages " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-05-05 08:39:03 -05:00
elif i == ' sent_tweets ' :
2015-05-04 11:51:47 -05:00
sent_tweets = buffersController . baseBufferController ( self . view . nb , " get_user_timeline " , " sent_tweets " , session , session . db [ " user_name " ] , bufferType = " dmPanel " , screen_name = session . db [ " user_name " ] )
self . buffers . append ( sent_tweets )
self . view . insert_buffer ( sent_tweets . buffer , name = _ ( u " Sent tweets " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-05-05 08:39:03 -05:00
elif i == ' favorites ' :
2015-05-04 11:51:47 -05:00
favourites = buffersController . baseBufferController ( self . view . nb , " get_favorites " , " favourites " , session , session . db [ " user_name " ] )
self . buffers . append ( favourites )
2014-12-31 00:07:27 -06:00
2015-11-03 10:07:06 -06:00
self . view . insert_buffer ( favourites . buffer , name = _ ( u " Likes " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-05-05 08:39:03 -05:00
elif i == ' followers ' :
2015-05-04 11:51:47 -05:00
followers = buffersController . peopleBufferController ( self . view . nb , " get_followers_list " , " followers " , session , session . db [ " user_name " ] , screen_name = session . db [ " user_name " ] )
self . buffers . append ( followers )
self . view . insert_buffer ( followers . buffer , name = _ ( u " Followers " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-05-05 08:39:03 -05:00
elif i == ' friends ' :
2015-05-04 11:51:47 -05:00
friends = buffersController . peopleBufferController ( self . view . nb , " get_friends_list " , " friends " , session , session . db [ " user_name " ] , screen_name = session . db [ " user_name " ] )
self . buffers . append ( friends )
self . view . insert_buffer ( friends . buffer , name = _ ( u " Friends " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-05-05 08:39:03 -05:00
elif i == ' blocks ' :
2015-05-04 11:51:47 -05:00
blocks = buffersController . peopleBufferController ( self . view . nb , " list_blocks " , " blocked " , session , session . db [ " user_name " ] )
self . buffers . append ( blocks )
self . view . insert_buffer ( blocks . buffer , name = _ ( u " Blocked users " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-05-05 08:39:03 -05:00
elif i == ' muted ' :
2015-06-11 16:09:46 -05:00
muted = buffersController . peopleBufferController ( self . view . nb , " list_mutes " , " muted " , session , session . db [ " user_name " ] )
2015-05-04 11:51:47 -05:00
self . buffers . append ( muted )
self . view . insert_buffer ( muted . buffer , name = _ ( u " Muted users " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-05-05 08:39:03 -05:00
elif i == ' events ' :
2015-05-04 11:51:47 -05:00
events = buffersController . eventsBufferController ( self . view . nb , " events " , session , session . db [ " user_name " ] , bufferType = " dmPanel " , screen_name = session . db [ " user_name " ] )
self . buffers . append ( events )
self . view . insert_buffer ( events . buffer , name = _ ( u " Events " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2014-11-12 20:41:29 -06:00
timelines = buffersController . emptyPanel ( self . view . nb , " timelines " , session . db [ " user_name " ] )
self . buffers . append ( timelines )
self . view . insert_buffer ( timelines . buffer , name = _ ( u " Timelines " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
for i in session . settings [ " other_buffers " ] [ " timelines " ] :
tl = buffersController . baseBufferController ( self . view . nb , " get_user_timeline " , " %s -timeline " % ( i , ) , session , session . db [ " user_name " ] , bufferType = None , screen_name = i )
self . buffers . append ( tl )
2015-06-26 08:27:43 -05:00
self . view . insert_buffer ( tl . buffer , name = _ ( u " Timeline for {} " ) . format ( i , ) , pos = self . view . search ( " timelines " , session . db [ " user_name " ] ) )
2015-03-17 05:12:29 -06:00
favs_timelines = buffersController . emptyPanel ( self . view . nb , " favs_timelines " , session . db [ " user_name " ] )
self . buffers . append ( favs_timelines )
2015-11-03 10:07:06 -06:00
self . view . insert_buffer ( favs_timelines . buffer , name = _ ( u " Likes timelines " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-03-17 05:12:29 -06:00
for i in session . settings [ " other_buffers " ] [ " favourites_timelines " ] :
tl = buffersController . baseBufferController ( self . view . nb , " get_favorites " , " %s -favorite " % ( i , ) , session , session . db [ " user_name " ] , bufferType = None , screen_name = i )
self . buffers . append ( tl )
2015-11-03 10:07:06 -06:00
self . view . insert_buffer ( tl . buffer , name = _ ( u " Likes for {} " ) . format ( i , ) , pos = self . view . search ( " favs_timelines " , session . db [ " user_name " ] ) )
2015-03-17 05:12:29 -06:00
tl . timer = RepeatingTimer ( 300 , tl . start_stream )
tl . timer . start ( )
2015-12-09 11:51:37 -06:00
followers_timelines = buffersController . emptyPanel ( self . view . nb , " followers_timelines " , session . db [ " user_name " ] )
self . buffers . append ( followers_timelines )
self . view . insert_buffer ( followers_timelines . buffer , name = _ ( u " Followers ' Timelines " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
for i in session . settings [ " other_buffers " ] [ " followers_timelines " ] :
tl = buffersController . peopleBufferController ( self . view . nb , " get_followers_list " , " %s -followers " % ( i , ) , session , session . db [ " user_name " ] , screen_name = i )
self . buffers . append ( tl )
self . view . insert_buffer ( tl . buffer , name = _ ( u " Followers for {} " ) . format ( i , ) , pos = self . view . search ( " favs_timelines " , session . db [ " user_name " ] ) )
tl . timer = RepeatingTimer ( 300 , tl . start_stream )
tl . timer . start ( )
friends_timelines = buffersController . emptyPanel ( self . view . nb , " friends_timelines " , session . db [ " user_name " ] )
self . buffers . append ( friends_timelines )
2016-01-09 00:25:28 -06:00
self . view . insert_buffer ( friends_timelines . buffer , name = _ ( u " Friends ' Timelines " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-12-09 11:51:37 -06:00
for i in session . settings [ " other_buffers " ] [ " friends_timelines " ] :
tl = buffersController . peopleBufferController ( self . view . nb , " get_friends_list " , " %s -friends " % ( i , ) , session , session . db [ " user_name " ] , screen_name = i )
self . buffers . append ( tl )
self . view . insert_buffer ( tl . buffer , name = _ ( u " Friends for {} " ) . format ( i , ) , pos = self . view . search ( " favs_timelines " , session . db [ " user_name " ] ) )
tl . timer = RepeatingTimer ( 300 , tl . start_stream )
tl . timer . start ( )
2015-04-27 16:08:02 -05:00
lists = buffersController . emptyPanel ( self . view . nb , " lists " , session . db [ " user_name " ] )
self . buffers . append ( lists )
self . view . insert_buffer ( lists . buffer , name = _ ( u " Lists " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
for i in session . settings [ " other_buffers " ] [ " lists " ] :
tl = buffersController . listBufferController ( self . view . nb , " get_list_statuses " , " %s -list " % ( i , ) , session , session . db [ " user_name " ] , bufferType = None , list_id = utils . find_list ( i , session . db [ " lists " ] ) )
session . lists . append ( tl )
self . buffers . append ( tl )
self . view . insert_buffer ( tl . buffer , name = _ ( u " List for {} " ) . format ( i ) , pos = self . view . search ( " timelines " , session . db [ " user_name " ] ) )
2014-11-12 20:41:29 -06:00
searches = buffersController . emptyPanel ( self . view . nb , " searches " , session . db [ " user_name " ] )
self . buffers . append ( searches )
self . view . insert_buffer ( searches . buffer , name = _ ( u " Searches " ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
for i in session . settings [ " other_buffers " ] [ " tweet_searches " ] :
2015-03-19 12:03:34 -06:00
tl = buffersController . searchBufferController ( self . view . nb , " search " , " %s -searchterm " % ( i , ) , session , session . db [ " user_name " ] , bufferType = " searchPanel " , q = i , count = session . settings [ " general " ] [ " max_tweets_per_call " ] )
2014-11-12 20:41:29 -06:00
self . buffers . append ( tl )
2015-06-26 08:27:43 -05:00
self . view . insert_buffer ( tl . buffer , name = _ ( u " Search for {} " ) . format ( i ) , pos = self . view . search ( " searches " , session . db [ " user_name " ] ) )
2014-11-12 20:41:29 -06:00
tl . timer = RepeatingTimer ( 180 , tl . start_stream )
tl . timer . start ( )
2015-02-03 04:39:46 -06:00
for i in session . settings [ " other_buffers " ] [ " trending_topic_buffers " ] :
buffer = buffersController . trendsBufferController ( self . view . nb , " %s _tt " % ( i , ) , session , session . db [ " user_name " ] , i )
buffer . start_stream ( )
2015-03-17 12:24:29 -06:00
buffer . searchfunction = self . search
2015-02-03 04:39:46 -06:00
self . buffers . append ( buffer )
2015-02-26 15:21:26 -06:00
buffer . timer = RepeatingTimer ( 300 , buffer . start_stream )
buffer . timer . start ( )
2015-08-31 08:15:37 -05:00
self . view . insert_buffer ( buffer . buffer , name = _ ( u " Trending topics for %s " ) % ( buffer . name_ ) , pos = self . view . search ( session . db [ " user_name " ] , session . db [ " user_name " ] ) )
2015-02-26 15:21:26 -06:00
2015-05-11 18:41:19 -05:00
def set_buffer_positions ( self , session ) :
" Sets positions for buffers if values exist in the database. "
for i in self . buffers :
2015-08-25 13:37:31 -05:00
if i . account == session . db [ " user_name " ] and session . db . has_key ( i . name + " _pos " ) and hasattr ( i . buffer , ' list ' ) :
2015-05-11 18:41:19 -05:00
i . buffer . list . select_item ( session . db [ str ( i . name + " _pos " ) ] )
2015-02-26 15:21:26 -06:00
def logout_account ( self , session_id ) :
for i in session_ . sessions :
if session_ . sessions [ i ] . session_id == session_id : session = session_ . sessions [ i ]
user = session . db [ " user_name " ]
2015-08-20 17:32:27 -05:00
delete_buffers = [ ]
for i in self . buffers :
if i . account == user and i . name != user :
delete_buffers . append ( i . name )
for i in delete_buffers :
self . destroy_buffer ( i , user )
2015-08-19 05:28:56 -05:00
session . db = None
2015-02-26 15:21:26 -06:00
def destroy_buffer ( self , buffer_name , account ) :
buffer = self . search_buffer ( buffer_name , account )
if buffer == None : return
buff = self . view . search ( buffer . name , buffer . account )
if buff == None : return
self . view . delete_buffer ( buff )
self . buffers . remove ( buffer )
del buffer
2014-11-12 20:41:29 -06:00
2015-10-03 04:34:43 -05:00
def search_topic ( self , term ) :
self . search ( value = term )
def search ( self , event = None , value = " " , * args , * * kwargs ) :
2015-02-25 08:39:06 -06:00
""" Searches words or users in twitter. This creates a new buffer containing the search results. """
2015-01-18 17:19:39 -06:00
log . debug ( " Creating a new search... " )
2015-03-17 12:24:29 -06:00
dlg = dialogs . search . searchDialog ( value )
2015-03-28 05:02:17 -06:00
if dlg . get_response ( ) == widgetUtils . OK and dlg . get ( " term " ) != " " :
2014-11-12 20:41:29 -06:00
term = dlg . get ( " term " )
buffer = self . get_best_buffer ( )
if dlg . get ( " tweets " ) == True :
if term not in buffer . session . settings [ " other_buffers " ] [ " tweet_searches " ] :
buffer . session . settings [ " other_buffers " ] [ " tweet_searches " ] . append ( term )
2015-12-09 17:25:46 -06:00
args = { " lang " : dlg . get_language ( ) , " result_type " : dlg . get_result_type ( ) }
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 " ] , * * args )
2014-11-12 20:41:29 -06:00
else :
2015-01-18 17:19:39 -06:00
log . error ( " A buffer for the %s search term is already created. You can ' t create a duplicate buffer. " % ( term , ) )
2014-11-12 20:41:29 -06:00
return
elif dlg . get ( " users " ) == True :
2015-03-28 05:58:57 -06:00
search = buffersController . searchPeopleBufferController ( self . view . nb , " search_users " , " %s -searchUser " % ( term , ) , buffer . session , buffer . session . db [ " user_name " ] , bufferType = None , q = term )
2015-12-26 23:28:46 -06:00
search . start_stream ( mandatory = True )
2015-07-06 06:06:28 -05:00
pos = self . view . search ( " searches " , buffer . session . db [ " user_name " ] )
2015-07-13 05:43:40 -05:00
self . insert_buffer ( search , pos )
2015-07-06 06:06:28 -05:00
self . view . insert_buffer ( search . buffer , name = _ ( u " Search for {} " ) . format ( term ) , pos = pos )
2014-11-12 20:41:29 -06:00
search . timer = RepeatingTimer ( 180 , search . start_stream )
search . timer . start ( )
dlg . Destroy ( )
2015-06-24 15:10:21 -05:00
def find ( self , * args , * * kwargs ) :
if ' string ' in kwargs :
string = kwargs [ ' string ' ]
else :
string = ' '
2015-06-24 14:45:14 -05:00
dlg = dialogs . find . findDialog ( string )
if dlg . get_response ( ) == widgetUtils . OK and dlg . get ( " string " ) != " " :
string = dlg . get ( " string " )
#If we still have an empty string for some reason (I.E. user clicked cancel, etc), return here.
if string == ' ' :
log . debug ( " Find canceled. " )
return
2015-06-24 14:26:15 -05:00
page = self . get_current_buffer ( )
if not hasattr ( page . buffer , " list " ) :
output . speak ( _ ( u " No session is currently in focus. Focus a session with the next or previous session shortcut. " ) , True )
return
count = page . buffer . list . get_count ( )
if count < 1 :
output . speak ( _ ( u " Empty buffer. " ) , True )
return
start = page . buffer . list . get_selected ( )
for i in xrange ( start , count ) :
page . buffer . list . select_item ( i )
if string . lower ( ) in page . get_message ( ) . lower ( ) :
return output . speak ( page . get_message ( ) , True )
2015-06-26 08:27:43 -05:00
output . speak ( _ ( u " {0} not found. " ) . format ( string , ) , True )
2015-06-24 14:26:15 -05:00
page . buffer . list . select_item ( start )
2015-06-26 11:00:02 -05:00
2015-02-26 10:09:13 -06:00
def edit_keystrokes ( self , * args , * * kwargs ) :
editor = keystrokeEditor . KeystrokeEditor ( )
if editor . changed == True :
register = False
# determines if we need to reassign the keymap.
if self . showing == False :
register = True
elif config . app [ " app-settings " ] [ " use_invisible_keyboard_shorcuts " ] == True :
register = True
# If there is a keyboard handler instance we need unregister all old keystrokes before register the new ones.
if hasattr ( self , " keyboard_handler " ) :
keymap = { }
for i in editor . hold_map :
if hasattr ( self , i ) : keymap [ editor . hold_map [ i ] ] = getattr ( self , i )
self . unregister_invisible_keyboard_shorcuts ( keymap )
self . invisible_shorcuts_changed ( registered = register )
2014-11-12 20:41:29 -06:00
2014-12-29 20:58:30 -06:00
def learn_sounds ( self , * args , * * kwargs ) :
2015-02-25 08:39:06 -06:00
""" Opens the sounds tutorial for the current account. """
2015-01-20 15:40:33 -06:00
buffer = self . get_best_buffer ( )
SoundsTutorial . soundsTutorial ( buffer . session )
2014-12-29 20:58:30 -06:00
2015-10-03 04:34:43 -05:00
def view_user_lists ( self , * args , * * kwargs ) :
buff = self . get_best_buffer ( )
if not hasattr ( buff , " get_right_tweet " ) : return
tweet = buff . get_right_tweet ( )
if buff . type != " people " :
users = utils . get_all_users ( tweet , buff . session . db )
else :
users = [ tweet [ " screen_name " ] ]
dlg = dialogs . utils . selectUserDialog ( _ ( u " Select the user " ) , users )
if dlg . get_response ( ) == widgetUtils . OK :
user = dlg . get_user ( )
else :
return
l = listsController . listsController ( buff . session , user = user )
2014-11-12 20:41:29 -06:00
2015-04-27 16:08:02 -05:00
def add_to_list ( self , * args , * * kwargs ) :
buff = self . get_best_buffer ( )
if not hasattr ( buff , " get_right_tweet " ) : return
tweet = buff . get_right_tweet ( )
if buff . type != " people " :
users = utils . get_all_users ( tweet , buff . session . db )
else :
users = [ tweet [ " screen_name " ] ]
dlg = dialogs . utils . selectUserDialog ( _ ( u " Select the user " ) , users )
if dlg . get_response ( ) == widgetUtils . OK :
user = dlg . get_user ( )
else :
return
dlg = dialogs . lists . addUserListDialog ( )
dlg . populate_list ( [ compose . compose_list ( item ) for item in buff . session . db [ " lists " ] ] )
if dlg . get_response ( ) == widgetUtils . OK :
try :
list = buff . session . twitter . twitter . add_list_member ( list_id = buff . session . db [ " lists " ] [ dlg . get_item ( ) ] [ " id " ] , screen_name = user )
older_list = utils . find_item ( buff . session . db [ " lists " ] [ dlg . get_item ( ) ] [ " id " ] , buff . session . db [ " lists " ] )
2015-06-15 17:20:13 -05:00
listBuffer = self . search_buffer ( " %s -list " % ( buff . session . db [ " lists " ] [ dlg . get_item ( ) ] [ " name " ] . lower ( ) ) , buff . session . db [ " user_name " ] )
if listBuffer != None : listBuffer . get_user_ids ( )
2015-04-27 16:08:02 -05:00
buff . session . db [ " lists " ] . pop ( older_list )
buff . session . db [ " lists " ] . append ( list )
2015-06-15 17:20:13 -05:00
if listBuffer != None : pub . sendMessage ( " restart-streams " , streams = [ " timelinesStream " ] , session = buff . session )
2015-04-27 16:08:02 -05:00
except TwythonError as e :
output . speak ( " error %s : %s " % ( e . error_code , e . msg ) )
2014-11-12 20:41:29 -06:00
2015-08-31 10:08:34 -05:00
def remove_from_list ( self , * args , * * kwargs ) :
buff = self . get_best_buffer ( )
if not hasattr ( buff , " get_right_tweet " ) : return
tweet = buff . get_right_tweet ( )
if buff . type != " people " :
users = utils . get_all_users ( tweet , buff . session . db )
else :
users = [ tweet [ " screen_name " ] ]
dlg = dialogs . utils . selectUserDialog ( _ ( u " Select the user " ) , users )
if dlg . get_response ( ) == widgetUtils . OK :
user = dlg . get_user ( )
else :
return
dlg = dialogs . lists . removeUserListDialog ( )
dlg . populate_list ( [ compose . compose_list ( item ) for item in buff . session . db [ " lists " ] ] )
if dlg . get_response ( ) == widgetUtils . OK :
try :
list = buff . session . twitter . twitter . delete_list_member ( list_id = buff . session . db [ " lists " ] [ dlg . get_item ( ) ] [ " id " ] , screen_name = user )
older_list = utils . find_item ( buff . session . db [ " lists " ] [ dlg . get_item ( ) ] [ " id " ] , buff . session . db [ " lists " ] )
listBuffer = self . search_buffer ( " %s -list " % ( buff . session . db [ " lists " ] [ dlg . get_item ( ) ] [ " name " ] . lower ( ) ) , buff . session . db [ " user_name " ] )
if listBuffer != None : listBuffer . get_user_ids ( )
buff . session . db [ " lists " ] . pop ( older_list )
buff . session . db [ " lists " ] . append ( list )
if listBuffer != None : pub . sendMessage ( " restart-streams " , streams = [ " timelinesStream " ] , session = buff . session )
except TwythonError as e :
output . speak ( " error %s : %s " % ( e . error_code , e . msg ) )
2014-11-12 20:41:29 -06:00
2015-04-15 11:09:36 -05:00
def list_manager ( self , * args , * * kwargs ) :
s = self . get_best_buffer ( ) . session
l = listsController . listsController ( s )
2015-01-20 15:40:33 -06:00
def configuration ( self , * args , * * kwargs ) :
2015-02-25 08:39:06 -06:00
""" Opens the global settings dialogue. """
2015-01-20 15:40:33 -06:00
d = settings . globalSettingsController ( )
if d . response == widgetUtils . OK :
d . save_configuration ( )
2015-01-25 02:38:17 -06:00
if d . needs_restart == True :
commonMessageDialogs . needs_restart ( )
restart . restart_program ( )
def accountConfiguration ( self , * args , * * kwargs ) :
2015-02-25 08:39:06 -06:00
""" Opens the account settings dialogue for the current account. """
2015-01-25 02:38:17 -06:00
buff = self . get_best_buffer ( )
2015-01-27 17:09:28 -06:00
manager . manager . set_current_session ( buff . session . session_id )
d = settings . accountSettingsController ( buff , self )
if d . response == widgetUtils . OK :
d . save_configuration ( )
if d . needs_restart == True :
commonMessageDialogs . needs_restart ( )
buff . session . settings . write ( )
restart . restart_program ( )
2014-11-12 20:41:29 -06:00
2015-03-29 23:27:18 -06:00
def report_error ( self , * args , * * kwargs ) :
r = issueReporter . reportBug ( self . get_best_buffer ( ) . session . db [ " user_name " ] )
2015-02-26 10:26:46 -06:00
def check_for_updates ( self , * args , * * kwargs ) :
update = updater . do_update ( )
if update == False :
view . no_update_available ( )
2014-11-12 20:41:29 -06:00
2015-01-05 05:33:09 -06:00
def delete ( self , * args , * * kwargs ) :
2015-02-25 08:39:06 -06:00
""" Deletes an item in the current buffer.
Users can only remove their tweets and direct messages , other users ' tweets and people (followers, friends, blocked, etc) can not be removed using this method. " " "
2015-01-05 05:33:09 -06:00
buffer = self . view . get_current_buffer ( )
if hasattr ( buffer , " account " ) :
buffer = self . search_buffer ( buffer . name , buffer . account )
buffer . destroy_status ( )
2014-11-12 20:41:29 -06:00
2015-01-01 21:40:57 -06:00
def exit ( self , * args , * * kwargs ) :
2015-01-20 15:40:33 -06:00
if config . app [ " app-settings " ] [ " ask_at_exit " ] == True :
2015-04-04 21:25:52 -06:00
answer = commonMessageDialogs . exit_dialog ( self . view )
2015-02-03 04:39:46 -06:00
if answer == widgetUtils . YES :
self . exit_ ( )
else :
self . exit_ ( )
2015-02-25 08:39:06 -06:00
def exit_ ( self , * args , * * kwargs ) :
2015-08-25 13:37:31 -05:00
for i in self . buffers : i . save_positions ( )
2015-01-18 17:19:39 -06:00
log . debug ( " Exiting... " )
2015-01-20 15:40:33 -06:00
log . debug ( " Saving global configuration... " )
config . app . write ( )
2015-06-26 11:00:02 -05:00
config . keymap . write ( )
2015-01-13 12:31:37 -06:00
for item in session_ . sessions :
2015-03-09 13:53:47 -06:00
if session_ . sessions [ item ] . logged == False : continue
2015-01-18 17:19:39 -06:00
log . debug ( " Saving config for %s session " % ( session_ . sessions [ item ] . session_id , ) )
2015-01-13 12:31:37 -06:00
session_ . sessions [ item ] . settings . write ( )
2015-01-18 17:19:39 -06:00
log . debug ( " Disconnecting streams for %s session " % ( session_ . sessions [ item ] . session_id , ) )
2015-03-20 17:19:40 -06:00
if hasattr ( session_ . sessions [ item ] , " main_stream " ) : session_ . sessions [ item ] . main_stream . disconnect ( )
if hasattr ( session_ . sessions [ item ] , " timelinesStream " ) : session_ . sessions [ item ] . timelinesStream . disconnect ( )
2015-01-20 15:40:33 -06:00
session_ . sessions [ item ] . sound . cleaner . cancel ( )
2015-05-01 01:03:42 -05:00
log . debug ( " Shelving database for " + session_ . sessions [ item ] . session_id )
2015-05-09 22:12:17 -05:00
session_ . sessions [ item ] . shelve ( )
2015-05-01 01:03:42 -05:00
2015-04-03 16:57:08 -06:00
if system == " Windows " :
2015-03-20 17:19:40 -06:00
self . systrayIcon . RemoveIcon ( )
2014-11-12 20:41:29 -06:00
widgetUtils . exit_application ( )
2015-02-01 00:49:03 -06:00
def follow ( self , * args , * * kwargs ) :
buff = self . get_current_buffer ( )
if not hasattr ( buff , " get_right_tweet " ) : return
tweet = buff . get_right_tweet ( )
if buff . type != " people " :
users = utils . get_all_users ( tweet , buff . session . db )
else :
users = [ tweet [ " screen_name " ] ]
u = userActionsController . userActionsController ( buff , users )
def unfollow ( self , * args , * * kwargs ) :
buff = self . get_current_buffer ( )
if not hasattr ( buff , " get_right_tweet " ) : return
tweet = buff . get_right_tweet ( )
if buff . type != " people " :
users = utils . get_all_users ( tweet , buff . session . db )
else :
users = [ tweet [ " screen_name " ] ]
u = userActionsController . userActionsController ( buff , users , " unfollow " )
def mute ( self , * args , * * kwargs ) :
buff = self . get_current_buffer ( )
if not hasattr ( buff , " get_right_tweet " ) : return
tweet = buff . get_right_tweet ( )
if buff . type != " people " :
users = utils . get_all_users ( tweet , buff . session . db )
else :
users = [ tweet [ " screen_name " ] ]
u = userActionsController . userActionsController ( buff , users , " mute " )
def unmute ( self , * args , * * kwargs ) :
buff = self . get_current_buffer ( )
if not hasattr ( buff , " get_right_tweet " ) : return
tweet = buff . get_right_tweet ( )
if buff . type != " people " :
users = utils . get_all_users ( tweet , buff . session . db )
else :
users = [ tweet [ " screen_name " ] ]
u = userActionsController . userActionsController ( buff , users , " unmute " )
def block ( self , * args , * * kwargs ) :
buff = self . get_current_buffer ( )
if not hasattr ( buff , " get_right_tweet " ) : return
tweet = buff . get_right_tweet ( )
if buff . type != " people " :
users = utils . get_all_users ( tweet , buff . session . db )
else :
users = [ tweet [ " screen_name " ] ]
u = userActionsController . userActionsController ( buff , users , " block " )
def unblock ( self , * args , * * kwargs ) :
buff = self . get_current_buffer ( )
if not hasattr ( buff , " get_right_tweet " ) : return
tweet = buff . get_right_tweet ( )
if buff . type != " people " :
users = utils . get_all_users ( tweet , buff . session . db )
else :
users = [ tweet [ " screen_name " ] ]
u = userActionsController . userActionsController ( buff , users , " unblock " )
def report ( self , * args , * * kwargs ) :
buff = self . get_current_buffer ( )
if not hasattr ( buff , " get_right_tweet " ) : return
tweet = buff . get_right_tweet ( )
if buff . type != " people " :
users = utils . get_all_users ( tweet , buff . session . db )
else :
users = [ tweet [ " screen_name " ] ]
u = userActionsController . userActionsController ( buff , users , " report " )
2014-11-12 20:41:29 -06:00
2014-11-12 22:37:52 -06:00
def post_tweet ( self , event = None ) :
buffer = self . get_best_buffer ( )
2015-01-05 06:05:31 -06:00
buffer . post_tweet ( )
2014-11-12 20:41:29 -06:00
2015-01-02 09:38:44 -06:00
def post_reply ( self , * args , * * kwargs ) :
2015-01-05 05:33:09 -06:00
buffer = self . get_current_buffer ( )
2015-01-02 09:38:44 -06:00
if buffer . name == " sent_direct_messages " or buffer . name == " sent-tweets " : return
elif buffer . name == " direct_messages " :
buffer . direct_message ( )
else :
buffer . reply ( )
2014-11-12 20:41:29 -06:00
2015-01-19 12:15:57 -06:00
def send_dm ( self , * args , * * kwargs ) :
2015-01-05 05:33:09 -06:00
buffer = self . get_current_buffer ( )
2015-01-02 09:38:44 -06:00
if buffer . name == " sent_direct_messages " or buffer . name == " sent-tweets " : return
else :
buffer . direct_message ( )
2014-11-12 20:41:29 -06:00
2015-01-02 10:53:33 -06:00
def post_retweet ( self , * args , * * kwargs ) :
2015-01-05 05:33:09 -06:00
buffer = self . get_current_buffer ( )
2015-01-02 10:53:33 -06:00
if buffer . type == " dm " or buffer . type == " people " or buffer . type == " events " :
return
else :
buffer . retweet ( )
2014-11-12 20:41:29 -06:00
2015-01-02 10:53:33 -06:00
def add_to_favourites ( self , * args , * * kwargs ) :
2015-01-05 05:33:09 -06:00
buffer = self . get_current_buffer ( )
2015-01-02 10:53:33 -06:00
if buffer . type == " dm " or buffer . type == " people " or buffer . type == " events " :
return
else :
id = buffer . get_tweet ( ) [ " id " ]
call_threaded ( buffer . session . api_call , call_name = " create_favorite " , _sound = " favourite.ogg " , id = id )
2014-11-12 20:41:29 -06:00
2015-01-02 10:53:33 -06:00
def remove_from_favourites ( self , * args , * * kwargs ) :
2015-01-05 05:33:09 -06:00
buffer = self . get_current_buffer ( )
2015-01-02 10:53:33 -06:00
if buffer . type == " dm " or buffer . type == " people " or buffer . type == " events " :
return
else :
id = buffer . get_tweet ( ) [ " id " ]
call_threaded ( buffer . session . api_call , call_name = " destroy_favorite " , id = id )
2014-11-12 20:41:29 -06:00
2015-01-05 05:33:09 -06:00
def view_item ( self , * args , * * kwargs ) :
buffer = self . get_current_buffer ( )
if buffer . type == " baseBuffer " or buffer . type == " favourites_timeline " or buffer . type == " list " or buffer . type == " search " :
2015-06-01 17:52:23 -05:00
tweet , tweetsList = buffer . get_full_tweet ( )
msg = messages . viewTweet ( tweet , tweetsList )
2015-01-05 05:33:09 -06:00
elif buffer . type == " account " or buffer . type == " empty " :
return
2015-07-29 08:40:07 -05:00
elif buffer . name == " sent_tweets " :
tweet , tweetsList = buffer . get_full_tweet ( )
msg = messages . viewTweet ( tweet , tweetsList )
2015-01-05 05:33:09 -06:00
else :
2015-01-25 02:38:17 -06:00
non_tweet = buffer . get_formatted_message ( )
2015-04-08 13:34:50 -05:00
msg = messages . viewTweet ( non_tweet , [ ] , False )
2015-01-05 05:33:09 -06:00
2015-03-17 11:20:04 -06:00
def open_favs_timeline ( self , * args , * * kwargs ) :
self . open_timeline ( default = " favourites " )
def open_timeline ( self , default = " tweets " , * args , * * kwargs ) :
2015-02-22 11:38:22 -06:00
buff = self . get_best_buffer ( )
2015-02-12 10:29:51 -06:00
if not hasattr ( buff , " get_right_tweet " ) : return
tweet = buff . get_right_tweet ( )
if buff . type != " people " :
users = utils . get_all_users ( tweet , buff . session . db )
else :
users = [ tweet [ " screen_name " ] ]
2015-03-17 11:20:04 -06:00
dlg = dialogs . userSelection . selectUserDialog ( users = users , default = default )
2015-02-12 10:29:51 -06:00
if dlg . get_response ( ) == widgetUtils . OK :
2015-08-21 08:57:15 -05:00
usr = utils . if_user_exists ( buff . session . twitter . twitter , dlg . get_user ( ) )
2015-03-24 17:28:01 -06:00
if usr != None :
if usr [ " protected " ] == True :
if usr [ " following " ] == False :
commonMessageDialogs . no_following ( )
return
answer = commonMessageDialogs . protected_user ( )
if answer == widgetUtils . NO : return
2015-12-09 11:51:37 -06:00
tl_type = dlg . get_action ( )
if tl_type == " tweets " :
2015-08-21 09:12:54 -05:00
if usr [ " statuses_count " ] == 0 :
commonMessageDialogs . no_tweets ( )
return
2015-08-21 08:57:15 -05:00
if dlg . get_user ( ) in buff . session . settings [ " other_buffers " ] [ " timelines " ] :
2015-02-12 10:29:51 -06:00
commonMessageDialogs . timeline_exist ( )
return
2015-08-21 08:57:15 -05:00
tl = buffersController . baseBufferController ( self . view . nb , " get_user_timeline " , " %s -timeline " % ( dlg . get_user ( ) , ) , buff . session , buff . session . db [ " user_name " ] , bufferType = None , screen_name = dlg . get_user ( ) )
2015-02-12 10:29:51 -06:00
tl . start_stream ( )
2015-08-21 08:57:15 -05:00
pos = self . view . search ( " timelines " , buff . session . db [ " user_name " ] )
2015-08-07 16:44:33 -05:00
self . insert_buffer ( tl , pos + 1 )
2015-07-13 05:43:40 -05:00
# self.buffers.insert(pos+1, tl)
2015-07-06 06:06:28 -05:00
self . view . insert_buffer ( tl . buffer , name = _ ( u " Timeline for {} " ) . format ( dlg . get_user ( ) ) , pos = pos )
2015-08-21 08:57:15 -05:00
buff . session . settings [ " other_buffers " ] [ " timelines " ] . append ( dlg . get_user ( ) )
pub . sendMessage ( " restart-streams " , streams = [ " timelinesStream " ] , session = buff . session )
2015-08-31 08:42:28 -05:00
buff . session . sound . play ( " create_timeline.ogg " )
2015-12-09 11:51:37 -06:00
elif tl_type == " favourites " :
2015-08-21 09:12:54 -05:00
if usr [ " favourites_count " ] == 0 :
commonMessageDialogs . no_favs ( )
return
2015-10-23 11:33:56 -05:00
if dlg . get_user ( ) in buff . session . settings [ " other_buffers " ] [ " favourites_timelines " ] :
2015-03-17 05:12:29 -06:00
commonMessageDialogs . timeline_exist ( )
return
2015-08-21 08:57:15 -05:00
tl = buffersController . baseBufferController ( self . view . nb , " get_favorites " , " %s -favorite " % ( dlg . get_user ( ) , ) , buff . session , buff . session . db [ " user_name " ] , bufferType = None , screen_name = dlg . get_user ( ) )
pos = self . view . search ( " favs_timelines " , buff . session . db [ " user_name " ] )
2015-08-07 16:44:33 -05:00
self . insert_buffer ( tl , pos + 1 )
2015-07-13 05:43:40 -05:00
# self.buffers.insert(pos+1, tl)
2015-11-03 10:07:06 -06:00
self . view . insert_buffer ( buffer = tl . buffer , name = _ ( u " Likes for {} " ) . format ( dlg . get_user ( ) ) , pos = pos )
2015-03-17 05:12:29 -06:00
tl . start_stream ( )
tl . timer = RepeatingTimer ( 300 , tl . start_stream )
tl . timer . start ( )
2015-08-21 08:57:15 -05:00
buff . session . settings [ " other_buffers " ] [ " favourites_timelines " ] . append ( dlg . get_user ( ) )
buff . session . sound . play ( " create_timeline.ogg " )
2015-12-09 11:51:37 -06:00
elif tl_type == " followers " :
if usr [ " followers_count " ] == 0 :
commonMessageDialogs . no_followers ( )
return
if dlg . get_user ( ) in buff . session . settings [ " other_buffers " ] [ " followers_timelines " ] :
commonMessageDialogs . timeline_exist ( )
return
tl = buffersController . peopleBufferController ( self . view . nb , " get_followers_list " , " %s -followers " % ( dlg . get_user ( ) , ) , buff . session , buff . session . db [ " user_name " ] , screen_name = dlg . get_user ( ) )
pos = self . view . search ( " followers_timelines " , buff . session . db [ " user_name " ] )
self . insert_buffer ( tl , pos + 1 )
# self.buffers.insert(pos+1, tl)
self . view . insert_buffer ( buffer = tl . buffer , name = _ ( u " Followers for {} " ) . format ( dlg . get_user ( ) ) , pos = pos )
tl . start_stream ( )
tl . timer = RepeatingTimer ( 300 , tl . start_stream )
tl . timer . start ( )
buff . session . settings [ " other_buffers " ] [ " followers_timelines " ] . append ( dlg . get_user ( ) )
buff . session . sound . play ( " create_timeline.ogg " )
elif tl_type == " friends " :
if usr [ " friends_count " ] == 0 :
commonMessageDialogs . no_friends ( )
return
if dlg . get_user ( ) in buff . session . settings [ " other_buffers " ] [ " friends_timelines " ] :
commonMessageDialogs . timeline_exist ( )
return
tl = buffersController . peopleBufferController ( self . view . nb , " get_friends_list " , " %s -friends " % ( dlg . get_user ( ) , ) , buff . session , buff . session . db [ " user_name " ] , screen_name = dlg . get_user ( ) )
pos = self . view . search ( " friends_timelines " , buff . session . db [ " user_name " ] )
self . insert_buffer ( tl , pos + 1 )
self . view . insert_buffer ( buffer = tl . buffer , name = _ ( u " Friends for {} " ) . format ( dlg . get_user ( ) ) , pos = pos )
tl . start_stream ( )
tl . timer = RepeatingTimer ( 300 , tl . start_stream )
tl . timer . start ( )
buff . session . settings [ " other_buffers " ] [ " friends_timelines " ] . append ( dlg . get_user ( ) )
buff . session . sound . play ( " create_timeline.ogg " )
2015-02-12 10:29:51 -06:00
else :
commonMessageDialogs . user_not_exist ( )
2014-11-12 20:41:29 -06:00
2015-03-18 11:45:39 -06:00
def open_conversation ( self , * args , * * kwargs ) :
buffer = self . get_current_buffer ( )
id = buffer . get_right_tweet ( ) [ " id_str " ]
user = buffer . get_right_tweet ( ) [ " user " ] [ " screen_name " ]
2015-03-24 17:07:14 -06:00
search = buffersController . conversationBufferController ( self . view . nb , " search " , " %s -searchterm " % ( id , ) , buffer . session , buffer . session . db [ " user_name " ] , bufferType = " searchPanel " , since_id = id , q = " @ {0} " . format ( user , ) )
2015-03-18 11:45:39 -06:00
search . tweet = buffer . get_right_tweet ( )
search . start_stream ( start = True )
2015-07-06 06:06:28 -05:00
pos = self . view . search ( " searches " , buffer . session . db [ " user_name " ] )
2015-07-13 05:43:40 -05:00
# self.buffers.append(search)
self . insert_buffer ( search , pos )
2015-07-06 06:06:28 -05:00
self . view . insert_buffer ( search . buffer , name = _ ( u " Conversation with {0} " ) . format ( user ) , pos = pos )
2015-03-18 11:45:39 -06:00
search . timer = RepeatingTimer ( 300 , search . start_stream )
search . timer . start ( )
2015-01-19 12:15:57 -06:00
def show_hide ( self , * args , * * kwargs ) :
km = self . create_invisible_keyboard_shorcuts ( )
if self . showing == True :
if config . app [ " app-settings " ] [ " use_invisible_keyboard_shorcuts " ] == False :
self . register_invisible_keyboard_shorcuts ( km )
self . view . Hide ( )
2015-01-20 22:07:13 -06:00
self . fix_wrong_buffer ( )
2015-01-19 12:15:57 -06:00
self . showing = False
else :
if config . app [ " app-settings " ] [ " use_invisible_keyboard_shorcuts " ] == False :
self . unregister_invisible_keyboard_shorcuts ( km )
self . view . Show ( )
self . showing = True
2014-11-12 20:41:29 -06:00
2015-02-01 21:13:18 -06:00
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 ( )
2015-02-03 04:39:46 -06:00
if woeid in buff . session . settings [ " other_buffers " ] [ " trending_topic_buffers " ] : return
2015-02-01 21:13:18 -06:00
buffer = buffersController . trendsBufferController ( self . view . nb , " %s _tt " % ( woeid , ) , buff . session , buff . account , woeid )
2015-03-17 12:24:29 -06:00
buffer . searchfunction = self . search
2015-07-06 06:06:28 -05:00
pos = self . view . search ( buff . session . db [ " user_name " ] , buff . session . db [ " user_name " ] )
self . view . insert_buffer ( buffer . buffer , name = _ ( u " Trending topics for %s " ) % ( trends . get_string ( ) ) , pos = pos )
2015-02-01 21:13:18 -06:00
self . buffers . append ( buffer )
buffer . start_stream ( )
timer = RepeatingTimer ( 300 , buffer . start_stream )
timer . start ( )
buffer . session . settings [ " other_buffers " ] [ " trending_topic_buffers " ] . append ( woeid )
2015-02-03 05:10:01 -06:00
def reverse_geocode ( self , event = None ) :
try :
2015-02-11 16:14:25 -06:00
tweet = self . get_current_buffer ( ) . get_tweet ( )
2015-02-03 05:10:01 -06:00
if tweet [ " coordinates " ] != None :
x = tweet [ " coordinates " ] [ " coordinates " ] [ 0 ]
y = tweet [ " coordinates " ] [ " coordinates " ] [ 1 ]
address = geocoder . reverse_geocode ( y , x )
if event == None : output . speak ( address [ 0 ] . __str__ ( ) . decode ( " utf-8 " ) )
else : self . view . show_address ( address [ 0 ] . __str__ ( ) . decode ( " utf-8 " ) )
else :
output . speak ( _ ( u " There are no coordinates in this tweet " ) )
except GeocoderError :
output . speak ( _ ( u " There are no results for the coordinates in this tweet " ) )
except ValueError :
output . speak ( _ ( u " Error decoding coordinates. Try again later. " ) )
except KeyError :
pass
except AttributeError :
pass
def view_reverse_geocode ( self , event = None ) :
try :
tweet = self . get_current_buffer ( ) . get_right_tweet ( )
if tweet [ " coordinates " ] != None :
x = tweet [ " coordinates " ] [ " coordinates " ] [ 0 ]
y = tweet [ " coordinates " ] [ " coordinates " ] [ 1 ]
address = geocoder . reverse_geocode ( y , x )
Fix an error where the geolocate dialog wasn't loading properly
For some reason, a standard tweet dialog was being used to display this information, which comes along with spell check, translate, etc; functions a simple geolocate display box doesn't need.
The error was happening because the tweet show dialog was accepting (tweet, tweetList, is_tweet=True) as args, and the call to display the geodata was only providing geodata as tweet, and false as tweetList.
This method signature was erroring out because is_tweet was set to True by default; the False was being accepted as tweetList, which the method later tries to call __str__ which it doesn't have.
I could have just added the is_tweet keyword, but then I would need to change the signature so tweetList is set to none by default, update the method, bla, bla, bla. Too much work.
Instead I added another function in wxUI.commonMessageDialogs called view_geodata, which just accepts the data in question as an argument and displays that in a message box.
2016-03-22 09:21:27 -06:00
dlg = commonMessageDialogs . view_geodata ( address [ 0 ] . __str__ ( ) )
2015-02-03 05:10:01 -06:00
else :
output . speak ( _ ( u " There are no coordinates in this tweet " ) )
except GeocoderError :
output . speak ( _ ( u " There are no results for the coordinates in this tweet " ) )
except ValueError :
output . speak ( _ ( u " Error decoding coordinates. Try again later. " ) )
except KeyError :
pass
except AttributeError :
pass
2015-02-03 09:59:18 -06:00
def get_more_items ( self , * args , * * kwargs ) :
self . get_current_buffer ( ) . get_more_items ( )
2015-02-07 10:23:23 -06:00
def clear_buffer ( self , * args , * * kwargs ) :
self . get_current_buffer ( ) . clear_list ( )
2015-02-11 16:14:25 -06:00
def remove_buffer ( self , * args , * * kwargs ) :
buffer = self . get_current_buffer ( )
if not hasattr ( buffer , " account " ) : return
buff = self . view . search ( buffer . name , buffer . account )
2015-02-12 10:35:13 -06:00
answer = buffer . remove_buffer ( )
if answer == False : return
2015-03-14 17:38:26 -06:00
self . right ( )
2015-02-11 16:14:25 -06:00
self . view . delete_buffer ( buff )
buffer . session . sound . play ( " delete_timeline.ogg " )
self . buffers . remove ( buffer )
del buffer
2015-01-19 12:15:57 -06:00
def skip_buffer ( self , forward = True ) :
buff = self . get_current_buffer ( )
if buff . invisible == False :
self . view . advance_selection ( forward )
def buffer_changed ( self , * args , * * kwargs ) :
2015-03-12 08:31:39 -06:00
buffer = self . get_current_buffer ( )
if buffer . account != self . current_account :
self . current_account = buffer . account
if not hasattr ( buffer , " session " ) or buffer . session == None : return
muted = autoread = False
if buffer . name in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] :
muted = True
elif buffer . name in buffer . session . settings [ " other_buffers " ] [ " autoread_buffers " ] :
autoread = True
self . view . check_menuitem ( " mute_buffer " , muted )
self . view . check_menuitem ( " autoread " , autoread )
2015-01-19 12:15:57 -06:00
2015-01-20 22:07:13 -06:00
def fix_wrong_buffer ( self ) :
2015-03-30 10:55:56 -06:00
buf = self . get_best_buffer ( )
if buf == None :
for i in self . accounts :
buffer = self . view . search ( " home_timeline " , i )
if buffer != None : break
else :
buffer = self . view . search ( " home_timeline " , buf . session . db [ " user_name " ] )
2015-03-12 09:28:58 -06:00
self . view . change_buffer ( buffer )
2015-01-20 22:07:13 -06:00
2015-01-19 12:15:57 -06:00
def up ( self , * args , * * kwargs ) :
page = self . get_current_buffer ( )
2015-02-26 15:21:26 -06:00
if not hasattr ( page . buffer , " list " ) :
2015-05-01 10:05:42 -05:00
output . speak ( _ ( u " No session is currently in focus. Focus a session with the next or previous session shortcut. " ) , True )
2015-02-26 15:21:26 -06:00
return
2015-01-19 12:15:57 -06:00
position = page . buffer . list . get_selected ( )
index = position - 1
try :
page . buffer . list . select_item ( index )
except :
pass
if position == page . buffer . list . get_selected ( ) :
2015-01-20 15:40:33 -06:00
page . session . sound . play ( " limit.ogg " )
2015-05-11 19:25:35 -05:00
2015-01-19 12:15:57 -06:00
try :
2015-04-10 09:35:09 -05:00
output . speak ( page . get_message ( ) , True )
2015-01-19 12:15:57 -06:00
except :
pass
def down ( self , * args , * * kwargs ) :
page = self . get_current_buffer ( )
2015-02-26 15:21:26 -06:00
if not hasattr ( page . buffer , " list " ) :
2015-05-01 10:05:42 -05:00
output . speak ( _ ( u " No session is currently in focus. Focus a session with the next or previous session shortcut. " ) , True )
2015-02-26 15:21:26 -06:00
return
2015-01-19 12:15:57 -06:00
position = page . buffer . list . get_selected ( )
index = position + 1
try :
page . buffer . list . select_item ( index )
except :
pass
if position == page . buffer . list . get_selected ( ) :
2015-01-20 15:40:33 -06:00
page . session . sound . play ( " limit.ogg " )
2015-01-19 12:15:57 -06:00
try :
2015-04-10 09:35:09 -05:00
output . speak ( page . get_message ( ) , True )
2015-01-19 12:15:57 -06:00
except :
pass
def left ( self , * args , * * kwargs ) :
buff = self . view . get_current_buffer_pos ( )
buffer = self . get_current_buffer ( )
2015-02-26 15:21:26 -06:00
if not hasattr ( buffer . buffer , " list " ) :
2015-05-01 10:05:42 -05:00
output . speak ( _ ( u " No session is currently in focus. Focus a session with the next or previous session shortcut. " ) , True )
2015-02-26 15:21:26 -06:00
return
2015-01-19 12:15:57 -06:00
if buff == self . get_first_buffer ( buffer . account ) or buff == 0 :
self . view . change_buffer ( self . get_last_buffer ( buffer . account ) )
else :
self . view . change_buffer ( buff - 1 )
while self . get_current_buffer ( ) . invisible == False : self . skip_buffer ( False )
buffer = self . get_current_buffer ( )
2015-07-03 09:40:44 -05:00
if self . showing == True : buffer . buffer . set_focus_in_list ( )
2015-01-19 12:15:57 -06:00
try :
msg = _ ( u " %s , %s of %s " ) % ( self . view . get_buffer_text ( ) , buffer . buffer . list . get_selected ( ) + 1 , buffer . buffer . list . get_count ( ) )
except :
msg = _ ( u " %s . Empty " ) % ( self . view . get_buffer_text ( ) , )
2015-04-10 09:35:09 -05:00
output . speak ( msg , True )
2015-01-19 12:15:57 -06:00
def right ( self , * args , * * kwargs ) :
buff = self . view . get_current_buffer_pos ( )
buffer = self . get_current_buffer ( )
2015-02-26 15:21:26 -06:00
if not hasattr ( buffer . buffer , " list " ) :
2015-05-01 10:05:42 -05:00
output . speak ( _ ( u " No session is currently in focus. Focus a session with the next or previous session shortcut. " ) , True )
2015-02-26 15:21:26 -06:00
return
2015-01-19 12:15:57 -06:00
if buff == self . get_last_buffer ( buffer . account ) or buff + 1 == self . view . get_buffer_count ( ) :
self . view . change_buffer ( self . get_first_buffer ( buffer . account ) )
else :
self . view . change_buffer ( buff + 1 )
while self . get_current_buffer ( ) . invisible == False : self . skip_buffer ( True )
buffer = self . get_current_buffer ( )
2015-07-03 09:40:44 -05:00
if self . showing == True : buffer . buffer . set_focus_in_list ( )
2015-01-19 12:15:57 -06:00
try :
msg = _ ( u " %s , %s of %s " ) % ( self . view . get_buffer_text ( ) , buffer . buffer . list . get_selected ( ) + 1 , buffer . buffer . list . get_count ( ) )
except :
msg = _ ( u " %s . Empty " ) % ( self . view . get_buffer_text ( ) , )
2015-04-10 09:35:09 -05:00
output . speak ( msg , True )
2015-01-19 12:15:57 -06:00
def next_account ( self , * args , * * kwargs ) :
index = self . accounts . index ( self . current_account )
if index + 1 == len ( self . accounts ) :
index = 0
else :
index = index + 1
account = self . accounts [ index ]
self . current_account = account
buff = self . view . search ( " home_timeline " , account )
2015-02-26 15:21:26 -06:00
if buff == None :
2015-05-01 10:05:42 -05:00
output . speak ( _ ( u " {0} : This account is not logged into Twitter. " ) . format ( account ) , True )
2015-02-26 15:21:26 -06:00
return
2015-01-19 12:15:57 -06:00
self . view . change_buffer ( buff )
buffer = self . get_current_buffer ( )
2015-07-03 09:40:44 -05:00
if self . showing == True : buffer . buffer . set_focus_in_list ( )
2015-01-19 12:15:57 -06:00
try :
msg = _ ( u " %s . %s , %s of %s " ) % ( buffer . account , self . view . get_buffer_text ( ) , buffer . buffer . list . get_selected ( ) + 1 , buffer . buffer . list . get_count ( ) )
except :
msg = _ ( u " %s . Empty " ) % ( self . view . get_buffer_text ( ) , )
2015-04-10 09:35:09 -05:00
output . speak ( msg , True )
2015-01-19 12:15:57 -06:00
def previous_account ( self , * args , * * kwargs ) :
index = self . accounts . index ( self . current_account )
if index - 1 < 0 :
index = len ( self . accounts ) - 1
else :
index = index - 1
account = self . accounts [ index ]
self . current_account = account
buff = self . view . search ( " home_timeline " , account )
2015-02-26 15:21:26 -06:00
if buff == None :
2015-05-01 10:05:42 -05:00
output . speak ( _ ( u " {0} : This account is not logged into twitter. " ) . format ( account ) , True )
2015-02-26 15:21:26 -06:00
return
2015-01-19 12:15:57 -06:00
self . view . change_buffer ( buff )
buffer = self . get_current_buffer ( )
2015-07-03 09:40:44 -05:00
if self . showing == True : buffer . buffer . set_focus_in_list ( )
2015-01-19 12:15:57 -06:00
try :
msg = _ ( u " %s . %s , %s of %s " ) % ( buffer . account , self . view . get_buffer_text ( ) , buffer . buffer . list . get_selected ( ) + 1 , buffer . buffer . list . get_count ( ) )
except :
msg = _ ( u " %s . Empty " ) % ( self . view . get_buffer_text ( ) , )
2015-04-10 09:35:09 -05:00
output . speak ( msg , True )
2015-01-19 12:15:57 -06:00
2015-01-25 02:38:17 -06:00
def go_home ( self ) :
buffer = self . get_current_buffer ( )
buffer . buffer . list . select_item ( 0 )
try :
2015-04-10 09:35:09 -05:00
output . speak ( buffer . get_message ( ) , True )
2015-01-25 02:38:17 -06:00
except :
pass
def go_end ( self ) :
buffer = self . get_current_buffer ( )
buffer . buffer . list . select_item ( buffer . buffer . list . get_count ( ) - 1 )
try :
2015-04-10 09:35:09 -05:00
output . speak ( buffer . get_message ( ) , True )
2015-01-25 02:38:17 -06:00
except :
pass
def go_page_up ( self ) :
buffer = self . get_current_buffer ( )
if buffer . buffer . list . get_selected ( ) < = 20 :
index = 0
else :
index = buffer . buffer . list . get_selected ( ) - 20
buffer . buffer . list . select_item ( index )
try :
2015-04-10 09:35:09 -05:00
output . speak ( buffer . get_message ( ) , True )
2015-01-25 02:38:17 -06:00
except :
pass
def go_page_down ( self ) :
buffer = self . get_current_buffer ( )
if buffer . buffer . list . get_selected ( ) > = buffer . buffer . list . get_count ( ) - 20 :
index = buffer . buffer . list . get_count ( ) - 1
else :
index = buffer . buffer . list . get_selected ( ) + 20
buffer . buffer . list . select_item ( index )
try :
2015-04-10 09:35:09 -05:00
output . speak ( buffer . get_message ( ) , True )
2015-01-25 02:38:17 -06:00
except :
pass
2015-01-20 15:40:33 -06:00
def url ( self , * args , * * kwargs ) :
2015-03-17 12:24:29 -06:00
buffer = self . get_current_buffer ( )
buffer . url ( )
2015-01-20 15:40:33 -06:00
def audio ( self , * args , * * kwargs ) :
self . get_current_buffer ( ) . audio ( )
2015-02-01 21:13:18 -06:00
2015-01-20 15:40:33 -06:00
def volume_down ( self , * args , * * kwargs ) :
self . get_current_buffer ( ) . volume_down ( )
def volume_up ( self , * args , * * kwargs ) :
self . get_current_buffer ( ) . volume_up ( )
2015-01-19 12:15:57 -06:00
def create_invisible_keyboard_shorcuts ( self ) :
keymap = { }
2015-05-16 00:23:33 -05:00
for i in config . keymap [ " keymap " ] :
2015-01-19 12:15:57 -06:00
if hasattr ( self , i ) :
2015-05-16 00:23:33 -05:00
keymap [ config . keymap [ " keymap " ] [ i ] ] = getattr ( self , i )
2015-01-19 12:15:57 -06:00
return keymap
def register_invisible_keyboard_shorcuts ( self , keymap ) :
self . keyboard_handler = WXKeyboardHandler ( self . view )
self . keyboard_handler . register_keys ( keymap )
def unregister_invisible_keyboard_shorcuts ( self , keymap ) :
try :
self . keyboard_handler . unregister_keys ( keymap )
del self . keyboard_handler
except AttributeError :
pass
2014-11-12 20:41:29 -06:00
2015-01-20 15:40:33 -06:00
def notify ( self , session , play_sound = None , message = None , notification = False ) :
2015-03-11 17:17:29 -06:00
if session . settings [ " sound " ] [ " session_mute " ] == True : return
2014-11-12 20:41:29 -06:00
if play_sound != None :
2015-01-20 15:40:33 -06:00
session . sound . play ( play_sound )
2014-11-12 20:41:29 -06:00
if message != None :
output . speak ( message )
def manage_home_timelines ( self , data , user ) :
buffer = self . search_buffer ( " home_timeline " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
play_sound = " tweet_received.ogg "
2015-03-01 20:02:00 -06:00
if " home_timeline " not in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] :
self . notify ( buffer . session , play_sound = play_sound )
2015-02-07 10:23:23 -06:00
buffer . add_new_item ( data )
2014-11-12 20:41:29 -06:00
def manage_mentions ( self , data , user ) :
buffer = self . search_buffer ( " mentions " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
play_sound = " mention_received.ogg "
2015-03-15 18:24:15 -06:00
message = _ ( u " One mention from %s " ) % ( data [ " user " ] [ " name " ] )
2015-03-01 20:02:00 -06:00
if " mentions " not in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] :
self . notify ( buffer . session , play_sound = play_sound , message = message )
2015-02-07 10:23:23 -06:00
buffer . add_new_item ( data )
2014-11-12 20:41:29 -06:00
def manage_direct_messages ( self , data , user ) :
buffer = self . search_buffer ( " direct_messages " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
play_sound = " dm_received.ogg "
message = _ ( u " New direct message " )
2015-03-01 20:02:00 -06:00
if " direct_messages " not in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] :
self . notify ( buffer . session , play_sound = play_sound , message = message )
2015-02-07 10:23:23 -06:00
buffer . add_new_item ( data )
2014-11-12 20:41:29 -06:00
def manage_sent_dm ( self , data , user ) :
buffer = self . search_buffer ( " sent_direct_messages " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
play_sound = " dm_sent.ogg "
2015-03-01 20:02:00 -06:00
if " sent_direct_messages " not in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] :
self . notify ( buffer . session , play_sound = play_sound )
2015-02-07 10:23:23 -06:00
buffer . add_new_item ( data )
2014-11-12 20:41:29 -06:00
def manage_sent_tweets ( self , data , user ) :
buffer = self . search_buffer ( " sent_tweets " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
play_sound = " tweet_send.ogg "
2015-03-01 20:02:00 -06:00
if " sent_tweets " not in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] :
self . notify ( buffer . session , play_sound = play_sound )
2015-02-07 10:23:23 -06:00
buffer . add_new_item ( data )
2014-11-12 20:41:29 -06:00
def manage_events ( self , data , user ) :
buffer = self . search_buffer ( " events " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
play_sound = " new_event.ogg "
2015-03-01 20:02:00 -06:00
if " events " not in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] :
self . notify ( buffer . session , play_sound = play_sound )
2015-02-07 10:23:23 -06:00
buffer . add_new_item ( data )
2014-11-12 20:41:29 -06:00
def manage_followers ( self , data , user ) :
buffer = self . search_buffer ( " followers " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
play_sound = " update_followers.ogg "
2015-03-01 20:02:00 -06:00
if " followers " not in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] :
self . notify ( buffer . session , play_sound = play_sound )
2015-02-07 10:23:23 -06:00
buffer . add_new_item ( data )
2014-11-12 20:41:29 -06:00
def manage_friend ( self , data , user ) :
buffer = self . search_buffer ( " friends " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
buffer . add_new_item ( data )
2015-03-19 05:31:19 -06:00
pub . sendMessage ( " restart-streams " , streams = [ " main_stream " ] , session = buffer . session )
2014-11-12 20:41:29 -06:00
def manage_unfollowing ( self , item , user ) :
buffer = self . search_buffer ( " friends " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
buffer . remove_item ( item )
2015-03-19 05:31:19 -06:00
pub . sendMessage ( " restart-streams " , streams = [ " main_stream " ] , session = buffer . session )
2014-11-12 20:41:29 -06:00
def manage_favourite ( self , data , user ) :
buffer = self . search_buffer ( " favourites " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
play_sound = " favourite.ogg "
2015-03-01 20:02:00 -06:00
if " favourites " not in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] :
self . notify ( buffer . session , play_sound = play_sound )
2015-02-07 10:23:23 -06:00
buffer . add_new_item ( data )
2014-11-12 20:41:29 -06:00
def manage_unfavourite ( self , item , user ) :
buffer = self . search_buffer ( " favourites " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
buffer . remove_item ( item )
def manage_blocked_user ( self , data , user ) :
buffer = self . search_buffer ( " blocked " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
buffer . add_new_item ( data )
2015-03-19 05:31:19 -06:00
pub . sendMessage ( " restart-streams " , streams = [ " main_stream " ] , session = buffer . session )
2014-11-12 20:41:29 -06:00
def manage_unblocked_user ( self , item , user ) :
buffer = self . search_buffer ( " blocked " , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
buffer . remove_item ( item )
2015-03-19 05:31:19 -06:00
pub . sendMessage ( " restart-streams " , streams = [ " main_stream " ] , session = buffer . session )
2014-11-12 20:41:29 -06:00
def manage_item_in_timeline ( self , data , user , who ) :
2014-11-12 22:37:52 -06:00
buffer = self . search_buffer ( " %s -timeline " % ( who , ) , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2014-11-12 20:41:29 -06:00
play_sound = " tweet_timeline.ogg "
2016-04-02 06:57:50 -06:00
if " %s -timeline " % ( who , ) not in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] and buffer . session . settings [ " sound " ] [ " session_mute " ] == False :
2015-03-01 20:02:00 -06:00
self . notify ( buffer . session , play_sound = play_sound )
2015-03-14 17:38:26 -06:00
output . speak ( _ ( u " One tweet from %s " ) % ( data [ " user " ] [ " name " ] ) )
2015-02-07 10:23:23 -06:00
buffer . add_new_item ( data )
2014-11-12 20:41:29 -06:00
2015-04-27 16:08:02 -05:00
def manage_item_in_list ( self , data , user , where ) :
buffer = self . search_buffer ( " %s " % ( where , ) , user )
2015-06-04 17:15:03 -05:00
if buffer == None : return
2015-11-03 05:56:57 -06:00
play_sound = " list_tweet.ogg "
2016-04-02 06:57:50 -06:00
if " %s " % ( where , ) not in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] and buffer . session . settings [ " sound " ] [ " session_mute " ] == False :
2015-04-27 16:08:02 -05:00
self . notify ( buffer . session , play_sound = play_sound )
output . speak ( _ ( u " One tweet from %s " ) % ( data [ " user " ] [ " name " ] ) )
buffer . add_new_item ( data )
2014-12-31 00:07:27 -06:00
def start_buffers ( self , session ) :
2015-01-18 17:19:39 -06:00
log . debug ( " starting buffers... Session %s " % ( session . session_id , ) )
2014-12-31 00:07:27 -06:00
for i in self . buffers :
if i . session == session and i . needs_init == True :
i . start_stream ( )
2015-01-13 12:31:37 -06:00
log . debug ( " Starting the streaming endpoint " )
2014-12-31 00:07:27 -06:00
session . start_streaming ( )
2015-08-25 13:37:31 -05:00
def set_positions ( self ) :
for i in session_ . sessions :
self . set_buffer_positions ( i )
2015-01-13 12:31:37 -06:00
def manage_stream_errors ( self , session ) :
2015-10-14 17:30:41 -05:00
log . error ( " Restarting %s session streams. It will be destroyed " % ( session , ) )
2015-02-11 16:14:25 -06:00
s = session_ . sessions [ session ]
2015-11-23 10:30:23 -06:00
if hasattr ( s , " main_stream " ) :
s . main_stream . disconnect ( )
log . error ( " main stream disconnected " )
del s . main_stream
if hasattr ( s , " timelinesStream " ) :
s . timelinesStream . disconnect ( )
2015-10-14 20:38:42 -05:00
del s . timelinesStream
2015-11-23 10:30:23 -06:00
s . counter = 0
2016-07-27 11:56:38 -05:00
# s.reconnection_function_active = False
2015-11-03 04:42:38 -06:00
# for i in self.buffers:
# if i.invisible == True and i.session.session_id == s.session_id and i.type != "people":
# i.start_stream()
# s.listen_stream_error()
2015-01-13 12:31:37 -06:00
def check_connection ( self ) :
for i in session_ . sessions :
2015-02-26 15:21:26 -06:00
if session_ . sessions [ i ] . is_logged == False : continue
2015-01-13 12:31:37 -06:00
session_ . sessions [ i ] . check_connection ( )
2015-01-27 17:09:28 -06:00
def create_new_buffer ( self , buffer , account , create ) :
buff = self . search_buffer ( " home_timeline " , account )
if create == True :
if buffer == " favourites " :
favourites = buffersController . baseBufferController ( self . view . nb , " get_favorites " , " favourites " , buff . session , buff . session . db [ " user_name " ] )
self . buffers . append ( favourites )
2015-11-03 10:07:06 -06:00
self . view . insert_buffer ( favourites . buffer , name = _ ( u " Likes " ) , pos = self . view . search ( buff . session . db [ " user_name " ] , buff . session . db [ " user_name " ] ) )
2015-01-27 17:09:28 -06:00
favourites . start_stream ( )
if buffer == " followers " :
followers = buffersController . peopleBufferController ( self . view . nb , " get_followers_list " , " followers " , buff . session , buff . session . db [ " user_name " ] , screen_name = buff . session . db [ " user_name " ] )
self . buffers . append ( followers )
self . view . insert_buffer ( followers . buffer , name = _ ( u " Followers " ) , pos = self . view . search ( buff . session . db [ " user_name " ] , buff . session . db [ " user_name " ] ) )
followers . start_stream ( )
elif buffer == " friends " :
friends = buffersController . peopleBufferController ( self . view . nb , " get_friends_list " , " friends " , buff . session , buff . session . db [ " user_name " ] , screen_name = buff . session . db [ " user_name " ] )
self . buffers . append ( friends )
self . view . insert_buffer ( friends . buffer , name = _ ( u " Friends " ) , pos = self . view . search ( buff . session . db [ " user_name " ] , buff . session . db [ " user_name " ] ) )
friends . start_stream ( )
2015-03-10 09:44:21 -06:00
elif buffer == " blocked " :
2015-01-27 17:09:28 -06:00
blocks = buffersController . peopleBufferController ( self . view . nb , " list_blocks " , " blocked " , buff . session , buff . session . db [ " user_name " ] )
self . buffers . append ( blocks )
self . view . insert_buffer ( blocks . buffer , name = _ ( u " Blocked users " ) , pos = self . view . search ( buff . session . db [ " user_name " ] , buff . session . db [ " user_name " ] ) )
blocks . start_stream ( )
2015-03-10 09:44:21 -06:00
elif buffer == " muted " :
2015-01-27 17:09:28 -06:00
muted = buffersController . peopleBufferController ( self . view . nb , " get_muted_users_list " , " muted " , buff . session , buff . session . db [ " user_name " ] )
self . buffers . append ( muted )
self . view . insert_buffer ( muted . buffer , name = _ ( u " Muted users " ) , pos = self . view . search ( buff . session . db [ " user_name " ] , buff . session . db [ " user_name " ] ) )
muted . start_stream ( )
elif buffer == " events " :
events = buffersController . eventsBufferController ( self . view . nb , " events " , buff . session , buff . session . db [ " user_name " ] , bufferType = " dmPanel " , screen_name = buff . session . db [ " user_name " ] )
self . buffers . append ( events )
self . view . insert_buffer ( events . buffer , name = _ ( u " Events " ) , pos = self . view . search ( buff . session . db [ " user_name " ] , buff . session . db [ " user_name " ] ) )
2015-03-10 09:44:21 -06:00
elif create == False :
self . destroy_buffer ( buffer , buff . session . db [ " user_name " ] )
2015-06-05 05:21:49 -05:00
elif buffer == " list " :
if create in buff . session . settings [ " other_buffers " ] [ " lists " ] :
output . speak ( _ ( u " This list is already opened " ) , True )
return
tl = buffersController . listBufferController ( self . view . nb , " get_list_statuses " , create + " -list " , buff . session , buff . session . db [ " user_name " ] , bufferType = None , list_id = utils . find_list ( create , buff . session . db [ " lists " ] ) )
buff . session . lists . append ( tl )
2015-08-08 09:42:55 -05:00
pos = self . view . search ( " lists " , buff . session . db [ " user_name " ] )
self . insert_buffer ( tl , pos )
2015-06-05 05:21:49 -05:00
self . view . insert_buffer ( tl . buffer , name = _ ( u " List for {} " ) . format ( create ) , pos = self . view . search ( " lists " , buff . session . db [ " user_name " ] ) )
tl . start_stream ( )
buff . session . settings [ " other_buffers " ] [ " lists " ] . append ( create )
pub . sendMessage ( " restart-streams " , streams = [ " timelinesStream " ] , session = buff . session )
2015-01-27 17:09:28 -06:00
2015-02-12 10:29:51 -06:00
def restart_streams ( self , streams = [ ] , session = None ) :
for i in streams :
2015-02-26 10:09:13 -06:00
log . debug ( " Restarting the %s stream " % ( i , ) )
2015-02-12 10:29:51 -06:00
session . remove_stream ( i )
session . check_connection ( )
2015-02-26 10:09:13 -06:00
def invisible_shorcuts_changed ( self , registered ) :
if registered == True :
km = self . create_invisible_keyboard_shorcuts ( )
self . register_invisible_keyboard_shorcuts ( km )
elif registered == False :
km = self . create_invisible_keyboard_shorcuts ( )
self . unregister_invisible_keyboard_shorcuts ( km )
2015-02-26 16:09:26 -06:00
def about ( self , * args , * * kwargs ) :
self . view . about_dialog ( )
def visit_website ( self , * args , * * kwargs ) :
webbrowser . open ( application . url )
2015-03-04 17:52:27 -06:00
def manage_accounts ( self , * args , * * kwargs ) :
2015-04-22 15:34:44 -05:00
sm = sessionManager . sessionManagerController ( started = True )
2015-03-04 17:52:27 -06:00
sm . fill_list ( )
sm . show ( )
for i in sm . new_sessions :
2015-03-05 11:27:48 -06:00
self . create_buffers ( session_ . sessions [ i ] )
call_threaded ( self . start_buffers , session_ . sessions [ i ] )
for i in sm . removed_sessions :
if session_ . sessions [ i ] . logged == True :
self . logout_account ( session_ . sessions [ i ] . session_id )
self . destroy_buffer ( session_ . sessions [ i ] . settings [ " twitter " ] [ " user_name " ] , session_ . sessions [ i ] . settings [ " twitter " ] [ " user_name " ] )
self . accounts . remove ( session_ . sessions [ i ] . settings [ " twitter " ] [ " user_name " ] )
session_ . sessions . pop ( i )
2015-03-04 17:52:27 -06:00
2015-03-06 21:37:08 -06:00
def update_profile ( self , * args , * * kwargs ) :
2015-03-08 14:18:29 -06:00
r = user . profileController ( self . get_best_buffer ( ) . session )
def user_details ( self , * args , * * kwargs ) :
buffer = self . get_current_buffer ( )
if not hasattr ( buffer , " session " ) or buffer . session == None : return
if hasattr ( buffer , " user_details " ) :
buffer . user_details ( )
2015-03-06 21:37:08 -06:00
2015-03-11 16:36:22 -06:00
def toggle_autoread ( self , * args , * * kwargs ) :
buffer = self . get_current_buffer ( )
if hasattr ( buffer , " session " ) and buffer . session == None : return
if buffer . name not in buffer . session . settings [ " other_buffers " ] [ " autoread_buffers " ] :
buffer . session . settings [ " other_buffers " ] [ " autoread_buffers " ] . append ( buffer . name )
2015-04-10 09:35:09 -05:00
output . speak ( _ ( u " The auto-reading of new tweets is enabled for this buffer " ) , True )
2015-03-11 16:36:22 -06:00
elif buffer . name in buffer . session . settings [ " other_buffers " ] [ " autoread_buffers " ] :
buffer . session . settings [ " other_buffers " ] [ " autoread_buffers " ] . remove ( buffer . name )
2015-04-10 09:35:09 -05:00
output . speak ( _ ( u " The auto-reading of new tweets is disabled for this buffer " ) , True )
2015-03-11 16:36:22 -06:00
2015-03-11 17:17:29 -06:00
def toggle_session_mute ( self , * args , * * kwargs ) :
buffer = self . get_best_buffer ( )
if buffer . session . settings [ " sound " ] [ " session_mute " ] == False :
buffer . session . settings [ " sound " ] [ " session_mute " ] = True
2015-04-10 09:35:09 -05:00
output . speak ( _ ( u " Session mute on " ) , True )
2015-03-11 17:17:29 -06:00
elif buffer . session . settings [ " sound " ] [ " session_mute " ] == True :
buffer . session . settings [ " sound " ] [ " session_mute " ] = False
2015-05-16 18:09:11 -05:00
output . speak ( _ ( u " Session mute off " ) , True )
2015-03-11 17:17:29 -06:00
def toggle_buffer_mute ( self , * args , * * kwargs ) :
buffer = self . get_current_buffer ( )
if hasattr ( buffer , " session " ) and buffer . session == None : return
if buffer . name not in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] :
buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] . append ( buffer . name )
2015-04-10 09:35:09 -05:00
output . speak ( _ ( u " Buffer mute on " ) , True )
2015-03-11 17:17:29 -06:00
elif buffer . name in buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] :
buffer . session . settings [ " other_buffers " ] [ " muted_buffers " ] . remove ( buffer . name )
2015-04-10 09:35:09 -05:00
output . speak ( _ ( u " Buffer mute off " ) , True )
2015-03-11 17:17:29 -06:00
2015-07-06 12:05:03 -05:00
def view_documentation ( self , * args , * * kwargs ) :
lang = localization . get ( " documentation " )
os . chdir ( " documentation/ %s " % ( lang , ) )
webbrowser . open ( " manual.html " )
os . chdir ( " ../../ " )
2016-02-02 09:30:13 -06:00
def view_changelog ( self , * args , * * kwargs ) :
os . chdir ( " documentation " )
webbrowser . open ( " changelog.html " )
os . chdir ( " ../ " )
2015-07-13 05:43:40 -05:00
def insert_buffer ( self , buffer , position ) :
2015-08-08 09:42:55 -05:00
self . buffers . insert ( position , buffer )
2015-07-13 05:43:40 -05:00
2015-07-29 08:40:07 -05:00
def copy_to_clipboard ( self , * args , * * kwargs ) :
output . copy ( self . get_current_buffer ( ) . get_message ( ) )
output . speak ( _ ( u " Copied " ) )
2015-07-29 13:45:57 -05:00
def repeat_item ( self , * args , * * kwargs ) :
2015-08-06 13:54:26 -05:00
output . speak ( self . get_current_buffer ( ) . get_message ( ) )
2015-08-21 09:51:01 -05:00
def execute_action ( self , action ) :
if hasattr ( self , action ) :
getattr ( self , action ) ( )
2015-12-28 09:05:09 -06:00
def restart_streams_ ( self , session ) :
2015-12-26 09:02:08 -06:00
for i in self . buffers :
if i . session != None and i . session . session_id == session :
i . start_stream ( )
2015-08-06 13:54:26 -05:00
def __del__ ( self ) :
2015-12-26 09:02:08 -06:00
config . app . write ( )
def update_buffer ( self , * args , * * kwargs ) :
bf = self . get_current_buffer ( )
if not hasattr ( bf , " start_stream " ) :
output . speak ( _ ( u " Unable to update this buffer. " ) )
return
else :
output . speak ( _ ( u " Updating buffer... " ) )
n = bf . start_stream ( mandatory = True )
if n != None :
2016-04-16 13:31:37 -05:00
output . speak ( _ ( u " {0} items retrieved " ) . format ( n , ) )
def on_tweet_deleted ( self , data ) :
id = data [ " delete " ] [ " status " ] [ " id " ]
for i in self . buffers :
if hasattr ( i , " remove_tweet " ) and hasattr ( i , " name " ) :
i . remove_tweet ( id )