diff --git a/__init__.py b/__init__.py index a4242e3..c2ccfa1 100644 --- a/__init__.py +++ b/__init__.py @@ -148,33 +148,47 @@ class ABC3D_glyph_properties(bpy.types.PropertyGroup): description="Letter Spacing", ) + class ABC3D_text_properties(bpy.types.PropertyGroup): - def font_name_items(self, context): - out = [] - for f in Font.fonts.keys(): - out.append((f, f, "A Font")) - return tuple(out) - def face_name_items(self, context): - out = [] - for ff in Font.fonts[self.font_lol].faces.keys(): - out.append((ff, ff, "A Face")) - return tuple(out) - def font_name_update_callback(self, context): - self.face_lol = Font.fonts[self.font_lol].faces.keys()[0] - update_callback(self, context) + + def font_items_callback(self, context): + items = [] + for f in Font.get_loaded_fonts_and_faces(): + items.append((f"{f[0]} {f[1]}", f"{f[0]} {f[1]}", "")) + return items + + def font_default_callback(self, context): + d = context.scene.abc3d_data + items = self.font_items_callback(context) + if len(d.available_fonts) > 0: + if len(d.available_fonts) > d.active_text_index: + f = d.available_fonts[d.active_text_index] + return 0 #f"{f.font_name} {f.face_name}" + else: + f = d.available_fonts[0] + return 0 #f"{f.font_name} {f.face_name}" + + if type(self.font_name) != type(None) and type(self.face_name) != type(None): + return 0 #f"{self.font_name} {self.face_name}" + else: + return 0 #"" + def update_callback(self, context): butils.set_text_on_curve(self) + + def font_update_callback(self, context): + font_name, face_name = self.font.split(" ") + self.font_name = font_name + self.face_name = face_name + self.update_callback(context) + text_id: bpy.props.IntProperty() + font: bpy.props.EnumProperty( + items=font_items_callback, + update=font_update_callback, + ) font_name: bpy.props.StringProperty() face_name: bpy.props.StringProperty() - font_lol: bpy.props.EnumProperty( - items=font_name_items, - update=font_name_update_callback - ) - face_lol: bpy.props.EnumProperty( - items=face_name_items, - update=update_callback - ) text_object: bpy.props.PointerProperty(type=bpy.types.Object) text: bpy.props.StringProperty( update=update_callback @@ -466,6 +480,33 @@ class ABC3D_PT_TextPropertiesPanel(bpy.types.Panel): return t return None + # def font_items_callback(self, context): + # items = [] + # fonts = Font.get_loaded_fonts_and_faces() + # for f in fonts: + # items.append((f"{f[0]} {f[1]}", f"{f[0]} {f[1]}", "")) + # return items + + # def font_default_callback(self, context): + # t = self.get_active_text_properties(self) + # if type(t) != type(None): + # return f"{t.font_name} {t.face_name}" + # else: + # return None + + # def font_update_callback(self, context): + # font_name, face_name = self.font.split(" ") + # t = self.get_active_text_properties(self) + # t.font_name = font_name + # t.face_name = face_name + # butils.set_text_on_curve(t) + + # font: bpy.props.EnumProperty( + # items=font_items_callback, + # default=font_default_callback, + # update=font_update_callback, + # ) + @classmethod def poll(self,context): return type(self.get_active_text_properties(self)) != type(None) @@ -486,6 +527,7 @@ class ABC3D_PT_TextPropertiesPanel(bpy.types.Panel): return layout.label(text=f"Mom: {props.text_object.name}") + layout.row().prop(props, "font") layout.row().prop(props, "text") layout.row().prop(props, "letter_spacing") layout.row().prop(props, "font_size") @@ -675,6 +717,7 @@ class ABC3D_OT_PlaceText(bpy.types.Operator): def invoke(self, context, event): wm = context.window_manager + self.font_update_callback(context) return wm.invoke_props_dialog(self) def execute(self, context):