Some more mud.
import bpy
class box():
def __init__(self, area, x, y, w, h, left, right, layout):
#if they share a horizontal edge
self.area = area
self.x = x
self.y = y
self.h = h
self.w = w
self.left = left
self.right = right
self.layout = layout
def __repr__(self):
return "box %d %d %d %d" % (self.x, self.y, self.w, self.h)
context = bpy.context
window = context.window
print("WINDOW", window.width, window.height)
screen = window.screen
print("SCREEN:", screen.name)
areas = []
for area in screen.areas:
areas.append(box(area, area.x, window.height-(area.y + area.height), area.width, area.height, None, None, 'BOX'))
# sort areas by x, y
#areas = sorted(areas, key = lambda k:(k.x , k.y))
#make a tree
#searh for areas that share an edge
while len(areas) > 1:
#areas = sorted(areas, key = lambda k:(k.x , k.y))
for area in areas:
# share a vert edge
se = [a for a in areas if a != area and a.y == area.y and a.h == area.h]
if len(se):
a = se[0]
if a.x <= area.x:
left, right = a, area
else:
left, right = area, a
n = box(None, left.x, left.y,left.w + right.w + 1, left.h, left, right, 'COL')
areas.pop(areas.index(area))
areas.pop(areas.index(a))
areas.append(n)
#areas = sorted(areas, key = lambda k:(k.x , k.y))
for area in areas:
# share a horiz edge
sh = [a for a in areas if a != area and a.x == area.x and a.w == area.w]
if len(sh):
print("share a horiz edge")
a = sh[0]
print(a)
print(area)
# left is top, right bottom
if a.y < area.y:
left, right = a, area
else:
left, right = area, a
n = box(None, left.x, left.y, area.w, area.h + a.h + 1, left, right, 'ROW')
areas.pop(areas.index(area))
areas.pop(areas.index(a))
areas.append(n)
#traverse the tree
def traverse_binary_tree(node, layout):
if node.layout == "ROW":
col = layout.column()
left = col.row()
right = col.row()
elif node.layout == "COL":
row = layout.row()
right = row
left = row.row()
else:
box = layout.box()
box.prop(node.area, "type", text="")
if node.left:
traverse_binary_tree(node.left, left)
if node.right:
traverse_binary_tree(node.right, right)
root = areas[0]
class HelloWorldPanel(bpy.types.Panel):
"""Creates a Panel in the Object properties window"""
bl_label = "Hello World Panel"
bl_idname = "OBJECT_PT_hello"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"
def draw(self, context):
layout = self.layout
traverse_binary_tree(root, layout)
def register():
bpy.utils.register_class(HelloWorldPanel)
def unregister():
bpy.utils.unregister_class(HelloWorldPanel)
if __name__ == "__main__":
register()
need to set up nicer splits scales when making the tree now from the window area.