From 13bb4a8a88a285df3b0efcd2615c5a670536b0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Cort=C3=A9z?= Date: Sun, 27 Mar 2016 06:06:10 -0600 Subject: [PATCH] Implemented like and dislike buttons --- src/controller/posts.py | 29 +++++++++++++++++++++++------ src/vk/utils.py | 2 +- src/widgetUtils/wxUtils.py | 6 ++++++ src/wxUI/dialogs/postDialogs.py | 3 ++- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/controller/posts.py b/src/controller/posts.py index 93f2c59..9e9c8b6 100644 --- a/src/controller/posts.py +++ b/src/controller/posts.py @@ -28,9 +28,7 @@ class postController(object): self.post = postObject self.dialog = postDialogs.post() # self.dialog.comments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.show_comment) -# widgetUtils.connect_event(self.message.spellcheck, widgetUtils.BUTTON_PRESSED, self.spellcheck) -# widgetUtils.connect_event(self.message.translateButton, widgetUtils.BUTTON_PRESSED, self.translate) -# widgetUtils.connect_event(self.dialog.like, widgetUtils.BUTTON_PRESSED, self.post_like) + widgetUtils.connect_event(self.dialog.like, widgetUtils.BUTTON_PRESSED, self.post_like) widgetUtils.connect_event(self.dialog.comment, widgetUtils.BUTTON_PRESSED, self.add_comment) widgetUtils.connect_event(self.dialog.tools, widgetUtils.BUTTON_PRESSED, self.show_tools_menu) self.dialog.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.show_menu, self.dialog.comments.list) @@ -79,10 +77,29 @@ class postController(object): self.get_likes() self.get_reposts() self.get_comments() + if self.post["comments"]["can_post"] == 0: + self.dialog.disable("add_comment") + if self.post["likes"]["can_like"] == 0 and self.post["likes"]["user_likes"] == 0: + self.dialog.disable("like") + elif self.post["likes"]["user_likes"] == 1: + self.dialog.set("like", _(u"&Dislike")) + if self.post["likes"]["can_publish"] == 0: + self.dialog.disable("repost") + + def post_like(self, *args, **kwargs): + user = int(self.post["source_id"]) + id = int(self.post["post_id"]) + type_ = self.post["type"] + if self.dialog.get("like") == _(u"&Dislike"): + l = self.session.vk.client.likes.delete(owner_id=user, item_id=id, type=type_) + output.speak(_(u"You don't like this")) + self.dialog.set("like", _(u"&Like")) + else: + l = self.session.vk.client.likes.add(owner_id=user, item_id=id, type=type_) + output.speak(_(u"You liked this")) + self.dialog.set("like", _(u"&Dislike")) + self.dialog.set_likes(l["likes"]) - def _post_like(self, *args, **kwargs): - lk = self.session.like(self.post["id"]) - self.get_likes() def get_likes(self): self.dialog.set_likes(self.post["likes"]["count"]) diff --git a/src/vk/utils.py b/src/vk/utils.py index ab01b71..90a8252 100644 --- a/src/vk/utils.py +++ b/src/vk/utils.py @@ -6,7 +6,7 @@ import re import requests -STRING_TYPES = (str, bytes, bytearray) +STRING_TYPES = (str, bytes, bytearray, unicode) logger = logging.getLogger('vk') diff --git a/src/widgetUtils/wxUtils.py b/src/widgetUtils/wxUtils.py index cd179d8..627d56f 100644 --- a/src/widgetUtils/wxUtils.py +++ b/src/widgetUtils/wxUtils.py @@ -108,6 +108,12 @@ class BaseDialog(wx.Dialog): def get_title(self): return self.GetTitle() + def enable(self, control): + getattr(self, control).Enable(True) + + def disable(self, control): + getattr(self, control).Enable(False) + class mainLoopObject(wx.App): def __init__(self): diff --git a/src/wxUI/dialogs/postDialogs.py b/src/wxUI/dialogs/postDialogs.py index d819906..e6774d9 100644 --- a/src/wxUI/dialogs/postDialogs.py +++ b/src/wxUI/dialogs/postDialogs.py @@ -37,7 +37,8 @@ class basicPost(widgetUtils.BaseDialog): return self.shares def create_action_buttons(self, comment=True): - self.like = wx.Button(self.panel, -1, _(u"Like")) + self.like = wx.Button(self.panel, -1, _(u"&Like")) + self.repost = wx.Button(self.panel, -1, _(u"Repost")) if comment: self.comment = wx.Button(self.panel, -1, _(u"Add comment")) box = wx.BoxSizer(wx.HORIZONTAL) box.Add(self.like, 0, wx.ALL, 5)