colours.py

changeset 147
bec55b021ae7
parent 146
3555679d276b
parent 145
fde18c4d6784
equal deleted inserted replaced
146:3555679d276b 147:bec55b021ae7
17 def __repr__(self): 17 def __repr__(self):
18 return str.format('Colour({!r})', self.index) 18 return str.format('Colour({!r})', self.index)
19 @property 19 @property
20 def is_direct_colour(self): 20 def is_direct_colour(self):
21 return self.index >= 0x2000000 21 return self.index >= 0x2000000
22 @property
23 def is_ldconfig_colour(self):
24 return self.index in ldconfig_colour_data
25 @property
26 def name(self):
27 if self.is_ldconfig_colour:
28 return ldconfig_colour_data[self.index]['name']
29 else:
30 return str(self)
31 @property
32 def face_colour(self):
33 if self.is_ldconfig_colour:
34 return ldconfig_colour_data[self.index]['value']
35 elif self.is_direct_colour:
36 return '#%06X' % (self.index & 0xffffff)
37 else:
38 return '#000000'
39 @property
40 def is_valid(self):
41 return self.is_ldconfig_colour or self.is_direct_colour
42 def __eq__(self, other): 22 def __eq__(self, other):
43 return self.index == other.index 23 return self.index == other.index
44 def __lt__(self, other): 24 def __lt__(self, other):
45 return self.index < other.index 25 return self.index < other.index
46 def __le__(self, other): 26 def __le__(self, other):
93 line = line.strip() 73 line = line.strip()
94 if line.startswith('0 !COLOUR'): 74 if line.startswith('0 !COLOUR'):
95 colour = parse_ldconfig_ldr_line(line) 75 colour = parse_ldconfig_ldr_line(line)
96 yield (colour['code'], colour) 76 yield (colour['code'], colour)
97 77
98 # LDConfig lookup table
99 ldconfig_colour_data = {}
100
101 def load_colours(ldconfig_ldr): 78 def load_colours(ldconfig_ldr):
102 ''' 79 '''
103 Loads colours. Expects a file pointer to LDConfig.ldr as the parameter. 80 Loads colours. Expects a file pointer to LDConfig.ldr as the parameter.
81 Returns a lookup table
104 ''' 82 '''
105 global ldconfig_colour_data 83 return dict(parse_ldconfig_ldr(ldconfig_ldr))
106 ldconfig_colour_data = dict(parse_ldconfig_ldr(ldconfig_ldr))

mercurial