diff cagou/core/cagou_widget.py @ 405:84ff5c917064

widgets: implemented ordering in ContactItem and CagouWidget: ordering of slides in collection_carousel were using a specific key during the sort, this has been replaced by an ordering implemented directly into the classes. Ordering has also been implemented in ContactItem to have items appearing in a consistent order notably for opened chats.
author Goffi <goffi@goffi.org>
date Wed, 12 Feb 2020 20:02:58 +0100
parents d61bbbac4160
children 3c9ba4a694ef
line wrap: on
line diff
--- a/cagou/core/cagou_widget.py	Wed Feb 12 20:02:58 2020 +0100
+++ b/cagou/core/cagou_widget.py	Wed Feb 12 20:02:58 2020 +0100
@@ -18,6 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
+from functools import total_ordering
 from sat.core import log as logging
 from sat.core import exceptions
 from kivy.uix.behaviors import ButtonBehavior
@@ -83,6 +84,7 @@
         menu.ExtraSideMenu().show()
 
 
+@total_ordering
 class CagouWidget(BoxLayout):
     main_container = properties.ObjectProperty(None)
     header_input = properties.ObjectProperty(None)
@@ -118,6 +120,17 @@
             )
             self.header_box.add_widget(self.header_input)
 
+    def __lt__(self, other):
+        # XXX: sorting is notably used when collection_carousel is set
+        try:
+            target = str(self.target)
+        except AttributeError:
+            target = str(list(self.targets)[0])
+            other_target = str(list(other.targets)[0])
+        else:
+            other_target = str(other.target)
+        return target < other_target
+
     @property
     def screen_manager(self):
         if ((not self.global_screen_manager