# -*- coding: utf-8 -*- # This file is for code dealing specifically with blender import bpy from bpy.props import CollectionProperty from bpy.types import PropertyGroup, Panel, UIList, AddonPreferences, Operator from .subprocess_adapter import SubprocessOperatorMixin class RepositoryProperty(PropertyGroup): url = bpy.props.StringProperty(name="URL") class PACKAGE_UL_repositories(UIList): def draw_item(self, context, layout, data, item, icon, active_data, active_propname): split = layout.split(0.3) split.prop(item, "name") split.prop(item, "url") def invoke(self, onctext, event): pass class PackagePreferences(AddonPreferences): bl_idname = __package__ repositories = CollectionProperty(type=RepositoryProperty) active_repository = bpy.props.IntProperty() def draw(self, context): layout = self.layout row = layout.row() row.template_list("PACKAGE_UL_repositories", "", self, "repositories", self, "active_repository") col = row.column(align=True) col.operator("package.add_repository", icon="ZOOMIN", text="") col.operator("package.remove_repository", icon="ZOOMOUT", text="") class PACKAGE_OT_fetch(SubprocessOperatorMixin, bpy.types.Operator): bl_idname = "package.fetch" bl_label = "Update package list(s)" last_response = None def __init__(self): super().__init__() settings = bpy.context.window_manager.package_manager_settings self.subprocess = Process(target=blenderpack.fetch, args=(settings.url, self.pipe)) def handle_response(self, resp): self.__class__.last_response = resp self.report({'INFO'}, "Request returned %s" % self.__class__.last_response) def execute(self, context): return {'FINISHED'} class PACKAGE_OT_add_repository(bpy.types.Operator): bl_idname = "package.add_repository" bl_label = "Add Repository" def execute(self, context): prefs = context.user_preferences.addons[__package__].preferences prefs.repositories.add() return {'FINISHED'} class PACKAGE_OT_remove_repository(bpy.types.Operator): bl_idname = "package.remove_repository" bl_label = "Remove Repository" def execute(self, context): prefs = context.user_preferences.addons[__package__].preferences prefs.repositories.remove(prefs.active_repository) return {'FINISHED'} def register(): bpy.utils.register_class(RepositoryProperty) bpy.utils.register_class(PackagePreferences) bpy.utils.register_class(PACKAGE_OT_fetch) bpy.utils.register_class(PACKAGE_OT_add_repository) bpy.utils.register_class(PACKAGE_OT_remove_repository) bpy.utils.register_class(PACKAGE_UL_repositories) def unregister(): bpy.utils.unregister_class(RepositoryProperty) bpy.utils.unregister_class(PackagePreferences) bpy.utils.unregister_class(PACKAGE_OT_fetch) bpy.utils.unregister_class(PACKAGE_OT_add_repository) bpy.utils.unregister_class(PACKAGE_OT_remove_repository) bpy.utils.unregister_class(PACKAGE_UL_repositories)