fix: fix bug that there is no preset encoding names.
- fix the issue that there is no preset encoding names in list when enable plugin without any extra operations.
This commit is contained in:
@ -18,6 +18,12 @@ class BBP_OT_export_virtools(bpy.types.Operator, UTIL_file_browser.ExportVirtool
|
|||||||
return (
|
return (
|
||||||
PROP_preferences.get_raw_preferences().has_valid_blc_tex_folder()
|
PROP_preferences.get_raw_preferences().has_valid_blc_tex_folder()
|
||||||
and bmap.is_bmap_available())
|
and bmap.is_bmap_available())
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
# preset virtools encoding if possible
|
||||||
|
self.preset_vt_encodings_if_possible(context)
|
||||||
|
# call parent invoke function (same reason written in IMPORT module)
|
||||||
|
return super().invoke(context, event)
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
# check selecting first
|
# check selecting first
|
||||||
|
@ -18,6 +18,12 @@ class BBP_OT_import_virtools(bpy.types.Operator, UTIL_file_browser.ImportVirtool
|
|||||||
return (
|
return (
|
||||||
PROP_preferences.get_raw_preferences().has_valid_blc_tex_folder()
|
PROP_preferences.get_raw_preferences().has_valid_blc_tex_folder()
|
||||||
and bmap.is_bmap_available())
|
and bmap.is_bmap_available())
|
||||||
|
|
||||||
|
def invoke(self, context, event):
|
||||||
|
# preset virtools encoding if possible
|
||||||
|
self.preset_vt_encodings_if_possible(context)
|
||||||
|
# call parent invoke function (do no call self "execute", because we need show a modal window)
|
||||||
|
return super().invoke(context, event)
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
# check whether encoding list is empty to avoid real stupid user.
|
# check whether encoding list is empty to avoid real stupid user.
|
||||||
|
@ -195,6 +195,16 @@ class PropsVisitor():
|
|||||||
def get_ioport_encodings(self) -> tuple[str, ...]:
|
def get_ioport_encodings(self) -> tuple[str, ...]:
|
||||||
encodings = get_ioport_encodings(self.__mAssocScene)
|
encodings = get_ioport_encodings(self.__mAssocScene)
|
||||||
return tuple(i.encoding for i in encodings)
|
return tuple(i.encoding for i in encodings)
|
||||||
|
def preset_ioport_encodings(self) -> None:
|
||||||
|
"""
|
||||||
|
Set IOPort used encodings list as preset encoding list.
|
||||||
|
Please note that all old values will be overwritten.
|
||||||
|
"""
|
||||||
|
encodings = get_ioport_encodings(self.__mAssocScene)
|
||||||
|
encodings.clear()
|
||||||
|
for default_enc in UTIL_virtools_types.g_PyBMapDefaultEncodings:
|
||||||
|
item = encodings.add()
|
||||||
|
item.encoding = default_enc
|
||||||
def draw_ioport_encodings(self, layout: bpy.types.UILayout) -> None:
|
def draw_ioport_encodings(self, layout: bpy.types.UILayout) -> None:
|
||||||
target = get_ptrprop_resolver(self.__mAssocScene)
|
target = get_ptrprop_resolver(self.__mAssocScene)
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
@ -218,24 +228,11 @@ class PropsVisitor():
|
|||||||
col.separator()
|
col.separator()
|
||||||
col.operator(BBP_OT_clear_ioport_encodings.bl_idname, icon='TRASH', text='')
|
col.operator(BBP_OT_clear_ioport_encodings.bl_idname, icon='TRASH', text='')
|
||||||
|
|
||||||
@bpy.app.handlers.persistent
|
|
||||||
def _ioport_encodings_initializer(file_path: str):
|
|
||||||
# if we can fetch property, and it is empty after loading file
|
|
||||||
# we fill it with default value
|
|
||||||
encodings = get_ioport_encodings(bpy.context.scene)
|
|
||||||
if len(encodings) == 0:
|
|
||||||
for default_enc in UTIL_virtools_types.g_PyBMapDefaultEncodings:
|
|
||||||
item = encodings.add()
|
|
||||||
item.encoding = default_enc
|
|
||||||
|
|
||||||
def register() -> None:
|
def register() -> None:
|
||||||
bpy.utils.register_class(BBP_PG_bmap_encoding)
|
bpy.utils.register_class(BBP_PG_bmap_encoding)
|
||||||
bpy.utils.register_class(BBP_UL_bmap_encoding)
|
bpy.utils.register_class(BBP_UL_bmap_encoding)
|
||||||
bpy.utils.register_class(BBP_PG_ptrprop_resolver)
|
bpy.utils.register_class(BBP_PG_ptrprop_resolver)
|
||||||
|
|
||||||
# register ioport encodings default value
|
|
||||||
bpy.app.handlers.load_post.append(_ioport_encodings_initializer)
|
|
||||||
|
|
||||||
bpy.utils.register_class(BBP_OT_add_ioport_encodings)
|
bpy.utils.register_class(BBP_OT_add_ioport_encodings)
|
||||||
bpy.utils.register_class(BBP_OT_rm_ioport_encodings)
|
bpy.utils.register_class(BBP_OT_rm_ioport_encodings)
|
||||||
bpy.utils.register_class(BBP_OT_up_ioport_encodings)
|
bpy.utils.register_class(BBP_OT_up_ioport_encodings)
|
||||||
@ -253,9 +250,6 @@ def unregister() -> None:
|
|||||||
bpy.utils.unregister_class(BBP_OT_rm_ioport_encodings)
|
bpy.utils.unregister_class(BBP_OT_rm_ioport_encodings)
|
||||||
bpy.utils.unregister_class(BBP_OT_add_ioport_encodings)
|
bpy.utils.unregister_class(BBP_OT_add_ioport_encodings)
|
||||||
|
|
||||||
# unregister ioport encodings default value
|
|
||||||
bpy.app.handlers.load_post.remove(_ioport_encodings_initializer)
|
|
||||||
|
|
||||||
bpy.utils.unregister_class(BBP_PG_ptrprop_resolver)
|
bpy.utils.unregister_class(BBP_PG_ptrprop_resolver)
|
||||||
bpy.utils.unregister_class(BBP_UL_bmap_encoding)
|
bpy.utils.unregister_class(BBP_UL_bmap_encoding)
|
||||||
bpy.utils.unregister_class(BBP_PG_bmap_encoding)
|
bpy.utils.unregister_class(BBP_PG_bmap_encoding)
|
||||||
|
@ -340,6 +340,14 @@ class VirtoolsParams():
|
|||||||
translation_context = 'BBP/UTIL_ioport_shared.VirtoolsParams/property'
|
translation_context = 'BBP/UTIL_ioport_shared.VirtoolsParams/property'
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
|
|
||||||
|
def preset_vt_encodings_if_possible(self, context: bpy.types.Context):
|
||||||
|
"""
|
||||||
|
Set preset value for Virtools Encoding list if there is no value inside it.
|
||||||
|
"""
|
||||||
|
ptrprops = PROP_ptrprop_resolver.PropsVisitor(context.scene)
|
||||||
|
if len(ptrprops.get_ioport_encodings()) == 0:
|
||||||
|
ptrprops.preset_ioport_encodings()
|
||||||
|
|
||||||
def draw_virtools_params(self, context: bpy.types.Context, layout: bpy.types.UILayout, is_importer: bool) -> None:
|
def draw_virtools_params(self, context: bpy.types.Context, layout: bpy.types.UILayout, is_importer: bool) -> None:
|
||||||
header: bpy.types.UILayout
|
header: bpy.types.UILayout
|
||||||
body: bpy.types.UILayout
|
body: bpy.types.UILayout
|
||||||
@ -364,7 +372,6 @@ class VirtoolsParams():
|
|||||||
if self.use_compress:
|
if self.use_compress:
|
||||||
body.prop(self, 'compress_level')
|
body.prop(self, 'compress_level')
|
||||||
|
|
||||||
|
|
||||||
def general_get_vt_encodings(self, context: bpy.types.Context) -> tuple[str, ...]:
|
def general_get_vt_encodings(self, context: bpy.types.Context) -> tuple[str, ...]:
|
||||||
# get from ptrprop resolver then filter empty item
|
# get from ptrprop resolver then filter empty item
|
||||||
ptrprops = PROP_ptrprop_resolver.PropsVisitor(context.scene)
|
ptrprops = PROP_ptrprop_resolver.PropsVisitor(context.scene)
|
||||||
|
Reference in New Issue
Block a user