bpy.ops.screen.userpref_show() not Working #77000

Closed
opened 2020-05-23 19:15:13 +02:00 by Frank Hilton · 17 comments

System Information
Operating system: Win 10
Graphics card: Nivida GForce RTX 2060

Blender Version
Broken: (version: 2.82a (sub 7), branch: master, commit date: 2020-03-12 05:06, hash: 375c7dc4ca, type: Release
build date: 2020-03-12, 15:41:08)
Worked:: ?

Short description of error
Using "bpy.ops.screen.userpref_show()" in a script or add-on button doesn't display the Preference window at all.

I know the button works because I used another command and the command executed fine.
It also doesn't work in script editor either

Exact steps for others to reproduce the error
Got command from right-clicking and copying command off of preferences menu.
add "bpy.ops.screen.userpref_show()" to script or operator button

**System Information** Operating system: Win 10 Graphics card: Nivida GForce RTX 2060 **Blender Version** Broken: (version: 2.82a (sub 7), branch: master, commit date: 2020-03-12 05:06, hash: 375c7dc4caf4, type: Release build date: 2020-03-12, 15:41:08) Worked:: ? **Short description of error** Using "bpy.ops.screen.userpref_show()" in a script or add-on button doesn't display the Preference window at all. I know the button works because I used another command and the command executed fine. It also doesn't work in script editor either **Exact steps for others to reproduce the error** Got command from right-clicking and copying command off of preferences menu. add "bpy.ops.screen.userpref_show()" to script or operator button
Author

Added subscriber: @Pixelink

Added subscriber: @Pixelink
Member

Added subscriber: @Calra

Added subscriber: @Calra
Member

Can confirm, will wait for others to confirm it is a bug and not intended behavior.

Can confirm, will wait for others to confirm it is a bug and not intended behavior.

This issue was referenced by 8e4c74292a

This issue was referenced by 8e4c74292a76b7e22aafb63c65d474fa9d886001
Member

Added subscriber: @JulianEisel

Added subscriber: @JulianEisel
Member

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'
Member

I see why the operator wouldn't execute from the Python console. But it works fine if I execute it from a script or button.

Could you upload the failing code here? I have a fix ready but would like to know why it doesn't work from a button for you.

(For triagers: Please don't close this without checking with me first.)

I see why the operator wouldn't execute from the Python console. But it works fine if I execute it from a script or button. Could you upload the failing code here? I have a fix ready but would like to know why it doesn't work from a button for you. (For triagers: Please don't close this without checking with me first.)
Author

This is the code to the operator.
As I stated earlier, I know the button works because I put different commands in. Eliminated if it was my coding in the panel of my add on.

INIT

import bpy
from . filefuncs import PREF_OT_Operator

classes = (PREF_OT_Operator, QTASK_PT_Panel)

def register():
    for cls in classes:
        bpy.utils.register_class(cls)
        bpy.types.Scene.my_tool = bpy.props.PointerProperty(type=My_Settings)

def unregister():
    del bpy.types.Scene.my_tool
    for cls in reversed(classes):
        bpy.utils.unregister_class(cls)

PANEL (qtpanel.py)
row.operator('viewed3d.file_preferences', text="", icon="PREFERENCES")



OPERATOR (filefunc.py)

class PREF_OT_Operator(bpy.types.Operator):
    bl_idname = "viewed3d.file_preferences"
    bl_label = "Preferences"
    bl_description = "Preferences"

    def execute(self, context):
        bpy.ops.screen.userpref_show()
        return {'FINISHED'}
This is the code to the operator. As I stated earlier, I know the button works because I put different commands in. Eliminated if it was my coding in the panel of my add on. _INIT_ ``` import bpy from . filefuncs import PREF_OT_Operator classes = (PREF_OT_Operator, QTASK_PT_Panel) def register(): for cls in classes: bpy.utils.register_class(cls) bpy.types.Scene.my_tool = bpy.props.PointerProperty(type=My_Settings) def unregister(): del bpy.types.Scene.my_tool for cls in reversed(classes): bpy.utils.unregister_class(cls) ``` PANEL (qtpanel.py) row.operator('viewed3d.file_preferences', text="", icon="PREFERENCES") ``` ``` OPERATOR (filefunc.py) ``` class PREF_OT_Operator(bpy.types.Operator): bl_idname = "viewed3d.file_preferences" bl_label = "Preferences" bl_description = "Preferences" def execute(self, context): bpy.ops.screen.userpref_show() return {'FINISHED'} ```
Author

Here is a link to the entire addon if you want to download the zip
However, the version on the website has that button commented out

QuickTasks Addon

Here is a link to the entire addon if you want to download the zip However, the version on the website has that button commented out [QuickTasks Addon ](https://pixelinkmedia.pixnk.com/quicktasks.php)
Author

BTW... this is the error I get in the console...

ERROR (wm.operator): c:\b\win64_cmake_vs2017\win64_cmake_vs2017\blender.git\source\blender\windowmanager\intern\wm_event_system.c:1486 wm_operator_invoke: invalid operator call 'SCREEN_OT_userpref_show'

BTW... this is the error I get in the console... > ERROR (wm.operator): c:\b\win64_cmake_vs2017\win64_cmake_vs2017\blender.git\source\blender\windowmanager\intern\wm_event_system.c:1486 wm_operator_invoke: invalid operator call 'SCREEN_OT_userpref_show'
Member

Changed status from 'Needs User Info' to: 'Resolved'

Changed status from 'Needs User Info' to: 'Resolved'
Julian Eisel self-assigned this 2020-05-24 16:15:24 +02:00
Member

The reason this did not work is because the operator uses the invoke() function, so that there's an event to take the cursor position from. This cursor position is used to determine the window position.
So you were actually able to call the operator, but you had to call it in the invoke context: bpy.ops.screen.userpref_show('INVOKE_DEFAULT').

We can however get the cursor position differently and always use the execute() function then, which is what I've done now.

Also, since I've seen this mistake a few times recently: You don't need to create an operator in your example. screen.userpref_show() already is an operator and it can assigned to a button directly, e.g. layout.operator("screen.userpref_show").

The reason this did not work is because the operator uses the `invoke()` function, so that there's an event to take the cursor position from. This cursor position is used to determine the window position. So you were actually able to call the operator, but you had to call it in the invoke context: `bpy.ops.screen.userpref_show('INVOKE_DEFAULT')`. We can however get the cursor position differently and always use the `execute()` function then, which is what I've done now. Also, since I've seen this mistake a few times recently: You don't need to create an operator in your example. `screen.userpref_show()` already is an operator and it can assigned to a button directly, e.g. `layout.operator("screen.userpref_show")`.
Author

Okay... I will give it a try... Thanks

Okay... I will give it a try... Thanks
Member

Cool, it fixes info_log_show() and others as well, was about to ask.

Cool, it fixes `info_log_show()` and others as well, was about to ask.
Member

Added subscriber: @Harley

Added subscriber: @Harley
Member

@JulianEisel - cursor position is used to determine the window position.

Any idea why?

I can understand why we position our little "OK?" alerts close to the mouse pointer, but I can't see why the positioning of new windows would want to be influenced by the position of the mouse when you invoked it. You'd think we'd just want to initially center a new window using the bounds of the previous one. And then you wouldn't need an xy for WM_window_open_temp() and so don't need to use invoke.

If you look at that positioning logic as it is now it seems jankey anyway and would generally get you a left position that is off the screen and would just be corrected by the following wm_window_check_position(). Which is why Preferences is almost always hugging the left side of the monitor. The File Browser only centers nicely because it doesn't actually use the mouse position at all but just pretends the mouse is at screen center instead.

> @JulianEisel - cursor position is used to determine the window position. Any idea why? I can understand why we position our little "OK?" alerts close to the mouse pointer, but I can't see why the positioning of new windows would want to be influenced by the position of the mouse when you invoked it. You'd think we'd just want to initially center a new window using the bounds of the previous one. And then you wouldn't need an xy for WM_window_open_temp() and so don't need to use invoke. If you look at that positioning logic as it is now it seems jankey anyway and would generally get you a left position that is off the screen and would just be corrected by the following wm_window_check_position(). Which is why Preferences is almost always hugging the left side of the monitor. The File Browser only centers nicely because it doesn't actually use the mouse position at all but just pretends the mouse is at screen center instead.
Member

I'm fine with discussing and possibly changing that. I thought about it as well but didn't want to do design changes like that without discussing first. The only reason I changed code was that there was a simple solution, so it was quick to address.

Thinking about it though, I actually find it quite "smart" that Blender places the window under your cursor. If you open the Preferences, it's usually with the intend to interact with it immediately. If it opened at the center you have to move the mouse to it first. But Blender knows where your mouse is, it can just place the window under your cursor and you can skip that part.
Maybe having a predictable window position is more important than this supposed, tiny quality of life improvement.

IIRC for the File Browser we decided to center it always, because you'd often trigger it from a more centered position and it would just look slightly out of place then. For some reason its default size or aspect ratio also made it feel odd if placed under the cursor.

Anyway, these are just my current thoughts on this. It's all up for debate.

I'm fine with discussing and possibly changing that. I thought about it as well but didn't want to do design changes like that without discussing first. The only reason I changed code was that there was a simple solution, so it was quick to address. Thinking about it though, I actually find it quite "smart" that Blender places the window under your cursor. If you open the Preferences, it's usually with the intend to interact with it immediately. If it opened at the center you have to move the mouse to it first. But Blender knows where your mouse is, it can just place the window under your cursor and you can skip that part. Maybe having a predictable window position is more important than this supposed, tiny quality of life improvement. IIRC for the File Browser we decided to center it always, because you'd often trigger it from a more centered position and it would just look slightly out of place then. For some reason its default size or aspect ratio also made it feel odd if placed under the cursor. Anyway, these are just my current thoughts on this. It's all up for debate.
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#77000
No description provided.