changeset 817:6885c2fa9369

subcomposer halfway to having the editchoice widget Ignore-this: 21eb05393c045298c173e0869371aaf9
author drewp@bigasterisk.com
date Thu, 01 Nov 2012 04:00:16 +0000
parents cf19fd45a40e
children bf728997bfde
files bin/subcomposer
diffstat 1 files changed, 86 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/bin/subcomposer	Thu Nov 01 03:59:53 2012 +0000
+++ b/bin/subcomposer	Thu Nov 01 04:00:16 2012 +0000
@@ -5,6 +5,7 @@
 import Tkinter as tk
 import louie as dispatcher
 from twisted.internet import reactor, tksupport, task
+from rdflib import URIRef
 
 import run_local
 from light9.dmxchanedit import Levelbox
@@ -12,22 +13,91 @@
 from light9.uihelpers import toplevelat
 from light9.rdfdb.syncedgraph import SyncedGraph
 from light9.rdfdb import clientsession
+from light9.tkdnd import initTkdnd, dragSourceRegister, dropTargetRegister
+
+class EditChoice(tk.Frame):
+    """
+    widget for tying some UI to a shared resource for editing, or
+    unlinking it (which means associating it with a local resource
+    that's not named or shared). This object does not own the choice
+    of resource; the caller does.
+    """
+    def __init__(self, parent, getResource, onSetResource, onSetLocal):
+        want to pass an observable uri value and an observable isLocal for 2way sync
+        """
+        getResource is called to get the URI of the currently 
+        """
+        self.frame = tk.Frame(parent)
+        self.subSelection.pack(side='top')
+        tk.Label(self.subSelection, text="Editing:").pack(side='left')
+        self.currentSubFrame = tk.Frame(self.subSelection)
+        self.currentSubFrame.pack(side='left')
+
+        self.subIcon = tk.Label(self.currentSubFrame, text="sub1",
+                                borderwidth=2,
+                                relief='raised', padx=10, pady=10)
+        self.subIcon.pack()
+
+        dragSourceRegister(self.subIcon, 'copy', 'text/uri-list',
+                           lambda: self.currentSub.uri)
+        def onEv(*args):
+            print "ev", args
+            return "link"
+        self.onEv = onEv
+          
+        dropTargetRegister(self, onDrop=onEv,
+                           hoverStyle=dict(background="#555500", bd=3, relief='groove'))
+
+        tk.Label(self.currentSubFrame, text="local data (drag sub here)").pack()
+        tk.Button(text="unlink", command=self.switchToLocalSub)
+    
 
 class Subcomposer(tk.Frame):
+    """
+    <session> l9:currentSub ?sub is the URI of the sub we're tied to for displaying and
+    editing. If we don't have a currentSub, then we're actually
+    editing a session-local sub called <session> l9:currentSub <sessionLocalSub>
+
+    UI actions:
+    - drag a sub uri on here to make it the one we're editing
+
+    - button to clear the currentSub (putting it back to
+      sessionLocalSub, and also resetting sessionLocalSub to be empty
+      again)
+
+    - drag the sub uri off of here to send it to another receiver, but
+      session local sub is not easily addressable elsewhere
+
+    - make a new sub: transfers the current data (from a shared sub or
+      from the local one) to the new sub. If you're on a local sub,
+      the new sub is named automatically, ideally something brief,
+      pretty distinct, readable, and based on the lights that are
+      on. If you're on a named sub, the new one starts with a
+      'namedsub 2' style name. The uri can also be with a '2' suffix,
+      although maybe that will be stupid. If you change the name
+      before anyone knows about this uri, we could update the current
+      sub's uri to a slug of the new label.
+    
+    - rename this sub: not available if you're on a local sub. Sets
+      the label of a named sub. Might update the uri of the named sub
+      if it's new enough that no one else would have that uri. Not
+      sure where we measure that 'new enough' value. Maybe track if
+      the sub has 'never been dragged out of this subcomposer
+      session'? But subs will also show up in other viewers and
+      finders.
+
+    """
     def __init__(self, master, graph, session):
         tk.Frame.__init__(self, master, bg='black')
         self.graph = graph
         self.session = session
+        self.currentSub = Submaster.PersistentSubmaster(graph, URIRef('http://hello'))
 
         self.levelbox = Levelbox(self, graph)
         self.levelbox.pack(side='top')
 
-        self.savebox = EntryCommand(self, cmd=self.savenewsub)
-        self.savebox.pack(side='top')
-
-        self.loadbox = EntryCommand(self, verb="Load", cmd=self.loadsub)
-        self.loadbox.pack(side='top')
-
+        EditChoice(self).frame.pack(side='top')
+        
         def alltozero():
             for lev in self.levelbox.levels:
                 lev.setlevel(0)
@@ -36,6 +106,11 @@
 
         dispatcher.connect(self.sendupdate, "levelchanged")
 
+    def switchToLocalSub(self, *args):
+        """
+        stop editing a shared sub and go back to our local sub
+        """
+
     def fill_both_boxes(self, subname):
         for box in [self.savebox, self.loadbox]:
             box.set(subname)
@@ -104,12 +179,15 @@
     root=tk.Tk()
     root.config(bg='black')
     root.tk_setPalette("#004633")
-    if not opts.no_geometry:
-        toplevelat("subcomposer - %s" % opts.session, root)
+
+    initTkdnd(root.tk, 'tkdnd/trunk/')
 
     graph = SyncedGraph("subcomposer")
     session = clientsession.getUri('subcomposer', opts)
 
+    if not opts.no_geometry:
+        toplevelat("subcomposer - %s" % opts.session, root, graph, session)
+
     sc = Subcomposer(root, graph, session)
     sc.pack()