comparison cagou/core/widgets_handler.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 4d660b252487
children 3c9ba4a694ef
comparison
equal deleted inserted replaced
404:f7476818f9fb 405:84ff5c917064
495 continue 495 continue
496 if wid_hash == ignore.widget_hash: 496 if wid_hash == ignore.widget_hash:
497 continue 497 continue
498 yield w 498 yield w
499 499
500 def widgets_sort(self, widget):
501 """method used as key to sort the widgets
502
503 order of the widgets when changing slide is affected
504 @param widget(QuickWidget): widget to sort
505 @return: a value which will be used for sorting
506 """
507 try:
508 return str(widget.target).lower()
509 except AttributeError:
510 return str(list(widget.targets)[0]).lower()
511 500
512 def _updateHiddenSlides(self): 501 def _updateHiddenSlides(self):
513 """adjust carousel slides according to visible widgets""" 502 """adjust carousel slides according to visible widgets"""
514 if self._slides_update_lock or not self.carousel_active: 503 if self._slides_update_lock or not self.carousel_active:
515 return 504 return
520 self._slides_update_lock += 1 509 self._slides_update_lock += 1
521 visible_list = G.host.getVisibleList(current_slide.__class__) 510 visible_list = G.host.getVisibleList(current_slide.__class__)
522 # we ignore current_slide as it may not be visible yet (e.g. if an other 511 # we ignore current_slide as it may not be visible yet (e.g. if an other
523 # screen is shown 512 # screen is shown
524 hidden = list(self.hiddenList(visible_list, ignore=current_slide)) 513 hidden = list(self.hiddenList(visible_list, ignore=current_slide))
525 slides_sorted = sorted(set(hidden + [current_slide]), key=self.widgets_sort) 514 slides_sorted = sorted(set(hidden + [current_slide]))
526 to_remove = set(self.carousel.slides).difference({current_slide}) 515 to_remove = set(self.carousel.slides).difference({current_slide})
527 for w in to_remove: 516 for w in to_remove:
528 self.carousel.remove_widget(w) 517 self.carousel.remove_widget(w)
529 if hidden: 518 if hidden:
530 # no need to add more than two widgets (next and previous), 519 # no need to add more than two widgets (next and previous),