Refactored some functions to call wx's threads properly.
This commit is contained in:
parent
4e6126405f
commit
4e3c397ce5
@ -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
|
||||||
|
|
||||||
|
@ -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"]:
|
||||||
|
@ -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
|
||||||
|
@ -137,89 +137,90 @@ class mainLoopObject(wx.App):
|
|||||||
self.app.MainLoop()
|
self.app.MainLoop()
|
||||||
|
|
||||||
class multiselectionBaseList(wx.ListCtrl, listmix.CheckListCtrlMixin):
|
class multiselectionBaseList(wx.ListCtrl, listmix.CheckListCtrlMixin):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
wx.ListCtrl.__init__(self, *args, **kwargs)
|
wx.ListCtrl.__init__(self, *args, **kwargs)
|
||||||
listmix.CheckListCtrlMixin.__init__(self)
|
listmix.CheckListCtrlMixin.__init__(self)
|
||||||
self.Bind(wx.EVT_CHAR_HOOK, self.on_keydown)
|
self.Bind(wx.EVT_CHAR_HOOK, self.on_keydown)
|
||||||
self.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.on_focus)
|
self.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.on_focus)
|
||||||
|
|
||||||
def on_focus(self, event):
|
def on_focus(self, event):
|
||||||
currentItem = self.GetFocusedItem()
|
currentItem = self.GetFocusedItem()
|
||||||
if self.IsChecked(currentItem):
|
if self.IsChecked(currentItem):
|
||||||
pub.sendMessage("play-sound", sound="selected.ogg")
|
pub.sendMessage("play-sound", sound="selected.ogg")
|
||||||
event.Skip()
|
event.Skip()
|
||||||
|
|
||||||
def OnCheckItem(self, index, flag):
|
def OnCheckItem(self, index, flag):
|
||||||
if flag == True:
|
if flag == True:
|
||||||
pub.sendMessage("play-sound", sound="checked.ogg")
|
pub.sendMessage("play-sound", sound="checked.ogg")
|
||||||
else:
|
else:
|
||||||
pub.sendMessage("play-sound", sound="unchecked.ogg")
|
pub.sendMessage("play-sound", sound="unchecked.ogg")
|
||||||
|
|
||||||
|
def on_keydown(self, event):
|
||||||
|
if event.GetKeyCode() == wx.WXK_SPACE:
|
||||||
|
self.ToggleItem(self.GetFocusedItem())
|
||||||
|
event.Skip()
|
||||||
|
|
||||||
def on_keydown(self, event):
|
|
||||||
if event.GetKeyCode() == wx.WXK_SPACE:
|
|
||||||
self.ToggleItem(self.GetFocusedItem())
|
|
||||||
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
|
||||||
self.listArguments = listArguments
|
self.listArguments = listArguments
|
||||||
self.create_list(parent)
|
self.create_list(parent)
|
||||||
|
|
||||||
def set_windows_size(self, column, characters_max):
|
def set_windows_size(self, column, characters_max):
|
||||||
self.list.SetColumnWidth(column, characters_max*2)
|
self.list.SetColumnWidth(column, characters_max*2)
|
||||||
|
|
||||||
def set_size(self):
|
def set_size(self):
|
||||||
self.list.SetSize((self.list.GetBestSize()[0], 1000))
|
self.list.SetSize((self.list.GetBestSize()[0], 1000))
|
||||||
|
|
||||||
def create_list(self, parent):
|
def create_list(self, parent):
|
||||||
self.list = wx.ListCtrl(parent, -1, **self.listArguments)
|
self.list = wx.ListCtrl(parent, -1, **self.listArguments)
|
||||||
for i in range(0, len(self.columns)):
|
for i in range(0, len(self.columns)):
|
||||||
self.list.InsertColumn(i, "%s" % (self.columns[i]))
|
self.list.InsertColumn(i, "%s" % (self.columns[i]))
|
||||||
|
|
||||||
def insert_item(self, reversed, *item):
|
def insert_item(self, reversed, *item):
|
||||||
""" Inserts an item on the list."""
|
""" Inserts an item on the list."""
|
||||||
if reversed == False: items = self.list.GetItemCount()
|
if reversed == False: items = self.list.GetItemCount()
|
||||||
else: items = 0
|
else: items = 0
|
||||||
self.list.InsertItem(items, item[0])
|
self.list.InsertItem(items, item[0])
|
||||||
for i in range(1, len(self.columns)):
|
for i in range(1, len(self.columns)):
|
||||||
self.list.SetItem(items, i, item[i])
|
self.list.SetItem(items, i, item[i])
|
||||||
|
|
||||||
def remove_item(self, pos):
|
def remove_item(self, pos):
|
||||||
""" Deletes an item from the list."""
|
""" Deletes an item from the list."""
|
||||||
if pos > 0: self.list.Focus(pos-1)
|
if pos > 0: self.list.Focus(pos-1)
|
||||||
self.list.DeleteItem(pos)
|
self.list.DeleteItem(pos)
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
self.list.DeleteAllItems()
|
self.list.DeleteAllItems()
|
||||||
|
|
||||||
def get_selected(self):
|
def get_selected(self):
|
||||||
return self.list.GetFocusedItem()
|
return self.list.GetFocusedItem()
|
||||||
|
|
||||||
def select_item(self, pos):
|
def select_item(self, pos):
|
||||||
self.list.Focus(pos)
|
self.list.Focus(pos)
|
||||||
|
|
||||||
def get_count(self):
|
def get_count(self):
|
||||||
selected = self.list.GetItemCount()
|
selected = self.list.GetItemCount()
|
||||||
if selected == -1:
|
if selected == -1:
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
return selected
|
return selected
|
||||||
|
|
||||||
def Enable(self, value):
|
def Enable(self, value):
|
||||||
return self.list.Enable(value)
|
return self.list.Enable(value)
|
||||||
|
|
||||||
class multiselectionList(list):
|
class multiselectionList(list):
|
||||||
|
|
||||||
def create_list(self, parent):
|
def create_list(self, parent):
|
||||||
self.list = multiselectionBaseList(parent, -1, **self.listArguments)
|
self.list = multiselectionBaseList(parent, -1, **self.listArguments)
|
||||||
for i in range(0, len(self.columns)):
|
for i in range(0, len(self.columns)):
|
||||||
self.list.InsertColumn(i, "%s" % (self.columns[i]))
|
self.list.InsertColumn(i, "%s" % (self.columns[i]))
|
||||||
|
|
||||||
def get_multiple_selection(self):
|
def get_multiple_selection(self):
|
||||||
selected = []
|
selected = []
|
||||||
for item in range(0, self.list.GetItemCount()):
|
for item in range(0, self.list.GetItemCount()):
|
||||||
if self.list.IsChecked(item):
|
if self.list.IsChecked(item):
|
||||||
selected.append(item)
|
selected.append(item)
|
||||||
if len(selected) == 0 and self.list.GetFocusedItem() != -1:
|
if len(selected) == 0 and self.list.GetFocusedItem() != -1:
|
||||||
selected.append(self.list.GetFocusedItem())
|
selected.append(self.list.GetFocusedItem())
|
||||||
return selected
|
return selected
|
Loading…
Reference in New Issue
Block a user