From a6291b3ee284d816f447b634497dedb0214d227e Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Tue, 26 Feb 2019 08:38:49 -0600 Subject: [PATCH] Started the documents menu. For now it just allows to add and remove a document to your documents list --- src/controller/buffers.py | 58 ++++++++++++++++++++++++++------------- src/wxUI/menus.py | 13 +++++++++ 2 files changed, 52 insertions(+), 19 deletions(-) diff --git a/src/controller/buffers.py b/src/controller/buffers.py index 7a7e9e5..210bdb8 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -503,24 +503,6 @@ class topicBuffer(feedBuffer): return a = presenters.displayTopicPresenter(session=self.session, postObject=post, group_id=self.kwargs["group_id"], interactor=interactors.displayPostInteractor(), view=views.displayTopic()) -class documentCommunityBuffer(feedBuffer): - - def create_tab(self, parent): - self.tab = home.documentCommunityTab(parent) - self.connect_events() - self.tab.name = self.name - if hasattr(self, "can_post") and self.can_post == False and hasattr(self.tab, "post"): - self.tab.post.Enable(False) - - def onFocus(self, *args, **kwargs): - pass - - def open_post(self, *args, **kwargs): - """ Opens the currently focused post.""" - post = self.get_post() - if post == None: - return - class documentBuffer(feedBuffer): can_get_items = False @@ -533,7 +515,9 @@ class documentBuffer(feedBuffer): def connect_events(self): super(documentBuffer, self).connect_events() - widgetUtils.connect_event(self.tab.load, widgetUtils.BUTTON_PRESSED, self.load_documents) + # Check if we have a load button in the tab, because documents community buffers don't include it. + if hasattr(self.tab, "load"): + widgetUtils.connect_event(self.tab.load, widgetUtils.BUTTON_PRESSED, self.load_documents) def load_documents(self, *args, **kwargs): output.speak(_("Loading documents...")) @@ -541,6 +525,42 @@ class documentBuffer(feedBuffer): self.tab.load.Enable(False) wx.CallAfter(self.get_items) + def get_menu(self): + p = self.get_post() + if p == None: + return + if p["owner_id"] == self.session.user_id: + added = True + else: + added = False + m = menus.documentMenu(added) + widgetUtils.connect_event(m, widgetUtils.MENU, self.add_remove_document, menuitem=m.action) + return m + + def add_remove_document(self, *args, **kwargs): + p = self.get_post() + if p == None: + return + if p["owner_id"] == self.session.user_id: + result = self.session.vk.client.docs.delete(owner_id=p["owner_id"], doc_id=p["id"]) + if result == 1: + output.speak(_("The document has been successfully deleted.")) + self.session.db[self.name]["items"].pop(self.tab.list.get_selected()) + self.tab.list.remove_item(self.tab.list.get_selected()) + else: + result = self.session.vk.client.docs.add(owner_id=p["owner_id"], doc_id=p["id"]) + output.speak(_("The document has been successfully added.")) + +class documentCommunityBuffer(documentBuffer): + can_get_items = True + + def create_tab(self, parent): + self.tab = home.documentCommunityTab(parent) + self.connect_events() + self.tab.name = self.name + if hasattr(self, "can_post") and self.can_post == False and hasattr(self.tab, "post"): + self.tab.post.Enable(False) + class audioBuffer(feedBuffer): """ this buffer was supposed to be used with audio elements but is deprecated as VK removed its audio support for third party apps.""" diff --git a/src/wxUI/menus.py b/src/wxUI/menus.py index 2536610..c80fbf0 100644 --- a/src/wxUI/menus.py +++ b/src/wxUI/menus.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- +""" This module contains all context menus needed to be displayed in different sections. Basically any menu that is bigger than 2 menu items should be here.""" from __future__ import unicode_literals import wx class postMenu(wx.Menu): + """ Display a menu with actions related to posts in the news feed or walls. """ + def __init__(self, can_delete=False, *args, **kwargs): super(postMenu, self).__init__(*args, **kwargs) self.open = wx.MenuItem(self, wx.NewId(), _("Open")) @@ -74,6 +77,16 @@ class peopleMenu(wx.Menu): self.add = wx.MenuItem(self, wx.NewId(), _("Add to friends")) self.Append(self.add) +class documentMenu(wx.Menu): + def __init__(self, added=False, *args, **kwargs): + super(documentMenu, self).__init__(*args, **kwargs) + self.view_info = self.Append(wx.NewId(), _("View information")) + self.download = self.Append(wx.NewId(), _("Download document")) + if added == True: + self.action = self.Append(wx.NewId(), _("Remove from my documents")) + else: + self.action = self.Append(wx.NewId(), _("Add to my documents")) + class commentMenu(wx.Menu): def __init__(self, *args, **kwargs): super(commentMenu, self).__init__(*args, **kwargs)