1

I'm looking for a way to essentially screen capture a whole wxPanel, and save it as a PNG. The kicker is, there is no screen. I need to be able to "draw" the panel and save the drawn panel with no actual screen. I'm using Python 2.7, running on Ubuntu 12.04.

Is this possible?

Zobal
  • 143
  • 2
  • 11

3 Answers3

1

If there is no screen at all, i.e. no X11 display, then you wouldn't be able to even start a graphical wxWidgets program, so I'm not sure how exactly would you like this to work.

If you can start the program, then you can also use wxClientDC to capture the contents of any window: use its Blit() method to copy its contents to a wxMemoryDC into which you'd select the bitmap which will end up with the image of your window.

VZ.
  • 21,740
  • 3
  • 39
  • 42
  • I'm trying it with a screen just to get the image capture working. Here's what I have in the __init__ of a panel: `sizer = wx.BoxSizer(wx.VERTICAL)` `text = wx.StaticText(self, -1, "Heeeeeeerrreeeeee's a Panel!")` `sizer.Add(text, 1, wx.EXPAND | wx.ALL, 10)` `self.SetSizer(sizer)` `bitMap = wx.EmptyBitmap(500,500)` `memDCwx.MemoryDC(bitMap)` `clientDC = wx.ClientDC(self)` `clientDC.Blit(0,0,500,500,memDC,0,0)` `bitMap.SaveFile(fileName, wx.BITMAP_TYPE_PNG)` My image ends up as a 500 X 500 black box. – Zobal Jul 10 '13 at 17:23
1

I wrote a tutorial on how to do this sort of thing here:

However, as someone already pointed out, if X (or similar) is unavailable, then you won't be able to generate a GUI of any sort. Or perhaps you meant a headless box (i.e. no monitor) rather than no screen?

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • It's running on UBUNTU 12.04, with GRUB_CMDLINE_LINUX_DEFAULT set to "text", which I assume means X is not running. We've been successfully doing similar things with floatCanvas, which is based on wx, so I have hopes that this will work. Thanks for the link, it's exactly what I've been looking for! – Zobal Jul 10 '13 at 17:53
  • @VZ. You guys are right. This is not possible without X running. The way floatCanvas does it is to draw each pixel to the memoryDC and then blit it to the clientDC after the drawing is done. That way it doesn't matter if there is a screen or not. The wxApp does run though, and Frames and Panels are created despite the lack of X running. Interesting. Thanks for taking the time to help. – Zobal Jul 10 '13 at 21:34
0

I found the trick, and lo, its name is VFB: http://linux.die.net/man/1/xvfb

Zobal
  • 143
  • 2
  • 11