Wait for screen_full_area to complete

First I’m trying to make blender window go into maximised mode

Then I’m trying to make the VIEW_3D area to go into Full screen Area
enter image description here

and then make the camera fit view bound
enter image description here

and so far this is what I’ve come up with:

import bpy
import time
import functools
import subprocess

monitor_width,monitor_height = subprocess.Popen('xrandr | grep "\*" | cut -d" " -f4',shell=True, stdout=subprocess.PIPE).communicate()[0].split(b'x')

if(int(monitor_width)!=bpy.context.window.width or int(monitor_height)!=bpy.context.window.height):
    bpy.ops.wm.window_fullscreen_toggle()

# Maximize text editor in new workspace
for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        for space in area.spaces:
            if space.type == 'VIEW_3D':
                space.shading.type = 'RENDERED' #switch to Viewport Shading
                space.overlay.show_overlays=False # disables lines and grids
                space.show_gizmo=False #disables gizmos (eg. rotate view, move view, zoom in/out in the view, etc)
                space.region_3d.view_perspective = 'CAMERA' #sets into camera view
                
                with bpy.context.temp_override(area=area): #toggles fullscreen area
                    bpy.ops.screen.screen_full_area(use_hide_panels=True)
                
                for a in bpy.context.window.screen.areas: 
                    if a.type == 'VIEW_3D':
                        with bpy.context.temp_override(area=a,region=a.regions[0]):
                            if bpy.ops.view3d.view_center_camera.poll():
                                bpy.ops.view3d.view_center_camera() #fits camera in view bound
                break
        break

bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
time.sleep(5)

but the problem is that updating everything takes about 1-2 seconds so when it reaches sleep() the entire view gets stuck like this:
enter image description here

so how do I wait for the entire UI to finish updating and THEN invoke any function (in this case sleep()) ?

Why are you using time.sleep()? This will completely shut down your Blender event loop, disabling any updates, any input, even preventing you from closing Blender. Do this instead:
https://docs.blender.org/api/current/bpy.app.timers.html

I’m not actually using sleep, it’s just a placeholder function, what I really want to do is invoke a function AFTER the UI is completely in fullscreen

there’s no way to get notifications when an operator completes, as far as I’m aware- but you could register a short timer before you call the full screen op and then run your stuff when the timer completes.

1 Like

shouldn’t bpy.ops.wm.window_fullscreen_toggle() wait for the window to completely get into fullscreen and then move forward in the code?

last I checked it wasn’t an async function

UI updates are deferred until all script execution completes. This means that your entire operator runs to its completion before Blender even starts to switch to fullscreen.

related:
https://docs.blender.org/api/current/info_gotcha.html#can-i-redraw-during-script-execution

1 Like