Implemented audio album removal. An album selector has been created
This commit is contained in:
parent
dc88d68a6c
commit
42c8d9bbb7
@ -12,6 +12,7 @@ import posts
|
||||
import webbrowser
|
||||
import logging
|
||||
import longpoolthread
|
||||
import selector
|
||||
from pubsub import pub
|
||||
from mysc.repeating_timer import RepeatingTimer
|
||||
from mysc.thread_utils import call_threaded
|
||||
@ -120,6 +121,7 @@ class Controller(object):
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.configuration, menuitem=self.window.settings_dialog)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.new_timeline, menuitem=self.window.timeline)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.create_audio_album, menuitem=self.window.audio_album)
|
||||
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.delete_audio_album, menuitem=self.window.delete_audio_album)
|
||||
pub.subscribe(self.get_chat, "order-sent-message")
|
||||
|
||||
def disconnect_events(self):
|
||||
@ -160,6 +162,7 @@ class Controller(object):
|
||||
|
||||
def update_all_buffers(self):
|
||||
log.debug("Updating buffers...")
|
||||
self.session.audio_albums = self.session.vk.client.audio.getAlbums(owner_id=self.session.user_id)["items"]
|
||||
for i in self.buffers:
|
||||
if hasattr(i, "get_items"):
|
||||
i.get_items()
|
||||
@ -347,15 +350,15 @@ class Controller(object):
|
||||
|
||||
def get_audio_albums(self, user_id=None):
|
||||
albums = self.session.vk.client.audio.getAlbums(owner_id=user_id)
|
||||
print albums
|
||||
self.session.audio_albums = albums["items"]
|
||||
for i in albums["items"]:
|
||||
buffer = buffers.audioBuffer(parent=self.window.tb, name="{0}_album".format(i["id"],), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=user_id, album_id=i["id"])
|
||||
buffer = buffers.audioBuffer(parent=self.window.tb, name="{0}_audio_album".format(i["id"],), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=user_id, album_id=i["id"])
|
||||
name_ = _(u"Album: {0}").format(i["title"],)
|
||||
self.buffers.append(buffer)
|
||||
self.window.insert_buffer(buffer.tab, name_, self.window.search("albums"))
|
||||
buffer.get_items()
|
||||
# inserts a pause of 1 second here, so we'll avoid errors 6 in VK.
|
||||
time.sleep(1)
|
||||
time.sleep(0.4)
|
||||
|
||||
def create_audio_album(self, *args, **kwargs):
|
||||
d = creation.audio_album()
|
||||
@ -363,8 +366,23 @@ class Controller(object):
|
||||
response = self.session.vk.client.audio.addAlbum(title=d.get("title"))
|
||||
if response.has_key("album_id") == False: return
|
||||
album_id = response["album_id"]
|
||||
buffer = buffers.audioBuffer(parent=self.window.tb, name="{0}_album".format(album_id,), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=self.session.user_id, album_id=album_id)
|
||||
buffer = buffers.audioBuffer(parent=self.window.tb, name="{0}_audio_album".format(album_id,), composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"], user_id=self.session.user_id, album_id=album_id)
|
||||
name_ = _(u"Album: {0}").format(d.get("title"),)
|
||||
self.buffers.append(buffer)
|
||||
self.window.insert_buffer(buffer.tab, name_, self.window.search("albums"))
|
||||
buffer.get_items()
|
||||
buffer.get_items()
|
||||
self.session.audio_albums = self.session.vk.client.audio.getAlbums(owner_id=self.session.user_id)["items"]
|
||||
|
||||
def delete_audio_album(self, *args, **kwargs):
|
||||
answer = selector.audioAlbum(_(u"Select the album you want to delete"), self.session)
|
||||
if answer.item == None:
|
||||
return
|
||||
response = commonMessages.delete_audio_album()
|
||||
if response != widgetUtils.YES: return
|
||||
removal = self.session.vk.client.audio.deleteAlbum(album_id=answer.item)
|
||||
buffer = self.search("{0}_audio_album".format(answer.item,))
|
||||
buff = self.window.search(buffer.name)
|
||||
self.window.remove_buffer(buff)
|
||||
self.buffers.remove(buffer)
|
||||
del buffer
|
||||
self.session.audio_albums = self.session.vk.client.audio.getAlbums(owner_id=self.session.user_id)["items"]
|
||||
|
23
src/controller/selector.py
Normal file
23
src/controller/selector.py
Normal file
@ -0,0 +1,23 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import widgetUtils
|
||||
from wxUI.dialogs import selector as gui
|
||||
|
||||
class audioAlbum(object):
|
||||
|
||||
def __init__(self, title, session):
|
||||
super(audioAlbum, self).__init__()
|
||||
self.item = None
|
||||
self.session = session
|
||||
self.dialog = gui.selectAlbum(title=title, albums=self.get_albums_as_string())
|
||||
response = self.dialog.get_response()
|
||||
if response == widgetUtils.OK:
|
||||
self.item = self.search_item(self.dialog.get_string())
|
||||
|
||||
def get_albums_as_string(self):
|
||||
return [i["title"] for i in self.session.audio_albums]
|
||||
|
||||
def search_item(self, item):
|
||||
for i in self.session.audio_albums:
|
||||
if i["title"] == item:
|
||||
return i["id"]
|
||||
return None
|
@ -23,4 +23,7 @@ def show_error_code(code):
|
||||
return wx.MessageDialog(None, message, title, style=wx.ICON_ERROR).ShowModal()
|
||||
|
||||
def bad_authorisation():
|
||||
return wx.MessageDialog(None, _(u"authorisation failed. Your configuration will not be saved. Please close and open again the application for authorising your account. Make sure you have typed your credentials correctly."), _(u"Error"), style=wx.ICON_ERROR).ShowModal()
|
||||
return wx.MessageDialog(None, _(u"authorisation failed. Your configuration will not be saved. Please close and open again the application for authorising your account. Make sure you have typed your credentials correctly."), _(u"Error"), style=wx.ICON_ERROR).ShowModal()
|
||||
|
||||
def delete_audio_album():
|
||||
return wx.MessageDialog(None, _(u"Do you really want to delete this Album? this will be deleted from VK too."), _(u"Attention"), style=wx.ICON_QUESTION|wx.YES_NO).ShowModal()
|
||||
|
@ -2,8 +2,8 @@
|
||||
import wx
|
||||
|
||||
class selectAlbum(wx.Dialog):
|
||||
def __init__(self, albums):
|
||||
super(selectAlbum, self).__init__(parent=None, title=_(u"Select the album where you will upload the photo"))
|
||||
def __init__(self, title, albums):
|
||||
super(selectAlbum, self).__init__(parent=None, title=title)
|
||||
panel = wx.Panel(self)
|
||||
self.lista = wx.ListBox(panel, -1, choices=albums)
|
||||
self.lista.SetFocus()
|
@ -9,6 +9,9 @@ class mainWindow(wx.Frame):
|
||||
create = wx.Menu()
|
||||
self.audio_album = create.Append(wx.NewId(), _(u"Audio album"))
|
||||
app_.AppendMenu(wx.NewId(), _(u"Create"), create)
|
||||
delete = wx.Menu()
|
||||
self.delete_audio_album = delete.Append(wx.NewId(), _(u"Audio album"))
|
||||
app_.AppendMenu(wx.NewId(), _(u"Delete"), delete)
|
||||
self.settings_dialog = app_.Append(wx.NewId(), _(u"Preferences"))
|
||||
buffer = wx.Menu()
|
||||
search = wx.Menu()
|
||||
|
Loading…
Reference in New Issue
Block a user