changeset 734:d230824728aa

drag submasters out of keyboardcomposer Ignore-this: cbc405d57f6727db9690e527681202f3
author Drew Perttula <drewp@bigasterisk.com>
date Fri, 15 Jun 2012 06:09:49 +0000
parents 53da47fd5a90
children d6cea108ec48
files bin/keyboardcomposer light9/tkdnd.py
diffstat 2 files changed, 35 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/bin/keyboardcomposer	Fri Jun 15 02:18:43 2012 +0000
+++ b/bin/keyboardcomposer	Fri Jun 15 06:09:49 2012 +0000
@@ -18,6 +18,7 @@
 from light9 import dmxclient, showconfig, networking, prof
 from light9.uihelpers import toplevelat, bindkeys
 from light9.namespaces import L9
+from light9.tkdnd import initTkdnd, dragSourceRegister
 from bcf2000 import BCF2000
 
 nudge_keys = {
@@ -73,6 +74,9 @@
         self.scale.pack(side=BOTTOM, expand=1, fill=BOTH)
         bindkeys(self, "<Control-Key-l>", self.launch_subcomposer)
 
+        for w in [self, namelabel, levellabel]:
+            dragSourceRegister(w, 'copy', 'text/uri-list', sub.uri)
+
     def launch_subcomposer(self, *args):
         subprocess.Popen(["bin/subcomposer", "--no-geometry", self.name])
 
@@ -465,6 +469,8 @@
     s = Submasters(graph)
 
     root = Tk()
+    initTkdnd(root.tk, 'tkdnd/trunk/')
+    
     tl = toplevelat("Keyboard Composer", existingtoplevel=root)
 
     startLevels = None
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/light9/tkdnd.py	Fri Jun 15 06:09:49 2012 +0000
@@ -0,0 +1,29 @@
+from glob import glob
+from os.path import join, basename
+
+def initTkdnd(tk, tkdndBuildDir):
+    """
+    pass the 'tk' attribute of any Tkinter object, and the top dir of
+    your built tkdnd package
+    """
+    tk.call('source', join(tkdndBuildDir, 'library/tkdnd.tcl'))
+    for dll in glob(join(tkdndBuildDir,
+                         '*tkdnd*' + tk.call('info', 'sharedlibextension'))):
+        tk.call('tkdnd::initialise',
+                join(tkdndBuildDir, 'library'),
+                join('..', basename(dll)),
+                'tkdnd')
+
+def dragSourceRegister(widget,
+                       action='copy', datatype='text/uri-list', data=''):
+    widget.tk.call('tkdnd::drag_source', 'register', widget._w)
+
+    # with normal Tkinter bind(), the result of your handler isn't
+    # actually returned so the drag doesn't get launched. This is a
+    # corrected version of what bind() does when you pass a function,
+    # but I don't block my tuple from getting returned (as a tcl list)
+    funcId = widget._register(lambda: (action, datatype, data),
+                              widget._substitute,
+                              1 # needscleanup
+                              )
+    widget.bind("<<DragInitCmd>>", funcId)