def detail_xml(self): ''' to create a detailed xml based on a single palette, creating an analysis of each color ''' if 'palettes' in self._data: return None output = _xml_signature output += _xml_detailed_style output += _xml_header.format( name=self.name(), url=self.url() ) # First the palette itself: output += _xml_palette_header.format( name=self.name(), url=self.url() ) output += Color.xml( None, self.get() ) output += _xml_palette_trailer # Then for each color for i in range(self.count()): col = Color( self.get(i) ) output += _xml_swatches_header.format( id = col.hexs() ) output += col.xml('circle') output += col.xml('complement') output += col.xml('split') output += col.xml('triad') output += col.xml('tetrad') output += col.xml('blend') output += col.xml('tint', 10, 5) output += col.xml('shade', 10, 5) output += col.xml('saturate', 10, 5) output += col.xml('desaturate', 10, 5) output += _xml_swatches_trailer output += _xml_trailer return output
def xml(self): ''' to create an xml file with each palette shown ''' output = _xml_signature output += _xml_simple_style output += _xml_header.format( name=self.name(), url=self.url() ) if 'colors' in self._data: output += _xml_palette_header.format( name=self.name(), url=self.url() ) output += Color.xml( None, self.get() ) output += _xml_palette_trailer elif 'palettes' in self._data: for i in range(self.count()): tmp = self.get(i) output += _xml_palette_header.format( name=tmp.name(), url=tmp.url() ) output += Color.xml( None, tmp.get() ) output += _xml_palette_trailer output += _xml_trailer return output
def _main(argv): sourcefile = None palettenum = None color = None operation = None value = None times = None detailed = False # if no arguments given, print help if len(argv) == 0: _help(2) try: # parse the parameters opts, args = getopt.getopt(argv, "hs:n:c:o:v:t:d") except getopt.GetoptError as e: print(e) _help(2) for opt, val in opts: if opt == "-h": _help() elif opt in "-s": sourcefile = val elif opt == "-n": palettenum = int(val) elif opt == "-c": color = val elif opt == "-o": operation = val elif opt == "-v": # tetrad is the only one that accept a character as value if operation is not None and operation == "tetrad": value = val elif '.' in val: value = float(val) else: value = int(val) elif opt == "-t": times = int(val) elif opt == "-d": detailed = True # if source file is indicated if sourcefile is not None and sourcefile != "": # get and parse the data data = swatches() data.parse( sourcefile ) output = None # if palette num given and is positive number if palettenum is not None and palettenum >= 0: # create detail view for the palette if detailed: output = data.get(palettenum).detail_xml() # create simple view for the palette else: output = data.get(palettenum).xml() else: output = data.xml() print(output[:-1]) # if a single color was given elif color is not None: c = Color(color) output = None # in the case of a detail, create each transformation as a palette in # a simple view if detailed: output = _xml_signature output += _xml_simple_style output += _xml_header_nourl.format(name='Combinations of ' + c.hexs()) output += c.xml('circle', detailed=True) output += c.xml('complement', detailed=True) output += c.xml('split', detailed=True) output += c.xml('triad', detailed=True) output += c.xml('tetrad', detailed=True) output += c.xml('blend', detailed=True) output += c.xml('tint', 10, 5, detailed=True) output += c.xml('shade', 10, 5, detailed=True) output += c.xml('saturate', 10, 5, detailed=True) output += c.xml('desaturate', 10, 5, detailed=True) output += _xml_trailer # if an operation was given elif operation is not None: if value is not None and times is not None: output = c.xml(operation, value, times) elif value is not None: output = c.xml(operation, value) elif times is not None: output = c.xml(operation, times=times) else: output = c.xml(operation) else: output = c.xml() print(output[:-1]) else: _help(1) sys.exit(0)