diff --git a/bin/subcomposer b/bin/subcomposer --- a/bin/subcomposer +++ b/bin/subcomposer @@ -5,6 +5,7 @@ from optparse import OptionParser 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 import dmxclient, Patch, Sub 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): + """ + 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 l9:currentSub + + 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 @@ class Subcomposer(tk.Frame): 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 @@ if __name__ == "__main__": 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()