PyVirtualDisplay¶
About¶
pyvirtualdisplay is a python wrapper for Xvfb, Xephyr and Xvnc
- Links:
- Features:
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¶
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__":
# start Xephyr
Display(visible=1, size=(320, 240)).start()
# start Gnumeric
EasyProcess('gnumeric').start()
#-#
Image:

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:

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.
Hierarchy¶
![digraph G {
rankdir=LR;
node [fontsize=8,style=filled, fillcolor=white];
fontsize=8;
subgraph cluster_0 {
label = "pyvirtualdisplay";
style=filled;
subgraph cluster_2 {
style=filled;
fillcolor=white;
label = "wrappers";
XvfbDisplay;
XephyrDisplay;
XvncDisplay;
}
Display -> XvfbDisplay;
Display -> XephyrDisplay;
Display -> XvncDisplay;
SmartDisplay -> Display
}
XvfbDisplay -> Xvfb;
XephyrDisplay -> Xephyr;
XvncDisplay -> Xvnc;
application -> Display;
application -> SmartDisplay;
SmartDisplay -> pyscreenshot;
SmartDisplay -> PIL;
}](_images/graphviz-2a7f292edd482e66bab8c5fd75c0a824f4688f8e.png)
API¶
-
class
pyvirtualdisplay.
Display
(backend=None, visible=False, size=(1024, 768), color_depth=24, bgcolor='black', use_xauth=False, **kwargs)¶ Common class
Parameters: - color_depth – [8, 16, 24, 32]
- size – screen size (width,height)
- bgcolor – background color [‘black’ or ‘white’]
- visible – True -> Xephyr, False -> Xvfb
- backend – ‘xvfb’, ‘xvnc’ or ‘xephyr’, ignores
visible
- xauth – If a Xauthority file should be created.
-
start
()¶ start display
Return type: self
-
stop
()¶ stop display
Return type: self