New: Area Split/Join Pie #7

Merged
Demeter Dzadik merged 1 commits from new_editor_split_merge_pie into main 2024-08-21 02:31:39 +02:00
2 changed files with 84 additions and 0 deletions

View File

@ -37,6 +37,7 @@ module_names = (
"pie_editor_switch_menu",
"pie_defaults_menu",
"pie_proportional_menu",
"pie_editor_split_merge",
)

View File

@ -0,0 +1,83 @@
import bpy
from bpy.types import Menu, Operator
from bpy.props import StringProperty
from .hotkeys import register_hotkey
class SCREEN_OT_area_join_from_pie(Operator):
bl_idname = "screen.area_join_from_pie"
bl_label = "Join Areas"
bl_description = "Join two editor areas into one"
bl_options = {'REGISTER', 'UNDO'}
direction: StringProperty()
def invoke(self, context, event):
active = context.area
if not active:
return
# Thanks to Harley Acheson for explaining:
# https://devtalk.blender.org/t/join-two-areas-by-python-area-join-what-arguments-blender-2-80/18165/2
cursor = None
mouse_x, mouse_y = event.mouse_x, event.mouse_y
if self.direction == 'LEFT':
cursor = (active.x+2, mouse_y)
elif self.direction == 'RIGHT':
cursor = (active.x+active.width, mouse_y)
elif self.direction == 'UP':
cursor = (mouse_x, active.y+active.height)
elif self.direction == 'DOWN':
cursor = (mouse_x, active.y)
bpy.ops.screen.area_join('INVOKE_DEFAULT', cursor=cursor)
return {'FINISHED'}
class PIE_MT_area_split_merge(Menu):
bl_idname = "PIE_MT_area_split_merge"
bl_label = "Area Split/Join Pie"
def draw(self, context):
pie = self.layout.menu_pie()
pie.scale_y = 1.2
# 4 - LEFT
pie.operator('screen.area_join_from_pie', text="Join Left", icon='TRIA_LEFT').direction='LEFT'
# 6 - RIGHT
pie.operator('screen.area_join_from_pie', text="Join Right", icon='TRIA_RIGHT').direction='RIGHT'
# 2 - BOTTOM
pie.operator('screen.area_join_from_pie', text="Join Down", icon='TRIA_DOWN').direction='DOWN'
# 8 - TOP
pie.operator('screen.area_join_from_pie', text="Join Up", icon='TRIA_UP').direction='UP'
# 7 - TOP - LEFT
pie.separator()
# 9 - TOP - RIGHT
pie.separator()
# 1 - BOTTOM - LEFT
pie.separator()
# 3 - BOTTOM - RIGHT
area = context.area
icon = 'SPLIT_HORIZONTAL'
direction = 'HORIZONTAL'
if area.width > area.height:
icon = 'SPLIT_VERTICAL'
direction = 'VERTICAL'
pie.operator('screen.area_split', text="Split Area", icon=icon).direction=direction
registry = [
SCREEN_OT_area_join_from_pie,
PIE_MT_area_split_merge,
]
def register():
register_hotkey(
'wm.call_menu_pie',
op_kwargs={'name': 'PIE_MT_area_split_merge'},
hotkey_kwargs={'type': "ACCENT_GRAVE", 'value': "PRESS", 'alt': True},
key_cat="Window",
)