blroots/examples/simple/blroots_simple_example/panels/simple_panel.py

66 lines
1.7 KiB
Python

# blext
# Copyright (C) 2025 blext Project Contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import bpy
from .. import contracts as ct
class SimplePanel(bpy.types.Panel):
bl_idname = ct.PanelType.SimplePanel
bl_label = 'Simple Panel'
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = 'scene'
@classmethod
def poll(cls, _: bpy.types.Context) -> bool:
"""Always show panel in Scene properties.
Notes:
Run by Blender when trying to show a panel.
Returns:
Whether the panel can show.
"""
return True
def draw(self, context: bpy.types.Context) -> None:
"""Draw the panel w/options.
Notes:
Run by Blender when the panel needs to be displayed.
Parameters:
context: The Blender context object.
Must contain `context.window_manager` and `context.workspace`.
"""
scene = context.scene
layout = self.layout
# Property
scene.draw_blprop(layout, 'simple_integer')
# Operator
layout.label(text='Look ma, so many hands!')
layout.operator(ct.OperatorType.SimpleOperator)
####################
# - Blender Registration
####################
BL_REGISTER = [SimplePanel]