Hi Chris,

I did it but i still do not understand how the Mailing List does function. 
Do I only need to send the E-Mail to the following Adress and  it knows from 
the About Line to which Thread it is?
Mailing List for the wxPython Float Canvas. <[email protected]>

Since i once again didn't know what to do with the mailing list can you 
please sent it there and delete the 2nd Thread i opened for this issue. 
Thanks again for the good work and I hope you continue that way.

best regards
Christian

Here is the answer for my problem:

I Edited the NavCanvas Class and the GUIMouse in that way if i define a 
callback function as the 2nd Parameter a Rubberband will come up and the BB 
will be sent back to the calling event.
dxf2gcode_wx28.py line 687

        NC = NavCanvas.NavCanvas(self,self.MultiSelect,
                                     Debug = 0,
                                     BackgroundColor = "WHITE")

If None is given as the 2nd Argument nothing happens,

        NC = NavCanvas.NavCanvas(self,None,
                                     Debug = 0,
                                     BackgroundColor = "WHITE")

Please find attached the whole changes on Both Classes which are located in 
modified file dxf2gcode_b02_FloatCanvas_mod.py:
"""
A Panel that includes the FloatCanvas and Navigation controls

"""

import wx
import numpy as N
from wx.lib.floatcanvas import FloatCanvas, Resources, GUIMode
#import FloatCanvas, Resources, GUIMode

class NavCanvas(wx.Panel):
    """
    NavCanvas.py

    This is a high level window that encloses the FloatCanvas in a panel
    and adds a Navigation toolbar.

    """

    def __init__(self,
                   parent,
                   callback,
                   id = wx.ID_ANY,
                   size = wx.DefaultSize,
                   **kwargs): # The rest just get passed into FloatCanvas
        wx.Panel.__init__(self, parent, id, size=size)

        self.Modes = [("Pointer",  GUIMouseNew(None,callback), 
Resources.getPointerBitmap()),
                      ("Zoom In",  GUIMode.GUIZoomIn(), 
Resources.getMagPlusBitmap()),
                      ("Zoom Out", GUIMode.GUIZoomOut(), 
Resources.getMagMinusBitmap()),
                      ("Pan",      GUIMode.GUIMove(), 
Resources.getHandBitmap()),
                      ]

        self.BuildToolbar()
        ## Create the vertical sizer for the toolbar and Panel
        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.ToolBar, 0, wx.ALL | wx.ALIGN_LEFT | wx.GROW, 4)

        self.Canvas = FloatCanvas.FloatCanvas(self, **kwargs)
        box.Add(self.Canvas, 1, wx.GROW)

        self.SetSizerAndFit(box)

        # default to first mode
        #self.ToolBar.ToggleTool(self.PointerTool.GetId(), True)
        self.Canvas.SetMode(self.Modes[0][1])

        return None

    def BuildToolbar(self):
        """
        This is here so it can be over-ridden in a ssubclass, to add extra 
tools, etc
        """
        tb = wx.ToolBar(self)
        self.ToolBar = tb
        tb.SetToolBitmapSize((24,24))
        self.AddToolbarModeButtons(tb, self.Modes)
        self.AddToolbarZoomButton(tb)
        tb.Realize()
        ## fixme: remove this when the bug is fixed!
        #wx.CallAfter(self.HideShowHack) # this required on wxPython 2.8.3 
on OS-X

    def AddToolbarModeButtons(self, tb, Modes):
        self.ModesDict = {}
        for Mode in Modes:
            tool = tb.AddRadioTool(wx.ID_ANY, shortHelp=Mode[0], 
bitmap=Mode[2])
            self.Bind(wx.EVT_TOOL, self.SetMode, tool)
            self.ModesDict[tool.GetId()]=Mode[1]
        #self.ZoomOutTool = tb.AddRadioTool(wx.ID_ANY, 
bitmap=Resources.getMagMinusBitmap(), shortHelp = "Zoom Out")
        #self.Bind(wx.EVT_TOOL, lambda evt : 
self.SetMode(Mode=self.GUIZoomOut), self.ZoomOutTool)

    def AddToolbarZoomButton(self, tb):
        tb.AddSeparator()

        self.ZoomButton = wx.Button(tb, label="Zoom To Fit")
        tb.AddControl(self.ZoomButton)
        self.ZoomButton.Bind(wx.EVT_BUTTON, self.ZoomToFit)


    def HideShowHack(self):
        #fixme: remove this when the bug is fixed!
        """
        Hack to hide and show button on toolbar to get around OS-X bug on
        wxPython2.8 on OS-X
        """
        self.ZoomButton.Hide()
        self.ZoomButton.Show()

    def SetMode(self, event):
        Mode = self.ModesDict[event.GetId()]
        self.Canvas.SetMode(Mode)

    def ZoomToFit(self,Event):
        self.Canvas.ZoomToBB()
        self.Canvas.SetFocus() # Otherwise the focus stays on the Button, 
and wheel events are lost.

#Klasse mit den Inhalten des Canvas & Verbindung zu den Konturen
class GUIMouseNew(GUIMode.GUIBase):
    """

    Mouse mode checks for a hit test, and if nothing is hit,
    raises a FloatCanvas mouse event for each event.

    """
    def __init__(self, canvas=None, Callback= None):
        GUIMode.GUIBase.__init__(self, canvas)
        self.Callback = Callback
        self.StartRBBox = None
        self.PrevRBBox = None
        self.Cursor = self.Cursors.MagPlusCursor
        self.Cursor = wx.NullCursor

    # Handlers
    def OnLeftDown(self, event):
        if not self.Callback is None:
            self.StartRBBox = N.array( event.GetPosition() )
            self.PrevRBBox = None
            self.Canvas.CaptureMouse()
        else:

            EventType = FloatCanvas.EVT_FC_LEFT_DOWN
            if not self.Canvas.HitTest(event, EventType):
                self.Canvas._RaiseMouseEvent(event, EventType)

    def OnLeftUp(self, event):
        if event.LeftUp() and not self.StartRBBox is None and not 
self.Callback is None:
            self.PrevRBBox = None
            EndRBBox = event.GetPosition()
            StartRBBox = self.StartRBBox
            # if mouse has moved less that ten pixels, don't use the box.
            if ( abs(StartRBBox[0] - EndRBBox[0]) > 10
                    and abs(StartRBBox[1] - EndRBBox[1]) > 10 ):
                EndRBBox = self.Canvas.PixelToWorld(EndRBBox)
                StartRBBox = self.Canvas.PixelToWorld(StartRBBox)
                BB = N.array(((min(EndRBBox[0],StartRBBox[0]),
                                min(EndRBBox[1],StartRBBox[1])),
                            (max(EndRBBox[0],StartRBBox[0]),
                                max(EndRBBox[1],StartRBBox[1]))),N.float_)
                self.Callback(BB)
            else:
                EventType = FloatCanvas.EVT_FC_LEFT_UP
                #print 'habs auch gekriegt'
                if not self.Canvas.HitTest(event, EventType):
                    self.Canvas._RaiseMouseEvent(event, EventType)
            self.StartRBBox = None
        if self.Callback is None:
                EventType = FloatCanvas.EVT_FC_LEFT_UP
                #print 'habs auch gekriegt'
                if not self.Canvas.HitTest(event, EventType):
                    self.Canvas._RaiseMouseEvent(event, EventType)



    def OnLeftDouble(self, event):
        EventType = FloatCanvas.EVT_FC_LEFT_DCLICK
        if not self.Canvas.HitTest(event, EventType):
                self.Canvas._RaiseMouseEvent(event, EventType)

    def OnMiddleDown(self, event):
        EventType = FloatCanvas.EVT_FC_MIDDLE_DOWN
        if not self.Canvas.HitTest(event, EventType):
            self.Canvas._RaiseMouseEvent(event, EventType)

    def OnMiddleUp(self, event):
        EventType = FloatCanvas.EVT_FC_MIDDLE_UP
        if not self.Canvas.HitTest(event, EventType):
            self.Canvas._RaiseMouseEvent(event, EventType)

    def OnMiddleDouble(self, event):
        EventType = FloatCanvas.EVT_FC_MIDDLE_DCLICK
        if not self.Canvas.HitTest(event, EventType):
            self.Canvas._RaiseMouseEvent(event, EventType)

    def OnRightDown(self, event):
        EventType = FloatCanvas.EVT_FC_RIGHT_DOWN
        if not self.Canvas.HitTest(event, EventType):
            self.Canvas._RaiseMouseEvent(event, EventType)

    def OnRightUp(self, event):
        EventType = FloatCanvas.EVT_FC_RIGHT_UP
        if not self.Canvas.HitTest(event, EventType):
            self.Canvas._RaiseMouseEvent(event, EventType)

    def OnRightDouble(self, event):
        EventType = FloatCanvas.EVT_FC_RIGHT_DCLICK
        if not self.Canvas.HitTest(event, EventType):
            self.Canvas._RaiseMouseEvent(event, EventType)

    def OnWheel(self, event):
        EventType = FloatCanvas.EVT_FC_MOUSEWHEEL
        self.Canvas._RaiseMouseEvent(event, EventType)

    def OnMove(self, event):
        # Always raise the Move event.
        self.Canvas.MouseOverTest(event)
        self.Canvas._RaiseMouseEvent(event,FloatCanvas.EVT_FC_MOTION)
        if event.Dragging() and event.LeftIsDown() and not (self.StartRBBox 
is None):
            xy0 = self.StartRBBox
            xy1 = N.array( event.GetPosition() )
            wh  = xy1 - xy0

            dc = wx.ClientDC(self.Canvas)
            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 = ( xy0, wh )
            dc.DrawRectanglePointSize( *self.PrevRBBox )
            dc.EndDrawing()

    def UpdateScreen(self):
        """
        Update gets called if the screen has been repainted in the middle of 
a zoom in
        so the Rubber Band Box can get updated
        """
        if self.PrevRBBox is not None:
            dc = wx.ClientDC(self.Canvas)
            dc.SetPen(wx.Pen('WHITE', 2, wx.SHORT_DASH))
            dc.SetBrush(wx.TRANSPARENT_BRUSH)
            dc.SetLogicalFunction(wx.XOR)
            dc.DrawRectanglePointSize(*self.PrevRBBox)



