VirtualBox

Changeset 24450 in vbox


Ignore:
Timestamp:
Nov 6, 2009 3:33:38 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
54515
Message:

Python: shell command to save guest screenshot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxShell/vboxshell.py

    r23994 r24450  
    334334    vbox.unregisterCallback(cb)
    335335
     336
     337def takeScreenshot(ctx,console,args):
     338    from PIL import Image
     339    display = console.display
     340    if len(args) > 0:
     341        f = args[0]
     342    else:
     343        f = "/tmp/screenshot.png"
     344    if len(args) > 1:
     345        w = args[1]
     346    else:
     347        w = console.display.width
     348    if len(args) > 2:
     349        h = args[2]
     350    else:
     351        h = console.display.height
     352    print "Saving screenshot (%d x %d) in %s..." %(w,h,f)
     353    data = display.takeScreenShotSlow(w,h)
     354    size = (w,h)
     355    mode = "RGBA"   
     356    im = Image.frombuffer(mode, size, data, "raw", mode, 0, 1)
     357    im.save(f, "PNG")
     358
     359
    336360def cmdExistingVm(ctx,mach,cmd,args):
    337361    mgr=ctx['mgr']
     
    362386         'guest':           lambda: guestExec(ctx, mach, console, args),
    363387         'monitorGuest':    lambda: monitorGuest(ctx, mach, console, args),
    364          'save':            lambda: progressBar(ctx,console.saveState())
     388         'save':            lambda: progressBar(ctx,console.saveState()),
     389         'screenshot':      lambda: takeScreenshot(ctx,console,args)
    365390         }
    366391    try:
     
    614639        return 0
    615640    cmdExistingVm(ctx, mach, 'guest', ' '.join(args[2:]))
     641    return 0
     642
     643def screenshotCmd(ctx, args):
     644    if (len(args) < 3):
     645        print "usage: screenshot name file <width> <height>"
     646        return 0
     647    mach = argsToMach(ctx,args)
     648    if mach == None:
     649        return 0
     650    cmdExistingVm(ctx, mach, 'screenshot', args[2:])
    616651    return 0
    617652
     
    9711006            'sleep':['Sleep for specified number of seconds: sleep 3.14159', sleepCmd, 0],
    9721007            'shell':['Execute external shell command: shell "ls /etc/rc*"', shellCmd, 0],
    973             'exportVm':['Export VM in OVF format: export Win /tmp/win.ovf', exportVMCmd, 0]
     1008            'exportVm':['Export VM in OVF format: export Win /tmp/win.ovf', exportVMCmd, 0],
     1009            'screenshot':['Take VM screenshot to a file: screenshot Win /tmp/win.png 1024 768', screenshotCmd, 0]
    9741010            }
    9751011
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette