comparison 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
comparison
equal deleted inserted replaced
404:f7476818f9fb 405:84ff5c917064
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 20
21 from functools import total_ordering
21 from sat.core import log as logging 22 from sat.core import log as logging
22 from sat.core import exceptions 23 from sat.core import exceptions
23 from kivy.uix.behaviors import ButtonBehavior 24 from kivy.uix.behaviors import ButtonBehavior
24 from kivy.uix.boxlayout import BoxLayout 25 from kivy.uix.boxlayout import BoxLayout
25 from kivy.uix.dropdown import DropDown 26 from kivy.uix.dropdown import DropDown
81 def on_extra_menu(self, *args): 82 def on_extra_menu(self, *args):
82 self.dismiss() 83 self.dismiss()
83 menu.ExtraSideMenu().show() 84 menu.ExtraSideMenu().show()
84 85
85 86
87 @total_ordering
86 class CagouWidget(BoxLayout): 88 class CagouWidget(BoxLayout):
87 main_container = properties.ObjectProperty(None) 89 main_container = properties.ObjectProperty(None)
88 header_input = properties.ObjectProperty(None) 90 header_input = properties.ObjectProperty(None)
89 header_box = properties.ObjectProperty(None) 91 header_box = properties.ObjectProperty(None)
90 use_header_input = False 92 use_header_input = False
115 self.header_input.bind( 117 self.header_input.bind(
116 on_text_validate=lambda *args: self.onHeaderInput(), 118 on_text_validate=lambda *args: self.onHeaderInput(),
117 text=self.onHeaderInputComplete, 119 text=self.onHeaderInputComplete,
118 ) 120 )
119 self.header_box.add_widget(self.header_input) 121 self.header_box.add_widget(self.header_input)
122
123 def __lt__(self, other):
124 # XXX: sorting is notably used when collection_carousel is set
125 try:
126 target = str(self.target)
127 except AttributeError:
128 target = str(list(self.targets)[0])
129 other_target = str(list(other.targets)[0])
130 else:
131 other_target = str(other.target)
132 return target < other_target
120 133
121 @property 134 @property
122 def screen_manager(self): 135 def screen_manager(self):
123 if ((not self.global_screen_manager 136 if ((not self.global_screen_manager
124 and not (self.plugin_info_class is not None 137 and not (self.plugin_info_class is not None