2016-02-13 17:06:36 -06:00
# -*- coding: utf-8 -*-
2016-02-15 16:49:09 -06:00
import os
2016-02-13 17:06:36 -06:00
import arrow
import messages
import languageHandler
import widgetUtils
import output
import wx
import webbrowser
2016-02-15 15:09:33 -06:00
import utils
2016-02-17 17:37:57 -06:00
from sessionmanager import session # We'll use some functions from there
2016-02-13 17:06:36 -06:00
from pubsub import pub
from wxUI . dialogs import postDialogs , urlList
from extra import SpellChecker , translator
from mysc . thread_utils import call_threaded
from wxUI import menus
2016-03-25 12:11:57 -06:00
def get_user ( id , profiles ) :
2016-04-03 06:49:15 -05:00
""" Returns an user name and last name based in the id receibed. """
2016-03-25 12:11:57 -06:00
for i in profiles :
if i [ " id " ] == id :
2016-03-26 22:03:43 -06:00
return u " {0} {1} " . format ( i [ " first_name " ] , i [ " last_name " ] )
return _ ( u " Unknown username " )
2016-03-25 12:11:57 -06:00
2016-04-03 06:49:15 -05:00
def add_attachment ( attachment ) :
msg = u " "
tpe = " "
if attachment [ " type " ] == " link " :
msg = u " {0} : {1} " . format ( attachment [ " link " ] [ " title " ] , attachment [ " link " ] [ " url " ] )
tpe = _ ( u " Link " )
elif attachment [ " type " ] == " photo " :
tpe = _ ( u " Photo " )
msg = attachment [ " photo " ] [ " text " ]
if msg == " " :
msg = " photo with no description available "
elif attachment [ " type " ] == " video " :
msg = u " {0} " . format ( attachment [ " video " ] [ " title " ] , )
tpe = _ ( u " Video " )
2016-04-04 03:40:42 -05:00
elif attachment [ " type " ] == " audio " :
msg = u " {0} " . format ( " " . join ( session . compose_audio ( attachment [ " audio " ] ) ) )
tpe = _ ( u " Audio " )
2016-04-07 04:14:33 -05:00
elif attachment [ " type " ] == " doc " :
msg = u " {0} " . format ( attachment [ " doc " ] [ " title " ] )
tpe = _ ( u " {0} document " ) . format ( attachment [ " doc " ] [ " ext " ] )
2016-04-03 06:49:15 -05:00
return [ tpe , msg ]
2016-03-31 17:27:36 -06:00
def get_message ( status ) :
message = " "
2016-04-04 10:23:02 -05:00
if status . has_key ( " text " ) :
message = utils . clean_text ( status [ " text " ] )
2016-03-31 17:27:36 -06:00
return message
2016-02-13 17:06:36 -06:00
class postController ( object ) :
def __init__ ( self , session , postObject ) :
super ( postController , self ) . __init__ ( )
self . session = session
self . post = postObject
2016-04-03 06:49:15 -05:00
# Posts from newsfeed contains this source_id instead from_id in walls. Also it uses post_id and walls use just id.
2016-03-31 16:55:46 -06:00
if self . post . has_key ( " source_id " ) :
self . user_identifier = " source_id "
self . post_identifier = " post_id "
2016-04-07 04:14:33 -05:00
# print self.post["type"]
2016-03-31 16:55:46 -06:00
else :
self . user_identifier = " from_id "
self . post_identifier = " id "
2016-02-13 17:06:36 -06:00
self . dialog = postDialogs . post ( )
2016-03-26 23:33:32 -06:00
# self.dialog.comments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.show_comment)
2016-03-27 06:06:10 -06:00
widgetUtils . connect_event ( self . dialog . like , widgetUtils . BUTTON_PRESSED , self . post_like )
2016-02-13 17:06:36 -06:00
widgetUtils . connect_event ( self . dialog . comment , widgetUtils . BUTTON_PRESSED , self . add_comment )
widgetUtils . connect_event ( self . dialog . tools , widgetUtils . BUTTON_PRESSED , self . show_tools_menu )
2016-03-28 05:19:28 -06:00
widgetUtils . connect_event ( self . dialog . repost , widgetUtils . BUTTON_PRESSED , self . post_repost )
2016-04-04 10:23:02 -05:00
# self.dialog.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.show_menu, self.dialog.comments.list)
# self.dialog.Bind(wx.EVT_LIST_KEY_DOWN, self.show_menu_by_key, self.dialog.comments.list)
2016-03-26 23:33:32 -06:00
call_threaded ( self . load_all_components )
2016-04-07 04:14:33 -05:00
# if self.post.has_key("attachments"): print self.post["attachments"]
2016-04-03 06:49:15 -05:00
self . attachments = [ ]
2016-03-25 12:11:57 -06:00
def get_comments ( self ) :
2016-03-31 16:55:46 -06:00
user = self . post [ self . user_identifier ]
id = self . post [ self . post_identifier ]
2016-03-26 22:03:43 -06:00
self . comments = self . session . vk . client . wall . getComments ( owner_id = user , post_id = id , need_likes = 1 , count = 100 , extended = 1 , preview_length = 0 )
2016-03-25 12:11:57 -06:00
comments_ = [ ]
2016-03-26 22:03:43 -06:00
for i in self . comments [ " items " ] :
from_ = get_user ( i [ " from_id " ] , self . comments [ " profiles " ] )
2016-03-25 12:11:57 -06:00
if len ( i [ " text " ] ) > 140 :
text = i [ " text " ] [ : 141 ]
else :
text = i [ " text " ]
original_date = arrow . get ( i [ " date " ] )
created_at = original_date . humanize ( locale = languageHandler . getLanguage ( ) )
likes = str ( i [ " likes " ] [ " count " ] )
comments_ . append ( ( from_ , text , created_at , likes ) )
self . dialog . insert_comments ( comments_ )
2016-02-17 17:37:57 -06:00
def get_post_information ( self ) :
2016-03-31 16:55:46 -06:00
from_ = self . session . get_user_name ( self . post [ self . user_identifier ] )
if self . post . has_key ( " copy_history " ) :
title = _ ( u " repost from {0} " ) . format ( from_ , )
else :
title = _ ( u " Post from {0} " ) . format ( from_ , )
self . dialog . set_title ( title )
message = u " "
2016-03-31 17:27:36 -06:00
message = get_message ( self . post )
2016-04-03 06:49:15 -05:00
self . get_attachments ( self . post )
2016-03-31 17:27:36 -06:00
if self . post . has_key ( " copy_history " ) :
nm = u " \n "
for i in self . post [ " copy_history " ] :
nm + = u " {0} : {1} \n \n " . format ( self . session . get_user_name ( i [ " from_id " ] ) , get_message ( i ) )
2016-04-03 06:49:15 -05:00
self . get_attachments ( i )
2016-03-31 17:27:36 -06:00
message + = nm
2016-03-31 16:55:46 -06:00
self . dialog . set_post ( message )
2016-02-13 17:06:36 -06:00
2016-04-03 06:49:15 -05:00
def get_attachments ( self , post ) :
attachments = [ ]
if post . has_key ( " attachments " ) :
for i in post [ " attachments " ] :
attachments . append ( add_attachment ( i ) )
2016-04-04 10:23:02 -05:00
self . attachments . append ( i )
2016-04-03 06:49:15 -05:00
if len ( self . attachments ) > 0 :
self . dialog . attachments . list . Enable ( True )
2016-04-04 10:23:02 -05:00
self . dialog . attachments . list . Bind ( wx . EVT_LIST_ITEM_ACTIVATED , self . open_attachment )
self . dialog . insert_attachments ( attachments )
2016-04-03 06:49:15 -05:00
2016-02-13 17:06:36 -06:00
def load_all_components ( self ) :
2016-03-26 23:33:32 -06:00
self . get_post_information ( )
2016-02-13 17:06:36 -06:00
self . get_likes ( )
2016-03-26 23:33:32 -06:00
self . get_reposts ( )
2016-02-13 17:06:36 -06:00
self . get_comments ( )
2016-03-27 06:06:10 -06:00
if self . post [ " comments " ] [ " can_post " ] == 0 :
self . dialog . disable ( " add_comment " )
if self . post [ " likes " ] [ " can_like " ] == 0 and self . post [ " likes " ] [ " user_likes " ] == 0 :
self . dialog . disable ( " like " )
elif self . post [ " likes " ] [ " user_likes " ] == 1 :
self . dialog . set ( " like " , _ ( u " &Dislike " ) )
if self . post [ " likes " ] [ " can_publish " ] == 0 :
self . dialog . disable ( " repost " )
def post_like ( self , * args , * * kwargs ) :
2016-04-03 06:49:15 -05:00
if self . post . has_key ( " owner_id " ) == False :
user = int ( self . post [ self . user_identifier ] )
else :
user = int ( self . post [ " owner_id " ] )
2016-03-31 16:55:46 -06:00
id = int ( self . post [ self . post_identifier ] )
2016-04-03 06:49:15 -05:00
if self . post . has_key ( " type " ) :
type_ = self . post [ " type " ]
else :
type_ = " post "
2016-03-27 06:06:10 -06:00
if self . dialog . get ( " like " ) == _ ( u " &Dislike " ) :
l = self . session . vk . client . likes . delete ( owner_id = user , item_id = id , type = type_ )
output . speak ( _ ( u " You don ' t like this " ) )
2016-04-03 06:49:15 -05:00
self . post [ " likes " ] [ " count " ] = l [ " likes " ]
self . post [ " likes " ] [ " user_likes " ] = 2
self . get_likes ( )
2016-03-27 06:06:10 -06:00
self . dialog . set ( " like " , _ ( u " &Like " ) )
else :
l = self . session . vk . client . likes . add ( owner_id = user , item_id = id , type = type_ )
output . speak ( _ ( u " You liked this " ) )
self . dialog . set ( " like " , _ ( u " &Dislike " ) )
2016-04-03 06:49:15 -05:00
self . post [ " likes " ] [ " count " ] = l [ " likes " ]
self . post [ " likes " ] [ " user_likes " ] = 1
self . get_likes ( )
2016-02-13 17:06:36 -06:00
2016-03-28 05:19:28 -06:00
def post_repost ( self , * args , * * kwargs ) :
2016-03-31 16:55:46 -06:00
object_id = " wall {0} _ {1} " . format ( self . post [ self . user_identifier ] , self . post [ self . post_identifier ] )
2016-03-28 05:19:28 -06:00
p = messages . post ( title = _ ( u " Repost " ) , caption = _ ( u " Add your comment here " ) , text = " " )
if p . message . get_response ( ) == widgetUtils . OK :
msg = p . message . get_text ( ) . encode ( " utf-8 " )
self . session . vk . client . wall . repost ( object = object_id , message = msg )
2016-02-13 17:06:36 -06:00
def get_likes ( self ) :
2016-03-26 23:33:32 -06:00
self . dialog . set_likes ( self . post [ " likes " ] [ " count " ] )
2016-02-13 17:06:36 -06:00
2016-03-26 23:33:32 -06:00
def get_reposts ( self ) :
self . dialog . set_shares ( self . post [ " reposts " ] [ " count " ] )
2016-02-13 17:06:36 -06:00
def add_comment ( self , * args , * * kwargs ) :
comment = messages . comment ( title = _ ( u " Add a comment " ) , caption = " " , text = " " )
if comment . message . get_response ( ) == widgetUtils . OK :
msg = comment . message . get_text ( ) . encode ( " utf-8 " )
try :
2016-03-31 16:55:46 -06:00
user = self . post [ self . user_identifier ]
id = self . post [ self . post_identifier ]
2016-03-26 22:03:43 -06:00
self . session . vk . client . wall . addComment ( owner_id = user , post_id = id , text = msg )
2016-02-13 17:06:36 -06:00
output . speak ( _ ( u " You ' ve posted a comment " ) )
2016-03-26 22:03:43 -06:00
if self . comments [ " count " ] < 100 :
2016-02-13 17:06:36 -06:00
self . clear_comments_list ( )
self . get_comments ( )
except Exception as msg :
print msg
def clear_comments_list ( self ) :
self . dialog . comments . clear ( )
2016-04-03 06:49:15 -05:00
def show_comment ( self , * args , * * kwargs ) :
2016-02-13 17:06:36 -06:00
c = comment ( self . session , self . comments [ " data " ] [ self . dialog . comments . get_selected ( ) ] )
c . dialog . get_response ( )
def show_menu ( self , * args , * * kwargs ) :
if self . dialog . comments . get_count ( ) == 0 : return
menu = menus . commentMenu ( )
widgetUtils . connect_event ( self . dialog , widgetUtils . MENU , self . show_comment , menuitem = menu . open )
widgetUtils . connect_event ( self . dialog , widgetUtils . MENU , self . comment_like , menuitem = menu . like )
widgetUtils . connect_event ( self . dialog , widgetUtils . MENU , self . comment_unlike , menuitem = menu . unlike )
self . dialog . PopupMenu ( menu , self . dialog . comments . list . GetPosition ( ) )
def show_menu_by_key ( self , ev ) :
if ev . GetKeyCode ( ) == wx . WXK_WINDOWS_MENU :
self . show_menu ( )
def show_tools_menu ( self , * args , * * kwargs ) :
menu = menus . toolsMenu ( )
widgetUtils . connect_event ( self . dialog , widgetUtils . MENU , self . open_url , menuitem = menu . url )
widgetUtils . connect_event ( self . dialog , widgetUtils . MENU , self . translate , menuitem = menu . translate )
widgetUtils . connect_event ( self . dialog , widgetUtils . MENU , self . spellcheck , menuitem = menu . CheckSpelling )
self . dialog . PopupMenu ( menu , self . dialog . tools . GetPosition ( ) )
def comment_like ( self , * args , * * kwargs ) :
comment_id = self . comments [ " data " ] [ self . dialog . comments . get_selected ( ) ] [ " id " ]
self . session . like ( comment_id )
output . speak ( _ ( u " You do like this comment " ) )
def comment_unlike ( self , * args , * * kwargs ) :
comment_id = self . comments [ " data " ] [ self . dialog . comments . get_selected ( ) ] [ " id " ]
self . session . unlike ( comment_id )
output . speak ( _ ( u " You don ' t like this comment " ) )
def translate ( self , * args , * * kwargs ) :
dlg = translator . gui . translateDialog ( )
if dlg . get_response ( ) == widgetUtils . OK :
text_to_translate = self . dialog . post_view . GetValue ( ) . encode ( " utf-8 " )
source = [ x [ 0 ] for x in translator . translator . available_languages ( ) ] [ dlg . get ( " source_lang " ) ]
dest = [ x [ 0 ] for x in translator . translator . available_languages ( ) ] [ dlg . get ( " dest_lang " ) ]
msg = translator . translator . translate ( text_to_translate , source , dest )
self . dialog . post_view . ChangeValue ( msg )
output . speak ( _ ( u " Translated " ) )
else :
return
def spellcheck ( self , * args , * * kwargs ) :
text = self . dialog . post_view . GetValue ( )
checker = SpellChecker . spellchecker . spellChecker ( text , " " )
if hasattr ( checker , " fixed_text " ) :
self . dialog . post_view . ChangeValue ( checker . fixed_text )
def open_url ( self , * args , * * kwargs ) :
text = self . dialog . post_view . GetValue ( )
urls = find_urls ( text )
url = None
if len ( urls ) == 0 : return
if len ( urls ) == 1 :
url = urls [ 0 ]
elif len ( urls ) > 1 :
url_list = urlList . urlList ( )
url_list . populate_list ( urls )
if url_list . get_response ( ) == widgetUtils . OK :
url = urls [ url_list . get_item ( ) ]
if url != None :
output . speak ( _ ( u " Opening URL... " ) , True )
webbrowser . open_new_tab ( url )
2016-04-04 10:23:02 -05:00
def open_attachment ( self , * args , * * kwargs ) :
index = self . dialog . attachments . get_selected ( )
attachment = self . attachments [ index ]
if attachment [ " type " ] == " audio " :
a = audio ( session = self . session , postObject = [ attachment [ " audio " ] ] )
a . dialog . get_response ( )
a . dialog . Destroy ( )
if attachment [ " type " ] == " link " :
output . speak ( _ ( u " Opening URL... " ) , True )
webbrowser . open_new_tab ( attachment [ " link " ] [ " url " ] )
2016-04-07 04:14:33 -05:00
elif attachment [ " type " ] == " doc " :
output . speak ( _ ( u " Opening document in web browser... " ) )
webbrowser . open ( attachment [ " doc " ] [ " url " ] )
2016-04-04 10:23:02 -05:00
elif attachment [ " type " ] == " video " :
# it seems VK doesn't like to attach video links as normal URLS, so we'll have to
# get the full video object and use its "player" key which will open a webbrowser in their site with a player for the video.
# see https://vk.com/dev/attachments_w and and https://vk.com/dev/video.get
# However, the flash player isn't good for visually impaired people (when you press play you won't be able to close the window with alt+f4), so it could be good to use the HTML5 player.
# For firefox, see https://addons.mozilla.org/ru/firefox/addon/force-html5-video-player-at-vk/
# May be I could use a dialogue here for inviting people to use this addon in firefox. It seems it isn't possible to use this html5 player from the player URL.
object_id = " {0} _ {1} " . format ( attachment [ " video " ] [ " owner_id " ] , attachment [ " video " ] [ " id " ] )
video_object = self . session . vk . client . video . get ( owner_id = attachment [ " video " ] [ " owner_id " ] , videos = object_id )
video_object = video_object [ " items " ] [ 0 ]
output . speak ( _ ( u " Opening video in web browser... " ) , True )
webbrowser . open_new_tab ( video_object [ " player " ] )
elif attachment [ " type " ] == " photo " :
output . speak ( _ ( u " Opening photo in web browser... " ) , True )
# Possible photo sizes for looking in the attachment information. Try to use the biggest photo available.
possible_sizes = [ 1280 , 604 , 130 , 75 ]
url = " "
for i in possible_sizes :
if attachment [ " photo " ] . has_key ( " photo_ {0} " . format ( i , ) ) :
url = attachment [ " photo " ] [ " photo_ {0} " . format ( i , ) ]
if url != " " :
webbrowser . open_new_tab ( url )
else :
print attachment [ " photo " ] . keys ( )
2016-02-13 17:06:36 -06:00
class comment ( object ) :
def __init__ ( self , session , comment_object ) :
super ( comment , self ) . __init__ ( )
self . session = session
self . comment = comment_object
self . dialog = postDialogs . comment ( )
from_ = self . comment [ " from " ] [ " name " ]
message = self . comment [ " message " ]
original_date = arrow . get ( self . comment [ " created_time " ] , " YYYY-MM-DTHH:m:sZ " , locale = " en " )
created_at = original_date . humanize ( locale = languageHandler . getLanguage ( ) )
self . dialog . set_post ( message )
self . dialog . set_title ( _ ( u " Comment from {0} " ) . format ( from_ , ) )
widgetUtils . connect_event ( self . dialog . like , widgetUtils . BUTTON_PRESSED , self . post_like )
call_threaded ( self . get_likes )
def get_likes ( self ) :
self . likes = self . session . fb . client . get_connections ( id = self . comment [ " id " ] , connection_name = " likes " , summary = True )
self . dialog . set_likes ( self . likes [ " summary " ] [ " total_count " ] )
def post_like ( self , * args , * * kwargs ) :
lk = self . session . like ( self . comment [ " id " ] )
self . get_likes ( )
2016-02-15 15:09:33 -06:00
class audio ( postController ) :
def __init__ ( self , session , postObject ) :
2016-02-24 10:30:07 -06:00
self . added_audios = { }
2016-02-15 15:09:33 -06:00
self . session = session
self . post = postObject
self . dialog = postDialogs . audio ( )
2016-02-24 10:30:07 -06:00
widgetUtils . connect_event ( self . dialog . list , widgetUtils . LISTBOX_CHANGED , self . handle_changes )
self . load_audios ( )
self . fill_information ( 0 )
2016-02-15 16:49:09 -06:00
widgetUtils . connect_event ( self . dialog . download , widgetUtils . BUTTON_PRESSED , self . download )
2016-02-15 17:49:39 -06:00
widgetUtils . connect_event ( self . dialog . play , widgetUtils . BUTTON_PRESSED , self . play )
2016-02-19 04:17:49 -06:00
widgetUtils . connect_event ( self . dialog . add , widgetUtils . BUTTON_PRESSED , self . add_to_library )
widgetUtils . connect_event ( self . dialog . remove , widgetUtils . BUTTON_PRESSED , self . remove_from_library )
def add_to_library ( self , * args , * * kwargs ) :
2016-02-24 10:30:07 -06:00
post = self . post [ self . dialog . get_audio ( ) ]
2016-02-19 04:17:49 -06:00
args = { }
2016-02-24 10:30:07 -06:00
args [ " audio_id " ] = post [ " id " ]
if post . has_key ( " album_id " ) :
args [ " album_id " ] = post [ " album_id " ]
args [ " owner_id " ] = post [ " owner_id " ]
2016-02-19 04:17:49 -06:00
audio = self . session . vk . client . audio . add ( * * args )
if audio != None and int ( audio ) > 21 :
2016-02-24 10:30:07 -06:00
self . added_audios [ post [ " id " ] ] = audio
2016-02-19 04:17:49 -06:00
self . dialog . change_state ( " add " , False )
self . dialog . change_state ( " remove " , True )
def remove_from_library ( self , * args , * * kwargs ) :
2016-02-24 10:30:07 -06:00
post = self . post [ self . dialog . get_audio ( ) ]
2016-02-19 04:17:49 -06:00
args = { }
2016-02-24 10:30:07 -06:00
if self . added_audios . has_key ( post [ " id " ] ) :
args [ " audio_id " ] = self . added_audios [ post [ " id " ] ]
args [ " owner_id " ] = self . session . user_id
2016-02-19 04:17:49 -06:00
else :
2016-02-24 10:30:07 -06:00
args [ " audio_id " ] = post [ " id " ]
args [ " owner_id " ] = post [ " owner_id " ]
2016-02-19 04:17:49 -06:00
result = self . session . vk . client . audio . delete ( * * args )
if int ( result ) == 1 :
self . dialog . change_state ( " add " , True )
self . dialog . change_state ( " remove " , False )
2016-02-24 10:30:07 -06:00
if self . added_audios . has_key ( post [ " id " ] ) :
self . added_audios . pop ( post [ " id " ] )
def fill_information ( self , index ) :
post = self . post [ index ]
if post . has_key ( " artist " ) :
self . dialog . set ( " artist " , post [ " artist " ] )
if post . has_key ( " title " ) :
self . dialog . set ( " title " , post [ " title " ] )
if post . has_key ( " duration " ) :
self . dialog . set ( " duration " , utils . seconds_to_string ( post [ " duration " ] ) )
self . dialog . set_title ( u " {0} - {1} " . format ( post [ " title " ] , post [ " artist " ] ) )
2016-02-15 15:09:33 -06:00
call_threaded ( self . get_lyrics )
2016-02-24 10:30:07 -06:00
if post [ " owner_id " ] == self . session . user_id or self . added_audios . has_key ( post [ " id " ] ) == True :
self . dialog . change_state ( " remove " , True )
self . dialog . change_state ( " add " , False )
else :
self . dialog . change_state ( " add " , True )
self . dialog . change_state ( " remove " , False )
2016-02-15 15:09:33 -06:00
def get_lyrics ( self ) :
2016-02-24 10:30:07 -06:00
post = self . post [ self . dialog . get_audio ( ) ]
if post . has_key ( " lyrics_id " ) :
l = self . session . vk . client . audio . getLyrics ( lyrics_id = int ( post [ " lyrics_id " ] ) )
2016-02-15 16:49:09 -06:00
self . dialog . set ( " lyric " , l [ " text " ] )
2016-02-26 13:27:30 -06:00
else :
self . dialog . change_state ( " lyric " , False )
2016-02-15 16:49:09 -06:00
def download ( self , * args , * * kwargs ) :
2016-02-24 10:30:07 -06:00
post = self . post [ self . dialog . get_audio ( ) ]
f = u " {0} - {1} .mp3 " . format ( post [ " title " ] , post [ " artist " ] )
2016-02-15 16:49:09 -06:00
path = self . dialog . get_destination_path ( f )
if path != None :
2016-02-24 10:30:07 -06:00
pub . sendMessage ( " download-file " , url = post [ " url " ] , filename = path )
2016-02-15 17:49:39 -06:00
def play ( self , * args , * * kwargs ) :
2016-02-24 10:30:07 -06:00
post = self . post [ self . dialog . get_audio ( ) ]
2016-03-26 12:02:19 -06:00
pub . sendMessage ( " play-audio " , audio_object = post )
2016-02-24 10:30:07 -06:00
def load_audios ( self ) :
for i in self . post :
s = u " {0} - {1} . {2} " . format ( i [ " title " ] , i [ " artist " ] , utils . seconds_to_string ( i [ " duration " ] ) )
self . dialog . insert_audio ( s )
2016-02-25 05:08:56 -06:00
self . dialog . list . SetSelection ( 0 )
2016-02-25 17:48:27 -06:00
if len ( self . post ) == 1 :
self . dialog . list . Enable ( False )
self . dialog . title . SetFocus ( )
2016-02-24 10:30:07 -06:00
def handle_changes ( self , * args , * * kwargs ) :
p = self . dialog . get_audio ( )
self . fill_information ( p )
2016-02-17 17:37:57 -06:00
class friendship ( object ) :
def __init__ ( self , session , post ) :
self . session = session
self . post = post
self . dialog = postDialogs . friendship ( )
list_of_friends = self . get_friend_names ( )
from_ = self . session . get_user_name ( self . post [ " source_id " ] )
title = _ ( u " {0} added the following friends " ) . format ( from_ , )
self . dialog . set_title ( title )
self . set_friends_list ( list_of_friends )
def get_friend_names ( self ) :
2016-03-23 11:48:30 -06:00
self . friends = self . post [ " friends " ] [ " items " ]
return [ self . session . get_user_name ( i [ " user_id " ] ) for i in self . friends ]
2016-02-17 17:37:57 -06:00
def set_friends_list ( self , friendslist ) :
for i in friendslist :
self . dialog . friends . insert_item ( False , * [ i ] )