def union(one, other): """Returns a new bbox that covers one and other. Assumes that the positive y direction is DOWN. """ left = min(one.left, other.left) right = max(one.right, other.right) top = min(one.top, other.top) bottom = max(one.bottom, other.bottom) return BBox([[left, top], [right, bottom]])
def drawme(self, diag, pos, flip, tags=tuple()): """Draws the Thing.""" p = pos.copy() # intag is attached to items that should be considered # inside the box intag = self.tags[0] + 'inside' # draw the bindings for binding in self.bindings: # check whether the key was already drawn drawn = binding.key.isdrawn() # draw the binding binding.draw(diag, p, flip, tags=tags) # apply intag to the dots self.canvas.addtag_withtag(intag, binding.dot.tags) if drawn: # if the key was already drawn, then the binding # contains two dots, so we should add intag to the # second one. if binding.dot2: self.canvas.addtag_withtag(intag, binding.dot2.tags) else: # if the key wasn't drawn yet, it should be # considered inside this mapping self.canvas.addtag_withtag(intag, binding.key.tags) # move down to the position for the next binding p.y = binding.get_bbox().bottom + 1.8 if len(self.bindings): # if there are any bindings, draw a box around them bbox = self.canvas.bbox(intag) item = self.canvas.box(bbox, tags=tags, **self.boxoptions) else: # otherwise just draw a box bbox = BBox([p.copy(), p.copy()]) item = self.canvas.box(bbox, padx=0.4, pady=0.4, tags=tags, **self.boxoptions) # make the box clickable self.bind(item) self.boxitem = item # put the label above the box if self.label: p = bbox.upperleft() item = self.canvas.offset_text(p, self.label, anchor=SW, font=SMALLFONT, tags=tags) # make the label clickable self.bind(item) # if the whole mapping is not in the right position, shift it. if flip == 1: dx = pos.x - self.get_bbox().left else: dx = pos.x - self.get_bbox().right self.canvas.move(self.tags, dx, 0, transform=True)