comparison cagou/core/cagou_main.py @ 385:6dacaf81339a

core: return newly switched widget in switchWidget and doAction
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2020 20:47:17 +0100
parents eb3f622d8791
children de066b72f5a8
comparison
equal deleted inserted replaced
384:3669a26ef7d9 385:6dacaf81339a
735 self.addNote("", _("room {} has been joined").format(widget.target)) 735 self.addNote("", _("room {} has been joined").format(widget.target))
736 736
737 def switchWidget(self, old, new=None): 737 def switchWidget(self, old, new=None):
738 """Replace old widget by new one 738 """Replace old widget by new one
739 739
740 old(CagouWidget, None): CagouWidget instance or a child 740 @param old(CagouWidget, None): CagouWidget instance or a child
741 None to select automatically widget to switch 741 None to select automatically widget to switch
742 new(CagouWidget): new widget instance 742 @param new(CagouWidget): new widget instance
743 None to use default widget 743 None to use default widget
744 @return (CagouWidget): new widget
744 """ 745 """
745 if old is None: 746 if old is None:
746 old = self.getWidgetToSwitch() 747 old = self.getWidgetToSwitch()
747 if new is None: 748 if new is None:
748 factory = self.default_wid['factory'] 749 factory = self.default_wid['factory']
765 "trying to switch widget") 766 "trying to switch widget")
766 767
767 # selected_widget can be modified in changeWidget, so we need to set it before 768 # selected_widget can be modified in changeWidget, so we need to set it before
768 self.selected_widget = new 769 self.selected_widget = new
769 to_change.whwrapper.changeWidget(new) 770 to_change.whwrapper.changeWidget(new)
771 return new
770 772
771 def _addVisibleWidget(self, widget): 773 def _addVisibleWidget(self, widget):
772 """declare a widget visible 774 """declare a widget visible
773 775
774 for internal use only! 776 for internal use only!
861 def getWidgetToSwitch(self): 863 def getWidgetToSwitch(self):
862 """Choose best candidate when we need to switch widget and old is not specified 864 """Choose best candidate when we need to switch widget and old is not specified
863 865
864 @return (CagouWidget): widget to switch 866 @return (CagouWidget): widget to switch
865 """ 867 """
866 if self._selected_widget_main is not None: 868 if (self._selected_widget_main is not None
869 and self._selected_widget_main.whwrapper is not None):
867 # we are not on the main screen, we want to switch a widget from main screen 870 # we are not on the main screen, we want to switch a widget from main screen
868 return self._selected_widget_main 871 return self._selected_widget_main
869 elif self.selected_widget is not None: 872 elif (self.selected_widget is not None
873 and isinstance(self.selected_widget, CagouWidget)
874 and self.selected_widget.whwrapper is not None):
870 return self.selected_widget 875 return self.selected_widget
871 # no widget is selected we check if we have any default widget 876 # no widget is selected we check if we have any default widget
872 default_cls = self.default_class 877 default_cls = self.default_class
873 for w in self.visible_widgets: 878 for w in self.visible_widgets:
874 if isinstance(w, default_cls): 879 if isinstance(w, default_cls):
882 887
883 @param action(unicode): action to do, can be: 888 @param action(unicode): action to do, can be:
884 - chat: open a chat widget 889 - chat: open a chat widget
885 @param target(unicode): target of the action 890 @param target(unicode): target of the action
886 @param profiles(list[unicode]): profiles to use 891 @param profiles(list[unicode]): profiles to use
892 @return (CagouWidget, None): new widget
887 """ 893 """
888 try: 894 try:
889 # FIXME: Q&D way to get chat plugin, should be replaced by a clean method 895 # FIXME: Q&D way to get chat plugin, should be replaced by a clean method
890 # in host 896 # in host
891 plg_infos = [p for p in self.getPluggedWidgets() 897 plg_infos = [p for p in self.getPluggedWidgets()
892 if action in p['import_name']][0] 898 if action in p['import_name']][0]
893 except IndexError: 899 except IndexError:
894 log.warning("No plugin widget found to do {action}".format(action=action)) 900 log.warning("No plugin widget found to do {action}".format(action=action))
895 else: 901 else:
896 factory = plg_infos['factory'] 902 factory = plg_infos['factory']
897 self.switchWidget(None, 903 return self.switchWidget(
904 None,
898 factory(plg_infos, target=target, profiles=profiles)) 905 factory(plg_infos, target=target, profiles=profiles))
899 906
900 ## bridge handlers ## 907 ## bridge handlers ##
901 908
902 def otrStateHandler(self, state, dest_jid, profile): 909 def otrStateHandler(self, state, dest_jid, profile):