Mercurial > libervia-desktop-kivy
comparison cagou/plugins/plugin_wid_chat.py @ 354:aa860c10acfc
chat: new chat selector:
Using the new ScreenManager feature, a widget to select a chat to display is shown when a
user opens the chat (except if an entity jid is specified, in which case it opens directly
the Chat widget), or when user presses ESC.
When on ChatSelector, pressing ESC brings to the root widget (i.e. default widget).
The ChatSelect is a first draft, it is planned to show opened chats, rooms, and a way to
create new chats.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 17 Jan 2020 18:44:35 +0100 |
parents | 19422bbd9c8e |
children | 307c2501d8b2 |
comparison
equal
deleted
inserted
replaced
353:19422bbd9c8e | 354:aa860c10acfc |
---|---|
20 from functools import partial | 20 from functools import partial |
21 import mimetypes | 21 import mimetypes |
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 | |
26 from kivy.uix import screenmanager | |
25 from kivy.metrics import sp, dp | 27 from kivy.metrics import sp, dp |
26 from kivy.clock import Clock | 28 from kivy.clock import Clock |
27 from kivy import properties | 29 from kivy import properties |
28 from kivy.uix.dropdown import DropDown | 30 from kivy.uix.dropdown import DropDown |
29 from kivy.core.window import Window | 31 from kivy.core.window import Window |
378 | 380 |
379 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): | 381 class Chat(quick_chat.QuickChat, cagou_widget.CagouWidget): |
380 message_input = properties.ObjectProperty() | 382 message_input = properties.ObjectProperty() |
381 messages_widget = properties.ObjectProperty() | 383 messages_widget = properties.ObjectProperty() |
382 history_scroll = properties.ObjectProperty() | 384 history_scroll = properties.ObjectProperty() |
385 global_screen_manager = True | |
383 collection_carousel = True | 386 collection_carousel = True |
384 | 387 |
385 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, | 388 def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, |
386 subject=None, statuses=None, profiles=None): | 389 subject=None, statuses=None, profiles=None): |
390 self.show_chat_selector = False | |
387 if statuses is None: | 391 if statuses is None: |
388 statuses = {} | 392 statuses = {} |
389 quick_chat.QuickChat.__init__( | 393 quick_chat.QuickChat.__init__( |
390 self, host, target, type_, nick, occupants, subject, statuses, | 394 self, host, target, type_, nick, occupants, subject, statuses, |
391 profiles=profiles) | 395 profiles=profiles) |
410 self.history_count = 0 | 414 self.history_count = 0 |
411 | 415 |
412 def on_kv_post(self, __): | 416 def on_kv_post(self, __): |
413 self.postInit() | 417 self.postInit() |
414 | 418 |
419 def screenManagerInit(self, screen_manager): | |
420 screen_manager.transition = screenmanager.SlideTransition(direction='down') | |
421 sel_screen = Screen(name='chat_selector') | |
422 chat_selector = ChatSelector(profile=self.profile) | |
423 sel_screen.add_widget(chat_selector) | |
424 screen_manager.add_widget(sel_screen) | |
425 if self.show_chat_selector: | |
426 transition = screen_manager.transition | |
427 screen_manager.transition = NoTransition() | |
428 screen_manager.current = 'chat_selector' | |
429 screen_manager.transition = transition | |
430 | |
415 def __str__(self): | 431 def __str__(self): |
416 return "Chat({})".format(self.target) | 432 return "Chat({})".format(self.target) |
417 | 433 |
418 def __repr__(self): | 434 def __repr__(self): |
419 return self.__str__() | 435 return self.__str__() |
422 def factory(cls, plugin_info, target, profiles): | 438 def factory(cls, plugin_info, target, profiles): |
423 profiles = list(profiles) | 439 profiles = list(profiles) |
424 if len(profiles) > 1: | 440 if len(profiles) > 1: |
425 raise NotImplementedError("Multi-profiles is not available yet for chat") | 441 raise NotImplementedError("Multi-profiles is not available yet for chat") |
426 if target is None: | 442 if target is None: |
443 show_chat_selector = True | |
427 target = G.host.profiles[profiles[0]].whoami | 444 target = G.host.profiles[profiles[0]].whoami |
428 return G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None, | 445 else: |
429 on_existing_widget=G.host.getOrClone, | 446 show_chat_selector = False |
430 profiles=profiles) | 447 wid = G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None, |
448 on_existing_widget=G.host.getOrClone, | |
449 profiles=profiles) | |
450 wid.show_chat_selector = show_chat_selector | |
451 return wid | |
431 | 452 |
432 @property | 453 @property |
433 def message_widgets_rev(self): | 454 def message_widgets_rev(self): |
434 return self.messages_widget.children | 455 return self.messages_widget.children |
456 | |
457 ## keyboard ## | |
458 def key_input(self, window, key, scancode, codepoint, modifier): | |
459 if key == 27: | |
460 screen_manager = self.screen_manager | |
461 screen_manager.transition.direction = 'down' | |
462 screen_manager.current = 'chat_selector' | |
463 return True | |
464 | |
435 | 465 |
436 ## header ## | 466 ## header ## |
437 | 467 |
438 def changeWidget(self, jid_): | 468 def changeWidget(self, jid_): |
439 """change current widget for a new one with given jid | 469 """change current widget for a new one with given jid |
834 callback=self._backHistoryGetCb, | 864 callback=self._backHistoryGetCb, |
835 errback=self._backHistoryGetEb, | 865 errback=self._backHistoryGetEb, |
836 ) | 866 ) |
837 | 867 |
838 | 868 |
869 class ChatSelector(cagou_widget.CagouWidget): | |
870 profile = properties.StringProperty() | |
871 plugin_info_class = Chat | |
872 | |
873 def on_select(self, contact_button): | |
874 contact_jid = jid.JID(contact_button.jid) | |
875 plugin_info = G.host.getPluginInfo(main=Chat) | |
876 factory = plugin_info['factory'] | |
877 self.screen_manager.transition.direction = 'up' | |
878 carousel = self.whwrapper.carousel | |
879 current_slides = {w.target: w for w in carousel.slides} | |
880 if contact_jid in current_slides: | |
881 slide = current_slides[contact_jid] | |
882 idx = carousel.slides.index(slide) | |
883 carousel.index = idx | |
884 self.screen_manager.current = '' | |
885 else: | |
886 G.host.switchWidget( | |
887 self, factory(plugin_info, contact_jid, profiles=[self.profile])) | |
888 | |
889 @property | |
890 def profiles(self): | |
891 return [self.profile] | |
892 | |
893 def key_input(self, window, key, scancode, codepoint, modifier): | |
894 if key == 27: | |
895 # we go back to root screen | |
896 G.host.switchWidget(self) | |
897 return True | |
898 | |
899 | |
839 PLUGIN_INFO["factory"] = Chat.factory | 900 PLUGIN_INFO["factory"] = Chat.factory |
840 quick_widgets.register(quick_chat.QuickChat, Chat) | 901 quick_widgets.register(quick_chat.QuickChat, Chat) |