Implemented like and dislike buttons

This commit is contained in:
Manuel Cortez 2016-03-27 06:06:10 -06:00
parent 6a3ddaa489
commit 13bb4a8a88
4 changed files with 32 additions and 8 deletions

View File

@ -28,9 +28,7 @@ class postController(object):
self.post = postObject self.post = postObject
self.dialog = postDialogs.post() self.dialog = postDialogs.post()
# self.dialog.comments.list.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.show_comment) # 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.dialog.like, widgetUtils.BUTTON_PRESSED, self.post_like)
# 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.comment, widgetUtils.BUTTON_PRESSED, self.add_comment) 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) 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) 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_likes()
self.get_reposts() self.get_reposts()
self.get_comments() 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): def get_likes(self):
self.dialog.set_likes(self.post["likes"]["count"]) self.dialog.set_likes(self.post["likes"]["count"])

View File

@ -6,7 +6,7 @@ import re
import requests import requests
STRING_TYPES = (str, bytes, bytearray) STRING_TYPES = (str, bytes, bytearray, unicode)
logger = logging.getLogger('vk') logger = logging.getLogger('vk')

View File

@ -108,6 +108,12 @@ class BaseDialog(wx.Dialog):
def get_title(self): def get_title(self):
return self.GetTitle() 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): class mainLoopObject(wx.App):
def __init__(self): def __init__(self):

View File

@ -37,7 +37,8 @@ class basicPost(widgetUtils.BaseDialog):
return self.shares return self.shares
def create_action_buttons(self, comment=True): 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")) if comment: self.comment = wx.Button(self.panel, -1, _(u"Add comment"))
box = wx.BoxSizer(wx.HORIZONTAL) box = wx.BoxSizer(wx.HORIZONTAL)
box.Add(self.like, 0, wx.ALL, 5) box.Add(self.like, 0, wx.ALL, 5)