modal operator and dislocated button tooltip #86678

Open
opened 2021-03-17 21:24:18 +01:00 by Jakub Uhlik · 4 comments

System Information
Operating system: macOS-10.13.6-x86_64-i386-64bit 64 Bits

Blender Version
Broken: version: 2.93.0 Alpha, branch: master, commit date: 2021-03-15 19:47, hash: be51d671b5, 2.83.12 as well
Worked: ?

Short description of error
sidebar button tooltip is dislocated and does not fade out when modal operator is used with some heavier processing in background and timing is just right

Exact steps for others to reproduce the error
run simplified code and do as in video. original code uses gpu module to draw in viewport (hence tag_redraw()) and is constantly ray casting prepared bvhtree (simulated by sleep()). your timing have to be just right to get the result. i'm sorry, but it is happening very randomly. sometimes almost on each button hit, sometimes not even once.

tooltip.mp4


import time
import bpy
from bpy.types import Panel, Operator


class Manager():
    _tool = None


class A_OT_op(Operator):
    bl_idname = "a.op"
    bl_label = "Op"
    bl_description = "Op"
    
    @classmethod
    def poll(cls, context, ):
        if(context.space_data.type == 'VIEW_3D'):
            if(Manager._tool is None):
                return True
        return False
    
    def _tag_redraw(self, ):
        for window in bpy.context.window_manager.windows:
            for area in window.screen.areas:
                if(area.type == 'VIEW_3D'):
                    area.tag_redraw()
    
    def _is_viewport(self, context, event, ):
        def in_region(r):
            x = r.x
            y = r.y
            w = r.width
            h = r.height
            if(mx > x and mx < x + w):
                if(my > y and my < y + h):
                    return True
            return False
        
        for a in context.screen.areas:
            if(a.type == 'VIEW_3D'):
                mx = event.mouse_x
                my = event.mouse_y
                
                for r in a.regions:
                    if(r.type in ('TOOL_HEADER', 'HEADER', 'TOOLS', 'UI', 'HUD', )):
                        if(in_region(r)):
                            return False
                    elif(r.type == 'WINDOW'):
                        if(in_region(r)):
                            return True
        return False
    
    def modal(self, context, event, ):
        if(not self._is_viewport(context, event, )):
            context.window.cursor_modal_restore()
            return {'PASS_THROUGH'}
        else:
            context.window.cursor_modal_set('PAINT_CROSS')
            self._tag_redraw()
        
        if(event.type in {'MIDDLEMOUSE', 'WHEELUPMOUSE', 'WHEELDOWNMOUSE'}):
            # allow navigation..
            context.window.cursor_modal_restore()
            return {'PASS_THROUGH'}
        elif(event.type == 'MOUSEMOVE'):
            
            time.sleep(0.1)
            
        elif(event.type == 'LEFTMOUSE'):
            pass
        elif(event.type in {'RIGHTMOUSE', 'ESC', }):
            context.window.cursor_modal_restore()
            self._tag_redraw()
            Manager._tool = None
            return {'CANCELLED'}
        return {'RUNNING_MODAL'}
    
    def invoke(self, context, event, ):
        time.sleep(0.1)
        
        Manager._tool = self
        context.window_manager.modal_handler_add(self)
        self._tag_redraw()
        return {'RUNNING_MODAL'}


class A_PT_main(Panel):
    bl_space_type = 'VIEW_3D'
    bl_region_type = 'UI'
    bl_category = "A"
    bl_label = "A"
    bl_options = set()
    
    def draw(self, context):
        l = self.layout
        c = l.column()
        y = 2.0
        cc = c.column(align=True)
        
        r = cc.row(align=True)
        r.scale_y = y
        r.alert = True
        r.operator('a.op')
        
        r = cc.row(align=True)
        r.scale_y = y
        r.alert = True
        r.operator('a.op')
        
        r = cc.row(align=True)
        r.scale_y = y
        r.alert = True
        r.operator('a.op')
        
        r = cc.row(align=True)
        r.scale_y = y
        r.alert = True
        r.operator('a.op')
        
        r = cc.row(align=True)
        r.scale_y = y
        r.alert = True
        r.operator('a.op')        


classes = (
    A_OT_op,
    A_PT_main,
)


def register():
    for cls in classes:
        bpy.utils.register_class(cls)


def unregister():
    for cls in reversed(classes):
        bpy.utils.unregister_class(cls)


if __name__ == "__main__":
    register()

