Niels Menke wrote:
> I didn't want the hand cursor to appear in MoveMode, so i tried to 
> overwrite
> class GUIRightMove(GUIMove).__init__ to not set it.
> 
> class GUIRightMove(GUIMove):
>   def __init__(self, parent):
>       GUIBase.__init__(self, parent)
>   def __init__(self, canvas):
>       GUIBase.__init__(self, canvas)
>       self.StartMove = None
>       self.PrevMoveXY = None
> 
> However, i get the message
>   File 
> "C:\Python24\lib\site-packages\wx-2.8-msw-unicode\wx\lib\floatcanvas\GUIMode.py",
>  
> line 177, in OnLeftDown
>     self.Canvas.SetCursor(self.GrabCursor)
> AttributeError: GUIRightMove instance has no attribute 'GrabCursor'

That error is happening in the OnLeftDown() method -- it's trying to set 
the cursor when you click on Canvas and start to move it. ( I think, in 
your case, it's with a Right click, but that is mapped to the original 
OnLeftDown method). You could fix this my re-defining self.GrabCursor as 
  wx.NullCursor, but see below first.

> Second, i found someone already setting
>     from wx.lib.floatcanvas.GUIMode import GUIMouse
>     self.canvas.SetMode(GUIMouse(self.canvas))
> in the __init__ of our workspace class. So by setting it to GUIMove, i'm 
> essentially breaking that, also breaking the left mouse button events 
> from GUIMouse (that are still needed).

> TypeError: unbound method OnLeftDown() must be called with GUIMouse 
> instance as first argument (got MouseEvent instance instead)
> Is it possible for me to fix this?

We need to step back and re-evaluate a bit here:

It looks like what you really need is a whole new GUIMode -- you've got 
to decide exactly what you want every Mouse Event to do. That's actually 
the entire point of the GUIModes concept -- you can make your own 
GUIMode that behaves exactly the way you want it to.

I think that your needs are different enough from the default that 
trying to cobble together the existing pieces is going to be very hard 
to do. Rather, I think you need to start from the beginning. I suggest 
you derive from GUIMouse, then override the methods that you need to 
change. You can borrow a lot of the code that's in GUIMode.py

>   OnLeftDown = GUIMouse.OnLeftDown

> TypeError: unbound method OnLeftDown() must be called with GUIMouse instance 
> as first argument (got MouseEvent instance instead) 

Yes, I ran into this too. I thought that you should be able to do this, 
given Pythons dynamic nature, but it turns out you can't. You have two 
options:

1) The easy way is to simply copy and paste the code you need into your 
new class.

2) The "right" way is to put the methods that are needed by more than 
one GUIMode class into a mix-in class -- then derive both of your 
subclasses from that. i.e.:

   a) The OnLeftDown, OnLeftUp, and MoveImage methods all get put into a 
"MoveImageMixin" class (maybe with different names, like StartMove(), 
EndMove(), .....

   b) Now the default GUIMove and your new class both derive from 
MoveImageMixin, and they can then both have access to those methods.

This requires a bit of refactoring of the GUIMode.py module -- patches 
accepted.

This is actually a good time to do this -- I've been messing with 
GUIMode.py a bit anyway.

-Chris











-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[EMAIL PROTECTED]
_______________________________________________
FloatCanvas mailing list
[email protected]
http://mail.mithis.com/cgi-bin/mailman/listinfo/floatcanvas

Reply via email to