wx.INVERT issues

The only problem is that I am running a huge application and while I am
drawing the rubberband it is possible to do other things around the
canvas so I cannot afford to be restricted to one function. Even if I
wanted to I could not enforce then to stay out of the menus and toolbars
because it's a completely different event cycle.

I also tried the Wx.Copy cheat and had no luck for some reason

Cole Harris
Enterasys Networks
Phone: 978-684-1652
Email: coharris@enterasys.com
www. http://www.enterasys.com

···

-----Original Message-----
From: Alex Tweedly [mailto:alex@tweedly.net]
Sent: Thursday, September 08, 2005 5:40 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] wx.INVERT issues

Harris, Cole wrote:

Hi all,

I recently was informed about the SetLogicalFunction(wx.INVERT) in
order to draw a line on the screen and have it follow the cursor and
then delete the last known line coords. It works excellent except I

run

into a problem with the wx.INVERT when I use certain built in functions
of wxpython. For example if I call self.Refresh() this will act as a
call to wx.INVERT and I will lose my tracking of the procedure thus
drawing a random line and it not being erased. Is there a way to turn
it off unless you are within the function using it?
Thanks
-cole

Probably best is to put a call to GetLogicalFunction() at the start of
your function to draw the rubber-band, and then restore it when done
.....

e.g.
def rubberBand(... DC, ...):
    initialMode = DC.GetLogicalFunction()
    DC.SetLogicalFunction(wxINVERT)
   ......
   // whatever you do for the rubber band ..
   ....
    DC.SetLogicalFunction(initialMode)
    return

You could cheat and simply restore it to wxCOPY (the default), and
ensure that any other places which change the mode also restore to
wxCOPY - but I prefer the above.

--
Alex Tweedly http://www.tweedly.net

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.19/93 - Release Date:
08/09/2005

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Harris, Cole wrote:

The only problem is that I am running a huge application and while I am
drawing the rubberband it is possible to do other things around the
canvas so I cannot afford to be restricted to one function. Even if I
wanted to I could not enforce then to stay out of the menus and toolbars
because it's a completely different event cycle.

I also tried the Wx.Copy cheat and had no luck for some reason

The other option then is to use a different DC - but I'm afraid I've never done that, so can't really help .....

···

--
Alex Tweedly http://www.tweedly.net

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.10.19/93 - Release Date: 08/09/2005

Cole,

I've generally used wx.XOR rather than wx.INVERT, as it works better if you have gray as a color, though that won't solve your problem.

However, I've never had your problem either. Perhaps I don't quite understand what you are doing.

Harris, Cole wrote:

while I am
drawing the rubberband it is possible to do other things around the
canvas so I cannot afford to be restricted to one function. Even if I
wanted to I could not enforce then to stay out of the menus and toolbars
because it's a completely different event cycle.

hmm. When wx is in a given callback, it can't go and do something else. I don't see how the user can be manipulating other things while also moving the mouse!

If you start your drawing on a LeftDownEvent, then when there is a LeftUp, you can do your cleanup. I don't think you can get other event in between those, at least not easily!

It works well for me in FloatCanvas. Take a look at wx/lib/floatcanvas/FloatCanvas.py

here is an excerpt, that I think has all the relevant code:

     def LeftDownEvent(self,event):
         if self.GUIMode:
             if self.GUIMode == "ZoomIn":
                 self.StartRBBox = array( event.GetPosition() )
                 self.PrevRBBox = None
                 self.CaptureMouse()

     def LeftUpEvent(self,event):
         if self.HasCapture():
             self.ReleaseMouse()
         if self.GUIMode:
             if self.GUIMode == "ZoomIn":
                 if event.LeftUp() and not self.StartRBBox is None:
                     self.PrevRBBox = None
                     EndRBBox = event.GetPosition()
                     StartRBBox = self.StartRBBox

                     # Do the zooming in

                     self.StartRBBox = None

     def MotionEvent(self,event):
         if self.GUIMode:
             if self.GUIMode == "ZoomIn":
                 if event.Dragging() and event.LeftIsDown() and not (self.StartRBBox is None):
                     # this is a little complicated, because I want to

                     # keep the RBbox with the same aspect ratio as the
                     # window.
                     xy0 = self.StartRBBox
                     xy1 = array( event.GetPosition() )
                     wh = abs(xy1 - xy0)
                     wh[0] = max(wh[0], int(wh[1]*self.AspectRatio))
                     wh[1] = int(wh[0] / self.AspectRatio)
                     xy_c = (xy0 + xy1) / 2
                     dc = wx.ClientDC(self)
                     dc.BeginDrawing()
                     dc.SetPen(wx.Pen('WHITE', 2, wx.SHORT_DASH))
                     dc.SetBrush(wx.TRANSPARENT_BRUSH)
                     dc.SetLogicalFunction(wx.XOR)
                     if self.PrevRBBox:
                         dc.DrawRectanglePointSize(*self.PrevRBBox)
                     self.PrevRBBox = ( xy_c - wh/2, wh )
                     dc.DrawRectanglePointSize( *self.PrevRBBox )
                     dc.EndDrawing()