Mercurial > code > home > repos > light9
annotate bin/subcomposer @ 1858:7772cc48e016
reformat all python
Ignore-this: 1135b78893f8b3d31badddda7f45678f
author | drewp@bigasterisk.com |
---|---|
date | Tue, 21 May 2019 23:56:12 +0000 |
parents | f140153c087c |
children | f066d6e874db |
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 |
1697
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1692
diff
changeset
|
19 |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1692
diff
changeset
|
20 from run_local import log |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
21 import time, logging |
1697
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1692
diff
changeset
|
22 |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1692
diff
changeset
|
23 log.setLevel(logging.DEBUG) |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1692
diff
changeset
|
24 |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
25 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
|
26 import logging, urllib |
0 | 27 import Tkinter as tk |
802 | 28 import louie as dispatcher |
803 | 29 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
|
30 from rdflib import URIRef, RDF, RDFS, Literal |
0 | 31 |
209
1a84c5e83d3e
dmxserver and subcomposer work in new layout
drewp@bigasterisk.com
parents:
201
diff
changeset
|
32 from light9.dmxchanedit import Levelbox |
1133 | 33 from light9 import dmxclient, Submaster, prof, showconfig, networking |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
34 from light9.Patch import get_channel_name |
455
9dd2baa41cca
subcomposer remembers window position
drewp@bigasterisk.com
parents:
450
diff
changeset
|
35 from light9.uihelpers import toplevelat |
1692 | 36 from rdfdb.syncedgraph import SyncedGraph |
1698
f140153c087c
bring back clientsession which doesn't belong in rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1697
diff
changeset
|
37 from light9 import clientsession |
850 | 38 from light9.tkdnd import initTkdnd |
39 from light9.namespaces import L9 | |
1692 | 40 from rdfdb.patch import Patch |
850 | 41 from light9.observable import Observable |
42 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
|
43 from light9.subcomposer import subcomposerweb |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
44 |
0 | 45 |
46 class Subcomposer(tk.Frame): | |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
47 """ |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
48 <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
|
49 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
|
50 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
|
51 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
52 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
|
53 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
|
54 special cases. |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
55 |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
56 Contains an EditChoice widget |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
57 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
58 Dependencies: |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
59 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
60 graph (?session :currentSub ?s) -> self.currentSub |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
61 self.currentSub -> graph |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
62 self.currentSub -> self._currentChoice (which might be Local) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
63 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
|
64 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
65 inside the current sub: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
66 graph -> Submaster levels (handled in Submaster) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
67 Submaster levels -> OneLevel widget |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
68 OneLevel widget -> Submaster.editLevel |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
69 Submaster.editLevel -> graph (handled in Submaster) |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
70 |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
71 """ |
1858 | 72 |
810 | 73 def __init__(self, master, graph, session): |
0 | 74 tk.Frame.__init__(self, master, bg='black') |
803 | 75 self.graph = graph |
810 | 76 self.session = session |
1267
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
77 self.launchTime = time.time() |
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
78 self.localSerial = 0 |
0 | 79 |
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
|
80 # 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
|
81 # 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
|
82 # 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
|
83 # 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
|
84 self._currentChoice = Observable(Local) |
0 | 85 |
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
|
86 # this is a PersistentSubmaster (even for local) |
1858 | 87 self.currentSub = Observable( |
88 Submaster.PersistentSubmaster(graph, self.switchToLocal())) | |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
89 |
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
90 def pc(val): |
850 | 91 log.info("change viewed sub to %s", val) |
1858 | 92 |
850 | 93 self._currentChoice.subscribe(pc) |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
94 |
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
|
95 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
|
96 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
|
97 |
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 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
|
99 self.setupSubChoiceLinks() |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
100 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
|
101 |
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 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 b.pack() |
1858 | 110 |
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
|
111 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
|
112 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
|
113 box.destroy() |
1858 | 114 |
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
|
115 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
|
116 e.focus() |
1858 | 117 |
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
|
118 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
|
119 """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
|
120 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
|
121 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
|
122 urllib.quote(newName, safe='')) |
1858 | 123 with self.graph.currentState(tripleFilter=(uri, None, None)) as current: |
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
|
124 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
|
125 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
|
126 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
|
127 raise ValueError("new uri %s is in use" % newUri) |
1858 | 128 |
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
|
129 # 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
|
130 # 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
|
131 |
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 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
|
133 |
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 # these are in separate patches for clarity as i'm debugging this |
1858 | 135 self.graph.patch( |
136 Patch(addQuads=[ | |
137 (newUri, RDFS.label, Literal(newName), newUri), | |
138 ], | |
139 delQuads=[ | |
140 (newUri, RDF.type, L9['LocalSubmaster'], newUri), | |
141 ])) | |
142 self.graph.patchObject(self.session, self.session, L9['currentSub'], | |
143 newUri) | |
144 | |
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
|
145 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
|
146 # 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
|
147 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
|
148 |
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 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
|
150 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
|
151 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
|
152 return u |
1858 | 153 |
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
|
154 delQuads = self.currentSub().allQuads() |
1858 | 155 addQuads = [(repl(s), p, repl(o), newUri) for s, p, o, c in 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
|
156 # 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
|
157 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
|
158 self.graph.patch(Patch(addQuads=[], delQuads=delQuads)) |
1858 | 159 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
160 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
|
161 graph = self.graph |
1858 | 162 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
163 def ann(): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
164 print "currently: session=%s currentSub=%r _currentChoice=%r" % ( |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
165 self.session, self.currentSub(), self._currentChoice()) |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
166 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
167 @graph.addHandler |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
168 def graphChanged(): |
1267
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
169 # some bug where SC is making tons of graph edits and many |
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
170 # are failing. this calms things down. |
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
171 log.warn('skip graphChanged') |
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
172 return |
1858 | 173 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
174 s = graph.value(self.session, L9['currentSub']) |
1267
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
175 log.debug('HANDLER getting session currentSub from graph: %s', s) |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
176 if s is None: |
932 | 177 s = self.switchToLocal() |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
178 self.currentSub(Submaster.PersistentSubmaster(graph, s)) |
0 | 179 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
180 @self.currentSub.subscribe |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
181 def subChanged(newSub): |
1267
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
182 log.debug('HANDLER currentSub changed to %s', newSub) |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
183 if newSub is None: |
1858 | 184 graph.patchObject(self.session, self.session, L9['currentSub'], |
185 None) | |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
186 return |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
187 self.sendupdate() |
1858 | 188 graph.patchObject(self.session, self.session, L9['currentSub'], |
189 newSub.uri) | |
0 | 190 |
911
4b9997ab0e4f
push some logs down to debug. -v flag on SC. another tripleFilter optimization
Drew Perttula <drewp@bigasterisk.com>
parents:
880
diff
changeset
|
191 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
|
192 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
|
193 if newSub and localStmt in current: |
1267
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
194 log.debug(' HANDLER set _currentChoice to Local') |
880
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
195 self._currentChoice(Local) |
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
196 else: |
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
197 # i think right here is the point that the last local |
1267
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
198 # becomes garbage, and we could clean it up. |
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
199 log.debug(' HANDLER set _currentChoice to newSub.uri') |
880
e09e3d1d83d5
slightly better behavior when the graph is out of sync. add LocalSubmaster type
drewp@bigasterisk.com
parents:
874
diff
changeset
|
200 self._currentChoice(newSub.uri) |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
201 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
202 dispatcher.connect(self.levelsChanged, "sub levels changed") |
1858 | 203 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
204 @self._currentChoice.subscribe |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
205 def choiceChanged(newChoice): |
1267
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
206 log.debug('HANDLER choiceChanged to %s', newChoice) |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
207 if newChoice is Local: |
932 | 208 newChoice = self.switchToLocal() |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
209 if newChoice is not None: |
1267
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
210 newSub = Submaster.PersistentSubmaster(graph, newChoice) |
1858 | 211 log.debug('write new choice to currentSub, from %r to %r', |
212 self.currentSub(), newSub) | |
1267
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
213 self.currentSub(newSub) |
0 | 214 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
215 def levelsChanged(self, sub): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
216 if sub == self.currentSub(): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
217 self.sendupdate() |
1858 | 218 |
932 | 219 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
|
220 """ |
dcab422615ca
working on local->global sub action. creation of new file in rdfdb is still a problem
drewp@bigasterisk.com
parents:
914
diff
changeset
|
221 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
|
222 """ |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
223 # 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
|
224 # subcomposer process and don't use PersistentSubmaster at all? |
1267
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
225 localId = "%s-%s" % (self.launchTime, self.localSerial) |
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
226 self.localSerial += 1 |
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
227 new = URIRef("http://light9.bigasterisk.com/sub/local/%s" % localId) |
ce8a71fab284
trying to fix SC bad graph reload behavior, but this barely works. other tools have trouble too
drewp@bigasterisk.com
parents:
1164
diff
changeset
|
228 log.debug('making up a local sub %s', new) |
1858 | 229 self.graph.patch( |
230 Patch(addQuads=[ | |
231 (new, RDF.type, L9['Submaster'], self.session), | |
232 (new, RDF.type, L9['LocalSubmaster'], self.session), | |
233 ])) | |
234 | |
874
167a61d3cfbf
subcomposer put local subs into the graph with a type edge.
Drew Perttula <drewp@bigasterisk.com>
parents:
867
diff
changeset
|
235 return new |
1858 | 236 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
237 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
|
238 self.levelbox = Levelbox(self, self.graph, self.currentSub) |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
239 self.levelbox.pack(side='top') |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
240 |
1858 | 241 tk.Button( |
242 self, | |
243 text="All to zero", | |
244 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
|
245 |
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
|
246 def savenewsub(self, subname): |
1858 | 247 leveldict = {} |
248 for i, lev in zip(range(len(self.levels)), self.levels): | |
249 if lev != 0: | |
250 leveldict[get_channel_name(i + 1)] = lev | |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
251 |
1858 | 252 s = Submaster.Submaster(subname, levels=leveldict) |
0 | 253 s.save() |
802 | 254 |
0 | 255 def sendupdate(self): |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
256 d = self.currentSub().get_dmx_list() |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
257 dmxclient.outputlevels(d, twisted=True) |
802 | 258 |
0 | 259 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
260 def launch(opts, args, root, graph, session): |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
261 if not opts.no_geometry: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
262 toplevelat("subcomposer - %s" % opts.session, root, graph, session) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
263 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
264 sc = Subcomposer(root, graph, session) |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
265 sc.pack() |
1858 | 266 |
1164
65f0179a9254
subcomposer has a web ui with buttons for toggling lights
drewp@bigasterisk.com
parents:
1133
diff
changeset
|
267 subcomposerweb.init(graph, session, sc.currentSub) |
818
bf728997bfde
start the observable between editchoice and the editor
drewp@bigasterisk.com
parents:
817
diff
changeset
|
268 |
1858 | 269 tk.Label(root, |
270 text="Bindings: B1 adjust level; B2 set full; B3 instant bump", | |
271 font="Helvetica -12 italic", | |
272 anchor='w').pack(side='top', fill='x') | |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
273 |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
274 if len(args) == 1: |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
275 # 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
|
276 # 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
|
277 # 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
|
278 # session (except when quitting and restarting, to get the |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
279 # 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
|
280 # this tool should probably default to making new sessions |
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
281 # usually instead of loading the same one |
1858 | 282 graph.patchObject(session, session, L9['currentSub'], URIRef(args[0])) |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
283 |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
284 task.LoopingCall(sc.sendupdate).start(10) |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
285 |
149 | 286 |
0 | 287 ############################# |
288 | |
289 if __name__ == "__main__": | |
838
321fc6150ee3
subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents:
834
diff
changeset
|
290 parser = OptionParser(usage="%prog [suburi]") |
1858 | 291 parser.add_option('--no-geometry', |
292 action='store_true', | |
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
|
293 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
|
294 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
|
295 |
810 | 296 clientsession.add_option(parser) |
342
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
297 opts, args = parser.parse_args() |
2c782ca93e73
subcomposer takes sub name on cmdline
Drew Perttula <drewp@bigasterisk.com>
parents:
334
diff
changeset
|
298 |
911
4b9997ab0e4f
push some logs down to debug. -v flag on SC. another tripleFilter optimization
Drew Perttula <drewp@bigasterisk.com>
parents:
880
diff
changeset
|
299 log.setLevel(logging.DEBUG if opts.v else logging.INFO) |
1858 | 300 |
301 root = tk.Tk() | |
0 | 302 root.config(bg='black') |
147 | 303 root.tk_setPalette("#004633") |
817
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
304 |
6885c2fa9369
subcomposer halfway to having the editchoice widget
drewp@bigasterisk.com
parents:
810
diff
changeset
|
305 initTkdnd(root.tk, 'tkdnd/trunk/') |
0 | 306 |
1114
a38955ba6f40
rdfdb port is now in the config
Drew Perttula <drewp@bigasterisk.com>
parents:
932
diff
changeset
|
307 graph = SyncedGraph(networking.rdfdb.url, "subcomposer") |
810 | 308 session = clientsession.getUri('subcomposer', opts) |
803 | 309 |
1858 | 310 graph.initiallySynced.addCallback(lambda _: launch(opts, args, root, graph, |
311 session)) | |
557
4e558643c952
subcomposer: squelch the exception we got every time we exited
David McClosky <dmcc@bigasterisk.com>
parents:
458
diff
changeset
|
312 |
810 | 313 root.protocol('WM_DELETE_WINDOW', reactor.stop) |
1858 | 314 tksupport.install(root, ms=10) |
803 | 315 prof.run(reactor.run, profile=False) |