Skip to content

Instantly share code, notes, and snippets.

@kilon kilon/morpheasExample.py
Last active Sep 8, 2017

Embed
What would you like to do?
import bpy
import bgl
import blf
from morpheas import *
# this class is defining the action performed when the button is clicked
clase AButtonAction:
def onLeftClick(morph):
print("the button has been clicked")
morph.texture = "buttonClickedIcon"
def draw_callback_px(self, context):
#draw the morphs
self.world.draw()
class ModalDrawOperator(bpy.types.Operator):
"""Draw a line with the mouse"""
bl_idname = "view3d.modal_operator"
bl_label = "Simple Modal View3D Operator"
def __init__(self):
self.world = None
# create button
self.abutton = ButtonMorph(texture="buttonIcon",onLeftClickAction = AButtonAction)
self.world.addMorph(self.abutton)
def modal(self, context, event):
context.area.tag_redraw()
self.world.onEvent(event)
if self.world.consumedEvent:
return {'RUNNING_MODAL'}
else:
return {'PASS THROUGH'}
def invoke(self, context, event):
# create the world
self.world = World()
if context.area.type == 'VIEW_3D':
# the arguments we pass the the callback
args = (self, context)
# Add the region OpenGL drawing callback
# draw in view space with 'POST_VIEW' and 'PRE_VIEW'
self._handle = bpy.types.SpaceView3D.draw_handler_add(draw_callback_px, args, 'WINDOW', 'POST_PIXEL')
self.mouse_path = []
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
else:
self.report({'WARNING'}, "View3D not found, cannot run operator")
return {'CANCELLED'}
def register():
bpy.utils.register_class(ModalDrawOperator)
def unregister():
bpy.utils.unregister_class(ModalDrawOperator)
if __name__ == "__main__":
register()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.