So I was trying to pretty up a GUI. It took 20 minutes to write code to
place names in a circle and draw arrows to the names that are related
(actually, the names are filenames, and the arrows represent 'import' or
'from ... import' statements).
It's taken a couple of hours to try to clean it up so that the arrows go
up to the bounding box of the text, but not inside.
Here was the plan: Compute the line that connects the centers of the
text objects. Figure out where that line intersects the bounding boxes
of the texts, and draw the lines to the intersection points instead of
center-to-center.
It all works ... except that I don't get the right bounding boxes.
Here's the code:
----
# x0,y0 is one text object; x1,y1 is the other.
print "Center coords: (%.1f,%.1f) and (%.1f, %.1f)" % (x0,y0,x1,y1)
start_id = self.mainw.f.c.find_closest(x0,y0)[0] # <---- should
return the text object itself, right?
start_x0,start_y0,start_x1,start_y1 = self.mainw.f.c.bbox(start_id)
print "Bounding box near (x0,y0): (%.1f,%.1f) x (%.1f,%.1f)" % \
(start_x0,start_y0,start_x1,start_y1)
end_id = self.mainw.f.c.find_closest(x1,y1)[0] # <---- and the other
one ...
end_x0,end_y0,end_x1,end_y1 = self.mainw.f.c.bbox(end_id)
print "Bounding box near (x1,y1): (%.1f,%.1f) x (%.1f,%.1f)" % \
(end_x0,end_y0,end_x1,end_y1)
----
To my shock, find_closest returns the same start_id and end_id ...
namely, 1 ... every single time. Tkinter appears to be unable to
capture the object closest to the coordinates, or else I'm not
understanding how to use .find_closest(). Here's a typical result:
Center coords: (200.0,380.0) and (375.5, 240.1) # (x0,y0) and (x1,y1)
start_id: 1
Bounding box near (x0,y0): (29.0,4.0) x (31.0,17.0)
end_id: 1
Bounding box near (x1,y1): (29.0,4.0) x (31.0,17.0)
Truncating around box near x0,y0
Testing point (29, 516.36794949889111)
Testing point (31, 514.77300272112632)
Testing point (671.48908696117667, 4)
Testing point (655.18760257156146, 17)
fall-through # <---- Well, duh! None of these points is on the
bounding box.
Truncating around box near x1,y1
Testing point (29, 516.36794949889111)
Testing point (31, 514.77300272112632)
Testing point (671.48908696117667, 4)
Testing point (655.18760257156146, 17)
fall-through # Ditto.
The bounding box in every single case is (29,4) x (31,17). What's going
on? (Also, there isn't an object bounded by those coordinates on my
screen!!)
Thanks,
Jeff Cagle