-
Notifications
You must be signed in to change notification settings - Fork 335
/
Copy pathSampleMouseCallback.py
60 lines (47 loc) · 1.86 KB
/
SampleMouseCallback.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
################################################################################
# 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
# 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"
# The 'main' function
def mouse_event_helper_func():
if sc.sticky.has_key('SampleMouseCallback'):
callback = sc.sticky['SampleMouseCallback']
if callback:
callback.Enabled = False
callback = None
sc.sticky.Remove('SampleMouseCallback')
else:
callback = MouseCallbackClass()
callback.Enabled = True
sc.sticky['SampleMouseCallback'] = callback
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()