Mercurial > code > home > repos > light9
changeset 692:ccdd04f4ca7d
subterm display is working
Ignore-this: 54254c7f9d6cd89bd80031ed1cf92066
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Fri, 08 Jun 2012 05:11:41 +0000 |
parents | 62d83d456f2e |
children | 810bedfc9a93 |
files | bin/curvecalc light9/curvecalc/curvecalc.glade light9/curvecalc/subtermview.py |
diffstat | 3 files changed, 113 insertions(+), 242 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/curvecalc Fri Jun 08 04:00:36 2012 +0000 +++ b/bin/curvecalc Fri Jun 08 05:11:41 2012 +0000 @@ -53,19 +53,6 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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)
--- a/light9/curvecalc/curvecalc.glade Fri Jun 08 04:00:36 2012 +0000 +++ b/light9/curvecalc/curvecalc.glade Fri Jun 08 05:11:41 2012 +0000 @@ -264,6 +264,7 @@ <property name="can_focus">True</property> <property name="receives_default">False</property> <property name="use_action_appearance">False</property> + <property name="xalign">0.5</property> <property name="draw_indicator">True</property> </object> <packing> @@ -280,6 +281,7 @@ <property name="can_focus">True</property> <property name="receives_default">False</property> <property name="use_action_appearance">False</property> + <property name="xalign">0.5</property> <property name="draw_indicator">True</property> </object> <packing> @@ -351,200 +353,48 @@ </packing> </child> <child> - <object class="GtkScrolledWindow" id="subterms"> + <object class="GtkExpander" id="expander1"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="hscrollbar_policy">never</property> + <property name="expanded">True</property> <child> - <object class="GtkVBox" id="vbox3"> + <object class="GtkScrolledWindow" id="scrolledwindow2"> <property name="visible">True</property> - <property name="can_focus">False</property> + <property name="can_focus">True</property> + <property name="vscrollbar_policy">always</property> <child> - <object class="GtkHBox" id="subterm1"> + <object class="GtkViewport" id="viewport1"> <property name="visible">True</property> <property name="can_focus">False</property> - <child> - <object class="GtkLabel" id="label9"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">sub song01</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> + <property name="shadow_type">none</property> <child> - <object class="GtkHBox" id="hbox6"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <child> - <object class="GtkEntry" id="entry1"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">●</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label10"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">ok</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkHBox" id="subterm2"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <child> - <object class="GtkLabel" id="label11"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">sub song01</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkHBox" id="hbox5"> + <object class="GtkTable" id="subterms"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="n_columns">2</property> <child> - <object class="GtkEntry" id="entry2"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">●</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> + <placeholder/> </child> <child> - <object class="GtkLabel" id="label12"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">ok</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> + <placeholder/> </child> </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> </child> </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> </child> - <child> - <object class="GtkHBox" id="subterm3"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <child> - <object class="GtkLabel" id="label13"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">sub song01</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkHBox" id="hbox7"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <child> - <object class="GtkEntry" id="entry3"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">●</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label14"> - <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="label" translatable="yes">ok</property> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">2</property> - </packing> - </child> + </object> + </child> + <child type="label"> + <object class="GtkLabel" id="subtermsLabel"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Subterms</property> </object> </child> </object> <packing> - <property name="expand">False</property> - <property name="fill">False</property> + <property name="expand">True</property> + <property name="fill">True</property> <property name="position">2</property> </packing> </child>
--- a/light9/curvecalc/subtermview.py Fri Jun 08 04:00:36 2012 +0000 +++ b/light9/curvecalc/subtermview.py Fri Jun 08 05:11:41 2012 +0000 @@ -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 @@ 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