Refactored some functions to call wx's threads properly.

This commit is contained in:
Manuel Cortez 2019-06-10 09:26:10 -05:00
parent 4e6126405f
commit 4e3c397ce5
4 changed files with 78 additions and 75 deletions

View File

@ -14,6 +14,8 @@
* Fixed an error with two factor authentication in the recent socializer version. Now it works reliably again. * Fixed an error with two factor authentication in the recent socializer version. Now it works reliably again.
* Fixed an error when trying to attach a photo to a wall post. The error was fixed in the [vk_api](https://github.com/python273/vk_api) module and the fix was sent to the developer of the library, so he will be able to merge it in the next version. In the meantime, socializer already includes the fix for this method, so you can upload photos to wall posts normally. * Fixed an error when trying to attach a photo to a wall post. The error was fixed in the [vk_api](https://github.com/python273/vk_api) module and the fix was sent to the developer of the library, so he will be able to merge it in the next version. In the meantime, socializer already includes the fix for this method, so you can upload photos to wall posts normally.
* Fixed an error retrieving some group information for the current session. * Fixed an error retrieving some group information for the current session.
* When posting in a topic, links will be posted properly.
### Changes ### Changes

View File

@ -80,7 +80,7 @@ class baseBuffer(object):
def insert(self, item, reversed=False): def insert(self, item, reversed=False):
""" 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.""" """ 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_) wx.CallAfter(self.tab.list.insert_item, reversed, *item_)
def get_items(self, show_nextpage=False): def get_items(self, show_nextpage=False):
""" Retrieve items from the VK API. This function is called repeatedly by the main controller and users could call it implicitly as well with the update buffer option. """ Retrieve items from the VK API. This function is called repeatedly by the main controller and users could call it implicitly as well with the update buffer option.
@ -1143,9 +1143,9 @@ class chatBuffer(baseBuffer):
if show_nextpage == False: if show_nextpage == False:
if self.tab.history.GetValue() != "" and num > 0: if self.tab.history.GetValue() != "" and num > 0:
v = [i for i in self.session.db[self.name]["items"][:num]] v = [i for i in self.session.db[self.name]["items"][:num]]
[self.insert(i, False) for i in v] [wx.CallAfter(self.insert, i, False) for i in v]
else: else:
[self.insert(i) for i in self.session.db[self.name]["items"][:num]] [wx.CallAfter(self.insert, i) for i in self.session.db[self.name]["items"][:num]]
else: else:
if num > 0: if num > 0:
# At this point we save more CPU and mathematical work if we just delete everything in the chat history and readd all messages. # At this point we save more CPU and mathematical work if we just delete everything in the chat history and readd all messages.
@ -1155,7 +1155,7 @@ class chatBuffer(baseBuffer):
self.chats = dict() self.chats = dict()
self.tab.history.SetValue("") self.tab.history.SetValue("")
v = [i for i in self.session.db[self.name]["items"]] v = [i for i in self.session.db[self.name]["items"]]
[self.insert(i) for i in v] [wx.CallAfter(self.insert, i) for i in v]
# Now it's time to set back the focus in the post. # Now it's time to set back the focus in the post.
for i in self.chats.keys(): for i in self.chats.keys():
if self.chats[i] == focused_post["id"]: if self.chats[i] == focused_post["id"]:

View File

@ -411,7 +411,7 @@ class Controller(object):
if user == None: if user == None:
log.exception("Getting user manually...") log.exception("Getting user manually...")
user = self.session.vk.client.users.get(user_ids=event.user_id, fields="last_seen")[0] user = self.session.vk.client.users.get(user_ids=event.user_id, fields="last_seen")[0]
online_buffer.add_person(user) wx.CallAfter(online_buffer.add_person, user)
def user_offline(self, event): def user_offline(self, event):
""" Sends a notification of an user logging off in VK. """ Sends a notification of an user logging off in VK.
@ -424,7 +424,7 @@ class Controller(object):
sound = "friend_offline.ogg" sound = "friend_offline.ogg"
self.notify(msg, sound, self.session.settings["chat"]["notifications"]) self.notify(msg, sound, self.session.settings["chat"]["notifications"])
online_friends = self.search("online_friends") online_friends = self.search("online_friends")
online_friends.remove_person(event.user_id) wx.CallAfter(online_friends.remove_person, event.user_id)
def notify(self, message="", sound="", type="native"): def notify(self, message="", sound="", type="native"):
""" display a notification in Socializer. """ display a notification in Socializer.
@ -512,7 +512,7 @@ class Controller(object):
# Let's add this to the buffer. # Let's add this to the buffer.
# ToDo: Clean this code and test how is the database working with this set to True. # ToDo: Clean this code and test how is the database working with this set to True.
buffer.session.db[buffer.name]["items"].append(message) buffer.session.db[buffer.name]["items"].append(message)
buffer.insert(self.session.db[buffer.name]["items"][-1], False) wx.CallAfter(buffer.insert, self.session.db[buffer.name]["items"][-1], False)
self.session.soundplayer.play("message_received.ogg") self.session.soundplayer.play("message_received.ogg")
wx.CallAfter(self.reorder_buffer, buffer) wx.CallAfter(self.reorder_buffer, buffer)
# Check if we have to read the message aloud # Check if we have to read the message aloud

View File

@ -159,6 +159,7 @@ class multiselectionBaseList(wx.ListCtrl, listmix.CheckListCtrlMixin):
if event.GetKeyCode() == wx.WXK_SPACE: if event.GetKeyCode() == wx.WXK_SPACE:
self.ToggleItem(self.GetFocusedItem()) self.ToggleItem(self.GetFocusedItem())
event.Skip() event.Skip()
class list(object): class list(object):
def __init__(self, parent, *columns, **listArguments): def __init__(self, parent, *columns, **listArguments):
self.columns = columns self.columns = columns