diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2019-12-02 12:26:17 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2019-12-02 12:27:04 +0300 |
commit | a1bae2663e95a8ebe851453b254c980402d2dad0 (patch) | |
tree | c5897b94edfce28b2be503f86baa311d01741647 /io_import_palette/__init__.py | |
parent | 6d5d8e187d913bbe4a477b063678c36eb50f1ce7 (diff) |
Palettes: Import ASE and Krita/Gimp palettes
Differential revision: https://developer.blender.org/D6247
Diffstat (limited to 'io_import_palette/__init__.py')
-rw-r--r-- | io_import_palette/__init__.py | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/io_import_palette/__init__.py b/io_import_palette/__init__.py new file mode 100644 index 00000000..431179ca --- /dev/null +++ b/io_import_palette/__init__.py @@ -0,0 +1,131 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +# <pep8-80 compliant> + +bl_info = { + "name": "Import Palettes", + "author": "Antonio Vazquez", + "version": (1, 0, 0), + "blender": (2, 81, 6), + "location": "File > Import", + "description": "Import Palettes", + "warning": "", + "category": "Import-Export"} + +import sys +import os + +# ---------------------------------------------- +# Add to Phyton path (once only) +# ---------------------------------------------- +path = sys.path +flag = False +for item in path: + if "io_import_palette" in item: + flag = True +if flag is False: + sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'io_import_palette')) + +# ---------------------------------------------- +# Import modules +# ---------------------------------------------- +if "bpy" in locals(): + import imp + + imp.reload(import_ase) + imp.reload(import_krita) +else: + import import_ase + import import_krita + +import bpy +from bpy.props import ( + StringProperty, +) +from bpy_extras.io_utils import ( + ImportHelper, + path_reference_mode, +) + + +class ImportASE(bpy.types.Operator, ImportHelper): + """Load a Palette File""" + bl_idname = "import_ase.read" + bl_label = "Import ASE" + bl_options = {'PRESET', 'UNDO'} + + filename_ext = ".ase" + filter_glob: StringProperty( + default="*.ase", + options={'HIDDEN'}, + ) + + def execute(self, context): + return import_ase.load(context, self.properties.filepath) + + def draw(self, context): + pass + + +class importKPL(bpy.types.Operator, ImportHelper): + """Load a File""" + bl_idname = "import_krita.read" + bl_label = "Import Palette" + bl_options = {'PRESET', 'UNDO'} + + filename_ext = ".kpl" + filter_glob: StringProperty( + default="*.kpl;*gpl", + options={'HIDDEN'}, + ) + + def execute(self, context): + return import_krita.load(context, self.properties.filepath) + + def draw(self, context): + pass + + +def menu_func_import(self, context): + self.layout.operator(importKPL.bl_idname, text="KPL Palette (.kpl)") + self.layout.operator(ImportASE.bl_idname, text="ASE Palette (.ase)") + + +classes = ( + ImportASE, + importKPL, +) + + +def register(): + for cls in classes: + bpy.utils.register_class(cls) + + bpy.types.TOPBAR_MT_file_import.append(menu_func_import) + + +def unregister(): + bpy.types.TOPBAR_MT_file_import.remove(menu_func_import) + + for cls in classes: + bpy.utils.unregister_class(cls) + + +if __name__ == "__main__": + register() |