New features: add or remove audio files to the library (needs work for reflecting these changes in buffers)
This commit is contained in:
parent
34cbfb2251
commit
4fd4bd07a4
@ -190,8 +190,42 @@ class audio(postController):
|
||||
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.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):
|
||||
args = {}
|
||||
args["audio_id"] = self.post["aid"]
|
||||
if self.post.has_key("album_id"):
|
||||
args["album_id"] = self.post["album_id"]
|
||||
args["owner_id"] = self.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.dialog.change_state("add", False)
|
||||
self.dialog.change_state("remove", True)
|
||||
|
||||
def remove_from_library(self, *args, **kwargs):
|
||||
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
|
||||
else:
|
||||
args["audio_id"] = self.post["aid"]
|
||||
args["owner_id"] = self.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)
|
||||
|
||||
def fill_information(self):
|
||||
if self.post.has_key("artist"):
|
||||
|
@ -134,12 +134,21 @@ class audio(widgetUtils.BaseDialog):
|
||||
sizer.Add(lbox, 0, wx.ALL, 5)
|
||||
self.play = wx.Button(panel, wx.NewId(), _(u"Play"))
|
||||
self.download = wx.Button(panel, wx.NewId(), _(u"Download"))
|
||||
self.add = wx.Button(panel, wx.NewId(), _(u"Add to your library"))
|
||||
self.remove = wx.Button(panel, wx.NewId(), _(u"Remove from your library"))
|
||||
self.add.Enable(False)
|
||||
self.remove.Enable(False)
|
||||
close = wx.Button(panel, wx.ID_CANCEL)
|
||||
bbox = wx.BoxSizer(wx.HORIZONTAL)
|
||||
bbox.Add(self.play, 0, wx.ALL, 5)
|
||||
bbox.Add(self.download, 0, wx.ALL, 5)
|
||||
bbox.Add(self.add, 0, wx.ALL, 5)
|
||||
bbox.Add(self.remove, 0, wx.ALL, 5)
|
||||
bbox.Add(close, 0, wx.ALL, 5)
|
||||
|
||||
def change_state(self, button_name, state):
|
||||
getattr(self, button_name).Enable(state)
|
||||
|
||||
def get_destination_path(self, filename):
|
||||
saveFileDialog = wx.FileDialog(self, _(u"Save this file"), "", filename, _(u"Audio Files(*.mp3)|*.mp3"), wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT)
|
||||
if saveFileDialog.ShowModal() == wx.ID_OK:
|
||||
|
Loading…
Reference in New Issue
Block a user