comparison src/browser/sat_browser/panels.py @ 496:0924710b666a

browser_side: remove the annoying (esp. when editing a message) scrolling each time you select a microblog entry
author souliane <souliane@mailoo.org>
date Thu, 17 Jul 2014 12:59:33 +0200
parents 587fe75d1b16
children 60be99de3808
comparison
equal deleted inserted replaced
495:587fe75d1b16 496:0924710b666a
480 @param new_avatar: path to the new image""" 480 @param new_avatar: path to the new image"""
481 self.avatar.setUrl(new_avatar) 481 self.avatar.setUrl(new_avatar)
482 482
483 def onClick(self, sender): 483 def onClick(self, sender):
484 if sender == self: 484 if sender == self:
485 try: # prevent re-selection of the main entry after a comment has been focused
486 if self.__ignoreNextEvent:
487 self.__ignoreNextEvent = False
488 return
489 except AttributeError:
490 pass
491 self._blog_panel.setSelectedEntry(self) 485 self._blog_panel.setSelectedEntry(self)
492 elif sender == self.delete_label: 486 elif sender == self.delete_label:
493 self._delete() 487 self._delete()
494 elif sender == self.update_label: 488 elif sender == self.update_label:
495 self.edit(True) 489 self.edit(True)
496 elif sender == self.comment_label: 490 elif sender == self.comment_label:
497 self.__ignoreNextEvent = True
498 self._comment() 491 self._comment()
499 492
500 def __modifiedCb(self, content): 493 def __modifiedCb(self, content):
501 """Send the new content to the backend 494 """Send the new content to the backend
502 @return: False to restore the original content if a deletion has been cancelled 495 @return: False to restore the original content if a deletion has been cancelled
584 577
585 def _comment(self): 578 def _comment(self):
586 """Add an empty entry for a new comment""" 579 """Add an empty entry for a new comment"""
587 if self._current_comment: 580 if self._current_comment:
588 self._current_comment.bubble.setFocus(True) 581 self._current_comment.bubble.setFocus(True)
589 self._blog_panel.setSelectedEntry(self._current_comment) 582 self._blog_panel.setSelectedEntry(self._current_comment, True)
590 return 583 return
591 data = {'id': str(time()), 584 data = {'id': str(time()),
592 'new': True, 585 'new': True,
593 'type': 'comment', 586 'type': 'comment',
594 'author': self._blog_panel.host.whoami.bare, 587 'author': self._blog_panel.host.whoami.bare,
600 log.info("The entry of id %s can not be commented" % self.id) 593 log.info("The entry of id %s can not be commented" % self.id)
601 return 594 return
602 entry._parent_entry = self 595 entry._parent_entry = self
603 self._current_comment = entry 596 self._current_comment = entry
604 self.edit(True, entry) 597 self.edit(True, entry)
605 self._blog_panel.setSelectedEntry(entry) 598 self._blog_panel.setSelectedEntry(entry, True)
606 599
607 def edit(self, edit, entry=None): 600 def edit(self, edit, entry=None):
608 """Toggle the bubble between display and edit mode 601 """Toggle the bubble between display and edit mode
609 @edit: boolean value 602 @edit: boolean value
610 @entry: MicroblogEntry instance, or None to use self 603 @entry: MicroblogEntry instance, or None to use self
926 if comment.id == id_: 919 if comment.id == id_:
927 comment.removeFromParent() 920 comment.removeFromParent()
928 self.selected_entry = None 921 self.selected_entry = None
929 break 922 break
930 923
931 def setSelectedEntry(self, entry): 924 def ensureVisible(self, entry):
925 """Scroll to an entry to ensure its visibility
926
927 @param entry (MicroblogEntry): the entry
928 """
932 try: 929 try:
933 self.vpanel.getParent().ensureVisible(entry) # scroll to the clicked entry 930 self.vpanel.getParent().ensureVisible(entry) # scroll to the clicked entry
934 except AttributeError: 931 except AttributeError:
935 log.warning("FIXME: MicroblogPanel.vpanel should be wrapped in a ScrollPanel!") 932 log.warning("FIXME: MicroblogPanel.vpanel should be wrapped in a ScrollPanel!")
936 removeStyle = lambda entry: entry.removeStyleName('selected_entry') 933
934 def setSelectedEntry(self, entry, ensure_visible=False):
935 """Select an entry.
936
937 @param entry (MicroblogEntry): the entry to select
938 @param ensure_visible (boolean): if True, also scroll to the entry
939 """
940 if ensure_visible:
941 self.ensureVisible(entry)
942
937 if not self.host.uni_box or not entry.comments: 943 if not self.host.uni_box or not entry.comments:
938 entry.addStyleName('selected_entry') # blink the clicked entry 944 entry.addStyleName('selected_entry') # blink the clicked entry
939 clicked_entry = entry # entry may be None when the timer is done 945 clicked_entry = entry # entry may be None when the timer is done
940 Timer(500, lambda timer: removeStyle(clicked_entry)) 946 Timer(500, lambda timer: clicked_entry.removeStyleName('selected_entry'))
941 if not self.host.uni_box: 947 if not self.host.uni_box:
942 return # unibox is disabled 948 return # unibox is disabled
949
943 # from here the previous behavior (toggle main item selection) is conserved 950 # from here the previous behavior (toggle main item selection) is conserved
944 entry = entry if entry.comments else None 951 entry = entry if entry.comments else None
945 if self.selected_entry == entry: 952 if self.selected_entry == entry:
946 entry = None 953 entry = None
947 if self.selected_entry: 954 if self.selected_entry:
948 removeStyle(self.selected_entry) 955 self.selected_entry.removeStyleName('selected_entry')
949 if entry: 956 if entry:
950 log.debug("microblog entry selected (author=%s)" % entry.author) 957 log.debug("microblog entry selected (author=%s)" % entry.author)
951 entry.addStyleName('selected_entry') 958 entry.addStyleName('selected_entry')
952 self.selected_entry = entry 959 self.selected_entry = entry
953 960