Screen area maintenance "Close" function allowed to be scripted.
This patch allows the new area "close" operator to be called from python, like:
area = bpy.context.screen.areas[0] # Pick any area.
bpy.ops.screen.area_close({"area": area}) Differential D12307
Python: Allow Area Close via Scripting Authored by Harley Acheson (harley) on Aug 23 2021, 10:50 PM.
Details
Screen area maintenance "Close" function allowed to be scripted. This patch allows the new area "close" operator to be called from python, like: area = bpy.context.screen.areas[0] # Pick any area.
bpy.ops.screen.area_close({"area": area})
Diff Detail
Event TimelineComment Actions In principle this seems reasonable, notes:
Here is an update to this patch which addresses the issues noted:
Any issues with applying the updated patch? Comment Actions Hey @Campbell Barton (campbellbarton) and @Harley Acheson (harley), thanks for looking in to this! Just to give an example of how this can be used: Registering a hotkey via python that toggles an area. For example show and hide the timeline. For that you need to be able to somewhat reliably split and join / close areas. Especially for application templates that highly customize blender for a specific need it can be very useful to make this more approachable via the python api. Comment Actions Hi @Paul Golter (paulgolter) is this patch enough to do the kinds of manipulations you need? Or do other changes need to be made to support toggling areas? Comment Actions Hey @Campbell Barton (campbellbarton), Yes I just tested the patch, and it works fine! Thanks a lot. From a scripting perspective we need to do the usual context overriding which is always a little cumbersome. In any way this already helps a lot. Comment Actions
Sorry but I honestly don't know and am hoping to rely on you a bit here as I just don't use Python so am not used to considering it. This came about not from anyone directly asking me for scripted "close" but for at least three people in the last couple years asking for "Join" to work from Python. I was considering that Close and Join not working for them to be a failing of mine to not think of that earlier. I had planned on adding python support for both, but only started with Close because it would be more constructive for me - I wouldn't just make the same mistakes twice. Join is more problematic in that both a source and destination must be specified, so they'd need not only that confusing "cursor" at the common edge, but also a "direction". Your fixed version always closes the active area, not an arbitrary one - and works great. I honest don't know if that is enough for them or not. Can they change the active area non-interactively? If so, can we just do this and not do Join? Comment Actions @Harley Acheson (harley) the active area can be set as follows: area = bpy.context.screen.areas[0] # Pick any area.
bpy.ops.screen.area_close({"area": area})As for more advanced logic some possibilities:
This could be handled as part of ongoing development. Comment Actions
Okay, I had no idea that it worked like that. Tested it and works like magic. This Close then is so simple that we could conceivably commit only this and ignore the more complex "Join" for now? Area split and close should be enough to do anything anyone would want I think. With the only "bad" possibility of the wrong area taking over the closed area's space. But that is not destructive and easy to deal with. And if not we could do Join later? Comment Actions Will try to add an optional "Direction" argument to this. That way this one thing can do the job of Join too Comment Actions A few bits confuse me here, noted inline. One issue of exposing more advanced screen operations in Python is indeed how to pass the areas to use to the operators. Pointer properties are not an option unfortunately (e.g. bpy.ops.screen.foo(area=somearea)). This workaround via context overrides only works for single areas.
Comment Actions Having UUID's feels like an unnecessary indirection. for example, context.area.join(other_area) Years back there was an choice not to expose windowing operations in the same way we do for scene data (@Nathan Letwory (jesterking) made a patch for RNA/windowing data and it was either rejected/reverted). This could be re-evaluated, however if operators are "good-enough", we could continue to use them as there are already a lot of projects needing our attention. Comment Actions
No, an oversight now fixed. Thanks!
As far as I can see calling CTX_wm_window_set() causes no harm when called interactively, although maybe there is something I'm not aware of with that. So just made this a single exec function instead.
| |||||||||||||||||||||