Repository navigation
Expand file tree
/
Copy pathSampleMouseCallback.py
More file actions
61 lines (48 loc) · 1.89 KB
/
Copy pathSampleMouseCallback.py
File metadata and controls
61 lines (48 loc) · 1.89 KB
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
61
################################################################################
# SampleMouseCallback.py
# Copyright (c) 2013-2026, Robert McNeel & Associates.
# See License.md in the root of this repository for details.
################################################################################
# ! python3
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 'SampleMouseCallback' in sc.sticky:
callback = sc.sticky['SampleMouseCallback']
if callback:
callback.Enabled = False
callback = None
sc.sticky.pop('SampleMouseCallback', None)
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()