Hello,

A small question : sometimes I want to get the (x,y) hitcoords when
clicking on an 309x34 pixels image, and I would like x to be an integer in
[0, 308], but when self.canvas.ZoomToBB() has been used, sometimes the
(x,y) coordinates are a bit "off" of some pixels.

For example, when using     x = event.HitCoords[0] -
event.BoundingBox[0,0],  the range I get for x is [-1.2598, 302.24277]   =>
how to get [0,308] instead ?

Is there a parameter somewhere for HitCoords accuracy ? (high, medium,
etc.)

Best regards, Jo
____

import wx
from wx.lib.floatcanvas import FloatCanvas

class TestFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.canvas =FloatCanvas.FloatCanvas(self, BackgroundColor = "DARK
SLATE BLUE")
        MainSizer = wx.BoxSizer(wx.VERTICAL)
        MainSizer.Add(self.canvas, 4, wx.EXPAND)
        self.SetSizer(MainSizer)
        img = wx.Image('mypng(309x34).png')
        A = self.canvas.AddScaledBitmap(img, (0,0), Height=img.GetHeight(),
Position = 'tl')
        A.Bind(FloatCanvas.EVT_FC_MOTION, self.OnMotion)
        wx.CallAfter(self.canvas.ZoomToBB)

    def OnMotion(self, event):
        x, y = event.HitCoords[0] - event.BoundingBox[0,0],
event.BoundingBox[1,1] - event.HitCoords[1]
        print x, y     # the max range I can get for x is [-1.2598,
302.24277]   => how to get [0,308] instead ?

app = wx.App(0)
frame = TestFrame(None, title="Image hitcoords", size=(300,200))
frame.Show(True)
app.MainLoop()

<<attachment: mypng(309x34).png>>

import wx
from wx.lib.floatcanvas import FloatCanvas

class TestFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.canvas =FloatCanvas.FloatCanvas(self, BackgroundColor = "DARK SLATE BLUE")
        MainSizer = wx.BoxSizer(wx.VERTICAL)
        MainSizer.Add(self.canvas, 4, wx.EXPAND)
        self.SetSizer(MainSizer)
        img = wx.Image('mypng(309x34).png')   
        A = self.canvas.AddScaledBitmap(img, (0,0), Height=img.GetHeight(), Position = 'tl')
        A.Bind(FloatCanvas.EVT_FC_MOTION, self.OnMotion)
        wx.CallAfter(self.canvas.ZoomToBB)
                        
    def OnMotion(self, event):
        x, y = event.HitCoords[0] - event.BoundingBox[0,0], event.BoundingBox[1,1] - event.HitCoords[1]
        print x, y     # the max range I can get for x is [-1.2598, 302.24277]   => how to get [0,308] instead ?

app = wx.App(0)
frame = TestFrame(None, title="Image hitcoords", size=(300,200))
frame.Show(True)
app.MainLoop()

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

Reply via email to