**System Information** Operating system: macOS-10.13.6-x86_64-i386-64bit 64 Bits **Blender Version** Broken: version: 2.93.0 Alpha, branch: master, commit date: 2021-03-15 19:47, hash: `be51d671b5`, 2.83.12 as well Worked: ? **Short description of error** sidebar button tooltip is dislocated and does not fade out when modal operator is used with some heavier processing in background and timing is just right **Exact steps for others to reproduce the error** run simplified code and do as in video. original code uses gpu module to draw in viewport (hence tag_redraw()) and is constantly ray casting prepared bvhtree (simulated by sleep()). your timing have to be just right to get the result. i'm sorry, but it is happening very randomly. sometimes almost on each button hit, sometimes not even once. [tooltip.mp4](https://archive.blender.org/developer/F9896897/tooltip.mp4) ``` import time import bpy from bpy.types import Panel, Operator class Manager(): _tool = None class A_OT_op(Operator): bl_idname = "a.op" bl_label = "Op" bl_description = "Op" @classmethod def poll(cls, context, ): if(context.space_data.type == 'VIEW_3D'): if(Manager._tool is None): return True return False def _tag_redraw(self, ): for window in bpy.context.window_manager.windows: for area in window.screen.areas: if(area.type == 'VIEW_3D'): area.tag_redraw() def _is_viewport(self, context, event, ): def in_region(r): x = r.x y = r.y w = r.width h = r.height if(mx > x and mx < x + w): if(my > y and my < y + h): return True return False for a in context.screen.areas: if(a.type == 'VIEW_3D'): mx = event.mouse_x my = event.mouse_y for r in a.regions: if(r.type in ('TOOL_HEADER', 'HEADER', 'TOOLS', 'UI', 'HUD', )): if(in_region(r)): return False elif(r.type == 'WINDOW'): if(in_region(r)): return True return False def modal(self, context, event, ): if(not self._is_viewport(context, event, )): context.window.cursor_modal_restore() return {'PASS_THROUGH'} else: context.window.cursor_modal_set('PAINT_CROSS') self._tag_redraw() if(event.type in {'MIDDLEMOUSE', 'WHEELUPMOUSE', 'WHEELDOWNMOUSE'}): # allow navigation.. context.window.cursor_modal_restore() return {'PASS_THROUGH'} elif(event.type == 'MOUSEMOVE'): time.sleep(0.1) elif(event.type == 'LEFTMOUSE'): pass elif(event.type in {'RIGHTMOUSE', 'ESC', }): context.window.cursor_modal_restore() self._tag_redraw() Manager._tool = None return {'CANCELLED'} return {'RUNNING_MODAL'} def invoke(self, context, event, ): time.sleep(0.1) Manager._tool = self context.window_manager.modal_handler_add(self) self._tag_redraw() return {'RUNNING_MODAL'} class A_PT_main(Panel): bl_space_type = 'VIEW_3D' bl_region_type = 'UI' bl_category = "A" bl_label = "A" bl_options = set() def draw(self, context): l = self.layout c = l.column() y = 2.0 cc = c.column(align=True) r = cc.row(align=True) r.scale_y = y r.alert = True r.operator('a.op') r = cc.row(align=True) r.scale_y = y r.alert = True r.operator('a.op') r = cc.row(align=True) r.scale_y = y r.alert = True r.operator('a.op') r = cc.row(align=True) r.scale_y = y r.alert = True r.operator('a.op') r = cc.row(align=True) r.scale_y = y r.alert = True r.operator('a.op') classes = ( A_OT_op, A_PT_main, ) def register(): for cls in classes: bpy.utils.register_class(cls) def unregister(): for cls in reversed(classes): bpy.utils.unregister_class(cls) if __name__ == "__main__": register() ```
Author

Added subscriber: @JakubUhlik

Added subscriber: @JakubUhlik
Member

Added subscriber: @OmarEmaraDev

Added subscriber: @OmarEmaraDev
Member

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'

Changed status from 'Needs Triage' to: 'Needs Developer To Reproduce'
Member

I can reproduce that. It seems the tooltip initialization is delayed due to the modal until a later time where the cursor had already moved and the event state was updated.
Though I am not sure if this would be considered a bug.

I can reproduce that. It seems the tooltip initialization is delayed due to the modal until a later time where the cursor had already moved and the event state was updated. Though I am not sure if this would be considered a bug.
Philipp Oeser removed the
Interest
User Interface
label 2023-02-10 09:23:32 +01:00
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
2 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#86678
No description provided.