base gc class, callbacks part1

This commit is contained in:
ingvar1995 2017-07-16 22:51:20 +03:00
parent 87392ea95a
commit 9c129e925b
2 changed files with 48 additions and 0 deletions

View File

@ -374,6 +374,29 @@ def video_receive_frame(toxav, friend_number, width, height, y, u, v, ystride, u
except Exception as ex: except Exception as ex:
print(ex) print(ex)
# -----------------------------------------------------------------------------------------------------------------
# Callbacks - groups
# -----------------------------------------------------------------------------------------------------------------
def group_invite(tox, friend_number, gc_type, data, length, user_data):
invoke_in_main_thread(Profile.get_instance().group_invite, friend_number, gc_type, data[:length])
def group_message(tox, group_number, peer_number, message, length, user_data):
invoke_in_main_thread(Profile.get_instance().new_gc_message, group_number,
peer_number, TOX_MESSAGE_TYPE['NORMAL'], message[:length])
def group_action(tox, group_number, peer_number, message, length, user_data):
invoke_in_main_thread(Profile.get_instance().new_gc_message, group_number,
peer_number, TOX_MESSAGE_TYPE['ACTION'], message[:length])
def group_title(tox, group_number, peer_number, title, length, user_data):
invoke_in_main_thread(Profile.get_instance().new_gc_title, group_number,
title[:length])
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
# Callbacks - initialization # Callbacks - initialization
# ----------------------------------------------------------------------------------------------------------------- # -----------------------------------------------------------------------------------------------------------------
@ -410,3 +433,9 @@ def init_callbacks(tox, window, tray):
tox.callback_friend_lossless_packet(lossless_packet, 0) tox.callback_friend_lossless_packet(lossless_packet, 0)
tox.callback_friend_lossy_packet(lossy_packet, 0) tox.callback_friend_lossy_packet(lossy_packet, 0)
tox.callback_group_invite(group_invite)
tox.callback_group_message(group_message)
tox.callback_group_action(group_action)
tox.callback_group_title(group_title)
tox.callback_group_namelist_change(group_namelist_change)

19
toxygen/group_chat.py Normal file
View File

@ -0,0 +1,19 @@
import basecontact
class GroupChat(basecontact.BaseContact):
def __init__(self, name, status_message, widget, tox, group_number):
super().__init__(name, status_message, widget, None)
self._number = group_number
self._tox = tox
def set_name(self, name):
self._tox.group_set_title(self._number, name)
super().set_name(name)
def send_message(self, message):
self._tox.group_message_send(self._number, message.encode('utf-8'))
def new_title(self, title):
self._name = title