Mercurial > code > home > repos > light9
annotate bin/subcomposer @ 1164:65f0179a9254
subcomposer has a web ui with buttons for toggling lights
Ignore-this: f8cf76c46d81eec86c8945a61f6a594d
author | drewp@bigasterisk.com |
---|---|
date | Sun, 15 Jun 2014 02:23:39 +0000 |
parents | 0923efae4588 |
children | ce8a71fab284 |
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 |
924
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
21 import logging, urllib |
0 | 22 import Tkinter as tk |
802 | 23 import louie as dispatcher |
803 | 24 from twisted.internet import reactor, tksupport, task |
924
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
25 from rdflib import URIRef, RDF, RDFS, Literal |
0 | 26 |
833 | 27 from run_local import log |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
28 log.setLevel(logging.DEBUG) |
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
29 |
209
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
201
diff
changeset
|
30 from light9.dmxchanedit import Levelbox |
1133 | 31 from light9 import dmxclient, Submaster, prof, showconfig, networking |
32 | |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
33 from light9.Patch import get_channel_name |
455
9dd2baa41cca
subcomposer remembers window position
drewp@bigasterisk.com
parents:
450
diff
changeset
|
34 from light9.uihelpers import toplevelat |
803 | 35 from light9.rdfdb.syncedgraph import SyncedGraph |
810 | 36 from light9.rdfdb import clientsession |
850 | 37 from light9.tkdnd import initTkdnd |
38 from light9.namespaces import L9 | |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
39 from light9.rdfdb.patch import Patch |
850 | 40 from light9.observable import Observable |
41 from light9.editchoice import EditChoice, Local | |
1164
65f0179a9254
subcomposer has a web ui with buttons for toggling lights
drewp@bigasterisk.com
parents:
1133
diff
changeset
|
42 from light9.subcomposer import subcomposerweb |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
43 |
0 | 44 |
45 class Subcomposer(tk.Frame): | |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
46 """ |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
47 <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
|
48 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
|
49 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
|
50 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
51 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
|
52 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
|
53 special cases. |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
54 |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
55 Contains an EditChoice widget |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
56 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
57 Dependencies: |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
58 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
59 graph (?session :currentSub ?s) -> self.currentSub |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
60 self.currentSub -> graph |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
61 self.currentSub -> self._currentChoice (which might be Local) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
62 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
|
63 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
64 inside the current sub: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
65 graph -> Submaster levels (handled in Submaster) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
66 Submaster levels -> OneLevel widget |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
67 OneLevel widget -> Submaster.editLevel |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
68 Submaster.editLevel -> graph (handled in Submaster) |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
69 |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
70 """ |
810 | 71 def __init__(self, master, graph, session): |
0 | 72 tk.Frame.__init__(self, master, bg='black') |
803 | 73 self.graph = graph |
810 | 74 self.session = session |
0 | 75 |
924
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
76 # this is a URIRef or Local. Strangely, the Local case still |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
77 # has a uri, which you can get from |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
78 # self.currentSub.uri. Probably that should be on the Local |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
79 # object too, or maybe Local should be a subclass of URIRef |
867
4b3d7e8ba24a
subcomposer is nicer if we always have some Submaster object. and if you call all the init code
Drew Perttula <drewp@bigasterisk.com>
parents:
850
diff
changeset
|
80 self._currentChoice = Observable(Local) |
0 | 81 |
867
4b3d7e8ba24a
subcomposer is nicer if we always have some Submaster object. and if you call all the init code
Drew Perttula <drewp@bigasterisk.com>
parents:
850
diff
changeset
|
82 # this is a PersistentSubmaster (even for local) |
4b3d7e8ba24a
subcomposer is nicer if we always have some Submaster object. and if you call all the init code
Drew Perttula <drewp@bigasterisk.com>
parents:
850
diff
changeset
|
83 self.currentSub = Observable(Submaster.PersistentSubmaster( |
932 | 84 graph, self.switchToLocal())) |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
85 |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
86 def pc(val): |
850 | 87 log.info("change viewed sub to %s", val) |
88 self._currentChoice.subscribe(pc) | |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
89 |
924
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
90 ec = self.editChoice = EditChoice(self, self.graph, self._currentChoice) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
91 ec.frame.pack(side='top') |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
92 |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
93 ec.subIcon.bind("<ButtonPress-1>", self.clickSubIcon) |
867
4b3d7e8ba24a
subcomposer is nicer if we always have some Submaster object. and if you call all the init code
Drew Perttula <drewp@bigasterisk.com>
parents:
850
diff
changeset
|
94 self.setupSubChoiceLinks() |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
95 self.setupLevelboxUi() |
924
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
96 |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
97 def clickSubIcon(self, *args): |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
98 box = tk.Toplevel(self.editChoice.frame) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
99 box.wm_transient(self.editChoice.frame) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
100 tk.Label(box, text="Name this sub:").pack() |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
101 e = tk.Entry(box) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
102 e.pack() |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
103 b = tk.Button(box, text="Make global") |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
104 b.pack() |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
105 def clicked(*args): |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
106 self.makeGlobal(newName=e.get()) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
107 box.destroy() |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
108 |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
109 b.bind("<Button-1>", clicked) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
110 e.focus() |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
111 |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
112 def makeGlobal(self, newName): |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
113 """promote our local submaster into a non-local, named one""" |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
114 uri = self.currentSub().uri |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
115 newUri = showconfig.showUri() + ("/sub/%s" % |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
116 urllib.quote(newName, safe='')) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
117 with self.graph.currentState( |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
118 tripleFilter=(uri, None, None)) as current: |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
119 if (uri, RDF.type, L9['LocalSubmaster']) not in current: |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
120 raise ValueError("%s is not a local submaster" % uri) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
121 if (newUri, None, None) in current: |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
122 raise ValueError("new uri %s is in use" % newUri) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
123 |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
124 # the local submaster was storing in ctx=self.session, but now |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
125 # we want it to be in ctx=uri |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
126 |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
127 self.relocateSub(newUri, newName) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
128 |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
129 # these are in separate patches for clarity as i'm debugging this |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
130 self.graph.patch(Patch(addQuads=[ |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
131 (newUri, RDFS.label, Literal(newName), newUri), |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
132 ], delQuads=[ |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
133 (newUri, RDF.type, L9['LocalSubmaster'], newUri), |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
134 ])) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
135 self.graph.patchObject(self.session, |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
136 self.session, L9['currentSub'], newUri) |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
137 |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
138 def relocateSub(self, newUri, newName): |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
139 # maybe this goes in Submaster |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
140 uri = self.currentSub().uri |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
141 |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
142 def repl(u): |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
143 if u == uri: |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
144 return newUri |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
145 return u |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
146 delQuads = self.currentSub().allQuads() |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
147 addQuads = [(repl(s), p, repl(o), newUri) for s,p,o,c in delQuads] |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
148 # patch can't span contexts yet |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
149 self.graph.patch(Patch(addQuads=addQuads, delQuads=[])) |
929
c20c2eea6fce
another hack to stop graphfile from thinking its own new empty file means it should delete all the statements in that context
Drew Perttula <drewp@bigasterisk.com>
parents:
924
diff
changeset
|
150 self.graph.patch(Patch(addQuads=[], delQuads=delQuads)) |
924
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
151 |
867
4b3d7e8ba24a
subcomposer is nicer if we always have some Submaster object. and if you call all the init code
Drew Perttula <drewp@bigasterisk.com>
parents:
850
diff
changeset
|
152 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
153 def setupSubChoiceLinks(self): |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
154 graph = self.graph |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
155 def ann(): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
156 print "currently: session=%s currentSub=%r _currentChoice=%r" % ( |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
157 self.session, self.currentSub(), self._currentChoice()) |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
158 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
159 @graph.addHandler |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
160 def graphChanged(): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
161 s = graph.value(self.session, L9['currentSub']) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
162 if s is None: |
932 | 163 s = self.switchToLocal() |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
164 self.currentSub(Submaster.PersistentSubmaster(graph, s)) |
0 | 165 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
166 @self.currentSub.subscribe |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
167 def subChanged(newSub): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
168 if newSub is None: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
169 graph.patchObject(self.session, |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
170 self.session, L9['currentSub'], None) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
171 return |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
172 self.sendupdate() |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
173 graph.patchObject(self.session, |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
174 self.session, L9['currentSub'], newSub.uri) |
0 | 175 |
911
4b9997ab0e4f
push some logs down to debug. -v flag on SC. another tripleFilter optimization
Drew Perttula <drewp@bigasterisk.com>
parents:
880
diff
changeset
|
176 localStmt = (newSub.uri, RDF.type, L9['LocalSubmaster']) |
4b9997ab0e4f
push some logs down to debug. -v flag on SC. another tripleFilter optimization
Drew Perttula <drewp@bigasterisk.com>
parents:
880
diff
changeset
|
177 with graph.currentState(tripleFilter=localStmt) as current: |
4b9997ab0e4f
push some logs down to debug. -v flag on SC. another tripleFilter optimization
Drew Perttula <drewp@bigasterisk.com>
parents:
880
diff
changeset
|
178 if newSub and localStmt in current: |
880
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
179 self._currentChoice(Local) |
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
180 else: |
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
181 # i think right here is the point that the last local |
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
182 # becomes garbage, and we could clean it up. |
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
183 self._currentChoice(newSub.uri) |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
184 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
185 dispatcher.connect(self.levelsChanged, "sub levels changed") |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
186 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
187 @self._currentChoice.subscribe |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
188 def choiceChanged(newChoice): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
189 if newChoice is Local: |
932 | 190 newChoice = self.switchToLocal() |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
191 if newChoice is not None: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
192 self.currentSub(Submaster.PersistentSubmaster( |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
193 graph, newChoice)) |
0 | 194 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
195 def levelsChanged(self, sub): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
196 if sub == self.currentSub(): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
197 self.sendupdate() |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
198 |
932 | 199 def switchToLocal(self): |
924
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
200 """ |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
201 change our display to a local submaster |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
202 """ |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
203 # 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
|
204 # subcomposer process and don't use PersistentSubmaster at all? |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
205 |
932 | 206 new = URIRef("http://light9.bigasterisk.com/sub/local/%s" % time.time()) |
880
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
207 self.graph.patch(Patch(addQuads=[ |
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
208 (new, RDF.type, L9['Submaster'], self.session), |
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
209 (new, RDF.type, L9['LocalSubmaster'], self.session), |
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
210 ])) |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
211 |
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
212 return new |
838
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): |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
215 self.levelbox = Levelbox(self, self.graph, self.currentSub) |
838
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: | |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
225 leveldict[get_channel_name(i+1)]=lev |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
226 |
914 | 227 s=Submaster.Submaster(subname, levels=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 |
1164
65f0179a9254
subcomposer has a web ui with buttons for toggling lights
drewp@bigasterisk.com
parents:
1133
diff
changeset
|
239 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
240 sc = Subcomposer(root, graph, session) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
241 sc.pack() |
1164
65f0179a9254
subcomposer has a web ui with buttons for toggling lights
drewp@bigasterisk.com
parents:
1133
diff
changeset
|
242 |
65f0179a9254
subcomposer has a web ui with buttons for toggling lights
drewp@bigasterisk.com
parents:
1133
diff
changeset
|
243 subcomposerweb.init(graph, session, sc.currentSub) |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
244 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
245 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
|
246 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
|
247 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
248 if len(args) == 1: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
249 # 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
|
250 # 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
|
251 # 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
|
252 # session (except when quitting and restarting, to get the |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
253 # 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
|
254 # this tool should probably default to making new sessions |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
255 # usually instead of loading the same one |
850 | 256 graph.patchObject(session, |
257 session, L9['currentSub'], URIRef(args[0])) | |
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") |
911
4b9997ab0e4f
push some logs down to debug. -v flag on SC. another tripleFilter optimization
Drew Perttula <drewp@bigasterisk.com>
parents:
880
diff
changeset
|
268 parser.add_option('-v', action='store_true', help="log debug level") |
4b9997ab0e4f
push some logs down to debug. -v flag on SC. another tripleFilter optimization
Drew Perttula <drewp@bigasterisk.com>
parents:
880
diff
changeset
|
269 |
810 | 270 clientsession.add_option(parser) |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
271 opts, args = parser.parse_args() |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
272 |
911
4b9997ab0e4f
push some logs down to debug. -v flag on SC. another tripleFilter optimization
Drew Perttula <drewp@bigasterisk.com>
parents:
880
diff
changeset
|
273 log.setLevel(logging.DEBUG if opts.v else logging.INFO) |
4b9997ab0e4f
push some logs down to debug. -v flag on SC. another tripleFilter optimization
Drew Perttula <drewp@bigasterisk.com>
parents:
880
diff
changeset
|
274 |
0 | 275 root=tk.Tk() |
276 root.config(bg='black') | |
147 | 277 root.tk_setPalette("#004633") |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
278 |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
279 initTkdnd(root.tk, 'tkdnd/trunk/') |
0 | 280 |
1114
a38955ba6f40
rdfdb port is now in the config
Drew Perttula <drewp@bigasterisk.com>
parents:
932
diff
changeset
|
281 graph = SyncedGraph(networking.rdfdb.url, "subcomposer") |
810 | 282 session = clientsession.getUri('subcomposer', opts) |
803 | 283 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
284 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
|
285 |
810 | 286 root.protocol('WM_DELETE_WINDOW', reactor.stop) |
803 | 287 tksupport.install(root,ms=10) |
288 prof.run(reactor.run, profile=False) |