preferences.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import bpy
  2. import os
  3. dir_path = os.path.dirname(os.path.realpath(__file__))
  4. #
  5. def get_bl_addon_object(raise_error = False):
  6. from bpy import context
  7. try_these_first = ['bl_ext.repos.mantis', 'bl_ext.blender_modules_enabled.mantis']
  8. for mantis_key in try_these_first:
  9. bl_mantis_addon = context.preferences.addons.get(mantis_key)
  10. if bl_mantis_addon: break
  11. if bl_mantis_addon is None:
  12. if raise_error==True:
  13. raise RuntimeError("Mantis Preferences not found. This is a bug."
  14. " Please report it on gitlab.")
  15. if raise_error==False:
  16. print( "Mantis Preferences not found. This is a bug."
  17. " Please report it on gitlab.")
  18. return bl_mantis_addon
  19. class MantisPreferences(bpy.types.AddonPreferences):
  20. bl_idname = __package__
  21. # JSONprefix: bpy.props.StringProperty(
  22. # name = "Prefix code file",
  23. # subtype = 'FILE_PATH',
  24. # default = dir_path + '/preferences/prefix.json',)
  25. # JSONchiral: bpy.props.StringProperty(
  26. # name = "Chiral Identifier file",
  27. # subtype = 'FILE_PATH',
  28. # default = dir_path + '/preferences/chiral_identifier.json',)
  29. # JSONseperator:bpy.props.StringProperty(
  30. # name = "Seperator file",
  31. # subtype = 'FILE_PATH',
  32. # default = dir_path + '/preferences/seperator.json',)
  33. WidgetsLibraryFolder:bpy.props.StringProperty(
  34. name = "Widget Library Folder",
  35. subtype = 'FILE_PATH',
  36. default = os.path.join(dir_path, 'widgets'),)
  37. def draw(self, context):
  38. layout = self.layout
  39. layout.label(text="Mantis Preferences")
  40. layout.prop(self, "WidgetsLibraryFolder", icon='FILE_FOLDER')