def draw(self, context): layout = self.layout col = layout.column() # layout.template_icon_view(bkit_ratings, property, show_labels=False, scale=6.0, scale_popup=5.0) col.label(text=self.message) row = col.row() row.prop(self, 'rating_quality_ui', expand=True, icon_only=True, emboss=False) # row.label(text=str(self.rating_quality)) col.separator() row = layout.row() row.label(text=f"How many hours did this {self.asset_type} save you?") if self.asset_type in ('model', 'scene'): row = layout.row() if utils.profile_is_validator(): col.prop(self, 'rating_work_hours') row.prop(self, 'rating_work_hours_ui', expand=True, icon_only=False, emboss=True) if float(self.rating_work_hours_ui) > 100: utils.label_multiline(layout, text=f"\nThat's huge! please be sure to give such rating only to godly {self.asset_type}s.\n", width=500) elif float(self.rating_work_hours_ui) > 18: layout.separator() utils.label_multiline(layout, text=f"\nThat's a lot! please be sure to give such rating only to amazing {self.asset_type}s.\n", width=500) else: row = layout.row() row.prop(self, 'rating_work_hours_ui_1_5', expand=True, icon_only=False, emboss=True)
def draw(self, context): layout = self.layout col = layout.column() # layout.template_icon_view(bkit_ratings, property, show_labels=False, scale=6.0, scale_popup=5.0) col.label(text=self.message) row = col.row() row.prop(self, 'rating_quality_ui', expand=True, icon_only=True, emboss=False) col.separator() col.prop(self, 'rating_work_hours') if utils.profile_is_validator(): row = layout.row() if self.asset_type == 'model': row.prop(self, 'rating_work_hours_ui', expand=True, icon_only=False, emboss=True) else: row.prop(self, 'rating_work_hours_ui_1_5', expand=True, icon_only=False, emboss=True)
def draw_ratings_menu(self, context, layout): pcoll = icons.icon_collections["main"] profile_name = '' profile = bpy.context.window_manager.get('bkit profile') if profile and len(profile['user']['firstName']) > 0: profile_name = ' ' + profile['user']['firstName'] col = layout.column() # layout.template_icon_view(bkit_ratings, property, show_labels=False, scale=6.0, scale_popup=5.0) row = col.row() row.label(text='Quality:', icon='SOLO_ON') row = col.row() row.label(text='Please help the community by rating quality:') row = col.row() row.prop(self, 'rating_quality_ui', expand=True, icon_only=True, emboss=False) if self.rating_quality > 0: # row = col.row() row.label(text=f' Thanks{profile_name}!', icon='FUND') # row.label(text=str(self.rating_quality)) col.separator() col.separator() row = col.row() row.label(text='Complexity:', icon_value=pcoll['dumbbell'].icon_id) row = col.row() row.label(text=f"How many hours did this {self.asset_type} save you?") if utils.profile_is_validator(): row = col.row() row.prop(self, 'rating_work_hours') if self.asset_type in ('model', 'scene'): row = col.row() row.prop(self, 'rating_work_hours_ui', expand=True, icon_only=False, emboss=True) if float(self.rating_work_hours_ui) > 100: utils.label_multiline(col, text=f"\nThat's huge! please be sure to give such rating only to godly {self.asset_type}s.\n", width=500) elif float(self.rating_work_hours_ui) > 18: col.separator() utils.label_multiline(col, text=f"\nThat's a lot! please be sure to give such rating only to amazing {self.asset_type}s.\n", width=500) elif self.asset_type == 'hdr': row = col.row() row.prop(self, 'rating_work_hours_ui_1_10', expand=True, icon_only=False, emboss=True) else: row = col.row() row.prop(self, 'rating_work_hours_ui_1_5', expand=True, icon_only=False, emboss=True) if self.rating_work_hours > 0: row = col.row() row.label(text=f'Thanks{profile_name}, you are amazing!', icon='FUND')
def can_edit_asset(active_index=-1, asset_data=None): if active_index < 0 and not asset_data: return False profile = bpy.context.window_manager.get('bkit profile') if profile is None: return False if utils.profile_is_validator(): return True if not asset_data: sr = bpy.context.window_manager['search results'] asset_data = dict(sr[active_index]) # print(profile, asset_data) if int(asset_data['author']['id']) == int(profile['user']['id']): return True return False
def invoke(self, context, event): scene = bpy.context.scene ui_props = scene.blenderkitUI if ui_props.active_index > -1: sr = bpy.context.scene['search results'] asset_data = dict(sr[ui_props.active_index]) self.asset_id = asset_data['id'] self.asset_type = asset_data['assetType'] self.message = f"Rate asset {self.asset_name}" wm = context.window_manager if utils.profile_is_validator() and self.asset_type == 'model': # spawn a wider one for validators for the enum buttons return wm.invoke_props_dialog(self, width=500) else: return wm.invoke_props_dialog(self)
def query_to_url(self): query = self.query params = self.params # build a new request url = paths.get_api_url() + 'search/' # build request manually # TODO use real queries requeststring = '?query=' # if query.get('query') not in ('', None): requeststring += query['query'].lower() for i, q in enumerate(query): if q != 'query': requeststring += '+' requeststring += q + ':' + str(query[q]).lower() # result ordering: _score - relevance, score - BlenderKit score if query.get('query') is None and query.get( 'category_subtree') == None: # assumes no keywords and no category, thus an empty search that is triggered on start. # orders by last core file upload if query.get('verification_status') == 'uploaded': # for validators, sort uploaded from oldest requeststring += '+order:created' else: requeststring += '+order:-last_upload' elif query.get( 'author_id') is not None and utils.profile_is_validator(): requeststring += '+order:-created' else: if query.get('category_subtree') is not None: requeststring += '+order:-score,_score' else: requeststring += '+order:_score' requeststring += '&addon_version=%s' % params['addon_version'] if params.get('scene_uuid') is not None: requeststring += '&scene_uuid=%s' % params['scene_uuid'] # print('params', params) urlquery = url + requeststring return urlquery
def draw(self, context): layout = self.layout ui_props = context.scene.blenderkitUI sr = bpy.context.scene['search results'] sr = bpy.context.scene['search results orig']['results'] asset_data = sr[ui_props.active_index] author_id = str(asset_data['author']['id']) wm = bpy.context.window_manager if wm.get('bkit authors') is not None: a = bpy.context.window_manager['bkit authors'].get(author_id) if a is not None: # utils.p('author:', a) if a.get('aboutMeUrl') is not None: op = layout.operator('wm.url_open', text="Open Author's Website") op.url = a['aboutMeUrl'] op = layout.operator('view3d.blenderkit_search', text="Show Assets By Author") op.keywords = '' op.author_id = author_id op = layout.operator('view3d.blenderkit_search', text='Search Similar') op.keywords = asset_data['name'] + ' ' + asset_data['description'] + ' ' + ' '.join(asset_data['tags']) if asset_data.get('canDownload') != 0: if len(bpy.context.selected_objects)>0 and ui_props.asset_type == 'MODEL': aob = bpy.context.active_object if aob is None: aob = bpy.context.selected_objects[0] op = layout.operator('scene.blenderkit_download', text='Replace Active Models') op.asset_type = ui_props.asset_type op.asset_index = ui_props.active_index op.model_location = aob.location op.model_rotation = aob.rotation_euler op.target_object = aob.name op.material_target_slot = aob.active_material_index op.replace = True wm = bpy.context.window_manager profile = wm.get('bkit profile') if profile is not None: # validation if utils.profile_is_validator(): layout.label(text='Validation tools:') if asset_data['verificationStatus'] != 'uploaded': op = layout.operator('object.blenderkit_change_status', text='set Uploaded') op.asset_id = asset_data['id'] op.state = 'uploaded' if asset_data['verificationStatus'] != 'validated': op = layout.operator('object.blenderkit_change_status', text='Validate') op.asset_id = asset_data['id'] op.state = 'validated' if asset_data['verificationStatus'] != 'on_hold': op = layout.operator('object.blenderkit_change_status', text='Put on Hold') op.asset_id = asset_data['id'] op.state = 'on_hold' if asset_data['verificationStatus'] != 'rejected': op = layout.operator('object.blenderkit_change_status', text='Reject') op.asset_id = asset_data['id'] op.state = 'rejected' if author_id == str(profile['user']['id']): layout.label(text='Management tools:') row = layout.row() row.operator_context = 'INVOKE_DEFAULT' op = row.operator('object.blenderkit_change_status', text='Delete') op.asset_id = asset_data['id'] op.state = 'deleted'
def draw(self, context): s = context.scene ui_props = s.blenderkitUI user_preferences = bpy.context.preferences.addons['blenderkit'].preferences wm = bpy.context.window_manager layout = self.layout # layout.prop_tabs_enum(ui_props, "asset_type", icon_only = True) row = layout.row() # row.scale_x = 1.6 # row.scale_y = 1.6 # row.prop(ui_props, 'down_up', expand=True, icon_only=False) # row.label(text='') # row = row.split().row() # layout.alert = True # layout.alignment = 'CENTER' # row = layout.row(align = True) # split = row.split(factor=.5) # row.prop(ui_props, 'asset_type', expand=True, icon_only=True) # row = layout.column(align = False) layout.prop(ui_props, 'asset_type', expand=False, text='') w = context.region.width if user_preferences.login_attempt: draw_login_progress(layout) return if len(user_preferences.api_key) < 20 and user_preferences.asset_counter > 20: if user_preferences.enable_oauth: draw_login_buttons(layout) else: op = layout.operator("wm.url_open", text="Get your API Key", icon='QUESTION') op.url = paths.BLENDERKIT_SIGNUP_URL layout.label(text='Paste your API Key:') layout.prop(user_preferences, 'api_key', text='') layout.separator() # if bpy.data.filepath == '': # layout.alert = True # label_multiline(layout, text="It's better to save your file first.", width=w) # layout.alert = False # layout.separator() if ui_props.down_up == 'SEARCH': if utils.profile_is_validator(): search_props = utils.get_search_props() layout.prop(search_props, 'search_verification_status') if ui_props.asset_type == 'MODEL': # noinspection PyCallByClass draw_panel_model_search(self, context) if ui_props.asset_type == 'SCENE': # noinspection PyCallByClass draw_panel_scene_search(self, context) elif ui_props.asset_type == 'MATERIAL': draw_panel_material_search(self, context) elif ui_props.asset_type == 'BRUSH': if context.sculpt_object or context.image_paint_object: # noinspection PyCallByClass draw_panel_brush_search(self, context) else: label_multiline(layout, text='switch to paint or sculpt mode.', width=context.region.width) return elif ui_props.down_up == 'UPLOAD': if not ui_props.assetbar_on: text = 'Show asset preview - ;' else: text = 'Hide asset preview - ;' op = layout.operator('view3d.blenderkit_asset_bar', text=text, icon='EXPORT') op.keep_running = False op.do_search = False op.tooltip = 'Show/Hide asset preview' e = s.render.engine if e not in ('CYCLES', 'BLENDER_EEVEE'): rtext = 'Only Cycles and EEVEE render engines are currently supported. ' \ 'Please use Cycles for all assets you upload to BlenderKit.' label_multiline(layout, rtext, icon='ERROR', width=w) return; if ui_props.asset_type == 'MODEL': # label_multiline(layout, "Uploaded models won't be available in b2.79", icon='ERROR') if bpy.context.view_layer.objects.active is not None: draw_panel_model_upload(self, context) else: layout.label(text='selet object to upload') elif ui_props.asset_type == 'SCENE': draw_panel_scene_upload(self, context) elif ui_props.asset_type == 'MATERIAL': # label_multiline(layout, "Uploaded materials won't be available in b2.79", icon='ERROR') if bpy.context.view_layer.objects.active is not None and bpy.context.active_object.active_material is not None: draw_panel_material_upload(self, context) else: label_multiline(layout, text='select object with material to upload materials', width=w) elif ui_props.asset_type == 'BRUSH': if context.sculpt_object or context.image_paint_object: draw_panel_brush_upload(self, context) else: layout.label(text='switch to paint or sculpt mode.') elif ui_props.down_up == 'RATING': # the poll functions didn't work here, don't know why. if ui_props.asset_type == 'MODEL': # TODO improve poll here to parenting structures if bpy.context.view_layer.objects.active is not None and bpy.context.active_object.get( 'asset_data') != None: ad = bpy.context.active_object.get('asset_data') layout.label(text=ad['name']) draw_panel_model_rating(self, context) if ui_props.asset_type == 'MATERIAL': if bpy.context.view_layer.objects.active is not None and \ bpy.context.active_object.active_material is not None and \ bpy.context.active_object.active_material.blenderkit.asset_base_id != '': layout.label(text=bpy.context.active_object.active_material.blenderkit.name + ' :') # noinspection PyCallByClass draw_panel_material_ratings(self, context) if ui_props.asset_type == 'BRUSH': if context.sculpt_object or context.image_paint_object: props = utils.get_brush_props(context) if props.asset_base_id != '': layout.label(text=props.name + ' :') # noinspection PyCallByClass draw_panel_brush_ratings(self, context) if ui_props.asset_type == 'TEXTURE': layout.label(text='not yet implemented')
def draw_asset_context_menu(self, context, asset_data): layout = self.layout ui_props = context.scene.blenderkitUI author_id = str(asset_data['author']['id']) wm = bpy.context.window_manager if wm.get('bkit authors') is not None: a = bpy.context.window_manager['bkit authors'].get(author_id) if a is not None: # utils.p('author:', a) if a.get('aboutMeUrl') is not None: op = layout.operator('wm.url_open', text="Open Author's Website") op.url = a['aboutMeUrl'] op = layout.operator('view3d.blenderkit_search', text="Show Assets By Author") op.keywords = '' op.author_id = author_id op = layout.operator('view3d.blenderkit_search', text='Search Similar') op.keywords = asset_data['name'] + ' ' + asset_data['description'] + ' ' + ' '.join(asset_data['tags']) if asset_data.get('canDownload') != 0: if len(bpy.context.selected_objects) > 0 and ui_props.asset_type == 'MODEL': aob = bpy.context.active_object if aob is None: aob = bpy.context.selected_objects[0] op = layout.operator('scene.blenderkit_download', text='Replace Active Models') #this checks if the menu got called from right-click in assetbar(then index is 0 - x) or # from a panel(then replacement happens from the active model) if ui_props.active_index == -3: #called from addon panel o = utils.get_active_model() op.asset_base_id = o['asset_data']['assetBaseId'] else: op.asset_index = ui_props.active_index op.asset_type = ui_props.asset_type op.model_location = aob.location op.model_rotation = aob.rotation_euler op.target_object = aob.name op.material_target_slot = aob.active_material_index op.replace = True wm = bpy.context.window_manager profile = wm.get('bkit profile') if profile is not None: # validation if utils.profile_is_validator(): layout.label(text='Validation tools:') if asset_data['verificationStatus'] != 'uploaded': op = layout.operator('object.blenderkit_change_status', text='set Uploaded') op.asset_id = asset_data['id'] op.state = 'uploaded' if asset_data['verificationStatus'] != 'validated': op = layout.operator('object.blenderkit_change_status', text='Validate') op.asset_id = asset_data['id'] op.state = 'validated' if asset_data['verificationStatus'] != 'on_hold': op = layout.operator('object.blenderkit_change_status', text='Put on Hold') op.asset_id = asset_data['id'] op.state = 'on_hold' if asset_data['verificationStatus'] != 'rejected': op = layout.operator('object.blenderkit_change_status', text='Reject') op.asset_id = asset_data['id'] op.state = 'rejected' if author_id == str(profile['user']['id']): layout.label(text='Management tools:') row = layout.row() row.operator_context = 'INVOKE_DEFAULT' op = row.operator('object.blenderkit_change_status', text='Delete') op.asset_id = asset_data['id'] op.state = 'deleted'