Hi, Andrea.
rect = my_frame.GetScreenRect()
bitmap = TakeScreenShot(rect)
That hadn’t (past tense) been working for me, because I was calling it early in the process of painting the window (though, in my defense, after all the calls to create the widgets) and what I was getting was part of the screen that was not even in the window. If I call it as an event-driven call (like binding it to a button to take a snapshot of it), then it works fine.
In my poking about, I also found this short example of a similar mechanism*, though perhaps this has some drawbacks that I am not aware of or isn’t as cross-platform:
def window_to_bitmap(self,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
(*http://stackoverflow.com/questions/4773961/get-a-widgets-dc-in-wxpython)
Just for the fun of it, I have put together a small script showing
this screenshot/dragging stuff for a wx.TextCtrl inside a panel. The
script is very rough, and it could use some enhancements (i.e., use a
wx.ScrolledWindow instead of a wx.Panel as container, limit the bitmap
screenshot movement inside the panel area only and so on). It could
also be easily modified to show how to drag other widgets (i.e., a
wx.TreeCtrl, or a wx.Slider, almost anything).
Nice! Well, there it is then. Thanks, it’s fun to see in action! (wxpython 2.8.10.1, py2.5, winXP).
It works OK for me on Windows Vista, Python 2.7.2, wxPython 2.9.2.4
msw (classic).
So the million $ (or €) question: does it work well on Mac and Linux, folks?
Che