Module rgb2py
[hide private]
[frames] | no frames]

Source Code for Module rgb2py

 1  import re 
 2   
 3  f = open("/etc/X11/rgb.txt") 
 4   
 5  print "colors = {" 
 6  for l in f.readlines(): 
 7    if l.startswith("!"): continue 
 8    c = re.split("[ \t]+", l.strip()) 
 9    rgb, names = map(int, c[:3]), c[3:] 
10    rgb = [float(c) / 255.0 for c in rgb] 
11    for n in names: 
12      print '  %-24s: (%.2f, %.2f, %.2f),' % ('"%s"' % n.lower(), rgb[0], rgb[1], rgb[2]) 
13  print "}" 
14