Refactored some functions to call wx's threads properly.

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

View File

@@ -80,7 +80,7 @@ class baseBuffer(object):
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."""
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):
""" 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 self.tab.history.GetValue() != "" and num > 0:
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:
[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:
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.
@@ -1155,7 +1155,7 @@ class chatBuffer(baseBuffer):
self.chats = dict()
self.tab.history.SetValue("")
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.
for i in self.chats.keys():
if self.chats[i] == focused_post["id"]:

View File

@@ -411,7 +411,7 @@ class Controller(object):
if user == None:
log.exception("Getting user manually...")
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):
""" Sends a notification of an user logging off in VK.
@@ -424,7 +424,7 @@ class Controller(object):
sound = "friend_offline.ogg"
self.notify(msg, sound, self.session.settings["chat"]["notifications"])
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"):
""" display a notification in Socializer.
@@ -512,7 +512,7 @@ class Controller(object):
# Let's add this to the buffer.
# 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.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")
wx.CallAfter(self.reorder_buffer, buffer)
# Check if we have to read the message aloud