Skip to content

Commit

Permalink
fix an error when changing workspace with file picker opened.
Browse files Browse the repository at this point in the history
  • Loading branch information
matyalatte committed May 25, 2023
1 parent a78871f commit bc76599
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 17 deletions.
9 changes: 4 additions & 5 deletions addons/blender_dds_addon/ui/bpy_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,16 @@ def get_addon_preferences(context, addon_name):

def get_image_editor_space(context):
area = context.area
if area.type == 'IMAGE_EDITOR':
if area and area.type == 'IMAGE_EDITOR':
return area.spaces.active
return None


def get_selected_tex(context):
space = get_image_editor_space(context)
tex = space.image
if tex is None:
raise RuntimeError('Select an image on Image Editor.')
return tex
if space:
return space.image
return None


def load_texture(file, name, color_space='Non-Color'):
Expand Down
4 changes: 2 additions & 2 deletions addons/blender_dds_addon/ui/custom_properties.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bpy
from bpy.props import BoolProperty, EnumProperty, PointerProperty, CollectionProperty, IntProperty
from bpy.types import PropertyGroup
from .bpy_util import get_image_editor_space, dds_properties_exist
from .bpy_util import get_selected_tex, dds_properties_exist
from ..directx.dxgi_format import DXGI_FORMAT
from .texture_list import DDSTextureListItem, draw_texture_list

Expand Down Expand Up @@ -145,7 +145,7 @@ def draw(self, context):
if not dds_properties_exist():
return
layout = self.layout
tex = get_image_editor_space(context).image
tex = get_selected_tex(context)
if tex is None:
return
dds_props = tex.dds_props
Expand Down
15 changes: 9 additions & 6 deletions addons/blender_dds_addon/ui/export_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from ..directx.dds import is_hdr, DDS
from ..directx.texconv import Texconv
from .bpy_util import save_texture, dds_properties_exist, get_selected_tex, flush_stdout
from .bpy_util import save_texture, dds_properties_exist, get_image_editor_space, flush_stdout
from .texture_list import draw_texture_list


Expand Down Expand Up @@ -240,7 +240,14 @@ def execute_base(self, context, file=None, directory=None, is_dir=False):
count += 1
else:
# For DDS_OT_export_dds
tex = get_selected_tex(context)
space = get_image_editor_space(context)
if space is None:
raise RuntimeError('Image Editor should be activated.')
tex = space.image
if tex is None:
raise RuntimeError('An image should be selected on Image Editor.')
if dds_properties_exist() and tex.dds_props.dxgi_format == "NONE":
raise RuntimeError("DXGI format should NOT be 'None'.")
export_as_dds(context, tex, file)
count = 1

Expand Down Expand Up @@ -278,10 +285,6 @@ class DDS_OT_export_dds(DDS_OT_export_base, ExportHelper):
)

def invoke(self, context, event):
tex = get_selected_tex(context)
if dds_properties_exist() and tex.dds_props.dxgi_format == "NONE":
self.report({'ERROR'}, "Select a DXGI format for the image.")
return {'CANCELLED'}
return ExportHelper.invoke(self, context, event)

def execute(self, context):
Expand Down
7 changes: 3 additions & 4 deletions addons/blender_dds_addon/ui/texture_list.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bpy
from bpy.props import PointerProperty, EnumProperty
from bpy.types import PropertyGroup, Image, UIList, Operator
from .bpy_util import get_image_editor_space, dds_properties_exist
from .bpy_util import get_selected_tex, dds_properties_exist


class DDSTextureListItem(PropertyGroup):
Expand Down Expand Up @@ -38,8 +38,7 @@ def draw_filter(self, context, layout):
def get_tex(context):
if not dds_properties_exist():
return None
tex = get_image_editor_space(context).image
return tex
return get_selected_tex(context)


class DDS_OT_list_new_item(Operator):
Expand Down Expand Up @@ -130,7 +129,7 @@ def check_tex_status(context, extra_tex, layout, show_msg=False):
if show_msg:
layout.label(text="Specify a texture or remove this item.")
return
tex = get_image_editor_space(context).image
tex = get_selected_tex(context)
w, h = tex.size
extra_w, extra_h = extra_tex.size
if w != extra_w or h != extra_h:
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
ver 0.3.2
- Fixed an error when importing dds without image editor opened.
- Fixed an error when changing workspace with file picker opened.

ver 0.3.1
- Fixed an error when loading volume textures.

Expand Down

0 comments on commit bc76599

Please sign in to comment.