xvfb、xephyr和xvnc的python包装器

PyVirtualDispla的Python项目详细描述


pyvirtualdisplay是用于XvfbXephyrXvnc

链接:

TravisCoverallsLatest VersionSupported Python versionsLicenseCode HealthDocumentation

功能:
  • python包装器
  • 支持的Python版本:2.7、3.5、3.6、3.7
  • 后端:XvfbXephyrXvnc
已知问题:
  • 仅支持少数后端选项
可能的应用:
  • 图形用户界面测试
  • 自动图形用户界面屏幕截图

基本用法

启动xephyr:

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

用xvfb创建xmessage的屏幕截图:

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()

安装

一般

  • install Xvfb or Xephyr or Xvnc.

  • install pip

  • optional: pyscreenshot and PIL should be installed for ^{tt1}$ submodule

  • install the program:

    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

卸载

pip uninstall pyvirtualdisplay

用法

图形用户界面测试

在低分辨率上测试gnumeric

#-- 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()
#-#

图像:

_img/lowres.png

截图

在后台创建xmessage的屏幕截图:

#-- 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()
#-#

图像:

_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

有些程序需要一个功能性的xauthority文件。pyvirtualdisplay罐 生成一个并设置适当的环境变量 use_xauth=TrueDisplay构造函数。不过,请注意 功能需要安装xauth,否则 pyvirtualdisplay.xauth.NotFoundError已筹集。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
加密如何在Java中使用Skipjack(skip32)将数据库中的顺序整数随机化   java Android在两个活动之间传递数据获取NullPointerException   在构造函数中传递的java上下文显示错误   java将密钥添加到选定的密钥集   javascript为什么带有特殊字符的字符串在GET和POST方法中的行为不同?   java将反射。方法创建一个函数接口   设置Javasocket的端口   java通过一次按键调用MenuItem   java和引擎加载图形:为什么我的背景纹理很小,而且是颠倒的   如何将UV纹理从blender加载到opengl 安卓 java   跨Java虚拟机实现的jvm Java toString表示?   spring在Java服务器页面的上下文中这叫什么?