diff --git a/bpkg_manager/__init__.py b/bpkg_manager/__init__.py index fb589cb..12594ee 100644 --- a/bpkg_manager/__init__.py +++ b/bpkg_manager/__init__.py @@ -258,6 +258,7 @@ class BPKG_OT_refresh(SubprocMixin, bpy.types.Operator): subproc.SubprocError: self._subproc_error, subproc.DownloadError: self._subproc_download_error, subproc.Success: self._subproc_success, + subproc.Result: self._subproc_result, subproc.Aborted: self._subproc_aborted, } @@ -285,6 +286,12 @@ class BPKG_OT_refresh(SubprocMixin, bpy.types.Operator): self.report({'INFO'}, 'Package list retrieved successfully') self.quit() + def _subproc_result(self, result: subproc.Result): + prefs = bpy.context.user_preferences.addons[__package__].preferences + prefs['repo'] = result.data + self.report({'INFO'}, 'Package list retrieved successfully') + self.quit() + def _subproc_aborted(self, aborted: subproc.Aborted): self.report({'ERROR'}, 'Package list retrieval aborted per your request') self.quit() @@ -322,6 +329,40 @@ class BPKG_OT_hang(SubprocMixin, bpy.types.Operator): def report_process_died(self): self.report({'ERROR'}, 'Process died, exit code %s' % self.process.exitcode) +class USERPREF_PT_packages(bpy.types.Panel): + bl_label = "Package Management" + bl_space_type = 'USER_PREFERENCES' + bl_region_type = 'WINDOW' + bl_options = {'HIDE_HEADER'} + + log = logging.getLogger(__name__ + '.USERPREF_PT_packages') + + @classmethod + def poll(cls, context): + userpref = context.user_preferences + return (userpref.active_section == 'PACKAGES') + + def draw(self, context): + repo = context.user_preferences.addons[__package__].preferences['repo'] + layout = self.layout + + # top = layout.row() + # top.prop(context.window_manager, "addon_search", text="", icon='VIEWZOOM') + # top.prop( + + def draw_package(layout): + pass + + for pkg in repo['packages']: + row = layout.row() + + pkgbox = row.box() + left = pkgbox.split(.7) + row1 = left.row() + row2 = left.row() + row1.label(text=pkg['bl_info'].get('name', "MISSING NAME")) + row2.label(text=pkg['bl_info'].get('description', "MISSING DESCRIPTION")) + class PackageManagerPreferences(bpy.types.AddonPreferences): bl_idname = __package__ @@ -348,6 +389,7 @@ def register(): bpy.utils.register_class(BPKG_OT_install) bpy.utils.register_class(BPKG_OT_refresh) bpy.utils.register_class(BPKG_OT_hang) + bpy.utils.register_class(USERPREF_PT_packages) bpy.utils.register_class(PackageManagerPreferences) @@ -355,4 +397,5 @@ def unregister(): bpy.utils.unregister_class(BPKG_OT_install) bpy.utils.unregister_class(BPKG_OT_refresh) bpy.utils.unregister_class(BPKG_OT_hang) + bpy.utils.unregister_class(USERPREF_PT_packages) bpy.utils.unregister_class(PackageManagerPreferences) diff --git a/bpkg_manager/subproc.py b/bpkg_manager/subproc.py index c6d7793..f5147ef 100644 --- a/bpkg_manager/subproc.py +++ b/bpkg_manager/subproc.py @@ -66,6 +66,11 @@ class DownloadError(SubprocMessage): class Success(SubprocMessage): """Sent when an operation finished sucessfully.""" +class Result(SubprocMessage): + """Sent when an operation returns data to be used on the parent process.""" + + def __init__(self, data): + self.data = data class Aborted(SubprocMessage): """Sent as response to Abort message.""" @@ -492,7 +497,7 @@ def refresh(pipe_to_blender, storage_path: pathlib.Path, repository_url: str): pipe_to_blender.send(DownloadError(err.status_code, err.message)) repo.to_file(repo_path) # TODO: this always writes even if repo wasn't changed - pipe_to_blender.send(Success()) + pipe_to_blender.send(Result(repo.to_dict())) def debug_hang(): """Hangs for an hour. For testing purposes only."""