comparison cagou/plugins/plugin_wid_chat.py @ 367:abb57182ebfb

chat: prepend nick to message input when occupant avatar is touched on group chat.
author Goffi <goffi@goffi.org>
date Mon, 27 Jan 2020 21:17:08 +0100
parents 4d3a0c4f2430
children 4d660b252487
comparison
equal deleted inserted replaced
366:58e395c0777e 367:abb57182ebfb
22 import sys 22 import sys
23 from kivy.uix.boxlayout import BoxLayout 23 from kivy.uix.boxlayout import BoxLayout
24 from kivy.uix.textinput import TextInput 24 from kivy.uix.textinput import TextInput
25 from kivy.uix.screenmanager import Screen, NoTransition 25 from kivy.uix.screenmanager import Screen, NoTransition
26 from kivy.uix import screenmanager 26 from kivy.uix import screenmanager
27 from kivy.uix.behaviors import ButtonBehavior
27 from kivy.metrics import sp, dp 28 from kivy.metrics import sp, dp
28 from kivy.clock import Clock 29 from kivy.clock import Clock
29 from kivy import properties 30 from kivy import properties
30 from kivy.uix.dropdown import DropDown 31 from kivy.uix.dropdown import DropDown
31 from kivy.core.window import Window 32 from kivy.core.window import Window
71 72
72 # below this limit, new messages will be prepended 73 # below this limit, new messages will be prepended
73 INFINITE_SCROLL_LIMIT = dp(600) 74 INFINITE_SCROLL_LIMIT = dp(600)
74 75
75 76
76 class MessAvatar(Image): 77 class MessAvatar(ButtonBehavior, Image):
77 pass 78 pass
78 79
79 80
80 class MessageWidget(quick_chat.MessageWidget, BoxLayout): 81 class MessageWidget(quick_chat.MessageWidget, BoxLayout):
81 mess_data = properties.ObjectProperty() 82 mess_data = properties.ObjectProperty()
453 @property 454 @property
454 def message_widgets_rev(self): 455 def message_widgets_rev(self):
455 return self.messages_widget.children 456 return self.messages_widget.children
456 457
457 ## keyboard ## 458 ## keyboard ##
459
458 def key_input(self, window, key, scancode, codepoint, modifier): 460 def key_input(self, window, key, scancode, codepoint, modifier):
459 if key == 27: 461 if key == 27:
460 screen_manager = self.screen_manager 462 screen_manager = self.screen_manager
461 screen_manager.transition.direction = 'down' 463 screen_manager.transition.direction = 'down'
462 screen_manager.current = 'chat_selector' 464 screen_manager.current = 'chat_selector'
647 G.host.desktop_notif( 649 G.host.desktop_notif(
648 notif_msg, 650 notif_msg,
649 title=_("mention ({room_jid})").format( 651 title=_("mention ({room_jid})").format(
650 room_jid=self.target) 652 room_jid=self.target)
651 ) 653 )
654
655 # message input
656
657 def addNick(self, nick):
658 """Add a nickname to message_input if suitable"""
659 if (self.type == C.CHAT_GROUP and not self.message_input.text.startswith(nick)):
660 self.message_input.text = f'{nick}: {self.message_input.text}'
652 661
653 def onSend(self, input_widget): 662 def onSend(self, input_widget):
654 G.host.messageSend( 663 G.host.messageSend(
655 self.target, 664 self.target,
656 {'': input_widget.text}, # TODO: handle language 665 {'': input_widget.text}, # TODO: handle language