diff --git a/bin/curvecalc b/bin/curvecalc --- a/bin/curvecalc +++ b/bin/curvecalc @@ -53,19 +53,6 @@ def makeStatusLines(master): l.config(text=sn+": "+tf(val)), signame, weak=False) -def add_subterms_for_song(graph, song, curveset, subterms, master): - for st in graph.objects(song, L9['subterm']): - log.info("song %s has subterm %s", song, st) - try: - add_one_subterm(graph, graph.value(st, L9['sub']), curveset, - subterms, master, graph.value(st, L9['expression'])) - except rdflib.exceptions.UniquenessError: - print "working around curvecalc save corruption" - # curvecalc put all the expressions on one subterm, which is wrong - for expr in graph.objects(st, L9['expression']): - add_one_subterm(graph, graph.value(st, L9['sub']), - curveset, subterms, master, expr) - def makeGraph(): graphOrig = showconfig.getGraph() @@ -130,7 +117,8 @@ def createHelpLines(root): line.pack(side='top',fill='x') class Main(object): - def __init__(self): + def __init__(self, graph, song, curveset, subterms): + self.graph = graph wtree = gtk.Builder() wtree.add_from_file(sibpath(__file__, "../light9/curvecalc/curvecalc.glade")) mainwin = wtree.get_object("MainWindow") @@ -139,6 +127,23 @@ class Main(object): mainwin.show_all() #gobject.timeout_add(1000 // framerate, self.updateLoop) + mainwin.set_title("curvecalc - %s" % graph.label(song)) + + self.add_subterms_for_song(song, curveset, subterms, + wtree.get_object("subterms") + ) + + def add_subterms_for_song(self, song, curveset, subterms, master): + for st in self.graph.objects(song, L9['subterm']): + log.info("song %s has subterm %s", song, st) + add_one_subterm(self.graph, + self.graph.value(st, L9['sub']), + curveset, + subterms, + master, + self.graph.value(st, L9['expression'])) + master.show_all() + def main(): startTime = time.time() parser = optparse.OptionParser() @@ -165,17 +170,6 @@ def main(): music=Music() graph = makeGraph() - start=Main() - #gtk2reactor.install() - - if opts.startup_only: - log.debug("quitting now because of --startup-only") - return - - gtk.main() - 1/0 - ################### - curveset = Curveset(sliders=opts.sliders) subterms = [] @@ -194,7 +188,17 @@ def main(): maxtime = wavelength(musicfilename) dispatcher.connect(lambda: maxtime, "get max time", weak=False) - root.title("curvecalc - %s" % graph.label(song)) + start = Main(graph, song, curveset, subterms) + #gtk2reactor.install() + + if opts.startup_only: + log.debug("quitting now because of --startup-only") + return + + gtk.main() + 1/0 + ################### + if 'fixed top rows': zc = Zoomcontrol(root) @@ -225,8 +229,6 @@ def main(): createHelpLines(helpBox) helpBox.pack(side='top', fill='x') - add_subterms_for_song(graph, song, curveset, subterms, - subtermScroll.subwidget('window')) setupKeyBindings(root, song, subterms, curveset) setupMenubar(menubar, root, song, subterms, curveset) diff --git a/light9/curvecalc/curvecalc.glade b/light9/curvecalc/curvecalc.glade --- a/light9/curvecalc/curvecalc.glade +++ b/light9/curvecalc/curvecalc.glade @@ -264,6 +264,7 @@ True False False + 0.5 True @@ -280,6 +281,7 @@ True False False + 0.5 True @@ -351,200 +353,48 @@ - + True True - never + True - + True - False + True + always - + True False - - - True - False - sub song01 - - - True - True - 0 - - + none - - True - False - - - True - True - - False - False - - - True - True - 0 - - - - - True - False - ok - - - True - True - 1 - - - - - True - True - 1 - - - - - True - True - 0 - - - - - True - False - - - True - False - sub song01 - - - True - True - 0 - - - - + True False + 2 - - True - True - - False - False - - - True - True - 0 - + - - True - False - ok - - - True - True - 1 - + - - True - True - 1 - - - True - True - 1 - - - - True - False - - - True - False - sub song01 - - - True - True - 0 - - - - - True - False - - - True - True - - False - False - - - True - True - 0 - - - - - True - False - ok - - - True - True - 1 - - - - - True - True - 1 - - - - - True - True - 2 - - + + + + + True + False + Subterms - False - False + True + True 2 diff --git a/light9/curvecalc/subtermview.py b/light9/curvecalc/subtermview.py --- a/light9/curvecalc/subtermview.py +++ b/light9/curvecalc/subtermview.py @@ -1,40 +1,79 @@ -import Tix as tk +import gtk from louie import dispatcher from rdflib import RDF, RDFS, Literal from light9 import Submaster from light9.namespaces import L9 from light9.curvecalc.subterm import Subterm, Subexpr +class Subexprview(object): + def __init__(self, se): + self.subexpr = se -class Subexprview(tk.Frame): - def __init__(self,master,se,**kw): - self.subexpr=se - tk.Frame.__init__(self,master,**kw) - self.evar = tk.StringVar() - e = self.ent = tk.Entry(self,textvariable=self.evar) - e.pack(side='left',fill='x',exp=1) + self.box = gtk.HBox() + + self.entryBuffer = gtk.EntryBuffer("", -1) + self.entry = gtk.Entry() + self.error = gtk.Label("") + + self.box.pack_start(self.entry, expand=True) + self.box.pack_start(self.error, expand=False) + + self.entry.set_buffer(self.entryBuffer) self.expr_changed() - self.evar.trace_variable('w',self.evar_changed) + self.entryBuffer.connect("deleted-text", self.evar_changed) + self.entryBuffer.connect("inserted-text", self.evar_changed) dispatcher.connect(self.expr_changed,"expr_changed", sender=self.subexpr) - self.error = tk.Label(self) - self.error.pack(side='left') - dispatcher.connect(lambda exc: self.error.config(text=str(exc)), + + dispatcher.connect(lambda exc: self.error.set_text(str(exc)), "expr_error",sender=self.subexpr,weak=0) + def expr_changed(self): - if self.subexpr.expr!=self.evar.get(): - self.evar.set(self.subexpr.expr) + e = str(self.subexpr.expr) + if e != self.entryBuffer.get_text(): + self.entryBuffer.set_text(e, len(e)) + def evar_changed(self,*args): - self.subexpr.expr = self.evar.get() + print "hi change" + self.subexpr.expr = self.entryBuffer.get_text() -class Subtermview(tk.Frame): - def __init__(self, master, graph, st, **kw): +class Subtermview(object): + """ + has .label and .exprView widgets for you to put in a table + """ + def __init__(self, graph, st): self.subterm = st - tk.Frame.__init__(self,master,bd=1,relief='raised',**kw) - l = tk.Label(self, text="sub %s" % self.subterm.submaster.name) - l.pack(side='left') - sev=Subexprview(self,self.subterm.subexpr) - sev.pack(side='left',fill='both',exp=1) + + self.label = gtk.Label("sub %s" % self.subterm.submaster.name) + + sev = Subexprview(self.subterm.subexpr) + self.exprView = sev.box + + +def add_one_subterm(graph, subUri, curveset, subterms, master, expr=None): + subname = graph.label(subUri) + print "%s's label is %s" % (subUri, subname) + if not subname: # fake sub, like for a chase + st = graph.subjects(L9['sub'], subUri).next() + subname = graph.label(st) + print "using parent subterm's name instead. parent %r, name %r" % (st, subname) + assert subname, "%s has no name" % subUri + if expr is None: + expr = '%s(t)' % subname + + term = Subterm(Submaster.Submaster(graph=graph, name=subname, sub=subUri), + Subexpr(curveset, expr)) + subterms.append(term) + + stv = Subtermview(graph, term) + y = master.get_property('n-rows') + master.resize(y + 1, columns=2) + master.attach(stv.label, 0, 1, y, y + 1, xoptions=0) + master.attach(stv.exprView, 1, 2, y, y + 1) + + return term + + def makeSubtermCommandRow(master, curveset, subterms, root, ssv, graph): """ @@ -69,23 +108,3 @@ def makeSubtermCommandRow(master, curves dispatcher.connect(focus_entry, "focus new subterm", weak=False) return f - -def add_one_subterm(graph, subUri, curveset, subterms, master, expr=None): - subname = graph.label(subUri) - print "%s's label is %s" % (subUri, subname) - if not subname: # fake sub, like for a chase - st = graph.subjects(L9['sub'], subUri).next() - subname = graph.label(st) - print "using parent subterm's name instead. parent %r, name %r" % (st, subname) - assert subname, "%s has no name" % subUri - if expr is None: - expr = '%s(t)' % subname - - term = Subterm(Submaster.Submaster(graph=graph, name=subname, sub=subUri), - Subexpr(curveset,expr)) - subterms.append(term) - - stv=Subtermview(master, graph, term) - stv.pack(side='top',fill='x') - - return term