Python wrapper for Xvfb, Xephyr and Xvnc
Python
Latest commit be778a9 Jan 5, 2017 ponty remove support for python 2.6
Permalink
Failed to load latest commit information.
_img
docs doc: remove generated files Feb 17, 2016
pyvirtualdisplay Merge branch 'master' of github.com:ponty/PyVirtualDisplay Jan 3, 2017
tests test_xauth: make sure the Xauthority is deleted Aug 16, 2016
.coveragerc
.gitattributes
.gitignore
.travis.yml remove support for python 2.6 Jan 5, 2017
LICENSE.txt start Feb 11, 2011
MANIFEST.in use versioneer for versioning Apr 8, 2014
README.rst
Vagrantfile remove support for python 2.6 Jan 5, 2017
pavement.py doc Feb 15, 2016
requirements-doc.txt doc Feb 15, 2016
requirements-test.txt doc Feb 15, 2016
requirements.txt remove entrypoint2 dependency Nov 22, 2012
setup.py remove support for python 2.6 Jan 5, 2017
tox.ini remove support for python 2.6 Jan 5, 2017

README.rst

pyvirtualdisplay is a python wrapper for Xvfb, Xephyr and Xvnc

Links:

Travis Coveralls Latest Version Supported Python versions License Downloads Code Health Documentation

Features:
  • python wrapper
  • supported python versions: 2.7, 3.3, 3.4, 3.5
  • back-ends: Xvfb, Xephyr, Xvnc

Warning

at least one back-end should be installed

Known problems:
  • only a few back-end options are supported
Possible applications:
  • GUI testing
  • automatic GUI screenshot

Basic usages

Start Xephyr:

from pyvirtualdisplay import Display
xephyr=Display(visible=1, size=(320, 240)).start()

Create screenshot of xmessage with Xvfb:

from easyprocess import EasyProcess
from pyvirtualdisplay.smartdisplay import SmartDisplay
with SmartDisplay(visible=0, bgcolor='black') as disp:
    with EasyProcess('xmessage hello'):
        img = disp.waitgrab()
img.show()

Installation

General

  • install Xvfb or Xephyr or Xvnc.

  • install pip

  • optional: pyscreenshot and PIL should be installed for smartdisplay submodule

  • install the program:

    # as root
    pip install pyvirtualdisplay
    

Ubuntu 14.04

sudo apt-get install python-pip
sudo apt-get install xvfb xserver-xephyr vnc4server
sudo pip install pyvirtualdisplay
# optional
sudo apt-get install python-pil scrot
sudo pip install pyscreenshot
# optional for examples
sudo pip install entrypoint2

Uninstall

# as root
pip uninstall pyvirtualdisplay

Usage

GUI Test

Testing gnumeric on low resolution:

#-- include('examples/lowres.py') --#
from easyprocess import EasyProcess
from pyvirtualdisplay import Display

if __name__ == "__main__":
    Display(visible=1, size=(320, 240)).start()
    EasyProcess('gnumeric').start()
#-#

Image:

_img/lowres.png

Screenshot

Create screenshot of xmessage in background:

#-- include('examples/screenshot3.py') --#
'''
using :keyword:`with` statement
'''
from easyprocess import EasyProcess
from pyvirtualdisplay.smartdisplay import SmartDisplay

if __name__ == "__main__":
    with SmartDisplay(visible=0, bgcolor='black') as disp:
        with EasyProcess('xmessage hello'):
            img = disp.waitgrab()


    img.show()
#-#

Image:

_img/screenshot3.png

vncserver

#-- include('examples/vncserver.py') --#
'''
Example for Xvnc backend
'''

from easyprocess import EasyProcess
from pyvirtualdisplay.display import Display

if __name__ == "__main__":
    with Display(backend='xvnc', rfbport=5904) as disp:
        with EasyProcess('xmessage hello') as proc:
            proc.wait()
#-#

xauth

Some programs require a functional Xauthority file. PyVirtualDisplay can generate one and set the appropriate environment variables if you pass use_xauth=True to the Display constructor. Note however that this feature needs xauth installed, otherwise a pyvirtualdisplay.xauth.NotFoundError is raised.