Skip to content
Snippets Groups Projects
ui_panels.py 40.2 KiB
Newer Older
  • Learn to ignore specific revisions
  • Vilem Duha's avatar
    Vilem Duha committed
                op.category = c['slug']
                # TODO enable subcategories, now not working due to some bug on server probably
                if len(c['children']) > 0 and c['assetCount'] > 15:
                    # row = row.split()
                    op = row.operator('view3d.blenderkit_set_category', text='>>')
                    op.asset_type = ui_props.asset_type
                    op.category = c['slug']
                    # for c1 in c['children']:
                    #     if c1['assetCount']>0:
                    #         row = col.row()
                    #         split = row.split(percentage=.2)
                    #         row = split.split()
                    #         row = split.split()
                    #         ctext = '%s (%i)' % (c1['name'], c1['assetCount'])
                    #         op = row.operator('view3d.blenderkit_search', text=ctext)
                    #         op.category = c1['slug']
    
    
    class VIEW3D_PT_blenderkit_downloads(Panel):
        bl_category = "BlenderKit"
        bl_idname = "VIEW3D_PT_blenderkit_downloads"
        bl_space_type = 'VIEW_3D'
        bl_region_type = 'UI'
        bl_label = "Downloads"
    
        @classmethod
        def poll(cls, context):
            return len(download.download_threads) > 0
    
        def draw(self, context):
            layout = self.layout
            for threaddata in download.download_threads:
                tcom = threaddata[2]
                asset_data = threaddata[1]
                row = layout.row()
                row.label(text=asset_data['name'])
                row.label(text=str(int(tcom.progress)) + ' %')
    
                row.operator('scene.blenderkit_download_kill', text='', icon='CANCEL')
    
                if tcom.passargs.get('retry_counter', 0) > 0:
    
                    row = layout.row()
    
                    row.label(text='failed. retrying ... ', icon='ERROR')
                    row.label(text=str(tcom.passargs["retry_counter"]))
    
    
                    layout.separator()
    
    def header_search_draw(self, context):
    
        '''Top bar menu in 3d view'''
    
        preferences = bpy.context.preferences.addons['blenderkit'].preferences
        if preferences.search_in_header:
            layout = self.layout
            s = bpy.context.scene
            ui_props = s.blenderkitUI
            if ui_props.asset_type == 'MODEL':
                props = s.blenderkit_models
            if ui_props.asset_type == 'MATERIAL':
                props = s.blenderkit_mat
            if ui_props.asset_type == 'BRUSH':
                props = s.blenderkit_brush
    
    Vilém Duha's avatar
    Vilém Duha committed
            # the center snap menu is in edit and object mode if tool settings are off.
            if context.space_data.show_region_tool_header == True or context.mode[:4] not in ('EDIT', 'OBJE'):
    
                layout.separator_spacer()
    
            layout.prop(ui_props, "asset_type", text='', icon='URL')
            layout.prop(props, "search_keywords", text="", icon='VIEWZOOM')
            draw_assetbar_show_hide(layout, props)
    
    
    
    # We can store multiple preview collections here,
    # however in this example we only store "main"
    preview_collections = {}
    
    Vilem Duha's avatar
    Vilem Duha committed
    classess = (
        SetCategoryOperator,
    
    
    Vilém Duha's avatar
    Vilém Duha committed
        VIEW3D_PT_blenderkit_profile,
        VIEW3D_PT_blenderkit_login,
    
    Vilem Duha's avatar
    Vilem Duha committed
        VIEW3D_PT_blenderkit_unified,
        VIEW3D_PT_blenderkit_model_properties,
        VIEW3D_PT_blenderkit_downloads,
    
        OBJECT_MT_blenderkit_asset_menu,
        UrlPopupDialog
    
    Vilem Duha's avatar
    Vilem Duha committed
    )
    
    
    def register_ui_panels():
        for c in classess:
            bpy.utils.register_class(c)
    
        bpy.types.VIEW3D_MT_editor_menus.append(header_search_draw)
    
    Vilem Duha's avatar
    Vilem Duha committed
    
    
    def unregister_ui_panels():
        for c in classess:
            bpy.utils.unregister_class(c)
    
    Vilém Duha's avatar
    Vilém Duha committed
        bpy.types.VIEW3D_MT_editor_menus.remove(header_search_draw)