Commit a0b150e1 authored by Martin Owens's avatar Martin Owens 🤖

Make colors hashable and add color listing extension

parent 6656321b
Pipeline #141838923 failed with stages
in 3 minutes and 49 seconds
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<name>List All</name>
<id>org.inkscape.color.list</id>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu name="Color"/>
</effects-menu>
</effect>
<script>
<command location="inx" interpreter="python">color_list.py</command>
</script>
</inkscape-extension>
#!/usr/bin/env python
"""List all colors used in an svg document"""
from collections import defaultdict
import inkex
class ColorList(inkex.ColorExtension):
"""Make the colours darker"""
Please register or sign in to reply
_counts = defaultdict(int)
def effect(self):
super(ColorList, self).effect()
items = sorted(self._counts.items(), key=lambda v: -v[1])
for color, count in items:
self.msg("{count}: {color}".format(color=color, count=count))
def modify_color(self, name, color):
self._counts[color] += 1
return color
if __name__ == '__main__':
ColorList().run()
......@@ -247,6 +247,10 @@ class Color(list):
except ValueError:
raise ColorError("Bad color list")
def __hash__(self):
"""Allow colors to be hashable"""
return tuple(self.to_rgba()).__hash__()
def _set(self, index, value, spaces=('rgb', 'rgba')):
"""Set the color value in place, limits setter to specific color space"""
# Named colors are just rgb, so dump name memory
......
5: #75507b
5: red
5: #729fcf
5: #3465a4
4: #cc0000
3: #5c3566
3: blue
3: #000000
2: #2e3436
3: #75507b
3: red
3: #729fcf
3: #3465a4
2: #5c3566
2: blue
2: #cc0000
1: #2e3436
1: #000000
1: #5c3566
1: #75507b
1: red
1: #729fcf
1: #3465a4
1: blue
2: red
1: #5c3566
1: #75507b
1: #729fcf
1: #3465a4
1: blue
1: #2e3436
1: #cc0000
2: #75507b
2: red
2: #729fcf
2: #3465a4
2: #cc0000
1: #5c3566
1: blue
1: #2e3436
1: #000000
# coding=utf-8
from color_list import ColorList
from .test_inkex_extensions import ColorEffectTest
class ColorListTest(ColorEffectTest):
effect_class = ColorList
effect_name = 'test_color_list'
stderr_output = True
color_tests = []
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment