Member Avatar for rbyrd

The listing below draws a dot wherever the mouse is clicked on the panel, but it seems to work only if both lines

        self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        wx.EVT_LEFT_DOWN(self.panel, self.OnLeftDown)

are included. If one or the other is omitted the dot doesn't appear until the next mouse click (so the locations of the dots don't really correspond to the current mouse-click position). Furthermore, two identical values of the mouse coordinates, x, y, are generated in OnLeftDown. What I am doing wrong?

import wx

class Test(wx.Frame):
    def __init__(self,parent,title):
        noResize = wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX)
        super(Test,self).__init__(parent,style= noResize, title=title,size=(800,800))

        self.P = [ ]

        self.SetBackgroundColour((0,0,200))

        self.panel = wx.Panel(self)
        self.panel.SetBackgroundColour('#faf0e6')

        self.vbox = wx.BoxSizer(wx.VERTICAL)
        self.vbox.Add(self.panel,1, wx.EXPAND | wx.ALL, 5)
        self.SetSizer(self.vbox)

        self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
        wx.EVT_LEFT_DOWN(self.panel, self.OnLeftDown)

        self.Center()
        self.Show()

    def OnLeftDown(self, e):
        e.Skip()
        self.dc = wx.ClientDC(self.panel)
        self.dc.SetBrush(wx.Brush('BLUE', wx.SOLID))
        x, y = e.GetPosition()
        self.dc.DrawCircle(x,y,3)
        self.P.append( (x,y))


if __name__ == '__main__':

    app = wx.App()
    Test(None,title='TEST')
    app.MainLoop()

Interesting, I don't need line
wx.EVT_LEFT_DOWN(self.panel, self.OnLeftDown)

Could it be the version of wxPython?

I used installer
wxPython2.9-win32-2.9.1.1-py27.exe

Member Avatar for rbyrd

I'm using Mac osx 10.6.8, python 2.7.6 and wxPython2.9-osx-2.9.4.0-cocoa-py2.7.dmg installer. In this particular problem the dots do appear when either of the code lines in question is used alone, but then a given dot appears only upon the next mouse click (anywhere on the panel). The result is that the positions of the dots don't correspond to where the mouse is clicked. I can only achieve correspondence if I use both code lines. I don't know why this behavior should depend on the version of wxPython...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.