2014-11-12 20:41:29 -06:00
# -*- coding: utf-8 -*-
2019-06-06 11:52:23 -05:00
from __future__ import unicode_literals
2014-11-12 20:41:29 -06:00
import wx
from multiplatform_widgets import widgets
2015-04-19 19:28:27 -04:00
import application
2018-08-17 05:12:49 -05:00
2014-11-12 20:41:29 -06:00
class sessionManagerWindow ( wx . Dialog ) :
2015-03-05 11:27:48 -06:00
def __init__ ( self ) :
2016-02-20 13:51:12 +01:00
super ( sessionManagerWindow , self ) . __init__ ( parent = None , title = _ ( u " Session manager " ) , size = wx . DefaultSize )
2014-11-12 20:41:29 -06:00
panel = wx . Panel ( self )
sizer = wx . BoxSizer ( wx . VERTICAL )
2015-06-26 08:20:21 -05:00
label = wx . StaticText ( panel , - 1 , _ ( u " Accounts list " ) , size = wx . DefaultSize )
2014-11-12 20:41:29 -06:00
listSizer = wx . BoxSizer ( wx . HORIZONTAL )
2015-06-26 08:20:21 -05:00
self . list = widgets . list ( panel , _ ( u " Account " ) , style = wx . LC_SINGLE_SEL | wx . LC_REPORT )
2014-11-12 20:41:29 -06:00
listSizer . Add ( label , 0 , wx . ALL , 5 )
listSizer . Add ( self . list . list , 0 , wx . ALL , 5 )
sizer . Add ( listSizer , 0 , wx . ALL , 5 )
2015-06-26 08:20:21 -05:00
self . new = wx . Button ( panel , - 1 , _ ( u " New account " ) , size = wx . DefaultSize )
2015-03-05 11:27:48 -06:00
self . remove = wx . Button ( panel , - 1 , _ ( u " Remove account " ) )
2015-04-22 15:34:44 -05:00
self . configuration = wx . Button ( panel , - 1 , _ ( u " Global Settings " ) )
2014-11-12 20:41:29 -06:00
ok = wx . Button ( panel , wx . ID_OK , size = wx . DefaultSize )
ok . SetDefault ( )
cancel = wx . Button ( panel , wx . ID_CANCEL , size = wx . DefaultSize )
buttons = wx . BoxSizer ( wx . HORIZONTAL )
2015-03-05 11:27:48 -06:00
buttons . Add ( self . new , 0 , wx . ALL , 5 )
2015-04-22 15:34:44 -05:00
buttons . Add ( self . configuration , 0 , wx . ALL , 5 )
2014-11-12 20:41:29 -06:00
buttons . Add ( ok , 0 , wx . ALL , 5 )
buttons . Add ( cancel , 0 , wx . ALL , 5 )
sizer . Add ( buttons , 0 , wx . ALL , 5 )
panel . SetSizer ( sizer )
min = sizer . CalcMin ( )
self . SetClientSize ( min )
def fill_list ( self , sessionsList ) :
for i in sessionsList :
self . list . insert_item ( False , i )
if self . list . get_count ( ) > 0 :
self . list . select_item ( 0 )
self . list . list . SetSize ( self . list . list . GetBestSize ( ) )
def ok ( self , ev ) :
if self . list . get_count ( ) == 0 :
wx . MessageDialog ( None , _ ( u " You need to configure an account. " ) , _ ( u " Account Error " ) , wx . ICON_ERROR ) . ShowModal ( )
return
self . controller . do_ok ( )
self . EndModal ( wx . ID_OK )
2015-03-05 11:27:48 -06:00
def new_account_dialog ( self ) :
2015-05-16 03:31:53 -04:00
return wx . MessageDialog ( self , _ ( u " The request to authorize your Twitter account will be opened in your browser. You only need to do this once. Would you like to continue? " ) , _ ( u " Authorization " ) , wx . YES_NO ) . ShowModal ( )
2014-11-12 20:41:29 -06:00
def add_new_session_to_list ( self ) :
total = self . list . get_count ( )
2015-05-16 03:31:53 -04:00
name = _ ( u " Authorized account %d " ) % ( total + 1 )
2014-11-12 20:41:29 -06:00
self . list . insert_item ( False , name )
if self . list . get_count ( ) == 1 :
self . list . select_item ( 0 )
2015-03-05 11:27:48 -06:00
2014-11-12 20:41:29 -06:00
def show_unauthorised_error ( self ) :
2015-05-16 03:31:53 -04:00
wx . MessageDialog ( None , _ ( u " Your access token is invalid or the authorization has failed. Please try again. " ) , _ ( u " Invalid user token " ) , wx . ICON_ERROR ) . ShowModal ( )
2015-03-05 11:27:48 -06:00
def get_response ( self ) :
return self . ShowModal ( )
def remove_account_dialog ( self ) :
2015-04-05 23:39:55 +02:00
return wx . MessageDialog ( self , _ ( u " Do you really want to delete this account? " ) , _ ( u " Remove account " ) , wx . YES_NO ) . ShowModal ( )
2015-03-05 11:27:48 -06:00
def get_selected ( self ) :
return self . list . get_selected ( )
def remove_session ( self , sessionID ) :
self . list . remove_item ( sessionID )
2015-04-22 15:34:44 -05:00
def hide_configuration ( self ) :
2015-06-26 08:19:40 -05:00
self . configuration . Hide ( )
def destroy ( self ) :
2018-08-17 05:12:49 -05:00
self . Destroy ( )