Question about the Event binding

Hi, All:
     here is a sample code, where the wx.EVT_ENETER_WINDOWS, and
wx.EVT_LEAVE_WINDOWS doesn't work. It should be very easy to solve but
i just can't find it. And why does that happen?
     Thanks!

Sorry , forget to attached the code.

import wx

class DropMenuPanel(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        self.SetMinSize(wx.Size(100, 30))
        self.SetMaxSize(wx.Size(100, 30))
# self.SetBackgroundColour("white")

        self.Bind(wx.EVT_ENTER_WINDOW, self.enterwindow)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.leavewindow)
        self.Bind(wx.EVT_PAINT, self.OnPaint)

    def enterwindow(self, event):
        self.SetBackgroundColour("white")

    def leavewindow(self, event):
        self.SetBackgroundColour("black")

    def OnPaint(self, event):
        pdc = wx.PaintDC(self)
        try:
            dc = wx.GCDC(pdc)
        except:
            dc = pdc
        dc.Clear()
        w, h = self.GetTextExtent("Notes by ")
        dc.DrawText("Notes by ", 10, (30 - h)/2 )

class ThumbnailTextFilterBar(wx.Panel):

    def __init__(self, parent):
        wx.Panel.__init__(self, parent)
        bgcolor = wx.Colour(234, 238, 241, 255)
        self.SetBackgroundColour(bgcolor)

        FilterMenu = DropMenuPanel(self)
        Barsizer = wx.BoxSizer(wx.HORIZONTAL)
        Barsizer.Add(FilterMenu)

        searchctl = wx.SearchCtrl(self)
        Barsizer.Add(searchctl, -1, wx.ALL, 5)
        self.SetSizer(Barsizer)
        self.Layout()

        self.Bind(wx.EVT_PAINT, self.OnPaint)

    def OnPaint(self, event):
        pdc = wx.PaintDC(self)
        try:
            dc = wx.GCDC(pdc)
        except:
            dc = pdc
        dc.Clear()
        # Draw Saperate line
        dc.SetPen(wx.Pen((194, 201, 207), 1))
        #dc.SetPen(wx.Pen((255,255,255), 1))
        dc.DrawLine(0, 30, 700, 30)

app = wx.PySimpleApp()
frame = wx.Frame(None)
p = ThumbnailTextFilterBar(frame)
frame.Show()
app.MainLoop()

···

On Jan 17, 10:31 pm, zhengqing <zhengqing...@gmail.com> wrote:

Hi, All:
here is a sample code, where the wx.EVT_ENETER_WINDOWS, and
wx.EVT_LEAVE_WINDOWS doesn't work. It should be very easy to solve but
i just can't find it. And why does that happen?
Thanks!

Hello,

if you add self.Refresh() to your event handlers, as below

def enterwindow\(self, event\):
    self\.SetBackgroundColour\(&quot;white&quot;\)

          self.Refresh()

def leavewindow\(self, event\):
    self\.SetBackgroundColour\(&quot;black&quot;\)

          self.Refresh()

this changes the background of DropMenuPanel when the mouse moves into
and out of the window. I hope that is the behaviour you were looking
for?

If not the OP, it was kind of what I was looking for.

···

On Tue, Jan 18, 2011 at 8:12 AM, mdutia <m.b.dutia@ed.ac.uk> wrote:

Hello,

if you add self.Refresh() to your event handlers, as below

def enterwindow\(self, event\):
    self\.SetBackgroundColour\(&quot;white&quot;\)
     self\.Refresh\(\)
def leavewindow\(self, event\):
    self\.SetBackgroundColour\(&quot;black&quot;\)
     self\.Refresh\(\)

this changes the background of DropMenuPanel when the mouse moves into
and out of the window. I hope that is the behaviour you were looking
for?

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--
It sure does get lonely up under this bridge.

Hi,
   Thanks for the answer.
   But why here needs the Refresh() function.
   I thought the SetBackgroundcolour() function could change the color
immediately.

···

On Jan 18, 8:39 am, David Hutto <smokefl...@gmail.com> wrote:

On Tue, Jan 18, 2011 at 8:12 AM, mdutia <m.b.du...@ed.ac.uk> wrote:
> Hello,

> if you add self.Refresh() to your event handlers, as below

>> def enterwindow(self, event):
>> self.SetBackgroundColour("white")
> self.Refresh()

>> def leavewindow(self, event):
>> self.SetBackgroundColour("black")
> self.Refresh()

> this changes the background of DropMenuPanel when the mouse moves into
> and out of the window. I hope that is the behaviour you were looking
> for?

> --
> To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
> or visithttp://groups.google.com/group/wxPython-users?hl=en

If not the OP, it was kind of what I was looking for.

--
It sure does get lonely up under this bridge.

zhengqing wrote:

Hi,
   Thanks for the answer.
   But why here needs the Refresh() function.
   I thought the SetBackgroundcolour() function could change the color
immediately.

It changes the "registered" background color. That is, it changes a
data structure where the window remembers which background color to
use. The background color won't actually be used until the background
needs to be repainted, and that won't happen unless you ask for it.

This is a Good Thing. If you change the background color, the
foreground color, and the font, you wouldn't want the window to
immediately repaint itself three times. That's wasteful.

···

--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

It does change the color, but it does not tell the widget to repaint itself. That is what the Refresh is for.

···

On 1/18/11 9:20 AM, zhengqing wrote:

Hi,
    Thanks for the answer.
    But why here needs the Refresh() function.
    I thought the SetBackgroundcolour() function could change the color
immediately.

--
Robin Dunn
Software Craftsman