----- Original Message ----- 
From: "Christopher Barker" <[email protected]>
To: "Christian Kohlöffel" <[email protected]>; "Mailing List 
for the wxPython Float Canvas." <[email protected]>
Sent: Wednesday, February 04, 2009 10:52 PM
Subject: Re: [fc] Question for Floatcanvas Mailing List


Christian Kohlöffel wrote:
>> A possibility -- if LeftUp is caught in your code, and you don't call
>> event.Skip(), then RubberBAndBox may never get it, so it will keep
>> "Drawing" set to True, and keep drawing the box as you move.
>
> But the event.Skip() should be done in the Floatcanvas code because the
> first event which is evaluated  is the hit of the Line with the
> Floatcanvas function and Bind in line 1325:
> shape.geo_hdl.Bind(FloatCanvas.EVT_FC_LEFT_UP, self.ShapeGotHit)
>
> this event doesnt seem to be skipped.

Ah! good point -- In general, the Hit testing of objects has been used
by itself -- not in concert with other GUI actions.

 > I also could use a different Event
> like Middle Mouse or Double Click or similar but thats not what i want.

Nor should you.

> Is there a possibility to change the order of the events so that the
> first event will be the Rubberbandbox

The way to do this is to change the GUI modes. They are defined in
floatcanvas/GUIMode.py

You can derive from  GUIMouse, and add the add the Skip(), or, what I
might do, add the Rubber Band Box code in there -- that code could be in
a GUIMode mixin, that could be added to a GUIMode class when required.

However, it may be best that event.Skip() be added to all the methods of
the stock GUIMouse Mode. I'm a bit nervous about this, as it hasn't been
that way, and who knows what might break?

Please give it a try, and let us know how it works out!

> If you want i can also send my questions to the mailinglist  if you
> would prefer that.

Please do, I like to get it in the archives, and other folks may have ideas.

>> yes, you are right -- it assumes that you have the floatcanvas package
>> on your sys.path -- I wonder what the "right" way to do that relative
>> import is?

I've figured that out. In Utilities/GUI.py:

from .. import FloatCanvas


This will work on 2.5 and above, I think. The only issue is that it
WON'T work if you try to import GUI.py from the interpreter when inside
the floatcanvas package -- why the heck not, I don't know, but it makes
it hard to test code that uses relative imports -- oh well.

-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


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

Reply via email to