コード例 #1
0
    def update_images(self):
        sr = bpy.context.scene['search results']

        for asset_button in self.asset_buttons:
            asset_button.asset_index = asset_button.button_index + self.scroll_offset
            if asset_button.asset_index < len(sr):
                asset_button.visible = True

                asset_data = sr[asset_button.asset_index]

                iname = blenderkit.utils.previmg_name(asset_button.asset_index)
                # show indices for debug purposes
                # asset_button.text = str(asset_button.asset_index)
                img = bpy.data.images.get(iname)
                if not img:
                    img_filepath = paths.get_addon_thumbnail_path(
                        'thumbnail_notready.jpg')
                else:
                    img_filepath = img.filepath
                asset_button.set_image(img_filepath)
                v_icon = ui.verification_icons[asset_data.get(
                    'verificationStatus', 'validated')]
                if v_icon is not None:
                    img_fp = paths.get_addon_thumbnail_path(v_icon)
                    asset_button.validation_icon.set_image(img_fp)
                    asset_button.validation_icon.visible = True
                else:
                    asset_button.validation_icon.visible = False
            else:
                asset_button.visible = False
                asset_button.validation_icon.visible = False
コード例 #2
0
def get_hidden_image(tpath, bdata_name, force_reload=False):
    hidden_name = '.%s' % bdata_name
    img = bpy.data.images.get(hidden_name)

    if tpath.startswith('//'):
        tpath = bpy.path.abspath(tpath)

    gap = '\n\n\n'
    en = '\n'
    if img == None or (img.filepath != tpath):
        if tpath.startswith('//'):
            tpath = bpy.path.abspath(tpath)
        if not os.path.exists(tpath) or tpath == '':
            tpath = paths.get_addon_thumbnail_path('thumbnail_notready.jpg')

        if img is None:
            img = bpy.data.images.load(tpath)
            img.name = hidden_name
        else:
            if img.filepath != tpath:
                if img.packed_file is not None:
                    img.unpack(method='USE_ORIGINAL')

                img.filepath = tpath
                img.reload()
        img.colorspace_settings.name = 'Linear'
    elif force_reload:
        if img.packed_file is not None:
            img.unpack(method='USE_ORIGINAL')
        img.reload()
        img.colorspace_settings.name = 'Linear'
    return img
コード例 #3
0
def get_hidden_image(tpath, bdata_name, force_reload=False, colorspace='sRGB'):
    if bdata_name[0] == '.':
        hidden_name = bdata_name
    else:
        hidden_name = '.%s' % bdata_name
    img = bpy.data.images.get(hidden_name)

    if tpath.startswith('//'):
        tpath = bpy.path.abspath(tpath)

    if img == None or (img.filepath != tpath):
        if tpath.startswith('//'):
            tpath = bpy.path.abspath(tpath)
        if not os.path.exists(tpath) or os.path.isdir(tpath):
            tpath = paths.get_addon_thumbnail_path('thumbnail_notready.jpg')

        if img is None:
            img = bpy.data.images.load(tpath)
            img.name = hidden_name
        else:
            if img.filepath != tpath:
                if img.packed_file is not None:
                    img.unpack(method='USE_ORIGINAL')

                img.filepath = tpath
                img.reload()
        image_utils.set_colorspace(img, colorspace)

    elif force_reload:
        if img.packed_file is not None:
            img.unpack(method='USE_ORIGINAL')
        img.reload()
        image_utils.set_colorspace(img, colorspace)
    return img
コード例 #4
0
    def init_tooltip(self):
        self.tooltip_widgets = []
        tooltip_size = 500
        total_size = tooltip_size + 2 * self.assetbar_margin
        self.tooltip_panel = BL_UI_Drag_Panel(0, 0, total_size, total_size)
        self.tooltip_panel.bg_color = (0.0, 0.0, 0.0, 0.5)
        self.tooltip_panel.visible = False

        tooltip_image = BL_UI_Button(self.assetbar_margin, self.assetbar_margin, 1, 1)
        tooltip_image.text = ""
        img_path = paths.get_addon_thumbnail_path('thumbnail_notready.jpg')
        tooltip_image.set_image(img_path)
        tooltip_image.set_image_size((tooltip_size, tooltip_size))
        tooltip_image.set_image_position((0, 0))
        self.tooltip_image = tooltip_image
        self.tooltip_widgets.append(tooltip_image)

        bottom_panel_fraction = 0.1
        labels_start = total_size * (1 - bottom_panel_fraction) - self.margin

        dark_panel = BL_UI_Widget(0, labels_start, total_size, total_size * bottom_panel_fraction)
        dark_panel.bg_color = (0.0, 0.0, 0.0, 0.7)
        self.tooltip_widgets.append(dark_panel)

        name_label = self.new_text('', self.assetbar_margin*2, labels_start, text_size=16)
        self.asset_name = name_label
        self.tooltip_widgets.append(name_label)
        offset_y = 16 + self.margin
        # label = self.new_text('Left click or drag to append/link. Right click for more options.', self.assetbar_margin*2, labels_start + offset_y,
        #                       text_size=14)
        # self.tooltip_widgets.append(label)


        self.hide_tooltip()
