I've been working on a chat app using Kivy. When I receive a message, I decrypt it and then add it to the profile screen of the sender using the following code line. I'm using threading because I want to simultaneously listen for another incoming message.
Thread(target=lambda: Clock.schedule_once(lambda dt: chat_app.updateReceivingMessage(message, profile))).start()
The updateReceivingMessage function checks whether the received message is text or an image, and then adds it to the sender's profile screen accordingly as follow
def updateReceivingMessage(self, message, profile, msg_type):
if msg_type == 'image':
Clock.schedule_once(lambda dt, item= message: self.createImageChatBubble(item, profile) ,0.15*index)
elif msg_type == 'text':
Clock.schedule_once(lambda dt, item= message: self.createFileChatBubble(item, profile) ,0.15*index)
The createImageChatBubble and createMessageChatBubble functions add image or text messages to the sender's profile screen. These functions are defined as follows:
def createImageChatBubble(self, message, profile):
image,message, time, isRead, sender = message.split(";")
chatmsg = ImageChatBubble()
chatmsg.src= f"data:image/png;base64,{image}"
chatmsg.time= time
chatmsg.isRead= isRead
chatmsg.sender= sender
chatmsg.profile= profile
chatmsg.opacity= 0
anim=Animation(opacity=1, duration=0.1)
self.chat_screens[profile].ids['msglist'].add_widget(chatmsg)
anim.start(chatmsg)
def createMessageChatBubble(self, message, profile):
message, time, isRead, sender = message.split(";")
chatmsg= ChatBubble()
chatmsg.time= time
chatmsg.isRead= isRead
chatmsg.sender= sender
chatmsg.profile= profile
chatmsg.opacity= 0
anim=Animation(opacity= 1, duration= 0.1)
self.chat_screens[profile].ids['msglist'].add_widget(chatmsg)
anim.start(chatmsg)
Please note that ChatBubble and ImageChatBubble are custom widgets I've created to display text and image messages, respectively.
However, I'm facing an issue where the app freezes completely when receiving an image message. I'm unable to perform any actions. If you have any insights or suggestions on how to resolve this freezing issue, I'd greatly appreciate your help!
i am new in kivy and search on how to prevent freezing kivy i found this link which says using thread is a good idea. but i am not sure how to do it