0
$\begingroup$

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

Should be giving me a popup window that is 400 wide, but it isn’t. At least not right away:

https://www.youtube.com/watch?v=wF7U3YWBTvE

I made this toolbar icon viewer to help with my custom pie menu operator. Click the icon, it sets a string to a name that the user can copy-paste into the keymap. This will make the custom pie menu use an icon from the toolbar as well as the usual icon viewer. It’s all functional and good, my issue is the formatting of the popup for the tool icon viewer. I like that it is a floating window, I don’t want it to be like the other icon viewer. When it first pops up, the width is equal to whatever the width of the python console is, instead of 400 like it is supposed to be. If you move the mouse around in the popup window, it will eventually settle down and adjust itself to the correct width, very gradually in steps. How to avoid this awkwardness?

Here’s what I’ve modified in: \scripts\addons\development_icon_get.py

def draw_console_header(self, context):
    if not prefs().show_header:
        return
    self.layout.operator(IV_OT_icons_show.bl_idname)
    self.layout.operator(IV_OT_tool_icons_show.bl_idname)
class IV_OT_tool_icons_show(bpy.types.Operator):
    bl_idname = "iv.tool_icons_show"
    bl_label = "Toolbar Icon Viewer"

    def draw(self, context):
        layout = self.layout
        from bl_ui.space_toolsystem_common import ToolSelectPanelHelper
        inputs = context.preferences.inputs
        
        row = layout.row(align=True)
        row.prop(inputs, "tool_icon")
        row.separator_spacer()
        row.separator_spacer()
        row.separator_spacer()
        row.prop(inputs, "tool_section")
        row = layout.row(align=True)
        row.separator(factor=1.5)
        row = layout.row(align=True)

        if inputs.tool_section == 'OBJECT':
            row.operator("icon.generic_select", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.generic.select"), emboss=False)
            row.operator("icon.generic_select_box", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.generic.select_box"), emboss=False)
            row.operator("icon.generic_select_circle", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.generic.select_circle"), emboss=False)
            row.operator("icon.generic_select_lasso", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.generic.select_lasso"), emboss=False)
            row.operator("icon.generic_cursor", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.generic.cursor"), emboss=False)
            row.operator("icon.transform_translate", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.transform.translate"), emboss=False)
            row.operator("icon.transform_rotate", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.transform.rotate"), emboss=False)
            row.operator("icon.transform_resize", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.transform.resize"), emboss=False)
            row.operator("icon.transform_resize_cage", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.transform.resize.cage"), emboss=False)
            row.operator("icon.transform_transform", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.transform.transform"), emboss=False)
            row = layout.row(align=True)
            row.separator(factor=0.25)
            row = layout.row(align=True)
            row.operator("icon.gpencil_draw", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.gpencil.draw"), emboss=False)
            row.operator("icon.gpencil_draw_line", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.gpencil.draw.line"), emboss=False)
            row.operator("icon.gpencil_draw_poly", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.gpencil.draw.poly"), emboss=False)
            row.operator("icon.gpencil_draw_eraser", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.gpencil.draw.eraser"), emboss=False)
            row.operator("icon.view3d_ruler", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.view3d.ruler"), emboss=False)
            row.operator("icon.mesh_primitive_cube_add_gizmo", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.mesh.primitive_cube_add_gizmo"), emboss=False)
            row.operator("icon.mesh_primitive_cone_add_gizmo", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.mesh.primitive_cone_add_gizmo"), emboss=False)
            row.operator("icon.mesh_primitive_cylinder_add_gizmo", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.mesh.primitive_cylinder_add_gizmo"), emboss=False)
            row.operator("icon.mesh_primitive_sphere_add_gizmo", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.mesh.primitive_sphere_add_gizmo"), emboss=False)
            row.operator("icon.mesh_primitive_torus_add_gizmo", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.mesh.primitive_torus_add_gizmo"), emboss=False)
            row = layout.row(align=True)
            row.separator(factor=0.25)
            row = layout.row(align=True)
            row.operator("icon.mesh_primitive_grid_add_gizmo", icon_value=ToolSelectPanelHelper()._icon_value_from_icon_handle("ops.mesh.primitive_grid_add_gizmo"), emboss=False)

        elif inputs.tool_section == 'MESH':

        # and on and on, up to 168 toolbar icons get drawn here


    def close(self):
        bpy.context.window.screen = bpy.context.window.screen

    def cancel(self, context):
        IV_OT_tool_icons_show.instance = None

    def execute(self, context):
        if not IV_OT_tool_icons_show.instance:
            return {'CANCELLED'}
        IV_OT_tool_icons_show.instance = None

        return {'FINISHED'}

    def invoke(self, context, event):
        IV_OT_tool_icons_show.instance = self

        return context.window_manager.invoke_props_dialog(
            self, width=400)

$\endgroup$

1 Answer 1

0
$\begingroup$

row.separator_spacer() makes it do that weird adjustment thing. row.separator(factor=5.0) works good for what I needed.

row = layout.row(align=True)
row.prop(inputs, "tool_icon")
row.separator(factor=5.0)
row.prop(inputs, "tool_section")
row = layout.row(align=True)

if inputs.tool_section == 'OBJECT':
$\endgroup$

You must log in to answer this question.

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