Mercurial > code > home > repos > light9
comparison bin/curvecalc @ 950:41c6fbe95214
drag sub into curve area to get a curve+subterm and a 0..1 fade at the current play time
Ignore-this: ac77acf1cfbcfbce2f6b77da670b407
author | drewp@bigasterisk.com |
---|---|
date | Thu, 13 Jun 2013 21:59:32 +0000 |
parents | 183e3afea4cc |
children | 1e01727312f0 |
comparison
equal
deleted
inserted
replaced
949:022e997b50c4 | 950:41c6fbe95214 |
---|---|
88 | 88 |
89 self.refreshCurveView() | 89 self.refreshCurveView() |
90 | 90 |
91 self.makeStatusLines(wtree.get_object("status")) | 91 self.makeStatusLines(wtree.get_object("status")) |
92 | 92 |
93 | |
94 self.acceptDragsOnCurveViews() | |
95 | |
93 def connect(w): | 96 def connect(w): |
94 w.drag_dest_set(flags=gtk.DEST_DEFAULT_ALL, | 97 w.drag_dest_set(flags=gtk.DEST_DEFAULT_ALL, |
95 targets=[('text/uri-list', 0, 0)], | 98 targets=[('text/uri-list', 0, 0)], |
96 actions=gtk.gdk.ACTION_COPY) | 99 actions=gtk.gdk.ACTION_COPY) |
97 w.connect("drag-data-received", self.onDataReceived) | 100 w.connect("drag-data-received", self.onDataReceived) |
108 #connect(wtree.get_object("subterms")) # works for that area | 111 #connect(wtree.get_object("subterms")) # works for that area |
109 | 112 |
110 # may not work | 113 # may not work |
111 wtree.get_object("paned1").set_position(600) | 114 wtree.get_object("paned1").set_position(600) |
112 | 115 |
116 def acceptDragsOnCurveViews(self): | |
117 w = self.wtree.get_object("curves") | |
118 w.drag_dest_set(flags=gtk.DEST_DEFAULT_ALL, | |
119 targets=[('text/uri-list', 0, 0)], | |
120 actions=gtk.gdk.ACTION_COPY) | |
121 def recv(widget, context, x, y, selection, | |
122 targetType, time): | |
123 subUri = URIRef(selection.data.strip()) | |
124 print "into curves", subUri | |
125 with self.graph.currentState( | |
126 tripleFilter=(subUri, RDFS.label, None)) as current: | |
127 subName = current.label(subUri) | |
128 | |
129 try: | |
130 self.makeSubterm(subName, withCurve=True, | |
131 sub=subUri, | |
132 expr="%s(t)" % subName) | |
133 except SubtermExists: | |
134 # we're not making sure the expression/etc are | |
135 # correct-- user mihgt need to fix things | |
136 pass | |
137 curveView = self.curvesetView.row(subName).curveView | |
138 t = self.lastSeenInputTime # curveView.current_time() # new curve hasn't heard the time yet. this has gotten too messy- everyone just needs to be able to reach the time source | |
139 print "time", t | |
140 curveView.add_points([(t - .5, 0), | |
141 (t, 1)]) | |
142 w.connect("drag-data-received", recv) | |
143 | |
113 def onDataReceived(self, widget, context, x, y, selection, | 144 def onDataReceived(self, widget, context, x, y, selection, |
114 targetType, time): | 145 targetType, time): |
115 data = selection.data.strip() | 146 data = selection.data.strip() |
116 if '?' in data: | 147 if '?' in data: |
117 self.handleSubtermDrop(data) | 148 self.handleSubtermDrop(data) |
123 self.makeSubterm(subName, withCurve=True) | 154 self.makeSubterm(subName, withCurve=True) |
124 except SubtermExists: | 155 except SubtermExists: |
125 pass | 156 pass |
126 curveView = self.curvesetView.row(subName).curveView | 157 curveView = self.curvesetView.row(subName).curveView |
127 t = self.lastSeenInputTime # curveView.current_time() # new curve hasn't heard the time yet. this has gotten too messy- everyone just needs to be able to reach the time source | 158 t = self.lastSeenInputTime # curveView.current_time() # new curve hasn't heard the time yet. this has gotten too messy- everyone just needs to be able to reach the time source |
128 print "time", t | |
129 curveView.add_points([(t - .5, 0), | 159 curveView.add_points([(t - .5, 0), |
130 (t, 1)]) | 160 (t, 1)]) |
131 | 161 |
132 def onDragDataInNewSubZone(self, widget, context, x, y, selection, | 162 def onDragDataInNewSubZone(self, widget, context, x, y, selection, |
133 targetType, time): | 163 targetType, time): |
188 | 218 |
189 def songSubtermsContext(self): | 219 def songSubtermsContext(self): |
190 return self.currentSong() | 220 return self.currentSong() |
191 | 221 |
192 def makeSubterm(self, newname, withCurve=False, expr=None, sub=None): | 222 def makeSubterm(self, newname, withCurve=False, expr=None, sub=None): |
223 """ | |
224 raises SubtermExists if we had a subterm with a sub with the given | |
225 name. what about a no-sub term with the same label? who knows | |
226 """ | |
227 assert isinstance(newname, Literal), repr(newname) | |
228 if withCurve: | |
229 self.curveset.new_curve(newname, renameIfExisting=False) | |
230 if newname in self.all_subterm_labels(): | |
231 raise SubtermExists("have a subterm who sub is named %r" % newname) | |
193 with self.graph.currentState() as current: | 232 with self.graph.currentState() as current: |
194 song = self.currentSong() | 233 song = self.currentSong() |
195 for i in range(1000): | 234 for i in range(1000): |
196 uri = song + "/subterm/%d" % i | 235 uri = song + "/subterm/%d" % i |
197 if (uri, None, None) not in current: | 236 if (uri, None, None) not in current: |
209 quads.append((uri, L9['sub'], sub, ctx)) | 248 quads.append((uri, L9['sub'], sub, ctx)) |
210 if expr is not None: | 249 if expr is not None: |
211 quads.append((uri, L9['expression'], Literal(expr), ctx)) | 250 quads.append((uri, L9['expression'], Literal(expr), ctx)) |
212 self.graph.patch(Patch(addQuads=quads)) | 251 self.graph.patch(Patch(addQuads=quads)) |
213 | 252 |
214 if withCurve: | |
215 self.curveset.new_curve(newname) | |
216 return uri | 253 return uri |
217 | 254 |
255 def all_subterm_labels(self): | |
256 """ | |
257 Literal labels of subs in subterms. doesn't currently include labels of the | |
258 subterm resources. I'm not sure what I'm going to do with | |
259 those. | |
260 """ | |
261 labels = [] | |
262 with self.graph.currentState() as current: | |
263 for st in current.objects( | |
264 current.value(self.session, L9['currentSong']), | |
265 L9['subterm']): | |
266 sub = current.value(st, L9['sub']) | |
267 if sub is not None: | |
268 labels.append(current.label(sub)) | |
269 return labels | |
270 | |
218 def set_subterms_from_graph(self): | 271 def set_subterms_from_graph(self): |
219 """rebuild all the gtktable 'subterms' widgets and the | 272 """rebuild all the gtktable 'subterms' widgets and the |
220 self.currentSubterms list""" | 273 self.currentSubterms list""" |
221 song = self.graph.value(self.session, L9['currentSong']) | 274 song = self.graph.value(self.session, L9['currentSong']) |
222 | 275 |
283 results = dispatcher.send("onPlayPause") | 336 results = dispatcher.send("onPlayPause") |
284 times = [t for listener, t in results if t is not None] | 337 times = [t for listener, t in results if t is not None] |
285 self.music.playOrPause(t=times[0] if times else None) | 338 self.music.playOrPause(t=times[0] if times else None) |
286 | 339 |
287 def onSave(self, *args): | 340 def onSave(self, *args): |
341 # only doing curves still. I hope to eliminate all this. | |
288 with self.graph.currentState() as g: | 342 with self.graph.currentState() as g: |
289 song = g.value(self.session, L9['currentSong']) | 343 song = g.value(self.session, L9['currentSong']) |
290 | 344 |
291 log.info("saving curves for %r", song) | 345 log.info("saving curves for %r", song) |
292 self.curveset.save(basename=os.path.join( | 346 self.curveset.save(basename=os.path.join( |