Added album load an creation at startup

This commit is contained in:
Manuel Cortez 2016-06-19 12:25:06 -05:00
parent 47bab9d2c4
commit b278c8cde9
4 changed files with 64 additions and 5 deletions

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import time
import os
import wx
import utils
@ -17,7 +18,7 @@ from mysc.thread_utils import call_threaded
from sessionmanager import session
from wxUI import (mainWindow, commonMessages)
from wxUI.dialogs import search as searchDialogs
from wxUI.dialogs import timeline
from wxUI.dialogs import timeline, creation
from update import updater
log = logging.getLogger("controller.main")
@ -71,6 +72,10 @@ class Controller(object):
audios = buffers.empty(parent=self.window.tb, name="audios")
self.buffers.append(audios)
self.window.add_buffer(audios.tab, _(u"Music"))
albums = buffers.empty(parent=self.window.tb, name="albums")
self.buffers.append(albums)
self.window.insert_buffer(albums.tab, _(u"Albums"), self.window.search("audios"))
audio = buffers.audioBuffer(parent=self.window.tb, name="me_audio", composefunc="compose_audio", session=self.session, endpoint="get", parent_endpoint="audio", full_list=True, count=self.session.settings["buffers"]["count_for_audio_buffers"])
self.buffers.append(audio)
self.window.insert_buffer(audio.tab, _(u"My audios"), self.window.search("audios"))
@ -114,6 +119,7 @@ class Controller(object):
widgetUtils.connect_event(self.window, widgetUtils.MENU, self.changelog, menuitem=self.window.changelog)
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)
pub.subscribe(self.get_chat, "order-sent-message")
def disconnect_events(self):
@ -144,6 +150,8 @@ class Controller(object):
self.status_setter.start()
self.set_online()
self.create_unread_messages()
wx.CallAfter(self.get_audio_albums, self.session.user_id)
def in_post(self, buffer):
buffer = self.search(buffer)
buffer.get_items()
@ -336,3 +344,27 @@ class Controller(object):
i.reads = []
if ids != "":
response = self.session.vk.client.messages.markAsRead(message_ids=ids)
def get_audio_albums(self, user_id=None):
albums = self.session.vk.client.audio.getAlbums(owner_id=user_id)
print albums
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"])
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)
def create_audio_album(self, *args, **kwargs):
d = creation.audio_album()
if d.get_response() == widgetUtils.OK and d.get("title") != "":
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)
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()

View File

@ -268,7 +268,7 @@ class vkSession(object):
if data != None:
if type(data) == dict:
num = self.order_buffer(name, data["items"], show_nextpage)
if data["items"][0].has_key("first_name"):
if len(data["items"]) > 0 and data["items"][0].has_key("first_name"):
for i in data["items"]:
self.db["users"][i["id"]] = u"{0} {1}".format(i["first_name"], i["last_name"])
if data.has_key("profiles") and data.has_key("groups"):

View File

@ -0,0 +1,24 @@
import wx
import widgetUtils
class audio_album(widgetUtils.BaseDialog):
def __init__(self, *args, **kwargs):
super(audio_album, self).__init__(title=_(u"Create a new album"), parent=None)
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
lbl = wx.StaticText(panel, wx.NewId(), _(u"Album title"))
self.title = wx.TextCtrl(panel, wx.NewId())
box = wx.BoxSizer(wx.HORIZONTAL)
box.Add(lbl, 1, wx.ALL, 5)
box.Add(self.title, 1, wx.ALL, 5)
sizer.Add(box, 1, wx.ALL, 5)
ok = wx.Button(panel, wx.ID_OK, _(u"&OK"))
ok.SetDefault()
cancel = wx.Button(panel, wx.ID_CANCEL, _(u"&Close"))
btnsizer = wx.BoxSizer()
btnsizer.Add(ok, 0, wx.ALL, 5)
btnsizer.Add(cancel, 0, wx.ALL, 5)
sizer.Add(btnsizer, 0, wx.ALL, 5)
panel.SetSizer(sizer)
self.SetClientSize(sizer.CalcMin())

View File

@ -6,12 +6,15 @@ class mainWindow(wx.Frame):
def makeMenu(self):
mb = wx.MenuBar()
app_ = wx.Menu()
create = wx.Menu()
self.audio_album = create.Append(wx.NewId(), _(u"Audio album"))
app_.AppendMenu(wx.NewId(), _(u"Create"), create)
self.settings_dialog = app_.Append(wx.NewId(), _(u"Preferences"))
buffer = wx.Menu()
self.new_buffer = wx.Menu()
self.search_audios = self.new_buffer.Append(wx.NewId(), _(u"Audio"))
buffer.AppendMenu(wx.NewId(), _(u"Search"), self.new_buffer)
search = wx.Menu()
self.search_audios = search.Append(wx.NewId(), _(u"Audio"))
self.timeline = buffer.Append(wx.NewId(), _(u"&New timeline"))
buffer.AppendMenu(wx.NewId(), _(u"Search"), search)
self.update_buffer = buffer.Append(wx.NewId(), _(u"Update current buffer"))
self.load_previous_items = buffer.Append(wx.NewId(), _(u"Load previous items"))
self.remove_buffer_ = buffer.Append(wx.NewId(), _(u"&Remove buffer"))