Mercurial > code > home > repos > light9
annotate bin/subcomposer @ 838:321fc6150ee3
subcomposer's nice currently-editing DnD box
Ignore-this: f2a8542a4ab38dbe61b26c864da3bace
author | drewp@bigasterisk.com |
---|---|
date | Tue, 26 Mar 2013 07:04:22 +0000 |
parents | ae359590eb8a |
children | f987eb9c3672 |
rev | line source |
---|---|
729
b5efddd80dad
update more shbang lines
Drew Perttula <drewp@bigasterisk.com>
parents:
577
diff
changeset
|
1 #!bin/python |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
2 """ |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
3 subcomposer |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
4 session |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
5 observable(currentSub), a Submaster which tracks the graph |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
6 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
7 EditChoice widget |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
8 can change currentSub to another sub |
0 | 9 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
10 Levelbox widget |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
11 watch observable(currentSub) for a new sub, and also watch currentSub for edits to push to the OneLevel widgets |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
12 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
13 OneLevel widget |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
14 UI edits are caught here and go all the way back to currentSub |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
15 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
16 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
17 """ |
0 | 18 from __future__ import division, nested_scopes |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
19 import time, logging |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
20 from optparse import OptionParser |
831
0f7e99d02dc6
subcomposer support logging. don't start with a bogus sub
Drew Perttula <drewp@bigasterisk.com>
parents:
818
diff
changeset
|
21 import logging |
0 | 22 import Tkinter as tk |
802 | 23 import louie as dispatcher |
803 | 24 from twisted.internet import reactor, tksupport, task |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
25 from rdflib import URIRef |
0 | 26 |
833 | 27 from run_local import log |
209
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
201
diff
changeset
|
28 from light9.dmxchanedit import Levelbox |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
29 from light9 import dmxclient, Patch, Submaster, prof |
455
9dd2baa41cca
subcomposer remembers window position
drewp@bigasterisk.com
parents:
450
diff
changeset
|
30 from light9.uihelpers import toplevelat |
803 | 31 from light9.rdfdb.syncedgraph import SyncedGraph |
810 | 32 from light9.rdfdb import clientsession |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
33 from light9.tkdnd import initTkdnd, dragSourceRegister, dropTargetRegister |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
34 |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
35 class _NoNewVal(object): |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
36 pass |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
37 |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
38 class Observable(object): |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
39 """ |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
40 like knockout's observable. Hopefully this can be replaced by a |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
41 better python one |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
42 """ |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
43 def __init__(self, val): |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
44 self.val = val |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
45 self.subscribers = set() |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
46 |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
47 def __call__(self, newVal=_NoNewVal): |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
48 if newVal is _NoNewVal: |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
49 return self.val |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
50 self.val = newVal |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
51 for s in self.subscribers: |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
52 s(newVal) |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
53 |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
54 def subscribe(self, cb, callNow=True): |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
55 """cb is called with new values, and also right now with the |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
56 current value unless you opt out""" |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
57 self.subscribers.add(cb) |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
58 if callNow: |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
59 cb(self.val) |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
60 |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
61 class Local(object): |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
62 """placeholder for the local uri that EditChoice does not |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
63 manage. Set resourceObservable to Local to indicate that you're |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
64 unlinked""" |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
65 |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
66 class EditChoice(tk.Frame): |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
67 """ |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
68 Observable <-> linker UI |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
69 |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
70 widget for tying some UI to a shared resource for editing, or |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
71 unlinking it (which means associating it with a local resource |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
72 that's not named or shared). This object does not own the choice |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
73 of resource; the caller does. |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
74 """ |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
75 def __init__(self, parent, graph, resourceObservable): |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
76 """ |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
77 getResource is called to get the URI of the currently |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
78 """ |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
79 self.frame = tk.Frame(parent, relief='raised',border=8) |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
80 self.frame.pack(side='top') |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
81 tk.Label(self.frame, text="Editing:").pack(side='left') |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
82 self.currentSubFrame = tk.Frame(self.frame) |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
83 self.currentSubFrame.pack(side='left') |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
84 |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
85 self.subIcon = tk.Label(self.currentSubFrame, text="sub1", |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
86 borderwidth=2, |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
87 relief='raised', padx=10, pady=10) |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
88 self.subIcon.pack() |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
89 |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
90 self.resourceObservable = resourceObservable |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
91 resourceObservable.subscribe(self.uriChanged) |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
92 |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
93 dragSourceRegister(self.subIcon, 'copy', 'text/uri-list', |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
94 self.resourceObservable) |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
95 def onEv(ev): |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
96 self.resourceObservable(ev.data) |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
97 return "link" |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
98 self.onEv = onEv |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
99 |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
100 # it would be nice if I didn't receive my own drags here |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
101 dropTargetRegister(self.subIcon, typeList=["*"], onDrop=onEv, |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
102 hoverStyle=dict(background="#555500", bd=3, |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
103 relief='groove')) |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
104 |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
105 tk.Label(self.currentSubFrame, text="local data (drag sub here)").pack() |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
106 b=tk.Button(text="unlink", command=self.switchToLocalSub) |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
107 b.pack() |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
108 |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
109 |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
110 def uriChanged(self, newUri): |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
111 print "chg", newUri |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
112 # i guess i show the label and icon for this |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
113 if newUri is Local: |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
114 self.subIcon.config(text="(local)") |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
115 else: |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
116 self.subIcon.config(text=newUri) |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
117 |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
118 def switchToLocalSub(self): |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
119 self.resourceObservable(Local) |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
120 |
0 | 121 |
122 class Subcomposer(tk.Frame): | |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
123 """ |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
124 <session> l9:currentSub ?sub is the URI of the sub we're tied to for displaying and |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
125 editing. If we don't have a currentSub, then we're actually |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
126 editing a session-local sub called <session> l9:currentSub <sessionLocalSub> |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
127 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
128 I'm not sure that Locals should even be PersistentSubmaster with |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
129 uri and graph storage, but I think that way is making fewer |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
130 special cases. |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
131 |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
132 Contains an EditChoice widget |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
133 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
134 Dependencies: |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
135 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
136 graph (?session :currentSub ?s) -> self.currentSub |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
137 self.currentSub -> graph |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
138 self.currentSub -> self._currentChoice (which might be Local) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
139 self._currentChoice (which might be Local) -> self.currentSub |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
140 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
141 inside the current sub: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
142 graph -> Submaster levels (handled in Submaster) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
143 Submaster levels -> OneLevel widget |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
144 OneLevel widget -> Submaster.editLevel |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
145 Submaster.editLevel -> graph (handled in Submaster) |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
146 |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
147 """ |
810 | 148 def __init__(self, master, graph, session): |
0 | 149 tk.Frame.__init__(self, master, bg='black') |
803 | 150 self.graph = graph |
810 | 151 self.session = session |
0 | 152 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
153 # this is a PersistentSubmaster (even for local) or None if we're not initialized |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
154 self.currentSub = Observable(None) |
0 | 155 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
156 currentUri = Observable("http://curr") |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
157 |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
158 def pc(val): |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
159 print "change viewed sub to", val |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
160 currentUri.subscribe(pc) |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
161 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
162 EditChoice(self, self.graph, self._currentChoice).frame.pack(side='top') |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
163 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
164 def setupSubChoiceLinks(self): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
165 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
166 def ann(): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
167 print "currently: session=%s currentSub=%r _currentChoice=%r" % ( |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
168 self.session, self.currentSub(), self._currentChoice()) |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
169 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
170 @graph.addHandler |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
171 def graphChanged(): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
172 s = graph.value(self.session, L9['currentSub']) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
173 if s is None: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
174 s = self.makeLocal() |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
175 self.currentSub(Submaster.PersistentSubmaster(graph, s)) |
0 | 176 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
177 @self.currentSub.subscribe |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
178 def subChanged(newSub): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
179 if newSub is None: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
180 graph.patchObject(self.session, |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
181 self.session, L9['currentSub'], None) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
182 return |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
183 self.sendupdate() |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
184 graph.patchObject(self.session, |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
185 self.session, L9['currentSub'], newSub.uri) |
0 | 186 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
187 if newSub and 'local' in newSub.uri: # wrong- use rdf:type or something? |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
188 self._currentChoice(Local) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
189 else: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
190 # i think right here is the point that the last local |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
191 # becomes garbage, and we could clean it up. |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
192 self._currentChoice(newSub.uri) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
193 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
194 dispatcher.connect(self.levelsChanged, "sub levels changed") |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
195 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
196 @self._currentChoice.subscribe |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
197 def choiceChanged(newChoice): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
198 if newChoice is Local: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
199 newChoice = self.makeLocal() |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
200 if newChoice is not None: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
201 self.currentSub(Submaster.PersistentSubmaster( |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
202 graph, newChoice)) |
0 | 203 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
204 def levelsChanged(self, sub): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
205 if sub == self.currentSub(): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
206 self.sendupdate() |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
207 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
208 def makeLocal(self): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
209 # todo: put a type on this, so subChanged can identify it right |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
210 # todo: where will these get stored, or are they local to this |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
211 # subcomposer process and don't use PersistentSubmaster at all? |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
212 return URIRef("http://local/%s" % time.time()) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
213 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
214 def setupLevelboxUi(self): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
215 self.levelbox = Levelbox(self, graph, self.currentSub) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
216 self.levelbox.pack(side='top') |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
217 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
218 tk.Button(self, text="All to zero", |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
219 command=lambda *args: self.currentSub().clear()).pack(side='top') |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
220 |
351
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
342
diff
changeset
|
221 def savenewsub(self, subname): |
0 | 222 leveldict={} |
223 for i,lev in zip(range(len(self.levels)),self.levels): | |
224 if lev!=0: | |
225 leveldict[Patch.get_channel_name(i+1)]=lev | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
226 |
351
a6662d61ebcd
SC, KC, CC now run and seem to load and save ok. CC does not have any rdf for its data files
Drew Perttula <drewp@bigasterisk.com>
parents:
342
diff
changeset
|
227 s=Submaster.Submaster(subname,leveldict=leveldict) |
0 | 228 s.save() |
802 | 229 |
0 | 230 def sendupdate(self): |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
231 d = self.currentSub().get_dmx_list() |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
232 dmxclient.outputlevels(d, twisted=True) |
802 | 233 |
0 | 234 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
235 def launch(opts, args, root, graph, session): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
236 if not opts.no_geometry: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
237 toplevelat("subcomposer - %s" % opts.session, root, graph, session) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
238 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
239 sc = Subcomposer(root, graph, session) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
240 sc.pack() |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
241 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
242 tk.Label(root,text="Bindings: B1 adjust level; B2 set full; B3 instant bump", |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
243 font="Helvetica -12 italic",anchor='w').pack(side='top',fill='x') |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
244 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
245 if len(args) == 1: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
246 # it might be a little too weird that cmdline arg to this |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
247 # process changes anything else in the same session. But also |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
248 # I'm not sure who would ever make 2 subcomposers of the same |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
249 # session (except when quitting and restarting, to get the |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
250 # same window pos), so maybe it doesn't matter. But still, |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
251 # this tool should probably default to making new sessions |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
252 # usually instead of loading the same one |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
253 |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
254 def action(self, *args): |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
255 subname = self.entry.get() |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
256 self.cmd(subname) |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
257 print "sub", self.cmd, subname |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
258 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
259 task.LoopingCall(sc.sendupdate).start(10) |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
260 |
149 | 261 |
0 | 262 ############################# |
263 | |
264 if __name__ == "__main__": | |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
265 parser = OptionParser(usage="%prog [suburi]") |
458
8b307310cc1b
when KC launches SC to edit a sub, don't place the window right on the main SC window
drewp@bigasterisk.com
parents:
455
diff
changeset
|
266 parser.add_option('--no-geometry', action='store_true', |
8b307310cc1b
when KC launches SC to edit a sub, don't place the window right on the main SC window
drewp@bigasterisk.com
parents:
455
diff
changeset
|
267 help="don't save/restore window geometry") |
810 | 268 clientsession.add_option(parser) |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
269 opts, args = parser.parse_args() |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
270 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
271 logging.basicConfig(level=logging.DEBUG) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
272 |
0 | 273 root=tk.Tk() |
274 root.config(bg='black') | |
147 | 275 root.tk_setPalette("#004633") |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
276 |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
277 initTkdnd(root.tk, 'tkdnd/trunk/') |
0 | 278 |
803 | 279 graph = SyncedGraph("subcomposer") |
810 | 280 session = clientsession.getUri('subcomposer', opts) |
803 | 281 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
282 graph.initiallySynced.addCallback(lambda _: launch(opts, args, root, graph, session)) |
557
4e558643c952
subcomposer: squelch the exception we got every time we exited
David McClosky <dmcc@bigasterisk.com>
parents:
458
diff
changeset
|
283 |
810 | 284 root.protocol('WM_DELETE_WINDOW', reactor.stop) |
803 | 285 tksupport.install(root,ms=10) |
286 prof.run(reactor.run, profile=False) |