load installed fonts, fix some minor loading issues
This commit is contained in:
parent
8ce5e6c816
commit
0bf80e01b2
3 changed files with 69 additions and 20 deletions
52
__init__.py
52
__init__.py
|
@ -262,11 +262,16 @@ class ABC3D_PT_Panel(bpy.types.Panel):
|
|||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
layout.label(text=f"{__name__} panel")
|
||||
icon = 'NONE'
|
||||
if len(context.scene.abc3d_data.available_fonts) == 0:
|
||||
icon = 'ERROR'
|
||||
layout.row().label(text='no fonts loaded yet')
|
||||
|
||||
layout.operator(f"{__name__}.load_installed_fonts", text="load installed fonts", icon=icon)
|
||||
|
||||
|
||||
class ABC3D_PT_LoadFontPanel(bpy.types.Panel):
|
||||
bl_label = "Load a new font"
|
||||
bl_label = "Install a new font"
|
||||
bl_parent_id = "ABC3D_PT_Panel"
|
||||
bl_category = "ABC3D"
|
||||
bl_space_type = "VIEW_3D"
|
||||
|
@ -281,9 +286,9 @@ class ABC3D_PT_LoadFontPanel(bpy.types.Panel):
|
|||
abc3d = scene.abc3d
|
||||
abc3d_data = scene.abc3d_data
|
||||
|
||||
layout.label(text="Load FontFile:")
|
||||
layout.label(text="Install FontFile:")
|
||||
layout.row().prop(abc3d, "font_path")
|
||||
layout.row().operator('abc3d.loadfont', text='Load Font')
|
||||
layout.row().operator(f"{__name__}.loadfont", text='Load Font')
|
||||
|
||||
|
||||
class ABC3D_PT_FontList(bpy.types.Panel):
|
||||
|
@ -497,13 +502,6 @@ class ABC3D_OT_LoadFont(bpy.types.Operator):
|
|||
def execute(self, context):
|
||||
scene = bpy.context.scene
|
||||
|
||||
butils.ShowMessageBox(
|
||||
title=f"{__name__} Warning",
|
||||
icon="ERROR",
|
||||
message=f"We believe this functionality is currently not available.",
|
||||
)
|
||||
return {'CANCELLED'}
|
||||
|
||||
if not os.path.exists(scene.abc3d.font_path):
|
||||
butils.ShowMessageBox(
|
||||
title=f"{__name__} Warning",
|
||||
|
@ -516,6 +514,27 @@ class ABC3D_OT_LoadFont(bpy.types.Operator):
|
|||
|
||||
return {'FINISHED'}
|
||||
|
||||
class ABC3D_OT_LoadInstalledFonts(bpy.types.Operator):
|
||||
"""Load installed fontfiles from datapath."""
|
||||
bl_idname = f"{__name__}.load_installed_fonts"
|
||||
bl_label = "Loading installed Fonts."
|
||||
bl_options = {'REGISTER', 'UNDO'}
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
layout.label(text="Loading font files can take a long time.")
|
||||
|
||||
def invoke(self, context, event):
|
||||
return context.window_manager.invoke_props_dialog(self)
|
||||
|
||||
def execute(self, context):
|
||||
scene = bpy.context.scene
|
||||
|
||||
butils.load_installed_fonts()
|
||||
butils.update_available_fonts()
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
class ABC3D_OT_AddDefaultMetrics(bpy.types.Operator):
|
||||
"""Add default metrics to selected objects"""
|
||||
bl_idname = f"{__name__}.add_default_metrics"
|
||||
|
@ -735,9 +754,12 @@ class ABC3D_OT_SaveFontToFile(bpy.types.Operator):
|
|||
for obj in fontcollection.objects:
|
||||
if obj["font_name"] == selected_font.font_name:
|
||||
if not butils.is_metrics_object(obj):
|
||||
# butils.add_faces_to_metrics(obj)
|
||||
obj.select_set(True)
|
||||
export_objects.append(obj)
|
||||
else:
|
||||
obj.select_set(True)
|
||||
butils.add_faces_to_metrics(obj)
|
||||
export_objects.append(obj)
|
||||
|
||||
context_override = bpy.context.copy()
|
||||
context_override["selected_objects"] = list(export_objects)
|
||||
|
@ -1019,6 +1041,7 @@ classes = (
|
|||
ABC3D_PT_TextManagement,
|
||||
ABC3D_PT_FontCreation,
|
||||
ABC3D_PT_TextPropertiesPanel,
|
||||
ABC3D_OT_LoadInstalledFonts,
|
||||
ABC3D_OT_AddDefaultMetrics,
|
||||
ABC3D_OT_RemoveMetrics,
|
||||
ABC3D_OT_AlignMetricsToActiveObject,
|
||||
|
@ -1038,6 +1061,7 @@ def load_handler(self, dummy):
|
|||
if not bpy.app.timers.is_registered(butils.execute_queued_functions):
|
||||
bpy.app.timers.register(butils.execute_queued_functions)
|
||||
butils.run_in_main_thread(butils.update_available_fonts)
|
||||
# butils.run_in_main_thread(bpy.ops.abc3d.load_installed_fonts)
|
||||
|
||||
def load_handler_unload():
|
||||
if bpy.app.timers.is_registered(butils.execute_queued_functions):
|
||||
|
@ -1071,9 +1095,11 @@ def register():
|
|||
bpy.app.handlers.frame_change_post.append(on_frame_changed)
|
||||
|
||||
butils.run_in_main_thread(butils.clear_available_fonts)
|
||||
butils.run_in_main_thread(butils.load_available_fonts)
|
||||
# butils.run_in_main_thread(butils.load_installed_fonts)
|
||||
butils.run_in_main_thread(butils.update_available_fonts)
|
||||
|
||||
# bpy.ops.abc3d.load_installed_fonts()
|
||||
|
||||
Font.name_to_glyph_d = Font.generate_name_to_glyph_d()
|
||||
|
||||
def unregister():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue