diff --git a/bin/curvecalc b/bin/curvecalc --- a/bin/curvecalc +++ b/bin/curvecalc @@ -172,15 +172,27 @@ class Main(object): self.makeSubterm(newname, withCurve=wc) dialog.hide() - def currentSong(self): - with self.graph.currentState() as current: + def currentSong(self, current=None): + def fin(current): return current.value(self.session, L9['currentSong']) + if current is None: + with self.graph.currentState() as current: + return fin(current) + else: + return fin(current) - def songSubtermsContext(self): - return self.currentSong() + def songSubtermsContext(self, current=None): + return self.currentSong(current=current) def makeSubterm(self, newname, withCurve=False, expr=None, sub=None): - uri = self.currentSong() + "/sub/%f" % time.time() + with self.graph.currentState() as current: + song = self.currentSong(current=current) + for i in range(1000): + uri = song + "/subterm/%d" % i + if (uri, None, None) not in current: + break + else: + raise ValueError("can't pick a name for the new subterm") ctx = self.songSubtermsContext() quads = [ diff --git a/light9/curvecalc/curvecalc.glade b/light9/curvecalc/curvecalc.glade --- a/light9/curvecalc/curvecalc.glade +++ b/light9/curvecalc/curvecalc.glade @@ -526,7 +526,7 @@ - False + True True 0 @@ -535,11 +535,12 @@ True False + 18 Drop new sub here - True + False True 1 diff --git a/light9/curvecalc/subterm.py b/light9/curvecalc/subterm.py --- a/light9/curvecalc/subterm.py +++ b/light9/curvecalc/subterm.py @@ -100,6 +100,8 @@ class Subterm(object): else: # otherwise, return our submaster multiplied by the value # returned + if subexpr_eval == 0: + return Submaster.Submaster("zero", {}) subUri = current.value(self.uri, L9['sub']) sub = self.submasters.get_sub_by_uri(subUri) return sub * subexpr_eval @@ -113,6 +115,7 @@ class Subterm(object): expr = current.value(self.uri, L9['expression']) + expr = current.value(self.uri, L9['expression']) if not expr: dispatcher.send("expr_error", sender=self.uri, exc="no expr, using 0") return 0 diff --git a/light9/curvecalc/subtermview.py b/light9/curvecalc/subtermview.py --- a/light9/curvecalc/subtermview.py +++ b/light9/curvecalc/subtermview.py @@ -35,14 +35,13 @@ class Subexprview(object): def set_expression_from_graph(self): e = str(self.graph.value(self.ownerSubterm, L9['expression'])) - print "was going to set to %r" % e + print "from graph, set to %r" % e if e != self.entryBuffer.get_text(): self.entryBuffer.set_text(e, len(e)) def entry_changed(self, *args): log.info("want to patch to %r", self.entryBuffer.get_text()) - return self.graph.patchObject(self.saveContext, self.ownerSubterm, L9['expression'],