Python API 2.0 Reference
python/api1/py1ExternalDropCallback.py
1 """
2 To use, make sure that externalDropCallback.py is in your MAYA_PLUG_IN_PATH
3 then do the following:
4 
5 import maya
6 maya.cmds.loadPlugin("externalDropCallback.py")
7 
8 Drag and drop events should appear in the script editor output.
9 """
10 
11 import sys
12 import maya.OpenMaya as OpenMaya
13 import maya.OpenMayaUI as OpenMayaUI
14 
15 
16 # callback
17 class PyExternalDropCallback(OpenMayaUI.MExternalDropCallback):
18  instance = None
19 
20  def __init__(self):
21  OpenMayaUI.MExternalDropCallback.__init__(self)
22 
23  def externalDropCallback( self, doDrop, controlName, data ):
24  str = ("External Drop: doDrop = %d, controlName = %s" % (doDrop, controlName))
25 
26  # Mouse button
27  if data.mouseButtons() & OpenMayaUI.MExternalDropData.kLeftButton:
28  str += ", LMB"
29  if data.mouseButtons() & OpenMayaUI.MExternalDropData.kMidButton:
30  str += ", MMB"
31  if data.mouseButtons() & OpenMayaUI.MExternalDropData.kRightButton:
32  str += ", RMB"
33 
34  # Key modifiers
35  if data.keyboardModifiers() & OpenMayaUI.MExternalDropData.kShiftModifier:
36  str += ", SHIFT"
37  if data.keyboardModifiers() & OpenMayaUI.MExternalDropData.kControlModifier:
38  str += ", CONTROL"
39  if data.keyboardModifiers() & OpenMayaUI.MExternalDropData.kAltModifier:
40  str += ", ALT"
41 
42  # Data
43  if data.hasText():
44  str += (", text = %s" % data.text())
45  if data.hasUrls():
46  urls = data.urls()
47  for (i,url) in enumerate(urls):
48  str += (", url[%d] = %s" % (i, url))
49  # end
50  if data.hasHtml():
51  str += (", html = %s" % data.html())
52  if data.hasColor():
53  color = data.color()
54  str += (", color = (%d, %d, %d, %d)" % (color.r, color.g, color.b, color.a))
55  if data.hasImage():
56  str += (", image = true")
57  str += "\n"
58  sys.stdout.write( str )
59  return OpenMayaUI.MExternalDropCallback.kMayaDefault
60 
61 # end
62 
63 
64 # Initialize the plug-in
65 def initializePlugin(plugin):
66  try:
67  PyExternalDropCallback.instance = PyExternalDropCallback()
68  OpenMayaUI.MExternalDropCallback.addCallback( PyExternalDropCallback.instance )
69  sys.stdout.write("Successfully registered callback: PyExternalDropCallback\n")
70  except:
71  sys.stderr.write("Failed to register callback: PyExternalDropCallback\n")
72  raise
73 # end
74 
75 
76 # Uninitialize the plug-in
77 def uninitializePlugin(plugin):
78  try:
79  OpenMayaUI.MExternalDropCallback.removeCallback( PyExternalDropCallback.instance )
80  sys.stdout.write("Successfully deregistered callback: PyExternalDropCallback\n")
81  except:
82  sys.stderr.write("Failed to deregister callback: PyExternalDropCallback\n")
83  raise
84 # end
85 
86 #-
87 # ==========================================================================
88 # Copyright (C) 2011 Autodesk, Inc. and/or its licensors. All
89 # rights reserved.
90 #
91 # The coded instructions, statements, computer programs, and/or related
92 # material (collectively the "Data") in these files contain unpublished
93 # information proprietary to Autodesk, Inc. ("Autodesk") and/or its
94 # licensors, which is protected by U.S. and Canadian federal copyright
95 # law and by international treaties.
96 #
97 # The Data is provided for use exclusively by You. You have the right
98 # to use, modify, and incorporate this Data into other products for
99 # purposes authorized by the Autodesk software license agreement,
100 # without fee.
101 #
102 # The copyright notices in the Software and this entire statement,
103 # including the above license grant, this restriction and the
104 # following disclaimer, must be included in all copies of the
105 # Software, in whole or in part, and all derivative works of
106 # the Software, unless such copies or derivative works are solely
107 # in the form of machine-executable object code generated by a
108 # source language processor.
109 #
110 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
111 # AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED
112 # WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF
113 # NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
114 # PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR
115 # TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS
116 # BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL,
117 # DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK
118 # AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY
119 # OR PROBABILITY OF SUCH DAMAGES.
120 #
121 # ==========================================================================
122 #+
123 
124