Subprocess management: use a decorator
Use a decorator instead of a mixin to handle subprocess spawning and monitoring
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# This file is for code dealing specifically with blender
|
||||
|
||||
import logging
|
||||
import bpy
|
||||
from bpy.props import CollectionProperty
|
||||
from bpy.types import PropertyGroup, Panel, UIList, AddonPreferences, Operator
|
||||
from .subprocess_adapter import SubprocessOperatorMixin
|
||||
from .subprocess_adapter import subprocess_operator
|
||||
from . import bpackage as bpkg
|
||||
|
||||
class RepositoryProperty(PropertyGroup):
|
||||
url = bpy.props.StringProperty(name="URL")
|
||||
# status = bpy.props.EnumProperty(name="Status")
|
||||
|
||||
|
||||
class PACKAGE_UL_repositories(UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||
@@ -32,23 +36,37 @@ class PackagePreferences(AddonPreferences):
|
||||
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"
|
||||
row = layout.row()
|
||||
row.operator("package.refresh")
|
||||
|
||||
|
||||
@subprocess_operator
|
||||
class PACKAGE_OT_refresh(Operator):
|
||||
bl_idname = "package.refresh"
|
||||
bl_label = "Update package list(s)"
|
||||
|
||||
last_response = None
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
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 invoke(self, context, event):
|
||||
prefs = context.user_preferences.addons[__package__].preferences
|
||||
if 'repositories' not in prefs:
|
||||
return {'FINISHED'}
|
||||
# HACK: just do the active repo for now
|
||||
repo = bpkg.Repository(prefs['repositories'][prefs.active_repository].to_dict())
|
||||
self.proc_args = []
|
||||
self.proc_kwargs = {'target': repo.refresh}
|
||||
|
||||
def execute(self, context, event):
|
||||
pass
|
||||
|
||||
def modal(self, context, event):
|
||||
# try:
|
||||
self.poll_subprocess()
|
||||
# except:
|
||||
|
||||
def handle_response(self, resp):
|
||||
self.__class__.last_response = resp
|
||||
self.report({'INFO'}, "Request returned %s" % self.__class__.last_response)
|
||||
self.report({'INFO'}, "Request returned %s" % resp)
|
||||
|
||||
def execute(self, context):
|
||||
return {'FINISHED'}
|
||||
|
||||
class PACKAGE_OT_add_repository(bpy.types.Operator):
|
||||
bl_idname = "package.add_repository"
|
||||
@@ -73,7 +91,7 @@ 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_refresh)
|
||||
|
||||
bpy.utils.register_class(PACKAGE_OT_add_repository)
|
||||
bpy.utils.register_class(PACKAGE_OT_remove_repository)
|
||||
@@ -83,7 +101,7 @@ 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_refresh)
|
||||
|
||||
bpy.utils.unregister_class(PACKAGE_OT_add_repository)
|
||||
bpy.utils.unregister_class(PACKAGE_OT_remove_repository)
|
||||
|
Reference in New Issue
Block a user