From a2569b62ed97dbb4a8a2a1e3b48a8992356ac8e9 Mon Sep 17 00:00:00 2001 From: Demeter Dzadik Date: Sat, 17 Aug 2024 21:25:17 +0100 Subject: [PATCH] New: Area Split/Merge Pie --- source/__init__.py | 1 + source/pie_editor_split_merge.py | 83 ++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 source/pie_editor_split_merge.py diff --git a/source/__init__.py b/source/__init__.py index 5c01c86..8eb217f 100644 --- a/source/__init__.py +++ b/source/__init__.py @@ -37,6 +37,7 @@ module_names = ( "pie_editor_switch_menu", "pie_defaults_menu", "pie_proportional_menu", + "pie_editor_split_merge", ) diff --git a/source/pie_editor_split_merge.py b/source/pie_editor_split_merge.py new file mode 100644 index 0000000..f9fd6bc --- /dev/null +++ b/source/pie_editor_split_merge.py @@ -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", + ) -- 2.30.2