开发者

get a widgets dc in wxpython

im looking for a way to get a widget such as a panels device context if that is the right word. i want to get the bitmap of the panel with all its ch开发者_高级运维ild widgets so i can manipulate it in a paint dc for fade in fade out animations of panels. is this possible and if so whats the code? i was hoping for something like this.. wx.Panel.GetDCMap() which will return a bitmap of what is going to be painted to the screen so i can fade it. also this will need to grab the bitmap of what a widget will look like even if its hidden. else i could just use widget.GetScreenRect() then blit it to a buffer.. thanks


Nice question! I didn't think it would work, but I tried this and it did:

def window_to_bitmap(window):
    width, height = window.GetSize()
    bitmap = wx.EmptyBitmap(width, height)
    wdc = wx.WindowDC(window)
    mdc = wx.MemoryDC(bitmap)
    mdc.Blit(0, 0, width, height, wdc, 0, 0)
    return bitmap

Doesn't work if the window is hidden.

Moving the window far off screen sort of works, the client area is shown but the window decorations are not shown.

Calling SetTransparent(0) first has a similar effect as moving the window off screen.

Above tests done on 64-bit Windows 7.

If you only need the client area, you could do one of the above methods and tweak the function to create a bitmap with the client area only, like so:

def window_to_bitmap(window):
    width, height = window.GetClientSize()
    bitmap = wx.EmptyBitmap(width, height)
    wdc = wx.ClientDC(window)
    mdc = wx.MemoryDC(bitmap)
    mdc.Blit(0, 0, width, height, wdc, 0, 0)
    return bitmap
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