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):

# 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
                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

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

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:

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.


1 Like