2
$\begingroup$

I want my popups to be wider to fit the label but it seems it is limited to this width as shown with a label with ellipsis. How do I make it wider? I tried col.label(text=self.message, width=1000) but width does not work. What am I missing? Or is it possible to auto adjust like width=auto?

enter image description here

Here's this simple working popup class but with limited constant width.

import bpy
import bpy_types

class MyPopup(bpy.types.Operator):
    bl_idname = "wm.my_generic_popup"
    bl_label = "my message box"
    bl_description = "generic popup"
    bl_options = {'INTERNAL'}

    message: bpy.props.StringProperty(name="Message", default="")

    @classmethod
    def poll(cls, context: bpy_types.Context) -> bool:
        return True

    def invoke(self, context: bpy_types.Context, _: bpy.types.Event) -> set[str]:
        return context.window_manager.invoke_props_dialog(self)

    def draw(self, _: bpy_types.Context) -> None:
        layout: bpy.types.UILayout = self.layout
        col: bpy.types.UILayout = layout.column()
        col.label(text=self.message) #, width=1000) # DOES NOT WORK WITH width="1000"

    def execute(self, _: bpy_types.Context) -> set[str]:
        print("OK CLICKED")
        return {'FINISHED'}

def register() -> None:
    bpy.utils.register_class(MyPopup)

def unregister() -> None:
    bpy.utils.unregister_class(MyPopup)

def create_generic_popup(message: str) -> None:
    bpy.ops.wm.my_generic_popup('INVOKE_DEFAULT', message=message)

register()
create_generic_popup("Why is this very verry verrry verrrrry looooong text capped?")
$\endgroup$

1 Answer 1

4
$\begingroup$

use the width property of invoke_props_dialog()

context.window_manager.invoke_props_dialog(self, width=1000)

import bpy
import bpy_types

class MyPopup(bpy.types.Operator):
    bl_idname = "wm.my_generic_popup"
    bl_label = "my message box"
    bl_description = "generic popup"
    bl_options = {'INTERNAL'}

    message: bpy.props.StringProperty(name="Message", default="")

    @classmethod
    def poll(cls, context: bpy_types.Context) -> bool:
        return True

    def invoke(self, context: bpy_types.Context, _: bpy.types.Event) -> set[str]:
        return context.window_manager.invoke_props_dialog(self, width=1000)

    def draw(self, _: bpy_types.Context) -> None:
        layout: bpy.types.UILayout = self.layout
        col: bpy.types.UILayout = layout.column()
        col.label(text=self.message) #, width=1000) # DOES NOT WORK WITH width="1000"

    def execute(self, _: bpy_types.Context) -> set[str]:
        print("OK CLICKED")
        return {'FINISHED'}

def register() -> None:
    bpy.utils.register_class(MyPopup)

def unregister() -> None:
    bpy.utils.unregister_class(MyPopup)

def create_generic_popup(message: str) -> None:
    bpy.ops.wm.my_generic_popup('INVOKE_DEFAULT', message=message)

register()
create_generic_popup("Why is this very verry verrry verrrrry looooong text capped?")
$\endgroup$
3
  • $\begingroup$ Hi thank you very much for your answer! Is there also a way to auto adjust it depending on the text? Or only hard-coded? $\endgroup$
    – Megan Love
    Commented Mar 25 at 9:55
  • 1
    $\begingroup$ There is no such thing builtin. However you can work out a proportional relationship with a few tests (eg. a character takes roughly 20 pixels so if you have 20 characters you need at least 400 width or something like that). Note this will still be very weak and break if users use a different UI scale or a different alphabet I guess. $\endgroup$
    – Gorgious
    Commented Mar 25 at 10:18
  • $\begingroup$ @Gorgious yes exactly what I'm currently experimenting now haha thank you for confirming this limitation :) $\endgroup$
    – Megan Love
    Commented Mar 25 at 10:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .