bpy.types.Operator property "bl_property" does not work as expected #84563

Closed
opened 2021-01-10 06:17:52 +01:00 by Casey Connor · 14 comments

System Information
Operating system: Linux-5.8.0-36-generic-x86_64-with-debian-bullseye-sid 64 Bits
Graphics card: GeForce GTX 1060 6GB/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 450.102.04

Blender Version
Broken: version: 2.92.0 Alpha, branch: master, commit date: 2021-01-09 14:02, hash: 6154aa1529
Worked: not sure -- also broken in 2.91 and I believe earlier versions

Short description of error

setting bl_property on an Operator in a script does not seem to focus input field as expected

Exact steps for others to reproduce the error

This documentation for an Operator suggests that "bl_property" will be used to "select the default property when expanding an operator into a menu", which I believe to understand means that that property will be focused and ready for keyboard input.

• start blender with a fresh config directory
• enable Developer Extras in prefs->Interface
• open a text editor, paste in the script below
• run the script
• hit F3, enter "object.dialog_operator" and execute it
• observe that dialog appears, but float field is not focused, despite bl_property = "my_float"

If I have misunderstood something, my apologies; I have struggled to figure out how to make a property field focused and ready for input so that mousing to the field is not required, and this is the only thing I have found by internet searching. I have asked around and nobody seems to know how to do it, so I thought it was a bug.

import bpy
from bpy.props import *

class DialogOperator(bpy.types.Operator):
    bl_idname = "object.dialog_operator"
    bl_label = "Simple Dialog Operator"
    bl_property = "my_float"

    my_float = FloatProperty(name="Some Floating Point")

    def execute(self, context):
        return {'FINISHED'}

    def invoke(self, context, event):
        return context.window_manager.invoke_props_dialog(self)

def register():
    bpy.utils.register_class(DialogOperator)

def unregister():
    bpy.utils.unregister_class(DialogOperator)

if __name__ == "__main__":
    register()
**System Information** Operating system: Linux-5.8.0-36-generic-x86_64-with-debian-bullseye-sid 64 Bits Graphics card: GeForce GTX 1060 6GB/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 450.102.04 **Blender Version** Broken: version: 2.92.0 Alpha, branch: master, commit date: 2021-01-09 14:02, hash: `6154aa1529` Worked: not sure -- also broken in 2.91 and I believe earlier versions **Short description of error** setting bl_property on an Operator in a script does not seem to focus input field as expected **Exact steps for others to reproduce the error** [This documentation ](https://docs.blender.org/api/current/bpy.types.Operator.html#bpy.types.Operator.bl_property) for an Operator suggests that "bl_property" will be used to "select the default property when expanding an operator into a menu", which I believe to understand means that that property will be focused and ready for keyboard input. • start blender with a fresh config directory • enable Developer Extras in prefs->Interface • open a text editor, paste in the script below • run the script • hit F3, enter "object.dialog_operator" and execute it • observe that dialog appears, but float field is not focused, despite bl_property = "my_float" If I have misunderstood something, my apologies; I have struggled to figure out how to make a property field focused and ready for input so that mousing to the field is not required, and this is the only thing I have found by internet searching. I have asked around and nobody seems to know how to do it, so I thought it was a bug. ``` import bpy from bpy.props import * class DialogOperator(bpy.types.Operator): bl_idname = "object.dialog_operator" bl_label = "Simple Dialog Operator" bl_property = "my_float" my_float = FloatProperty(name="Some Floating Point") def execute(self, context): return {'FINISHED'} def invoke(self, context, event): return context.window_manager.invoke_props_dialog(self) def register(): bpy.utils.register_class(DialogOperator) def unregister(): bpy.utils.unregister_class(DialogOperator) if __name__ == "__main__": register() ```
Author

Added subscriber: @clepsydrae

Added subscriber: @clepsydrae
Member

Added subscriber: @filedescriptor

Added subscriber: @filedescriptor
Member

Changed status from 'Needs Triage' to: 'Archived'

Changed status from 'Needs Triage' to: 'Archived'
Member

From what I understand in the documentation, bl_property is used by bpy.types.Menu to select the property. I don't think this will work with dialogues the way you are trying to use it. Either way, this is not a bug.
If you need help learning or using Blender, please post a question on one of our [community websites ]], for instance https:*blender.stackexchange.com/ , https:*blenderartists.org/ or the [ https:*blender.chat/channel/support | #support channel on Blender chat . The bug tracker is only for bug reports.
Closing.

From what I understand in the documentation, `bl_property` is used by `bpy.types.Menu` to select the property. I don't think this will work with dialogues the way you are trying to use it. Either way, this is not a bug. If you need help learning or using Blender, please post a question on one of our [community websites ]], for instance [[ https:*blender.stackexchange.com/ | Blender's StackExchange ]], [[ https:*blenderartists.org/ | blenderartists.org ]] or the [[ https:*blender.chat/channel/support | #support channel on Blender chat ](https:*www.blender.org/community/). The bug tracker is only for bug reports. Closing.
Author

Added subscriber: @brecht

Added subscriber: @brecht
Author

Thanks -- I did ask on both belnderartists and stackexchange to no avail.

Here @brecht says that it is appropriate for use in an operator dialog: https://devtalk.blender.org/t/how-to-make-field-focused-in-props-dialog/2158/2

...hence I reported it as a bug. And it does in fact work for StringProperty, I have now learned, but not for FloatProperty. This feels like a bug to me, but I don't know enough to make that case.

Thanks -- I did ask on both belnderartists and stackexchange to no avail. Here @brecht says that it is appropriate for use in an operator dialog: https://devtalk.blender.org/t/how-to-make-field-focused-in-props-dialog/2158/2 ...hence I reported it as a bug. And it does in fact work for StringProperty, I have now learned, but not for FloatProperty. This feels like a bug to me, but I don't know enough to make that case.

This indeed only works for text fields. but I would not consider that a bug.

This indeed only works for text fields. but I would not consider that a bug.
Author

Ok, thanks for chiming in. I do wish that it would work on any property -- AFAIK this means it's impossible to make an operator that pops up a dialog from a keystroke that is ready for input without requiring moving the mouse to it and clicking?

It might be nice to update/clarify the documentation. I would submit new suggested text but I am underqualified. :-) E.g. I don't know how to interpret "Currently this is only used to select the default property when expanding an operator into a menu", or whether StringProperty is the only kind of property bl_property applies to.

Anyway, thanks for looking at this.

Ok, thanks for chiming in. I do wish that it would work on any property -- AFAIK this means it's impossible to make an operator that pops up a dialog from a keystroke that is ready for input without requiring moving the mouse to it and clicking? It might be nice to update/clarify the documentation. I would submit new suggested text but I am underqualified. :-) E.g. I don't know how to interpret "Currently this is only used to select the default property when expanding an operator into a menu", or whether StringProperty is the only kind of property bl_property applies to. Anyway, thanks for looking at this.

Added subscriber: @antoine.grasset

Added subscriber: @antoine.grasset

+1 this is confusing : I just struggled an hour not understanding with I couldn't focus a float field !
This could be a little patch to make the behaviour coherent and bring some productivity improvement.

@brecht I cannot seem to find in the code source how "bl_property" will bring a string field to focus... could you point me in the general direction ?

+1 this is confusing : I just struggled an hour not understanding with I couldn't focus a float field ! This could be a little patch to make the behaviour coherent and bring some productivity improvement. @brecht I cannot seem to find in the code source how "bl_property" will bring a string field to focus... could you point me in the general direction ?

In interface_templates.c:

      /* if button is operator's default property, and a text-field, enable focus for it
       * - this is used for allowing operators with popups to rename stuff with fewer clicks
       */
      if (is_popup) {
        if ((but->rnaprop == op->type->prop) && (but->type == UI_BTYPE_TEXT)) {
          UI_but_focus_on_enter_event(CTX_wm_window(C), but);
        }
      }
In `interface_templates.c`: ``` /* if button is operator's default property, and a text-field, enable focus for it * - this is used for allowing operators with popups to rename stuff with fewer clicks */ if (is_popup) { if ((but->rnaprop == op->type->prop) && (but->type == UI_BTYPE_TEXT)) { UI_but_focus_on_enter_event(CTX_wm_window(C), but); } } ```
Author

In case anyone is as foolish as I am, I tried removing "&& (but->type == UI_BTYPE_TEXT)" just to see if it would work for float properties, and it did not. :-)

In case anyone is as foolish as I am, I tried removing "&& (but->type == UI_BTYPE_TEXT)" just to see if it would work for float properties, and it did not. :-)

Added subscriber: @TinyNick

Added subscriber: @TinyNick

I have also encountered this as an unexpected result, but I was able to find a work around converting the string to a float. I conquer that it is not a bug but maybe this would be appropriate as a feature request instead? @brecht I made a post about my findings and work around here https://blenderartists.org/t/how-to-focus-on-an-integer-in-an-operator-in-an-addon/1287896/2 but this really only seems to be an issue for beginner programmers, because it seems that if you have a robust understanding of python its a pretty simple solution.

I have also encountered this as an unexpected result, but I was able to find a work around converting the string to a float. I conquer that it is not a bug but maybe this would be appropriate as a feature request instead? @brecht I made a post about my findings and work around here https://blenderartists.org/t/how-to-focus-on-an-integer-in-an-operator-in-an-addon/1287896/2 but this really only seems to be an issue for beginner programmers, because it seems that if you have a robust understanding of python its a pretty simple solution.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#84563
No description provided.