Show multiple audios in the newsfeed. Modified the audios displayer

This commit is contained in:
Manuel Cortez 2016-02-24 10:30:07 -06:00
parent 0ba3fc7399
commit f4f88e512e
4 changed files with 69 additions and 33 deletions

View File

@ -94,7 +94,8 @@ class baseBuffer(object):
def open_post(self):
post = self.session.db[self.name]["items"][self.tab.list.get_selected()]
if post.has_key("type") and post["type"] == "audio":
a = posts.audio(self.session, post["audio"][1])
print "opening audio"
a = posts.audio(self.session, post["audio"]["items"])
a.dialog.get_response()
a.dialog.Destroy()
elif post.has_key("type") and post["type"] == "friend":
@ -132,6 +133,7 @@ class audioBuffer(feedBuffer):
def open_post(self):
selected = self.tab.list.get_selected()
a = posts.audio(self.session, self.session.db[self.name]["items"][selected])
audios = [self.session.db[self.name]["items"][selected]]
a = posts.audio(self.session, audios)
a.dialog.get_response()
a.dialog.Destroy()

View File

@ -189,70 +189,91 @@ class comment(object):
class audio(postController):
def __init__(self, session, postObject):
self.added_audios = {}
self.session = session
self.post = postObject
self.dialog = postDialogs.audio()
self.fill_information()
if self.post["owner_id"] == self.session.user_id:
self.dialog.change_state("remove", True)
else:
self.dialog.change_state("add", True)
widgetUtils.connect_event(self.dialog.list, widgetUtils.LISTBOX_CHANGED, self.handle_changes)
print "loading audios..."
self.load_audios()
print "Filling information..."
self.fill_information(0)
widgetUtils.connect_event(self.dialog.download, widgetUtils.BUTTON_PRESSED, self.download)
widgetUtils.connect_event(self.dialog.play, widgetUtils.BUTTON_PRESSED, self.play)
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):
post = self.post[self.dialog.get_audio()]
args = {}
args["audio_id"] = self.post["id"]
if self.post.has_key("album_id"):
args["album_id"] = self.post["album_id"]
args["owner_id"] = self.post["owner_id"]
args["audio_id"] = post["id"]
if post.has_key("album_id"):
args["album_id"] = post["album_id"]
args["owner_id"] = post["owner_id"]
audio = self.session.vk.client.audio.add(**args)
if audio != None and int(audio) > 21:
self.audio_id = audio
self.owner_id = self.session.user_id
self.added_audios[post["id"]] = audio
self.dialog.change_state("add", False)
self.dialog.change_state("remove", True)
def remove_from_library(self, *args, **kwargs):
post = self.post[self.dialog.get_audio()]
args = {}
if hasattr(self, "audio_id"):
args["audio_id"] = self.audio_id
args["owner_id"] = self.owner_id
del self.audio_id, self.owner_id
if self.added_audios.has_key(post["id"]):
args["audio_id"] = self.added_audios[post["id"]]
args["owner_id"] = self.session.user_id
else:
args["audio_id"] = self.post["aid"]
args["owner_id"] = self.post["owner_id"]
args["audio_id"] = post["id"]
args["owner_id"] = post["owner_id"]
result = self.session.vk.client.audio.delete(**args)
print result
if int(result) == 1:
self.dialog.change_state("add", True)
self.dialog.change_state("remove", False)
if self.added_audios.has_key(post["id"]):
self.added_audios.pop(post["id"])
def fill_information(self):
if self.post.has_key("artist"):
self.dialog.set("artist", self.post["artist"])
if self.post.has_key("title"):
self.dialog.set("title", self.post["title"])
if self.post.has_key("duration"):
self.dialog.set("duration", utils.seconds_to_string(self.post["duration"]))
self.dialog.set_title(u"{0} - {1}".format(self.post["title"], self.post["artist"]))
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"]))
call_threaded(self.get_lyrics)
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)
def get_lyrics(self):
if self.post.has_key("lyrics_id"):
l = self.session.vk.client.audio.getLyrics(lyrics_id=int(self.post["lyrics_id"]))
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"]))
self.dialog.set("lyric", l["text"])
def download(self, *args, **kwargs):
f = u"{0} - {1}.mp3".format(self.post["title"], self.post["artist"])
post = self.post[self.dialog.get_audio()]
f = u"{0} - {1}.mp3".format(post["title"], post["artist"])
path = self.dialog.get_destination_path(f)
if path != None:
pub.sendMessage("download-file", url=self.post["url"], filename=path)
pub.sendMessage("download-file", url=post["url"], filename=path)
def play(self, *args, **kwargs):
pub.sendMessage("play-audio", audio_object=self.post["url"])
post = self.post[self.dialog.get_audio()]
pub.sendMessage("play-audio", audio_object=post["url"])
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)
def handle_changes(self, *args, **kwargs):
p = self.dialog.get_audio()
self.fill_information(p)
class friendship(object):

View File

@ -54,6 +54,7 @@ RADIOBUTTON = wx.EVT_RADIOBUTTON
# Taskbar mouse clicks.
TASKBAR_RIGHT_CLICK = wx.EVT_TASKBAR_RIGHT_DOWN
TASKBAR_LEFT_CLICK = wx.EVT_TASKBAR_LEFT_DOWN
LISTBOX_CHANGED = wx.EVT_LISTBOX
def exit_application():
""" Closes the current window cleanly. """

View File

@ -108,6 +108,12 @@ class audio(widgetUtils.BaseDialog):
super(audio, self).__init__(parent=None, *args, **kwargs)
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
lbl_list = wx.StaticText(panel, wx.NewId(), _(u"Audio files"))
self.list = wx.ListBox(panel, wx.NewId())
listS = wx.BoxSizer(wx.HORIZONTAL)
listS.Add(lbl_list, 0, wx.ALL, 5)
listS.Add(self.list, 0, wx.ALL, 5)
sizer.Add(listS, 0, wx.ALL, 5)
lbl_title = wx.StaticText(panel, wx.NewId(), _(u"Title"))
self.title = wx.TextCtrl(panel, wx.NewId(), size=(413, -1), style=wx.TE_READONLY|wx.TE_MULTILINE)
titleBox = wx.BoxSizer(wx.HORIZONTAL)
@ -155,6 +161,12 @@ class audio(widgetUtils.BaseDialog):
return saveFileDialog.GetPath()
saveFileDialog.Destroy()
def insert_audio(self, audio_):
self.list.Append(audio_)
def get_audio(self):
return self.list.GetSelection()
class friendship(widgetUtils.BaseDialog):
def __init__(self):
super(friendship, self).__init__(parent=None)