On Thu, Aug 19, 2010 at 12:46 AM, Matt Wilkie <[email protected]> wrote:

>   import sys
>   from PyQt4.QtGui import QPixmap, QApplication
>   app = QApplication(sys.argv)
>   QPixmap.grabWindow(QApplication.desktop().winId()).save('test.png', 'png')

Some changes are required when running as a Leo script:

import PyQt4.QtGui
import os

pix = PyQt4.QtGui.QPixmap
app = g.app.gui.qtApp
path = g.os_path_finalize_join(g.app.loadDir,'..','test.png')
pix.grabWindow(app.activeWindow().winId()).save(path, 'png')
g.es('created %s' % path)
os.system(path)

Notes:

1. We must use the running Qt app (g.app.gui.qtApp) when running as a
Leo script.  Otherwise Leo hangs.

2. The script takes a screenshot of the active window
(app.activeWindow()) rather than the entire screen.

3. The last line is optional: on Windows it opens the .png file in the
default viewer.

As a not unrelated to this script, It will probably be good to create
a script to resize the Leo window to a standard screenshot size.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en.

Reply via email to