Remove bl_options from menus which caused tests to fail
[blender-addons.git] / io_import_BrushSet.py
blobbd58fb37ff74c5e6e594b2251b9e5cad86835a27
1 # SPDX-FileCopyrightText: 2020-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 import bpy
6 import os
7 from bpy.props import (
8 StringProperty,
11 bl_info = {
12 "name": "Import BrushSet",
13 "author": "Daniel Grauer (kromar), CansecoGPC",
14 "version": (1, 3, 0),
15 "blender": (2, 80, 0),
16 "location": "File > Import > BrushSet",
17 "description": "Imports all image files from a folder.",
18 "warning": '', # used for warning icon and text in addons panel
19 "doc_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/Import-Export/BrushSet",
20 "tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
21 "category": "Import-Export",
24 fakeUser = False
27 def load_brush_set(dirpath):
28 extensions = tuple(bpy.path.extensions_image)
29 for file in os.listdir(dirpath):
30 if not file.lower().endswith(extensions):
31 continue
33 # Load the image into data.
34 path = os.path.join(dirpath, file)
35 try:
36 image = bpy.data.images.load(path)
37 except BaseException as ex:
38 print("Failed to load %r, error: %r" % (file, ex))
39 continue
41 image.use_fake_user = fakeUser
43 # Create new texture.
44 # NOTE: use the image name instead of `file` in case
45 # it's encoding isn't `utf-8` compatible.
46 texture = bpy.data.textures.new(image.name, 'IMAGE')
47 texture.use_fake_user = fakeUser
49 # Assign the image to the texture.
50 texture.image = image
52 print("imported:", repr(file))
54 print("Brush Set imported!")
56 # -----------------------------------------------------------------------------
59 class BrushSetImporter(bpy.types.Operator):
60 '''Load Brush Set'''
61 bl_idname = "import_image.brushset"
62 bl_label = "Import BrushSet"
64 directory: StringProperty(
65 name="Directory",
66 description="Directory",
67 maxlen=1024,
68 subtype='DIR_PATH',
71 def execute(self, context):
72 load_brush_set(self.directory)
73 return {'FINISHED'}
75 def invoke(self, context, event):
76 wm = context.window_manager
77 wm.fileselect_add(self)
78 return {'RUNNING_MODAL'}
80 # -----------------------------------------------------------------------------
83 def menu_func(self, context):
84 self.layout.operator(BrushSetImporter.bl_idname, text="Brush Set")
87 # -----------------------------------------------------------------------------
88 # GUI
90 '''
91 class Brush_set_UI(bpy.types.Panel):
93 bl_space_type ='USER_PREFERENCES'
94 bl_label = 'Brush_Path'
95 bl_region_type = 'WINDOW'
96 bl_options = {'HIDE_HEADER'}
98 def draw(self, context):
100 scn = context.scene
101 layout = self.layout
102 column = layout.column(align=True)
103 column.label(text='Brush Directory:')
104 column.prop(scn,'filepath')
107 # -----------------------------------------------------------------------------
109 classes = (
110 BrushSetImporter,
114 def register():
115 from bpy.utils import register_class
116 for cls in classes:
117 register_class(cls)
118 bpy.types.TOPBAR_MT_file_import.append(menu_func)
121 def unregister():
122 from bpy.utils import unregister_class
123 for cls in reversed(classes):
124 unregister_class(cls)
125 bpy.types.TOPBAR_MT_file_import.remove(menu_func)
128 if __name__ == "__main__":
129 register()