First off, thanks to Robin for diagnosing the problem I was having with
line.SetEnds(). (I've already thunk him individually, but that didn't go
to the list.)
···
*
So, I want to use OGL to build something that lets me move groups of
objects around. (Select, select, select, drag.) I'm sure there must be a
straightforward way to do this, but I've met with no success so far.
Perhaps someone can help to debug my brain.
Obvious attempt #1:
Make a subclass of wxShapeEvtHandler with an OnMovePre or OnMovePost
method that looks something like this (various boring but necessary
details elided):
def OnMovePost(self, x,y, x_old,y_old, display):
self.base_OnMovePost(blah blah)
shape = self.GetShape()
if not shape.Selected(): return
for each selected shape other than this one:
sh.Move(dc, sh.GetX()+x-old_x, sh.GetY()+y-old_y)
The first problem that arises with this is with the "other
than this one" condition: I can't find any better way of
testing for object identity than comparing the first 8 characters
of str(x.this), which (1) isn't actually documented as working,
(2) looks amazingly non-robust, (3) is terribly ugly, and (4)
feels like an order of magnitude more effort (for the machine)
than it should take. However, it seems to work.
With that sorted out, there's a more serious problem. If I have
shapes A,B,C selected and move B by dragging it around, then
B moves just as it ought to be but A,C appear to be copied
rather than moved: after the move there are two As, one in
its original place and one where it should have moved to,
and likewise for B. Sounds like I've failed to get things
refreshed or redrawn as they ought to be? Yes (especially as
dragging the window off-screen and on again fixes the problem),
but I've been unable to find any way of getting things refreshed
as they should be.
For instance, I tried attaching a method that does this to one of my
top-level frame's windows:
canvas = self.canvas
dc = wxClientDC(canvas)
canvas.Redraw(dc)
self.Refresh(true)
Invoking that doesn't help at all.
It seems to me that this ought to be the right approach. I assume
I'm just being dim somewhere along the line.
Obvious attempt #2:
Aha, the wxShapeCanvas class has methods with names like OnEndDragLeft,
which might be useful. Nope: they only get called when the drag doesn't
affect any shape on the canvas.
Obvious attempt #3:
There's a shape event handler method called OnEndDragLeft. Maybe
doing much the same with that as I did with OnMovePost might help?
Nope. Exactly the same story as before.
Aarggh!
*
I'm not subscribed to the wxpython-users list, so it would be helpful
if any replies could be at least cc'ed to me directly. (I'll keep
an eye on the list archives, which seem to be updated reasonably
often.)
Thanks!
--
Gareth McCaughan