diff --git a/rhinocommon/py/SamplePyMouseCallback/SampleMouseCallback.py b/rhinopython/SampleMouseCallback.py similarity index 69% rename from rhinocommon/py/SamplePyMouseCallback/SampleMouseCallback.py rename to rhinopython/SampleMouseCallback.py index 20d07ea5..27a35e83 100644 --- a/rhinocommon/py/SamplePyMouseCallback/SampleMouseCallback.py +++ b/rhinopython/SampleMouseCallback.py @@ -1,59 +1,46 @@ -# inspired by Dale Fugier's post here: https://discourse.mcneel.com/t/button-mouse-event-again/74625/14 - +################################################################################ +# SampleMouseCallback.py +# Copyright (c) 2019 Robert McNeel & Associates. +# See License.md in the root of this repository for details. +################################################################################ import scriptcontext as sc import Rhino -###################### -### EVENT HANDLERS ### -###################### +# Demonstrates how to use RhinoCommon's MouseCallback class class MouseCallbackClass(Rhino.UI.MouseCallback): - """""" + def OnMouseDown(self, e): print "OnMouseDown",e.Button - """ def OnEndMouseDown(self,e): print "OnEndMouseDown", e.Button - """ - """""" + def OnMouseUp(self,e): print "OnMouseUp",e.Button - """ def OnEndMouseUp(self,e): print "OnEndMouseUp",e.Button - """ - """""" + def OnMouseDoubleClick(self,e): print "OnMouseDoubleClick",e.Button - """ def OnMouseMove(self,e): print "OnMouseMove" - """ - """ + def OnEndMouseMove(self,e): print "OnEndMouseMove" - """ - """""" + def OnMouseEnter(self,e): print "OnMouseEnter", e.View.MainViewport.Name - """""" def OnMouseLeave(self,e): print "OnMouseLeave", e.View.MainViewport.Name - """""" def OnMouseHover(self,e): print "OnMouseHover" - - -############################## -### EVENT HELPER FUNCTIONS ### -############################## +# The 'main' function def mouse_event_helper_func(): - #Event trigger helper function if sc.sticky.has_key('SampleMouseCallback'): callback = sc.sticky['SampleMouseCallback'] if callback: @@ -64,10 +51,10 @@ def mouse_event_helper_func(): callback = MouseCallbackClass() callback.Enabled = True sc.sticky['SampleMouseCallback'] = callback - #Rhino.RhinoApp.WriteLine("Click somewhere...") print "Listening for mouse events..." - - +# Check to see if this file is being executed as the "main" python +# script instead of being used as a module by some other python script +# This allows us to use the module which ever way we want. if __name__ == "__main__": mouse_event_helper_func()