Changeset - ccdd04f4ca7d
[Not reviewed]
default
0 3 0
Drew Perttula - 13 years ago 2012-06-08 05:11:41
drewp@bigasterisk.com
subterm display is working
Ignore-this: 54254c7f9d6cd89bd80031ed1cf92066
3 files changed with 113 insertions and 242 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -50,25 +50,12 @@ def makeStatusLines(master):
 
        l = tk.Label(master, anchor='w', justify='left', text='%s:' % signame)
 
        l.pack(side='top',fill='x')
 
        dispatcher.connect(lambda val,l=l,sn=signame,tf=textfilter:
 
                           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()
 
    graph = Graph() # a copy, since we're going to add subs into it
 
    for s in graphOrig:
 
        graph.add(s)
 
@@ -127,21 +114,39 @@ def createHelpLines(root):
 
                     "Available in functions: nsin/ncos period=amp=1; within(a,b) bef(x) aft(x) compare to time; smoove(x) cubic smoothstep; chan(name); curvename(t) eval curve"]:
 
        line = tk.Label(root, text=helpline, font="Helvetica -12 italic",
 
                        anchor='w')
 
        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")
 
        mainwin.connect("destroy", gtk.main_quit)
 
        wtree.connect_signals(self)
 
        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()
 
    parser.set_usage("%prog [opts] [songURI]")
 
    parser.add_option("--sliders", action='store_true',
 
                      help='use hardware sliders')
 
@@ -162,23 +167,12 @@ def main():
 
    except IndexError:
 
        song = currentlyPlayingSong()
 

	
 
    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 = []
 

	
 
    subtermPath = graphPathForSubterms(song)
 
    try:
 
        graph.parse(subtermPath, format='n3')
 
@@ -191,13 +185,23 @@ def main():
 
    out = Output(subterms, music)
 

	
 
    musicfilename = showconfig.songOnDisk(song)
 
    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)
 
        zc.pack(side='top', fill='x')
 

	
 
    if 'panes':
 
@@ -222,14 +226,12 @@ def main():
 
        makeStatusLines(root)
 

	
 
        helpBox = tk.Frame(root)
 
        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)
 

	
 
    # curvesetview must already exist, since this makes 'add_curve'
 
    # signals for all the initial curves
 
    curveset.load(basename=os.path.join(showconfig.curvesDir(),
light9/curvecalc/curvecalc.glade
Show inline comments
 
@@ -261,12 +261,13 @@
 
                                            <property name="label" translatable="yes">C</property>
 
                                            <property name="use_action_appearance">False</property>
 
                                            <property name="visible">True</property>
 
                                            <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>
 
                                            <property name="expand">True</property>
 
                                            <property name="fill">True</property>
 
                                            <property name="position">0</property>
 
@@ -277,12 +278,13 @@
 
                                            <property name="label" translatable="yes">M</property>
 
                                            <property name="use_action_appearance">False</property>
 
                                            <property name="visible">True</property>
 
                                            <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>
 
                                            <property name="expand">True</property>
 
                                            <property name="fill">True</property>
 
                                            <property name="position">1</property>
 
@@ -348,206 +350,54 @@
 
            <property name="expand">True</property>
 
            <property name="fill">True</property>
 
            <property name="position">1</property>
 
          </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>
 
        <child>
 
          <object class="GtkHBox" id="hbox1">
 
            <property name="visible">True</property>
light9/curvecalc/subtermview.py
Show inline comments
 
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):
 
    """
 
    the row that starts with 'reload subs' button
 
    """
 
    f=tk.Frame(master,relief='raised',bd=1)
 
@@ -66,26 +105,6 @@ def makeSubtermCommandRow(master, curves
 
    def focus_entry():
 
        entry.focus()
 
        
 
    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
0 comments (0 inline, 0 general)