# HG changeset patch # User Goffi # Date 1579283075 -3600 # Node ID aa860c10acfc0474de91a039cd009eb2d567a5a2 # Parent 19422bbd9c8e22af25aca9109b91bacae5cd9b06 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. diff -r 19422bbd9c8e -r aa860c10acfc cagou/plugins/plugin_wid_chat.kv --- a/cagou/plugins/plugin_wid_chat.kv Fri Jan 17 18:44:35 2020 +0100 +++ b/cagou/plugins/plugin_wid_chat.kv Fri Jan 17 18:44:35 2020 +0100 @@ -22,6 +22,15 @@ #:import ScrollEffect kivy.effects.scroll.ScrollEffect +# Chat Selector + +: + JidSelector: + on_select: root.on_select(args[1]) + + +# Chat + : size_hint: None, None size: dp(30), dp(30) diff -r 19422bbd9c8e -r aa860c10acfc cagou/plugins/plugin_wid_chat.py --- a/cagou/plugins/plugin_wid_chat.py Fri Jan 17 18:44:35 2020 +0100 +++ b/cagou/plugins/plugin_wid_chat.py Fri Jan 17 18:44:35 2020 +0100 @@ -22,6 +22,8 @@ import sys from kivy.uix.boxlayout import BoxLayout from kivy.uix.textinput import TextInput +from kivy.uix.screenmanager import Screen, NoTransition +from kivy.uix import screenmanager from kivy.metrics import sp, dp from kivy.clock import Clock from kivy import properties @@ -380,10 +382,12 @@ message_input = properties.ObjectProperty() messages_widget = properties.ObjectProperty() history_scroll = properties.ObjectProperty() + global_screen_manager = True collection_carousel = True def __init__(self, host, target, type_=C.CHAT_ONE2ONE, nick=None, occupants=None, subject=None, statuses=None, profiles=None): + self.show_chat_selector = False if statuses is None: statuses = {} quick_chat.QuickChat.__init__( @@ -412,6 +416,18 @@ def on_kv_post(self, __): self.postInit() + def screenManagerInit(self, screen_manager): + screen_manager.transition = screenmanager.SlideTransition(direction='down') + sel_screen = Screen(name='chat_selector') + chat_selector = ChatSelector(profile=self.profile) + sel_screen.add_widget(chat_selector) + screen_manager.add_widget(sel_screen) + if self.show_chat_selector: + transition = screen_manager.transition + screen_manager.transition = NoTransition() + screen_manager.current = 'chat_selector' + screen_manager.transition = transition + def __str__(self): return "Chat({})".format(self.target) @@ -424,15 +440,29 @@ if len(profiles) > 1: raise NotImplementedError("Multi-profiles is not available yet for chat") if target is None: + show_chat_selector = True target = G.host.profiles[profiles[0]].whoami - return G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None, - on_existing_widget=G.host.getOrClone, - profiles=profiles) + else: + show_chat_selector = False + wid = G.host.widgets.getOrCreateWidget(cls, target, on_new_widget=None, + on_existing_widget=G.host.getOrClone, + profiles=profiles) + wid.show_chat_selector = show_chat_selector + return wid @property def message_widgets_rev(self): return self.messages_widget.children + ## keyboard ## + def key_input(self, window, key, scancode, codepoint, modifier): + if key == 27: + screen_manager = self.screen_manager + screen_manager.transition.direction = 'down' + screen_manager.current = 'chat_selector' + return True + + ## header ## def changeWidget(self, jid_): @@ -836,5 +866,36 @@ ) +class ChatSelector(cagou_widget.CagouWidget): + profile = properties.StringProperty() + plugin_info_class = Chat + + def on_select(self, contact_button): + contact_jid = jid.JID(contact_button.jid) + plugin_info = G.host.getPluginInfo(main=Chat) + factory = plugin_info['factory'] + self.screen_manager.transition.direction = 'up' + carousel = self.whwrapper.carousel + current_slides = {w.target: w for w in carousel.slides} + if contact_jid in current_slides: + slide = current_slides[contact_jid] + idx = carousel.slides.index(slide) + carousel.index = idx + self.screen_manager.current = '' + else: + G.host.switchWidget( + self, factory(plugin_info, contact_jid, profiles=[self.profile])) + + @property + def profiles(self): + return [self.profile] + + def key_input(self, window, key, scancode, codepoint, modifier): + if key == 27: + # we go back to root screen + G.host.switchWidget(self) + return True + + PLUGIN_INFO["factory"] = Chat.factory quick_widgets.register(quick_chat.QuickChat, Chat)