def _motion_notify_cb(self, widget, event): x, y = event.x, event.y i = self.get_index_at_pos(x, y) # Set the tooltip. # Passing the tooltip through a value of None is necessary for its # position on the screen to be updated to where the pointer is. Setting # it to None, and then to the desired value must happen in two separate # events for the tooltip window position update to be honoured. if i is None: # Not over a color, so use the static default if self._tooltip_index not in (-1, -2): # First such event: reset the tooltip. self._tooltip_index = -1 self.set_has_tooltip(False) self.set_tooltip_text("") elif self._tooltip_index != -2: # Second event over a non-color: set the tooltip text. self._tooltip_index = -2 self.set_has_tooltip(True) self.set_tooltip_text(self.STATIC_TOOLTIP_TEXT) elif self._tooltip_index != i: # Mouse pointer has moved to a different color, or away # from the two states above. if self._tooltip_index is not None: # First event for this i: reset the tooltip. self._tooltip_index = None self.set_has_tooltip(False) self.set_tooltip_text("") else: # Second event for this i: set the desired tooltip text. self._tooltip_index = i mgr = self.get_color_manager() tip = mgr.palette.get_color_name(i) color = mgr.palette.get_color(i) if color is None: tip = C_( "palette view", "Empty palette slot (drag a color here)", ) elif tip is None or tip.strip() == "": tip = "" # Anonymous colors don't get tooltips self.set_has_tooltip(True) self.set_tooltip_text(tip)