コード例 #5
0
ファイル: utils.py プロジェクト: sambler/myblenderaddons
def get_hidden_image(tpath, bdata_name, force_reload=False):
    hidden_name = '.%s' % bdata_name
    img = bpy.data.images.get(hidden_name)

    if tpath.startswith('//'):
        tpath = bpy.path.abspath(tpath)

    gap = '\n\n\n'
    en = '\n'
    if img == None or (img.filepath != tpath):
        if tpath.startswith('//'):
            tpath = bpy.path.abspath(tpath)
        if not os.path.exists(tpath) or tpath == '':
            tpath = paths.get_addon_thumbnail_path('thumbnail_notready.jpg')

        if img is None:
            img = bpy.data.images.load(tpath)
            img.name = hidden_name
        else:
            if img.filepath != tpath:
                if img.packed_file is not None:
                    img.unpack(method='USE_ORIGINAL')

                img.filepath = tpath
                img.reload()
    elif force_reload:
        if img.packed_file is not None:
            img.unpack(method='USE_ORIGINAL')
        img.reload()
    return img
コード例 #6
0
def get_thumbnail(name):
    p = paths.get_addon_thumbnail_path(name)
    name = '.%s' % name
    img = bpy.data.images.get(name)
    if img == None:
        img = bpy.data.images.load(p)
        img.name = name
        img.name = name

    return img
コード例 #7
0
ファイル: utils.py プロジェクト: sambler/myblenderaddons
def get_thumbnail(name):
    p = paths.get_addon_thumbnail_path(name)
    name = '.%s' % name
    img = bpy.data.images.get(name)
    if img == None:
        img = bpy.data.images.load(p)
        img.name = name
        img.name = name

    return img
コード例 #8
0
def get_thumbnail(name):
    p = paths.get_addon_thumbnail_path(name)
    name = '.%s' % name
    img = bpy.data.images.get(name)
    if img == None:
        img = bpy.data.images.load(p)
        img.colorspace_settings.name = 'Linear'
        img.name = name
        img.name = name

    return img
コード例 #9
0
def get_thumbnail(name):
    p = paths.get_addon_thumbnail_path(name)
    name = '.%s' % name
    img = bpy.data.images.get(name)
    if img == None:
        img = bpy.data.images.load(p)
        image_utils.set_colorspace(img, 'sRGB')
        img.name = name
        img.name = name

    return img
コード例 #10
0
def load_previews():

    scene = bpy.context.scene
    # FIRST START SEARCH
    props = scene.blenderkitUI
    directory = paths.get_temp_dir('%s_search' % props.asset_type.lower())
    s = bpy.context.scene
    results = s.get('search results')
    #
    if results is not None:
        inames = []
        tpaths = []

        i = 0
        for r in results:
            tpath = os.path.join(directory, r['thumbnail_small'])
            if not r['thumbnail_small']:
                tpath = paths.get_addon_thumbnail_path(
                    'thumbnail_not_available.jpg')

            iname = utils.previmg_name(i)

            # if os.path.exists(tpath):  # sometimes we are unlucky...
            img = bpy.data.images.get(iname)
            if img is None:
                img = bpy.data.images.load(tpath)
                img.name = iname
            elif img.filepath != tpath:
                # had to add this check for autopacking files...
                if img.packed_file is not None:
                    img.unpack(method='USE_ORIGINAL')
                img.filepath = tpath
                img.reload()
            img.colorspace_settings.name = 'sRGB'

            i += 1
