Howto catch clicks on transparent window?

Tim van der Leeuw wrote:

Hi,

I created a transparent window, and overlaid it over another window. I

see my transparent window in the taskbar, and I can see that it’s the

front-window. (I can also see that by the fact that the windows

underneath are slightly darker than usual, since I set the transparency

to 25).

However, I don’t seem to be able to catch any clicks in my transparent

window: they go right thru to the underlying window, and my

event-handlers for motion and left-down events don’t fire.

How to catch those clicks?

Platform, version and sample app please.

Platform: WinXP, SP2
Version: Python 2.5.2; wxPython: 2.8.7.1

Sample: Hmmm. Let me try to extract a sample.

This seems to work as an app, and exhibits (on my system) the same behaviour as in my app: clicks go thru the transparent window; the mouse-cursor is shaped as the cursor of the underlying window.

import wx

class AplOverlayWin(wx.Frame):
def init(self):
“”“Overlay the APL window, to capture clicks on it
and match those clicks on controls.”“”

    wx.Frame.__init__(self, None, -1, 'APL Capture', style=wx.TRANSPARENT_WINDOW)
    if not self.SetTransparent(25):
        print >> sys.stderr, 'Cannot set transparency for APL Overlay! :-('

        raise Exception("Cannot set transparency for APL overlay!")
   
    self.Bind(wx.EVT_LEFT_DOWN, self.on_click)
    self.Bind(wx.EVT_MOTION, self.on_motion)
    self.SetCursor(wx.StockCursor(wx.CURSOR_CROSS))

    return

def on_motion(self, event):
    print 'Motion: event pos:', event.GetPosition()
    return

def on_click(self, event):
    print 'OnClick (left-down)'

    pos = event.GetPosition()

if name == ‘main’:
app = wx.App()
app.RestoreStdio()
win = AplOverlayWin()
win.Show()

app.SetTopWindow(win)
app.MainLoop()           

(The transparent window is a bit darker than the rest of the screen; to see it better perhaps make it less transparent).

I hope that this is enough to tell me what I’m doing wrong?

(NB: I tried a different tactic, having a bitmap of the window I’m trying to overlay with my transparency. The bitmap works, but motion-events and leftdown-events on it don’t work. So I’ll have to try to figure out what I’m really doing wrong w/the event-handling. But with this transparent window, mouse-cursor and clicks really go thru. With the bitmap, at least they don’t go thru my window… So whatever I’m doing wrong in binding the events, at least it goes differently wrong here… sigh I’m afraid I don’t make sense anymore.)

Regards,

–Tim

···

On Mon, Mar 24, 2008 at 7:00 PM, Robin Dunn robin@alldunn.com wrote:

Robin Dunn

Software Craftsman

http://wxPython.org Java give you jitters? Relax with wxPython!


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users