2015-04-01 01:46:15 +02:00
from gi . repository import Gtk
import widgetUtils
2015-04-04 00:57:08 +02:00
class sessionManagerWindow ( widgetUtils . baseDialog ) :
2015-04-01 01:46:15 +02:00
def __init__ ( self ) :
super ( sessionManagerWindow , self ) . __init__ ( " Session Manager " , None , 0 , ( Gtk . STOCK_OK , widgetUtils . OK , Gtk . STOCK_CANCEL , widgetUtils . CANCEL ) )
self . list = widgetUtils . list ( " Session " )
2015-04-04 00:57:08 +02:00
self . box . add ( self . list . list )
2015-04-01 01:46:15 +02:00
btnBox = Gtk . Box ( spacing = 6 )
self . new = Gtk . Button ( " New account " )
self . remove = Gtk . Button ( " Remove account " )
2015-04-22 22:34:44 +02:00
self . configuration = Gtk . Button ( " Configuration " )
2015-04-01 01:46:15 +02:00
btnBox . add ( self . new )
btnBox . add ( self . remove )
2015-04-22 22:34:44 +02:00
btnBox . add ( self . configuration )
2015-04-04 00:57:08 +02:00
self . box . add ( btnBox )
2015-04-01 01:46:15 +02:00
self . show_all ( )
def fill_list ( self , sessionsList ) :
for i in sessionsList :
2015-04-04 00:57:08 +02:00
self . list . insert_item ( False , i )
2015-04-01 01:46:15 +02:00
if self . list . get_count ( ) > 0 :
self . list . select_item ( 0 )
def new_account_dialog ( self ) :
dialog = Gtk . MessageDialog ( self , 0 , Gtk . MessageType . QUESTION , Gtk . ButtonsType . YES_NO , " Authorization " )
dialog . format_secondary_text ( " The request for the required Twitter authorization to continue will be opened on your browser. You only need to do it once. Would you like to autorhise a new account now? " )
2015-04-04 00:57:08 +02:00
answer = dialog . run ( )
dialog . destroy ( )
return answer
2015-04-01 01:46:15 +02:00
def add_new_session_to_list ( self ) :
total = self . list . get_count ( )
name = " Authorised account %d " % ( total + 1 )
self . list . insert_item ( name )
if self . list . get_count ( ) == 1 :
self . list . select_item ( 0 )
def show_unauthorised_error ( self ) :
dialog = Gtk . MessageDialog ( self , 0 , Gtk . MessageType . ERROR , Gtk . ButtonsType . CANCEL , " Invalid user token " )
dialog . format_secondary_text ( " Your access token is invalid or the authorisation has failed. Please try again. " )
2015-04-04 00:57:08 +02:00
answer = dialog . run ( )
return answer
2015-04-01 01:46:15 +02:00
def remove_account_dialog ( self ) :
dialog = Gtk . MessageDialog ( self , 0 , Gtk . MessageType . QUESTION , Gtk . ButtonsType . YES_NO , " Remove account " )
dialog . format_secondary_text ( " Do you really want delete this account? " )
2015-04-04 00:57:08 +02:00
answer = dialog . run ( )
return answer
2015-04-01 01:46:15 +02:00
def get_selected ( self ) :
return self . list . get_selected ( )
def remove_session ( self , sessionID ) :
self . list . remove_item ( sessionID )