Skip to content

Commit

Permalink
NF: self-screenshot: first commit
Browse files Browse the repository at this point in the history
idea: might be useful for Builder tests; users might want it too, one request on the list

status: builder.BuilderFrame.getSelfie() can get and save a png image of the BuilderFrame
needs work:
- compensate for toolbar (?) height on Mac, linux
- set the image name + path
- ability to trigger (bind to a camera icon on toolbar?)
  • Loading branch information
jeremygray committed Aug 12, 2014
1 parent 9a66db6 commit d3562a4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions psychopy/app/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4593,6 +4593,25 @@ def generateScript(self, experimentPath):
return None
return script

def getSelfie(self, event=None):
"""Returns a bitmap snapshot of self, as it appears in the UI at this moment.
"""
# http://wxpython-users.1045709.n5.nabble.com/Screen-capture-via-wxPython-td2348994.html
offset = 0
htReduction = 0 # see link for ideas on how to set this
dc = wx.ClientDC(self)
rect = self.GetRect()
bmp = wx.EmptyBitmap(rect.width, rect.height - htReduction)
memdc = wx.MemoryDC()
memdc.SelectObject(bmp)

memdc.Blit(0, 0, rect.width, rect.height, dc, 0, offset)
memdc.SelectObject(wx.NullBitmap)

img = bmp.ConvertToImage()
fileName = "BuilderFrame_selfie.png"
img.SaveFile(fileName, wx.BITMAP_TYPE_PNG)


class ReadmeFrame(wx.Frame):
def __init__(self, parent):
Expand Down

0 comments on commit d3562a4

Please sign in to comment.