Skip to content

Commit

Permalink
Merge pull request #11 from opsaaaaa/master
Browse files Browse the repository at this point in the history
Renamed Unsorted to Selection/Z-index and added sort by x or y location options
  • Loading branch information
olibia authored May 26, 2021
2 parents 0cba98f + 522a2e7 commit cbb15ef
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
4 changes: 3 additions & 1 deletion generate_palette.inx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
<param name="default" type="bool" gui-text="Include default grays">false</param>
<param name="replace" type="bool" gui-text="Replace existing palette">false</param>
<param name="sort" type="optiongroup" appearance="combo" gui-text="Sort colors">
<option value="unsorted">Unsorted</option>
<option value="selection">Selection / Z-index</option>
<option value="hsl">By HSL values</option>
<option value="rgb">By RGB values</option>
<option value="x_location">X Location</option>
<option value="y_location">Y Location</option>
</param>

<spacer />
Expand Down
32 changes: 28 additions & 4 deletions generate_palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,25 @@ def get_node_prop(self, node, property):

return style.get(property, 'none')

def get_node_index(self, args):
node = args[1]


def get_node_index(self, item):
node = item[1]
id = node.attrib.get('id')

return self.options.ids.index(id)

def get_node_x(self, item):
node = item[1]
return node.bounding_box().center_x

def get_node_y(self, item):
node = item[1]
return node.bounding_box().center_y




def get_formatted_color(self, color):
rgb = inkex.Color(color).to_rgb()

Expand All @@ -119,11 +132,20 @@ def get_formatted_color(self, color):

return "%s %s %s" % (key, rgb, name)



def get_selected_colors(self):
colors = []
selected = list(self.svg.selected.items())

selected.sort(key=self.get_node_index)
if self.options.sort == 'y_location':
selected.sort(key=self.get_node_x)
selected.sort(key=self.get_node_y)
elif self.options.sort == 'x_location':
selected.sort(key=self.get_node_y)
selected.sort(key=self.get_node_x)
else:
selected.sort(key=self.get_node_index)

for id, node in selected:
if self.options.property in ['fill', 'both']:
Expand All @@ -142,11 +164,13 @@ def get_selected_colors(self):

colors = list(map(self.get_formatted_color, colors))

if self.options.sort != 'unsorted':
if self.options.sort == 'hsl' or self.options.sort == 'rgb':
colors.sort()

return list(map(lambda x : x[11:], colors))



def write_palette(self):
file = open(self.file_path, 'w')

Expand Down

0 comments on commit cbb15ef

Please sign in to comment.