Skip to content

Commit

Permalink
NF: Builder self-screenshot: initial commit
Browse files Browse the repository at this point in the history
motivation: might be useful for automating some Builder tests, fun for users (?)

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 40de3d4 commit 224c165
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions psychopy/app/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4593,6 +4593,27 @@ def generateScript(self, experimentPath):
return None
return script

def getSelfie(self, event=None):
"""Returns path to 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)

return os.path.abspath(fileName)


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

0 comments on commit 224c165

Please sign in to comment.