Skip to content
Snippets Groups Projects
ui.py 85.8 KiB
Newer Older
  • Learn to ignore specific revisions
  •             return {'RUNNING_MODAL'}
            else:
                self.report({'WARNING'}, "View3D not found, cannot run operator")
                return {'CANCELLED'}
    
    
    
    class RunAssetBarWithContext(bpy.types.Operator):
        """Regenerate cobweb"""
        bl_idname = "object.run_assetbar_fix_context"
        bl_label = "BlnenderKit assetbar with fixed context"
        bl_description = "Run assetbar with fixed context"
    
        bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}
    
    
        # def modal(self, context, event):
        #     return {'RUNNING_MODAL'}
    
    
            C_dict = utils.get_fake_context(context)
    
            if C_dict.get('window'):  # no 3d view, no asset bar.
    
                preferences = bpy.context.preferences.addons['blenderkit'].preferences
                if preferences.experimental_features:
    
                    bpy.ops.view3d.blenderkit_asset_bar_widget(C_dict, 'INVOKE_REGION_WIN', keep_running=True,
                                                               do_search=False)
    
    
                else:
                    bpy.ops.view3d.blenderkit_asset_bar(C_dict, 'INVOKE_REGION_WIN', keep_running=True, do_search=False)
    
            return {'FINISHED'}
    
    Vilém Duha's avatar
    Vilém Duha committed
    
    
    Vilem Duha's avatar
    Vilem Duha committed
        AssetBarOperator,
    
        AssetDragOperator,
    
        TransferBlenderkitData,
    
        UndoWithContext,
        ParticlesDropDialog
    
    # store keymap items here to access after registration
    addon_keymapitems = []
    
    def pre_load(context):
        ui_props = bpy.context.scene.blenderkitUI
        ui_props.assetbar_on = False
        ui_props.turn_off = True
        preferences = bpy.context.preferences.addons['blenderkit'].preferences
        preferences.login_attempt = False
    
    
    
    Vilem Duha's avatar
    Vilem Duha committed
    def register_ui():
    
    Vilem Duha's avatar
    Vilem Duha committed
            bpy.utils.register_class(c)
    
        args = (None, bpy.context)
    
    
        handler_2d = bpy.types.SpaceView3D.draw_handler_add(draw_callback_2d_progress, args, 'WINDOW', 'POST_PIXEL')
        handler_3d = bpy.types.SpaceView3D.draw_handler_add(draw_callback_3d_progress, args, 'WINDOW', 'POST_VIEW')
    
    Vilem Duha's avatar
    Vilem Duha committed
    
        wm = bpy.context.window_manager
    
        # spaces solved by registering shortcut to Window. Couldn't register object mode before somehow.
        if not wm.keyconfigs.addon:
            return
        km = wm.keyconfigs.addon.keymaps.new(name="Window", space_type='EMPTY')
    
    Vilém Duha's avatar
    Vilém Duha committed
        # asset bar shortcut
    
    Vilem Duha's avatar
    Vilem Duha committed
        kmi = km.keymap_items.new(AssetBarOperator.bl_idname, 'SEMI_COLON', 'PRESS', ctrl=False, shift=False)
        kmi.properties.keep_running = False
        kmi.properties.do_search = False
    
    Vilém Duha's avatar
    Vilém Duha committed
        # fast rating shortcut
    
        wm = bpy.context.window_manager
        km = wm.keyconfigs.addon.keymaps['Window']
        kmi = km.keymap_items.new(ratings.FastRateMenu.bl_idname, 'F', 'PRESS', ctrl=False, shift=False)
    
        addon_keymapitems.append(kmi)
    
        kmi = km.keymap_items.new(upload.FastMetadata.bl_idname, 'F', 'PRESS', ctrl=True, shift=False)
    
    Vilem Duha's avatar
    Vilem Duha committed
    
    
    def unregister_ui():
    
        global handler_2d, handler_3d
    
        pre_load(bpy.context)
    
        bpy.types.SpaceView3D.draw_handler_remove(handler_2d, 'WINDOW')
        bpy.types.SpaceView3D.draw_handler_remove(handler_3d, 'WINDOW')
    
    
    Vilem Duha's avatar
    Vilem Duha committed
            bpy.utils.unregister_class(c)
    
        wm = bpy.context.window_manager
        if not wm.keyconfigs.addon:
            return
    
    
        km = wm.keyconfigs.addon.keymaps.get('Window')
        if km:
            for kmi in addon_keymapitems:
                km.keymap_items.remove(kmi)