1
$\begingroup$

I see no "bl_label" in "AddonPreferences" in the Blender API. One of the buttons in my AddonPreferences is "Preferences" and it would be nice to remove the default "Preferences" bl_label. Please, tell me there is a simple, python way, to remove this, that I can add to my addon scripting.
I've tried adding:

bl_label = ""

To no avail, it still shows as seen below.

enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$

It's hardcoded in user prefs UI.

Agree it is a wasted line of space and have also looked into removing it.

Unfortunately the label is hardcoded in the user preferences space UI and used in the USERPREF_PT_addons panel which displays the addons in the user preferences.

Snippet from scripts/startup/bl_ui/space_userprefs.py

# Show addon user preferences
if is_enabled:
    addon_preferences = prefs.addons[module_name].preferences
    if addon_preferences is not None:
        draw = getattr(addon_preferences, "draw", None)
        if draw is not None:
            addon_preferences_class = type(addon_preferences)
            box_prefs = col_box.box()
            box_prefs.label(text="Preferences:")  ## <<------ HERE
            addon_preferences_class.layout = box_prefs
            try:
                draw(context)
            except:
                import traceback
                traceback.print_exc()
                box_prefs.label(text="Error (see console)", icon='ERROR')
            del addon_preferences_class.layout

which shows how the label is added to the UI layout box to draw into, using the draw method of your addon preferences class.

Options,

can edit it out in code above, and save over the original. Wouldn't recommend changing the UI code this way. Although in this case searching for box_prefs.label(text="Preferences:") in script to insert a hash comment character could be offered up to the user, who like us would like it gone.

Override with changes.

enter image description here

Make a class based on this one, with desired edits, and override by unregistering old, registering new, to override the old.

Silly example, image above. Re-write the draw method and reregister new class using it.

import bpy
from bl_ui.space_userpref import USERPREF_PT_addons

# unregister
if USERPREF_PT_addons.is_registered:
    bpy.utils.unregister_class(USERPREF_PT_addons)
    
def draw(self, context):
    self.layout.label(text="My New Addons Draw")
    
    
cls = type(
        "MyNewAddonsPrefs",
        (USERPREF_PT_addons, bpy.types.Panel),
        {
            "bl_idname" :  "USERPREF_PT_addons",
            "draw" :  draw,
            },
        )
        
bpy.utils.register_class(cls) 

Related

How to re-register a built-in operator?

Note.

One very handy little "trick" shown in snippet above is how the layout of the userprefs is "monkey patched" onto your addon prefs class, so within your addon prefs draw self.layout is the UI layout box.

$\endgroup$
1
  • $\begingroup$ Added a basic example, using old with own draw method. ie can re-use any or all of the original panel class. There are other ways to programmatically get the code string of the original draw method, make changes, compile the snippet. There is an old answer floating around re similar to changing the UI. (Suggestion since you're changing one part would be tempted to make the info area of an addon a panel popover. $\endgroup$
    – batFINGER
    May 7, 2021 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.