--- a/colours.py Fri Sep 18 21:57:36 2020 +0300 +++ b/colours.py Fri Sep 18 23:51:45 2020 +0300 @@ -15,33 +15,10 @@ else: return str(self.index) def __repr__(self): - try: - return 'colours.' + colours_inverse_dict[self.index] - except KeyError: - return str.format('Colour({!r})', self.index) + return str.format('Colour({!r})', self.index) @property def is_direct_colour(self): return self.index >= 0x2000000 - @property - def is_ldconfig_colour(self): - return self.index in ldconfig_colour_data - @property - def name(self): - if self.is_ldconfig_colour: - return ldconfig_colour_data[self.index]['name'] - else: - return str(self) - @property - def face_colour(self): - if self.is_ldconfig_colour: - return ldconfig_colour_data[self.index]['value'] - elif self.is_direct_colour: - return '#%06X' % (self.index & 0xffffff) - else: - return '#000000' - @property - def is_valid(self): - return self.is_ldconfig_colour or self.is_direct_colour def __eq__(self, other): return self.index == other.index def __lt__(self, other): @@ -98,27 +75,16 @@ colour = parse_ldconfig_ldr_line(line) yield (colour['code'], colour) -class colours: - ''' - LDConfig colour namespace, exists for interactive mode and for - Colour.__repr__ to return something pretty. - ''' - pass - -# LDConfig lookup tables -colours_inverse_dict = {} -ldconfig_colour_data = {} def load_colours(ldconfig_ldr): ''' Loads colours. Expects a file pointer to LDConfig.ldr as the parameter. + Returns a lookup table ''' - global ldconfig_colour_data ldconfig_colour_data = dict(parse_ldconfig_ldr(ldconfig_ldr)) for index, colour in ldconfig_colour_data.items(): identifier = colour['name'].replace(' ', '_').lower() - setattr(colours, identifier, Colour(index)) - colours_inverse_dict[index] = identifier + return ldconfig_colour_data # Interactive mode support (pass LDConfig.ldr path as a command-line argument) if __name__ == '__main__':