Page MenuHome

2.8: Python API: window's workspace can't be set in Application timer
Confirmed, NormalPublicKNOWN ISSUE


System Information
Operating system: Darwin-18.7.0-x86_64-i386-64bit 64 Bits
Graphics card: Intel HD Graphics 5000 OpenGL Engine Intel Inc. 4.1 INTEL-12.10.12

Blender Version
Broken: version: 2.82 (sub 1), branch: master (modified), commit date: 2019-10-31 23:45, hash: rBc11d3c1b9208
Worked: (optional)

Short description of error
In an app-level timer, trying to set the workspace on a window doesn't work. It looks like the call to WM_event_add_notifier in rna_Window_workspace_update always dispatches events to the context's current window rather than the Window object whose workspace attribute is being changed.

Exact steps for others to reproduce the error
Run this script in the Scripting workspace:

import bpy
def tick():[0].workspace =['Shading']
    return 0

Running the script does not switch workspaces to the Shading workspace. Calling the tick() function directly switches workspaces as expected.

Event Timeline

Philipp Oeser (lichtwerk) lowered the priority of this task from 90 to 50.Nov 7 2019, 1:09 PM

Can confirm.

However you can use the workaround from T62074: 2.8: Python API: crash due to missing window context in Application timer which is using an operator with custom context in the timer. This seems to work nicely:

import bpy

class TestOperator(bpy.types.Operator):
    bl_idname = "scene.test_operator"
    bl_label = "Test Operator"

    def execute(self, context):
        context.window.workspace =['Shading']
        return {'FINISHED'}


def tick():
    window =[0]
    ctx = {'window': window, 'screen': window.screen}  
    return 5.0
Philipp Oeser (lichtwerk) renamed this task from A window's workspace can't be set during app-level timer callbacks to 2.8: Python API: window's workspace can't be set in Application timer.Nov 7 2019, 1:11 PM
Jacques Lucke (JacquesLucke) changed the subtype of this task from "Report" to "Known Issue".Jan 22 2020, 3:49 PM
Campbell Barton (campbellbarton) added a project: Restricted Project.