Skip to content
Snippets Groups Projects
ui_panels.py 84.6 KiB
Newer Older
  • Learn to ignore specific revisions
  •         if platform.system() == 'Windows':
                self.win_close()
            else:
                self.mouse_trick(context,event.mouse_x, event.mouse_y)
            return {'FINISHED'}
    
    class UrlPopupDialog(bpy.types.Operator):
        """Generate Cycles thumbnail for model assets"""
        bl_idname = "wm.blenderkit_url_dialog"
        bl_label = "BlenderKit message:"
        bl_options = {'REGISTER', 'INTERNAL'}
    
        url: bpy.props.StringProperty(
            name="Url",
            description="url",
            default="")
    
        link_text: bpy.props.StringProperty(
            name="Url",
            description="url",
            default="Go to website")
    
        message: bpy.props.StringProperty(
            name="Text",
            description="text",
            default="")
    
        # @classmethod
        # def poll(cls, context):
        #     return bpy.context.view_layer.objects.active is not None
    
        def draw(self, context):
            layout = self.layout
    
            utils.label_multiline(layout, text=self.message, width=300)
    
    
            layout.active_default = True
            op = layout.operator("wm.url_open", text=self.link_text, icon='QUESTION')
    
            if not utils.user_logged_in():
                utils.label_multiline(layout,
                                      text='Already subscribed? You need to login to access your Full Plan.',
    
    
                layout.operator_context = 'EXEC_DEFAULT'
                layout.operator("wm.blenderkit_login", text="Login",
                                icon='URL').signup = False
    
            op.url = self.url
    
        def execute(self, context):
            return {'FINISHED'}
    
        def invoke(self, context, event):
            wm = context.window_manager
    
            return wm.invoke_props_dialog(self, width=300)
    
    class LoginPopupDialog(bpy.types.Operator):
    
        """Popup a dialog which enables the user to log in after being logged out automatically."""
        bl_idname = "wm.blenderkit_login_dialog"
    
        bl_label = "BlenderKit login"
        bl_options = {'REGISTER', 'INTERNAL'}
    
        message: bpy.props.StringProperty(
            name="Message",
            description="",
            default="Your were logged out from BlenderKit. Please login again. ")
    
        # @classmethod
        # def poll(cls, context):
        #     return bpy.context.view_layer.objects.active is not None
    
        def draw(self, context):
            layout = self.layout
            utils.label_multiline(layout, text=self.message)
    
            layout.active_default = True
    
            op = layout.operator
    
            op = layout.operator("wm.url_open", text=self.link_text, icon='QUESTION')
            op.url = self.url
    
        def execute(self, context):
    
    Vilém Duha's avatar
    Vilém Duha committed
            # start_thumbnailer(self, context)
    
            return {'FINISHED'}
    
        def invoke(self, context, event):
            wm = context.window_manager
    
            return wm.invoke_props_dialog(self)
    
    
    
    Vilem Duha's avatar
    Vilem Duha committed
    def draw_panel_categories(self, context):
        s = context.scene
        ui_props = s.blenderkitUI
        user_preferences = bpy.context.preferences.addons['blenderkit'].preferences
        layout = self.layout
        # row = layout.row()
        # row.prop(ui_props, 'asset_type', expand=True, icon_only=True)
        wm = bpy.context.window_manager
    
    Vilém Duha's avatar
    Vilém Duha committed
        if wm.get('bkit_categories') == None:
            return
    
    Vilem Duha's avatar
    Vilem Duha committed
        col = layout.column(align=True)
        if wm.get('active_category') is not None:
            acat = wm['active_category'][ui_props.asset_type]
            if len(acat) > 1:
                # we are in subcategory, so draw the parent button
                op = col.operator('view3d.blenderkit_set_category', text='...', icon='FILE_PARENT')
                op.asset_type = ui_props.asset_type
                op.category = ''
        cats = categories.get_category(wm['bkit_categories'], cat_path=acat)
        # draw freebies only in models parent category
    
        # if ui_props.asset_type == 'MODEL' and len(acat) == 1:
        #     op = col.operator('view3d.blenderkit_asset_bar', text='freebies')
        #     op.free_only = True
    
    Vilem Duha's avatar
    Vilem Duha committed
    
        for c in cats['children']:
    
    Vilém Duha's avatar
    Vilém Duha committed
            if c['assetCount'] > 0 or (utils.profile_is_validator() and user_preferences.categories_fix):
    
    Vilem Duha's avatar
    Vilem Duha committed
                row = col.row(align=True)
    
    Vilém Duha's avatar
    Vilém Duha committed
                if len(c['children']) > 0 and c['assetCount'] > 15 or (
                        utils.profile_is_validator() and user_preferences.categories_fix):
    
    Vilem Duha's avatar
    Vilem Duha committed
                    row = row.split(factor=.8, align=True)
                # row = split.split()
                ctext = '%s (%i)' % (c['name'], c['assetCount'])
    
    
                preferences = bpy.context.preferences.addons['blenderkit'].preferences
                if preferences.experimental_features:
                    op = row.operator('view3d.blenderkit_asset_bar_widget', text=ctext)
                else:
                    op = row.operator('view3d.blenderkit_asset_bar', text=ctext)
                    op.do_search = True
                    op.keep_running = True
    
    Vilém Duha's avatar
    Vilém Duha committed
                    op.tooltip = f"Browse {c['name']} category"
    
                    op.category = c['slug']
    
    Vilém Duha's avatar
    Vilém Duha committed
                if len(c['children']) > 0 and c['assetCount'] > 15 or (
                        utils.profile_is_validator() and user_preferences.categories_fix):
    
    Vilem Duha's avatar
    Vilem Duha committed
                    # 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
    
    Vilém Duha's avatar
    Vilém Duha committed
            for i, threaddata in enumerate(download.download_threads):
    
    Vilem Duha's avatar
    Vilem Duha committed
                tcom = threaddata[2]
                asset_data = threaddata[1]
                row = layout.row()
                row.label(text=asset_data['name'])
                row.label(text=str(int(tcom.progress)) + ' %')
    
                op = row.operator('scene.blenderkit_download_kill', text='', icon='CANCEL')
                op.thread_index = i
    
                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'''
    
    
        if not utils.guard_from_crash():
            return;
    
    
        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
    
            if ui_props.asset_type == 'HDR':
                props = s.blenderkit_HDR
            if ui_props.asset_type == 'SCENE':
                props = s.blenderkit_scene
    
    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", expand=True, icon_only=True, text='', icon='URL')
    
            layout.prop(props, "search_keywords", text="", icon='VIEWZOOM')
            draw_assetbar_show_hide(layout, props)
    
            layout.popover(panel="VIEW3D_PT_blenderkit_categories", text="", icon = 'OUTLINER')
            if ui_props.asset_type=='MODEL':
                layout.popover(panel="VIEW3D_PT_blenderkit_advanced_model_search", text="", icon = 'FILTER')
            elif ui_props.asset_type=='MATERIAL':
                layout.popover(panel="VIEW3D_PT_blenderkit_advanced_material_search", text="", icon = 'FILTER')
    
    def ui_message(title, message):
        def draw_message(self, context):
            layout = self.layout
    
            utils.label_multiline(layout, text=message, width=400)
    
        bpy.context.window_manager.popup_menu(draw_message, title=title, icon='INFO')
    
    # We can store multiple preview collections here,
    # however in this example we only store "main"
    preview_collections = {}
    
    Vilem Duha's avatar
    Vilem Duha committed
        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_advanced_model_search,
    
        VIEW3D_PT_blenderkit_advanced_material_search,
    
        VIEW3D_PT_blenderkit_categories,
        VIEW3D_PT_blenderkit_import_settings,
    
    Vilem Duha's avatar
    Vilem Duha committed
        VIEW3D_PT_blenderkit_model_properties,
    
    Vilém Duha's avatar
    Vilém Duha committed
        NODE_PT_blenderkit_material_properties,
    
        # VIEW3D_PT_blenderkit_ratings,
    
    Vilem Duha's avatar
    Vilem Duha committed
        VIEW3D_PT_blenderkit_downloads,
    
    Vilém Duha's avatar
    Vilém Duha committed
        # OBJECT_MT_blenderkit_resolution_menu,
    
        OBJECT_MT_blenderkit_asset_menu,
    
        OBJECT_MT_blenderkit_login_menu,
    
        AssetPopupCard,
    
        UrlPopupDialog,
    
        BlenderKitWelcomeOperator,
    
    Vilem Duha's avatar
    Vilem Duha committed
    def register_ui_panels():
    
    Vilem Duha's avatar
    Vilem Duha committed
            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():
    
        bpy.types.VIEW3D_MT_editor_menus.remove(header_search_draw)
    
            # print('unregister', c)
    
    Vilem Duha's avatar
    Vilem Duha committed
            bpy.utils.unregister_class(c)