diff options
| -rw-r--r-- | lib/extensions/palette_to_text.py | 4 | ||||
| -rw-r--r-- | lib/threads/catalog.py | 3 | ||||
| -rw-r--r-- | lib/threads/palette.py | 5 |
3 files changed, 11 insertions, 1 deletions
diff --git a/lib/extensions/palette_to_text.py b/lib/extensions/palette_to_text.py index 0944c649..db0c50cf 100644 --- a/lib/extensions/palette_to_text.py +++ b/lib/extensions/palette_to_text.py @@ -27,6 +27,10 @@ class PaletteToText(InkstitchExtension): return thread_palette = ThreadPalette(palette_file) + if not thread_palette.is_gimp_palette: + inkex.errormsg(_("Cannot read palette: invalid GIMP palette header")) + return + current_layer = self.svg.get_current_layer() x = 0 diff --git a/lib/threads/catalog.py b/lib/threads/catalog.py index c12ca1fe..68dc2009 100644 --- a/lib/threads/catalog.py +++ b/lib/threads/catalog.py @@ -42,6 +42,9 @@ class _ThreadCatalog(Sequence): for palette_file in glob(os.path.join(path, 'InkStitch*.gpl')): palette_basename = os.path.basename(palette_file) if palette_basename not in palettes: + palette = ThreadPalette(palette_file) + if not palette.is_gimp_palette: + continue self.palettes.append(ThreadPalette(palette_file)) palettes.append(palette_basename) diff --git a/lib/threads/palette.py b/lib/threads/palette.py index 7a6bf153..e0e3a0ab 100644 --- a/lib/threads/palette.py +++ b/lib/threads/palette.py @@ -40,8 +40,11 @@ class ThreadPalette(Set): with open(palette_file, encoding='utf8') as palette: line = palette.readline().strip() + + self.is_gimp_palette = True if line.lower() != "gimp palette": - raise ValueError("Invalid gimp palette header") + self.is_gimp_palette = False + return self.name = palette.readline().strip() if self.name.lower().startswith('name: ink/stitch: '): |
