In [1]:
from screenlayout.xrandr import XRandR

In [2]:
xr = XRandR()

In [3]:
def todict(obj, classkey=None):
    if isinstance(obj, dict):
        data = {}
        for (k, v) in obj.items():
            data[k] = todict(v, classkey)
        return data
    elif hasattr(obj, "_ast"):
        return todict(obj._ast())
    elif hasattr(obj, "__iter__"):
        return [todict(v, classkey) for v in obj]
    elif hasattr(obj, "__dict__"):
        data = dict([(key, todict(value, classkey)) 
            for key, value in obj.__dict__.iteritems() 
            if not callable(value) and not key.startswith('_')])
        if classkey is not None and hasattr(obj, "__class__"):
            data[classkey] = obj.__class__.__name__
        return data
    else:
        return obj

In [4]:
with open("screenlayout/test/files/xrandr_verbose01.txt") as f:
    print(xr._parse_raw_lines(f.read()))


('Screen 0: minimum 8 x 8, current 2390 x 768, maximum 32767 x 32767', [{'headline': 'LVDS1 connected primary 1366x768+1024+0 (0x4a) normal (normal left inverted right x axis y axis) 280mm x 170mm', 'EDID': '00ffffffffffff004ca349410000000000150104901c11780a859599574f8f2621505400000001010101010101010101010101010101121b567250000c303020250024ae100000190c12567250000c303020250024ae1000001900000000000000000000000000000000000000000002000c42f20b3c6914111e6e00000000db', 'details': [[['1366x768', '(0x4a)', '69.300MHz', '-HSync', '-VSync', '*current', '+preferred'], ' 1366', ' 768'], [['1366x768', '(0x122)', '46.200MHz', '-HSync', '-VSync'], ' 1366', ' 768'], [['1024x768', '(0x123)', '65.000MHz', '-HSync', '-VSync'], ' 1024', ' 768'], [['1024x576', '(0x124)', '46.995MHz', '-HSync', '+VSync'], ' 1024', ' 576'], [['960x540', '(0x125)', '40.784MHz', '-HSync', '+VSync'], ' 960', ' 540'], [['800x600', '(0x126)', '40.000MHz', '+HSync', '+VSync'], ' 800', ' 600'], [['800x600', '(0x127)', '36.000MHz', '+HSync', '+VSync'], ' 800', ' 600'], [['864x486', '(0x128)', '32.901MHz', '-HSync', '+VSync'], ' 864', ' 486'], [['640x480', '(0x129)', '25.175MHz', '-HSync', '-VSync'], ' 640', ' 480'], [['720x405', '(0x12a)', '22.176MHz', '-HSync', '+VSync'], ' 720', ' 405'], [['680x384', '(0x12b)', '19.677MHz', '-HSync', '+VSync'], ' 680', ' 384'], [['640x360', '(0x12c)', '17.187MHz', '-HSync', '+VSync'], ' 640', ' 360']]}, {'headline': 'DP1 disconnected (normal left inverted right x axis y axis)', 'EDID': None, 'details': []}, {'headline': 'DP2 disconnected (normal left inverted right x axis y axis)', 'EDID': None, 'details': []}, {'headline': 'HDMI1 disconnected (normal left inverted right x axis y axis)', 'EDID': None, 'details': []}, {'headline': 'HDMI2 disconnected (normal left inverted right x axis y axis)', 'EDID': None, 'details': []}, {'headline': 'VGA1 connected 1024x768+0+0 (0x123) normal (normal left inverted right x axis y axis) 0mm x 0mm', 'EDID': None, 'details': [[['1024x768', '(0x123)', '65.000MHz', '-HSync', '-VSync', '*current'], ' 1024', ' 768'], [['800x600', '(0x126)', '40.000MHz', '+HSync', '+VSync'], ' 800', ' 600'], [['800x600', '(0x127)', '36.000MHz', '+HSync', '+VSync'], ' 800', ' 600'], [['848x480', '(0x131)', '33.750MHz', '+HSync', '+VSync'], ' 848', ' 480'], [['640x480', '(0x129)', '25.175MHz', '-HSync', '-VSync'], ' 640', ' 480']]}, {'headline': 'VIRTUAL1 disconnected (normal left inverted right x axis y axis)', 'EDID': None, 'details': []}, {'headline': '', 'EDID': None, 'details': []}])

In [6]:
xr = None

In [7]:
xr = XRandR()

In [8]:
xr.load_from_x()

In [9]:
todict(xr.state)


Out[9]:
{'outputs': {'DP1': {'connected': False,
   'modes': [],
   'name': 'DP1',
   'rotations': [{}, {}, {}, {}]},
  'DP2': {'connected': False,
   'modes': [],
   'name': 'DP2',
   'rotations': [{}, {}, {}, {}]},
  'HDMI1': {'connected': False,
   'modes': [],
   'name': 'HDMI1',
   'rotations': [{}, {}, {}, {}]},
  'HDMI2': {'connected': False,
   'modes': [],
   'name': 'HDMI2',
   'rotations': [{}, {}, {}, {}]},
  'LVDS1': {'EDID': '00ffffffffffff004ca349410000000000150104901c11780a859599574f8f2621505400000001010101010101010101010101010101121b567250000c303020250024ae100000190c12567250000c303020250024ae1000001900000000000000000000000000000000000000000002000c42f20b3c6914111e6e00000000db',
   'connected': True,
   'modes': [[1366, 768],
    [1024, 768],
    [1024, 576],
    [960, 540],
    [800, 600],
    [864, 486],
    [640, 480],
    [720, 405],
    [680, 384],
    [640, 360]],
   'name': 'LVDS1',
   'rotations': [{}, {}, {}, {}]},
  'VGA1': {'EDID': '00ffffffffffff001e6d854b28360000041301036a261e78ea3231a3574c9d25115054a56b80314f454f614f81800101010101010101302a009851002a4030701300782d1100001e000000fd00384b1e530e000a202020202020000000fc004c313934320a20202020202020000000fc202020202020202020202020202000ea',
   'connected': True,
   'modes': [[1280, 1024],
    [1152, 864],
    [1024, 768],
    [832, 624],
    [800, 600],
    [640, 480],
    [720, 400]],
   'name': 'VGA1',
   'rotations': [{}, {}, {}, {}]},
  'VIRTUAL1': {'connected': False,
   'modes': [],
   'name': 'VIRTUAL1',
   'rotations': [{}, {}, {}, {}]}},
 'virtual': {'max': [32767, 32767], 'min': [8, 8]}}

In [ ]:
todict(xr.configuration)

In [ ]:
xr.configuration.outputs

In [ ]:
vars(xr.configuration.outputs["LVDS1"])

In [ ]:
vars(xr.state)

In [ ]:
xr.state.outputs

In [ ]:
vars(xr.state.outputs['VGA1'])

In [ ]:
xr2 =