コード例 #11
0
    def __init__(self):
        super().__init__()

        self.update_ui_size(bpy.context)

        ui_props = bpy.context.scene.blenderkitUI

        # todo move all this to update UI size

        self.draw_tooltip = False
        self.scroll_offset = 0

        self.text_color = (0.9, 0.9, 0.9, 1.0)
        button_bg_color = (0.2, 0.2, 0.2, .1)
        button_hover_color = (0.8, 0.8, 0.8, .2)

        self.init_tooltip()

        self.buttons = []
        self.asset_buttons = []
        self.validation_icons = []
        self.widgets_panel = []

        self.panel = BL_UI_Drag_Panel(0, 0, self.bar_width, self.bar_height)
        self.panel.bg_color = (0.0, 0.0, 0.0, 0.5)

        sr = bpy.context.scene['search results']

        for a in range(0, self.wcount):
            for b in range(0, self.hcount):
                asset_x = self.assetbar_margin + a * (self.button_size)
                asset_y = self.assetbar_margin + b * (self.button_size)
                new_button = BL_UI_Button(asset_x, asset_y, self.button_size,
                                          self.button_size)

                asset_idx = a + b * self.wcount + self.scroll_offset
                # asset_data = sr[asset_idx]
                # iname = blenderkit.utils.previmg_name(asset_idx)
                # img = bpy.data.images.get(iname)

                new_button.bg_color = button_bg_color
                new_button.hover_bg_color = button_hover_color
                new_button.text = ""  # asset_data['name']
                # if img:
                #     new_button.set_image(img.filepath)

                new_button.set_image_size((self.thumb_size, self.thumb_size))
                new_button.set_image_position((self.margin, self.margin))
                new_button.button_index = asset_idx
                new_button.search_index = asset_idx
                new_button.set_mouse_down(self.drag_drop_asset)
                new_button.set_mouse_down_right(self.asset_menu)
                new_button.set_mouse_enter(self.enter_button)
                new_button.set_mouse_exit(self.exit_button)
                new_button.text_input = self.handle_key_input
                self.asset_buttons.append(new_button)
                # add validation icon to button
                icon_size = 24
                validation_icon = BL_UI_Button(
                    asset_x + self.button_size - icon_size - self.margin,
                    asset_y + self.button_size - icon_size - self.margin, 0, 0)

                # v_icon = ui.verification_icons[asset_data.get('verificationStatus', 'validated')]
                # if v_icon is not None:
                #     img_fp = paths.get_addon_thumbnail_path(v_icon)
                #     validation_icon.set_image(img_fp)
                validation_icon.text = ''
                validation_icon.set_image_size((icon_size, icon_size))
                validation_icon.set_image_position((0, 0))
                self.validation_icons.append(validation_icon)
                new_button.validation_icon = validation_icon

        other_button_size = 30

        self.button_close = BL_UI_Button(self.bar_width - other_button_size,
                                         -0, other_button_size, 15)
        self.button_close.bg_color = button_bg_color
        self.button_close.hover_bg_color = button_hover_color
        self.button_close.text = "x"
        self.button_close.set_mouse_down(self.cancel_press)

        self.widgets_panel.append(self.button_close)
        scroll_width = 30
        self.button_scroll_down = BL_UI_Button(-scroll_width, 0, scroll_width,
                                               self.bar_height)
        self.button_scroll_down.bg_color = button_bg_color
        self.button_scroll_down.hover_bg_color = button_hover_color
        self.button_scroll_down.text = ""
        self.button_scroll_down.set_image(
            paths.get_addon_thumbnail_path('arrow_left.png'))
        self.button_scroll_down.set_image_size(
            (scroll_width, self.button_size))
        self.button_scroll_down.set_image_position(
            (0, int((self.bar_height - self.button_size) / 2)))

        self.button_scroll_down.set_mouse_down(self.scroll_down)

        self.widgets_panel.append(self.button_scroll_down)

        self.button_scroll_up = BL_UI_Button(self.bar_width, 0, scroll_width,
                                             self.bar_height)
        self.button_scroll_up.bg_color = button_bg_color
        self.button_scroll_up.hover_bg_color = button_hover_color
        self.button_scroll_up.text = ""
        self.button_scroll_up.set_image(
            paths.get_addon_thumbnail_path('arrow_right.png'))
        self.button_scroll_up.set_image_size((scroll_width, self.button_size))
        self.button_scroll_up.set_image_position(
            (0, int((self.bar_height - self.button_size) / 2)))

        self.button_scroll_up.set_mouse_down(self.scroll_up)

        self.widgets_panel.append(self.button_scroll_up)

        self.update_images()