def get_picked_element(self, event: MouseEvent, element: Artist = None, picked_element: Artist = None, last_selected: Artist = None): """ get the picked element that an event refers to. To implement selection of elements at the back with multiple clicks. """ # start with the figure if element is None: element = self.figure finished = False # iterate over all children for child in sorted(element.get_children(), key=lambda x: x.get_zorder()): # check if the element is contained in the event and has an active dragger #if child.contains(event)[0] and ((getattr(child, "_draggable", None) and getattr(child, "_draggable", # None).connected) or isinstance(child, GrabberGeneric) or isinstance(child, GrabbableRectangleSelection)): if child.get_visible() and child.contains(event)[0] and ( child.pickable() or isinstance(child, GrabberGeneric) ) and not (child.get_label() is not None and child.get_label().startswith("_")): # if the element is the last selected, finish the search if child == last_selected: return picked_element, True # use this element as the current best matching element picked_element = child # iterate over the children's children picked_element, finished = self.get_picked_element( event, child, picked_element, last_selected=last_selected) # if the subcall wants to finish, just break the loop if finished: break return picked_element, finished
def addChildren(color_artists: list, parent: Artist): """ find all the children of an Artist that use a color """ for artist in parent.get_children(): # ignore empty texts if isinstance(artist, mpl.text.Text) and artist.get_text() == "": continue # omit the helper objects generated by pylustrator if getattr(artist, "_no_save", False): continue # add the children of the item (not for text or ticks) if not isinstance(artist, (mpl.text.Text, mpl.axis.XTick, mpl.axis.YTick)): addChildren(color_artists, artist) # iterate over the elements for color_type_name in [ "edgecolor", "facecolor", "color", "markeredgecolor", "markerfacecolor" ]: colors = getattr(artist, "get_" + color_type_name, lambda: None)() # ignore colors that are not set if colors is None or len(colors) == 0: continue # convert to array if (not (isinstance(colors, np.ndarray) and len(colors.shape) > 1) and not isinstance(colors, list)) or \ getattr(colors, "cmap", None) is not None: colors = [colors] # iterate over the colors for color in colors: # test if it is a colormap try: cmap = color.cmap value = color.value except AttributeError: cmap = None # omit blacks and whites if mpl.colors.to_hex(color) == "#000000" or mpl.colors.to_hex( color) == "#ffffff": continue # if we have a colormap if cmap: if getattr(cmap, "get_color", None): # iterate over the colors of the colormap for index, color in enumerate(cmap.get_color()): # convert to hex color = mpl.colors.to_hex(color) # check if it is already in the dictionary if color not in color_artists: color_artists[color] = [] # add the artist color_artists[color].append( [color_type_name, artist, value, cmap, index]) else: # check if it is already in the dictionary if cmap not in color_artists: color_artists[cmap] = [] color_artists[cmap].append( [color_type_name, artist, value, cmap, value]) else: # ignore transparent colors if mpl.colors.to_rgba(color)[3] == 0: continue # convert to hey color = mpl.colors.to_hex(color) # check if it is already in the dictionary if color not in color_artists: color_artists[color] = [] # add the artist color_artists[color].append( [color_type_name, artist, None, None, None])