Initial release of Python XRandR

November 27, 2007 - 2 minute read -
floss ubuntu python xrandr displayconfiggtk

Python-xrandr is a high level API for the RandR extension of the X.org server. RandR allows you to switch resolution, refresgh rate and output settings on the fly without having to hack the xorg.conf file or to restart your x server.

This is the intial release of python-xrandr. It supports some basic functions, e.g. setting your refresh rate, size and rotation (RandR 1.1) and enabling, disabling and postioning of outputs (RandR 1.2). Python-xrandr comes with the command line tool pyxrandr. The tool is basically a rewrite of the original xrandr tool and a reference implementation of the bindings. See the man page or use the option –help for supported options. If you start pyxrandr without any options it will show you detailed information of your screens.

The video shows a demonstration of the following two commands:

pyxrandr --output VGA --preferred --right-of LVDS
pyxrandr --output VGA --off

You can download a package for Ubuntu ‘Gutsy’ 7.10 here or add the following repository URL in System > Administration > Software Sources: deb http://ppa.launchpad.net/displayconfig-gtk/ubuntu gutsy main

The source code is hosted in a bzr branch at Launchpad: ~displayconfig-gtk/python-xrandr/main.

Finally an example code which enables the DVI output:

from xrandr import xrandr

screen = xrandr.get_current_screen()
output = screen.get_output_by_name("DVI")
output.set_to_preferred_mode()
screen.apply_output_config()

Feel free to report bugs in our bug tracker or to send an email for comments and suggestions. In the future python-xrandr will be used as an additional backend in displayconfig-gtk.

Update I just release a small bug fix release 0.1.1 that solves a crash if no -dev packages have been installed and shrinks the screen after disabling an ouput