Simply connect HintLabel._move_to_elem to signal

This commit is contained in:
Florian Bruhin 2016-08-17 15:27:31 +02:00
parent 1d82ea8740
commit 955ed2f52d

View File

@ -84,8 +84,7 @@ class HintLabel(QLabel):
self.setAttribute(Qt.WA_StyledBackground, True) self.setAttribute(Qt.WA_StyledBackground, True)
style.set_register_stylesheet(self) style.set_register_stylesheet(self)
self._context.tab.contents_size_changed.connect( self._context.tab.contents_size_changed.connect(self._move_to_elem)
self._on_contents_size_changed)
self._move_to_elem() self._move_to_elem()
self.show() self.show()
@ -109,21 +108,18 @@ class HintLabel(QLabel):
match_color, matched, unmatched)) match_color, matched, unmatched))
self.adjustSize() self.adjustSize()
@pyqtSlot()
def _move_to_elem(self): def _move_to_elem(self):
"""Reposition the label to its element.""" """Reposition the label to its element."""
if self.elem.frame() is None:
# This sometimes happens for some reason...
log.hints.debug("Frame for {!r} vanished!".format(self))
self.hide()
return
no_js = config.get('hints', 'find-implementation') != 'javascript' no_js = config.get('hints', 'find-implementation') != 'javascript'
rect = self.elem.rect_on_view(no_js=no_js) rect = self.elem.rect_on_view(no_js=no_js)
self.move(rect.x(), rect.y()) self.move(rect.x(), rect.y())
@pyqtSlot()
def _on_contents_size_changed(self):
"""Reposition hints if contents size changed."""
if self.elem.frame() is None:
# This sometimes happens for some reason...
self.hide()
else:
self._move_to_elem()
def cleanup(self): def cleanup(self):
"""Clean up this element and hide it.""" """Clean up this element and hide it."""
self.hide() self.hide()