Load communities in a buffer dedicated to them
This commit is contained in:
parent
7c1766825b
commit
f029b9034d
@ -41,7 +41,7 @@ class baseBuffer(object):
|
|||||||
@parent wx.Treebook: parent for the buffer panel,
|
@parent wx.Treebook: parent for the buffer panel,
|
||||||
@name str: Name for saving this buffer's data in the local storage variable,
|
@name str: Name for saving this buffer's data in the local storage variable,
|
||||||
@session sessionmanager.session.vkSession: Session for performing operations in the Vk API. This session should be logged in when this class is instanciated.
|
@session sessionmanager.session.vkSession: Session for performing operations in the Vk API. This session should be logged in when this class is instanciated.
|
||||||
@composefunc str: This function will be called for composing the result which will be put in the listCtrl. Composefunc should existss in the sessionmanager.session module.
|
@composefunc str: This function will be called for composing the result which will be put in the listCtrl. Composefunc should exist in the sessionmanager.renderers module.
|
||||||
args and kwargs will be passed to get_items() without any filtering. Be careful there.
|
args and kwargs will be passed to get_items() without any filtering. Be careful there.
|
||||||
"""
|
"""
|
||||||
super(baseBuffer, self).__init__()
|
super(baseBuffer, self).__init__()
|
||||||
@ -72,7 +72,7 @@ class baseBuffer(object):
|
|||||||
self.tab = home.homeTab(parent)
|
self.tab = home.homeTab(parent)
|
||||||
|
|
||||||
def insert(self, item, reversed=False):
|
def insert(self, item, reversed=False):
|
||||||
""" Add a new item to the list. Uses session.composefunc for parsing the dictionary and create a valid result for putting it in the list."""
|
""" Add a new item to the list. Uses renderers.composefunc for parsing the dictionary and create a valid result for putting it in the list."""
|
||||||
item_ = getattr(renderers, self.compose_function)(item, self.session)
|
item_ = getattr(renderers, self.compose_function)(item, self.session)
|
||||||
self.tab.list.insert_item(reversed, *item_)
|
self.tab.list.insert_item(reversed, *item_)
|
||||||
|
|
||||||
@ -134,7 +134,7 @@ class baseBuffer(object):
|
|||||||
def upload_attachments(self, attachments):
|
def upload_attachments(self, attachments):
|
||||||
""" Upload attachments to VK before posting them.
|
""" Upload attachments to VK before posting them.
|
||||||
Returns attachments formatted as string, as required by VK API.
|
Returns attachments formatted as string, as required by VK API.
|
||||||
Currently this function only supports photos."""
|
Currently this function only supports photos and audios."""
|
||||||
# To do: Check the caption and description fields for this kind of attachments.
|
# To do: Check the caption and description fields for this kind of attachments.
|
||||||
local_attachments = ""
|
local_attachments = ""
|
||||||
uploader = upload.VkUpload(self.session.vk.session_object)
|
uploader = upload.VkUpload(self.session.vk.session_object)
|
||||||
@ -177,7 +177,7 @@ class baseBuffer(object):
|
|||||||
if pos != 0:
|
if pos != 0:
|
||||||
self.tab.PopupMenu(menu, pos)
|
self.tab.PopupMenu(menu, pos)
|
||||||
else:
|
else:
|
||||||
self.tab.PopupMenu(menu, ev.GetPosition())
|
self.tab.PopupMenu(menu, self.tab.list.list.GetPosition())
|
||||||
|
|
||||||
def show_menu_by_key(self, ev):
|
def show_menu_by_key(self, ev):
|
||||||
""" Show contextual menu when menu key is pressed"""
|
""" Show contextual menu when menu key is pressed"""
|
||||||
@ -290,7 +290,7 @@ class baseBuffer(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def open_person_profile(self, *args, **kwargs):
|
def open_person_profile(self, *args, **kwargs):
|
||||||
""" Views someone's user profile."""
|
""" Views someone's profile."""
|
||||||
selected = self.get_post()
|
selected = self.get_post()
|
||||||
if selected == None:
|
if selected == None:
|
||||||
return
|
return
|
||||||
@ -388,6 +388,21 @@ class feedBuffer(baseBuffer):
|
|||||||
self.user_key = "from_id"
|
self.user_key = "from_id"
|
||||||
self.post_key = "id"
|
self.post_key = "id"
|
||||||
|
|
||||||
|
class communityBuffer(feedBuffer):
|
||||||
|
|
||||||
|
def create_tab(self, parent):
|
||||||
|
self.tab = home.communityTab(parent)
|
||||||
|
|
||||||
|
def connect_events(self):
|
||||||
|
super(communityBuffer, self).connect_events()
|
||||||
|
widgetUtils.connect_event(self.tab.load, widgetUtils.BUTTON_PRESSED, self.load_community)
|
||||||
|
|
||||||
|
def load_community(self, *args, **kwargs):
|
||||||
|
output.speak(_(u"Loading community..."))
|
||||||
|
self.can_get_items = True
|
||||||
|
self.tab.load.Enable(False)
|
||||||
|
wx.CallAfter(self.get_items)
|
||||||
|
|
||||||
class audioBuffer(feedBuffer):
|
class audioBuffer(feedBuffer):
|
||||||
""" this buffer was supposed to be used with audio elements
|
""" this buffer was supposed to be used with audio elements
|
||||||
but is deprecated as VK removed its audio support for third party apps."""
|
but is deprecated as VK removed its audio support for third party apps."""
|
||||||
|
@ -119,6 +119,10 @@ class Controller(object):
|
|||||||
outgoing_requests = buffers.requestsBuffer(parent=self.window.tb, name="friend_requests_sent", composefunc="render_person", session=self.session, count=1000, out=1)
|
outgoing_requests = buffers.requestsBuffer(parent=self.window.tb, name="friend_requests_sent", composefunc="render_person", session=self.session, count=1000, out=1)
|
||||||
self.buffers.append(outgoing_requests)
|
self.buffers.append(outgoing_requests)
|
||||||
self.window.insert_buffer(outgoing_requests.tab, _(u"I follow"), self.window.search("requests"))
|
self.window.insert_buffer(outgoing_requests.tab, _(u"I follow"), self.window.search("requests"))
|
||||||
|
communities= buffers.empty(parent=self.window.tb, name="communities")
|
||||||
|
self.buffers.append(communities)
|
||||||
|
# Translators: name for the videos category in the tree view.
|
||||||
|
self.window.add_buffer(communities.tab, _(u"Communities"))
|
||||||
chats = buffers.empty(parent=self.window.tb, name="chats")
|
chats = buffers.empty(parent=self.window.tb, name="chats")
|
||||||
self.buffers.append(chats)
|
self.buffers.append(chats)
|
||||||
self.window.add_buffer(chats.tab, _(u"Chats"))
|
self.window.add_buffer(chats.tab, _(u"Chats"))
|
||||||
@ -201,10 +205,11 @@ class Controller(object):
|
|||||||
self.create_longpoll_thread()
|
self.create_longpoll_thread()
|
||||||
self.status_setter = RepeatingTimer(280, self.set_online)
|
self.status_setter = RepeatingTimer(280, self.set_online)
|
||||||
self.status_setter.start()
|
self.status_setter.start()
|
||||||
self.set_online(notify=True)
|
call_threaded(self.set_online, notify=True)
|
||||||
self.create_unread_messages()
|
call_threaded(self.create_unread_messages)
|
||||||
wx.CallAfter(self.get_audio_albums, self.session.user_id)
|
wx.CallAfter(self.get_audio_albums, self.session.user_id)
|
||||||
wx.CallAfter(self.get_video_albums, self.session.user_id)
|
wx.CallAfter(self.get_video_albums, self.session.user_id)
|
||||||
|
wx.CallAfter(self.get_communities, self.session.user_id)
|
||||||
|
|
||||||
def create_longpoll_thread(self, notify=False):
|
def create_longpoll_thread(self, notify=False):
|
||||||
try:
|
try:
|
||||||
@ -501,9 +506,9 @@ class Controller(object):
|
|||||||
name_ = _(u"Album: {0}").format(i["title"],)
|
name_ = _(u"Album: {0}").format(i["title"],)
|
||||||
self.buffers.append(buffer)
|
self.buffers.append(buffer)
|
||||||
self.window.insert_buffer(buffer.tab, name_, self.window.search("albums"))
|
self.window.insert_buffer(buffer.tab, name_, self.window.search("albums"))
|
||||||
buffer.get_items()
|
# buffer.get_items()
|
||||||
# inserts a pause of 1 second here, so we'll avoid errors 6 in VK.
|
# inserts a pause of 1 second here, so we'll avoid errors 6 in VK.
|
||||||
time.sleep(0.3)
|
# time.sleep(0.3)
|
||||||
|
|
||||||
def get_video_albums(self, user_id=None, create_buffers=True):
|
def get_video_albums(self, user_id=None, create_buffers=True):
|
||||||
log.debug("Create video albums...")
|
log.debug("Create video albums...")
|
||||||
@ -517,9 +522,30 @@ class Controller(object):
|
|||||||
name_ = _(u"Album: {0}").format(i["title"],)
|
name_ = _(u"Album: {0}").format(i["title"],)
|
||||||
self.buffers.append(buffer)
|
self.buffers.append(buffer)
|
||||||
self.window.insert_buffer(buffer.tab, name_, self.window.search("video_albums"))
|
self.window.insert_buffer(buffer.tab, name_, self.window.search("video_albums"))
|
||||||
buffer.get_items()
|
# buffer.get_items()
|
||||||
# inserts a pause of 1 second here, so we'll avoid errors 6 in VK.
|
# inserts a pause of 1 second here, so we'll avoid errors 6 in VK.
|
||||||
time.sleep(0.3)
|
# time.sleep(0.3)
|
||||||
|
|
||||||
|
def get_communities(self, user_id=None, create_buffers=True):
|
||||||
|
log.debug("Create community buffers...")
|
||||||
|
groups= self.session.vk.client.groups.get(user_id=user_id, extended=1, fields="city, country, place, description, wiki_page, members_count, counters, start_date, finish_date, can_post, can_see_all_posts, activity, status, contacts, links, fixed_post, verified, site, can_create_topic")
|
||||||
|
print groups.keys()
|
||||||
|
self.session.groups=groups["items"]
|
||||||
|
# Let's feed the local database cache with new groups coming from here.
|
||||||
|
data= dict(profiles=[], groups=groups["items"])
|
||||||
|
self.session.process_usernames(data)
|
||||||
|
if create_buffers:
|
||||||
|
for i in groups["items"]:
|
||||||
|
print i.keys()
|
||||||
|
buffer = buffers.communityBuffer(parent=self.window.tb, name="{0}_community".format(i["id"],), composefunc="render_status", session=self.session, endpoint="get", parent_endpoint="wall", count=self.session.settings["buffers"]["count_for_wall_buffers"], owner_id=-1*i["id"])
|
||||||
|
buffer.can_get_items = False
|
||||||
|
# Translators: {0} Will be replaced with a video album's title.
|
||||||
|
name_ =i["name"]
|
||||||
|
self.buffers.append(buffer)
|
||||||
|
self.window.insert_buffer(buffer.tab, name_, self.window.search("communities"))
|
||||||
|
# buffer.get_items()
|
||||||
|
# inserts a pause of 1 second here, so we'll avoid errors 6 in VK.
|
||||||
|
# time.sleep(0.3)
|
||||||
|
|
||||||
def create_audio_album(self, *args, **kwargs):
|
def create_audio_album(self, *args, **kwargs):
|
||||||
d = creation.audio_album()
|
d = creation.audio_album()
|
||||||
|
Loading…
Reference in New Issue
Block a user