changeset 11:49d30fc15884

core: added switchWidget method, to change a CagouWidget for an other one
author Goffi <goffi@goffi.org>
date Fri, 08 Jul 2016 20:17:52 +0200
parents 8b2836b5b6c7
children 30f6586f904b
files src/cagou.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/cagou.py	Fri Jul 08 20:17:09 2016 +0200
+++ b/src/cagou.py	Fri Jul 08 20:17:52 2016 +0200
@@ -35,6 +35,7 @@
 from profile_manager import ProfileManager
 from contact_list import ContactList
 from kivy.uix.boxlayout import BoxLayout
+from cagou_widget import CagouWidget
 import os.path
 
 
@@ -78,6 +79,20 @@
     def setPresenceStatus(self, show='', status=None, profile=C.PROF_KEY_NONE):
         log.info(u"Profile presence status set to {show}/{status}".format(show=show, status=status))
 
+    def switchWidget(self, old, new):
+        """Replace old widget by new one
+
+        old(CagouWidget): CagouWidget instance or a child
+        new(CagouWidget): new widget instance
+        """
+        for w in old.walk_reverse():
+            if isinstance(w, CagouWidget):
+                parent = w.parent
+                idx = parent.children.index(w)
+                parent.remove_widget(w)
+                parent.add_widget(new, index=idx)
+                break
+
 
 if __name__ == '__main__':
     Cagou().run()