Blenderforum

Normale Version: Python Programmierung: Enum Operator
Du siehst gerade eine vereinfachte Darstellung unserer Inhalte. Normale Ansicht mit richtiger Formatierung.
Hallo zusammen!  :-) 

ich erstelle gerade ein Addon mit dem ich automatisch einen Text hinzufüge und noch diverse andere Features ausführen möchte.
Eines davon ist die Auswahl von Schriftarten in einem Dropdown-Menü. 
Nun möchte ich gerne, dass im Dropdownmenü eine Vorschau der Schriftart erscheint, indem ich dem Text im Dropdownmenü schon die Textart zuweise.
Dafür dachte ich mir müsste man im Item irgendwie eine Font implementieren können. Ich hoffe es ist verständlich was ich meine. :-)
Wisst ihr, ob das möglich ist oder kann man die Schriftarten, die es in der GUI anzeigt, nicht ändern?

Hier hab ich schon mal nen Teil des Codes eingefügt, ganz unten sind dann eben die 3 items aufgelistet.
Später beim Execute weise ich dann den Variablen mit einer if-Funktion die verschiedenen Schriftarten zu.

Danke schon mal für eure Hilfe!


import bpy


class OBJECT_PT_TextTool(bpy.types.Panel):
    bl_label = "Text Tool"
    bl_idname = "OBJECT_PT_texttool"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Text Tool"
   

    def draw(self, context):
        layout = self.layout
        row = layout.row()
        row = layout.row()
        row = layout.split(factor= 0.05)
        row.label(text= "")
        row.operator("wm.textopbasic", text= "Add Text", icon= 'OUTLINER_OB_FONT')



class OBJECT_PT_Spacing(bpy.types.Panel):
    bl_label = "Spacing"
    bl_idname = "OBJECT_PT_spacing"
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "Text Tool"
    bl_parentid = "OBJECT_PT_texttool"
    bl_options = {"DEFAULT_CLOSED"}
   

    def draw(self, context):
        layout = self.layout
        text = context.object.data

        row = layout.row()
        row.label(text= "Set the Spacing Options")
       
        row = layout.split(factor= 0.45)
        row.label(text= "Character:")
        row.prop(text, "space_character", text= "")

        row = layout.split(factor= 0.45)
        row.label(text= "Word:")
        row.prop(text, "space_word", text= "")
       
        row = layout.split(factor= 0.45)
        row.label(text= "Line:")
        row.prop(text, "space_line", text= "")
       
class WM_OT_textOpBasic(bpy.types.Operator):
    """Open the Text Tool Dialog Box"""
    bl_idname = "wm.textopbasic"
    bl_label = "                            Text Tool Operator"
   

   
    text : bpy.props.StringProperty(name="Enter Text", default="")
   
    textfont : bpy.props.EnumProperty(name = "Text font", description = "Choose text font",
    items = [
              ('TF1', "Font1", "Textfont 1"),
              ('TF2', "Font2", "Textfont 2"),   
              ('TF3', "Font3", "Textfont 3") 
             
              ] )