def PrintPixelArrayTable(pix_arr, color_map=None): print """ <style> body { font-family: Arial, sans-serif; } table.grid { border-collapse:collapse; font-size: 6px; font-weight: bold; } .grid td { border:solid 1px #888; } .grid .square { overflow: hidden; width: 6px; height: 6px; text-align: center; } .swatch { padding: 12px; display: inline-block; } </style> """ colors = set() width, height = pix_arr.size print '<table class="grid">' for y in xrange(height): print '<tr>' for x in xrange(width): style = '' color = pix_arr[x,y] if color: style += ' background-color: %s' % _GetCssRgbColor(color) print '<td style="%s">' % style if color and color_map: text_color = _GetTextColor(color) print '<div class="square" style="color: %s">' % _GetCssRgbColor(_GetTextColor(color)) print color_map.get(color) print '</div>' print '</td>' print '</td>' print '</table>'
def PrintColorTable(color_map): for color in _GetColorMapColorsSortedByName(color_map): key = color_map.get(color) print '<h3>Color %s</h3>' % key print '<p>' print str(color) _PrintSwatch(color) print '</p>' print '<h4>Closest colors:</h4>' closest_colors = dmc_colors.GetClosestDMCColorsPairs(color)[:5] print '<table border=1>' print '<tr>' print '<th>Distance</th><th>DMC #</th><th>Name</th><th>Color</th>' print '<tr>' for dmc_color, distance in closest_colors: print '<tr>' print '<td>%s</td>' % distance print '<td>%s</td>' % dmc_color.number print '<td>%s</td>' % dmc_color.name print '<td>' _PrintSwatch(dmc_color.color) print str(dmc_color.color) print '</td>' print '</tr>' print '</table>'
def _GetColorMapColorsSortedByName(color_map): return sorted(color_map, key=lambda c: color_map.get(c))