Changeset - 16042667ab51
[Not reviewed]
default
0 3 0
Drew Perttula - 13 years ago 2012-06-10 08:47:19
drewp@bigasterisk.com
ui for making a new subterm
Ignore-this: 88632c01c5e8ffb6bca4159160b7b40
3 files changed with 168 insertions and 45 deletions:
0 comments (0 inline, 0 general)
bin/curvecalc
Show inline comments
 
@@ -9,27 +9,25 @@ now launches like this:
 
todo: curveview should preserve more objects, for speed maybe
 

	
 
"""
 
from __future__ import division
 

	
 
from twisted.internet import gtk2reactor
 
gtk2reactor.install()
 
from twisted.internet import reactor
 

	
 
import time, textwrap, os, optparse, urllib2, gtk, gobject, linecache, signal
 
import louie as dispatcher 
 
from twisted.python.util import sibpath
 
from rdflib import URIRef
 
from rdflib import Graph
 
import rdflib
 
from rdflib import URIRef, Graph, Literal, RDF, RDFS
 
import logging
 
log = logging.getLogger()
 

	
 
import run_local
 
from light9 import showconfig, prof
 
from light9.curvecalc.curve import Curveset
 
from light9.curvecalc import curveview 
 
from light9.curvecalc.musicaccess import Music, currentlyPlayingSong
 
from light9.wavelength import wavelength
 
from light9.namespaces import L9
 
from light9.curvecalc.subterm import read_all_subs, savekey, graphPathForSubterms
 
from light9.curvecalc.subtermview import add_one_subterm
 
@@ -59,41 +57,61 @@ class Main(object):
 
        if self.opts.reload:
 
            self.refreshTheme()
 
        mainwin.show_all()
 

	
 
        mainwin.connect("delete-event", lambda *args: reactor.crash())
 
        mainwin.set_title("curvecalc - %s" % graph.label(song))
 
        mainwin.parse_geometry("715x930+1080+26")
 

	
 
        # this is the only one i found that would set the size right,
 
        # but it's a minimum size, which i don't really want
 
        mainwin.set_size_request(1000, 1000)
 
        
 
        self.add_subterms_for_song(song, curveset, subterms,
 
                                   wtree.get_object("subterms")
 
                                   )
 
        self.add_subterms_for_song(song, curveset, subterms)
 
        self.refreshCurveView()       
 
        
 
        self.makeStatusLines(wtree.get_object("status"))
 

	
 
    def onNewCurve(self, *args):
 
        nc = self.wtree.get_object("newCurve")
 
        entry = self.wtree.get_object("newCurveName")
 
        # if you don't have songx, that should be the suggested name
 
        entry.set_text("")
 
        response = nc.run()
 
        if response == 1:
 
            self.curveset.new_curve(entry.get_text())
 
        nc.hide()
 

	
 
    def onNewSubterm(self, *args):
 
        ns = self.wtree.get_object("newSubterm")
 
        # the plan is to autocomplete this on existing subterm names
 
        # (but let you make one up, too)
 
        entry = self.wtree.get_object("newSubtermName").get_children()[0]
 
        entry.set_text("")
 
        if ns.run() == 1:
 
            newname = entry.get_text()
 
            makeCurve = self.wtree.get_object("newSubtermMakeCurve").get_active()
 

	
 
            uri = L9['sub/%s' % newname]
 
            self.graph.add((uri, RDF.type, L9.Subterm))
 
            self.graph.add((uri, RDFS.label, Literal(newname)))
 
            add_one_subterm(self.graph, uri,
 
                            self.curveset, self.subterms,
 
                            self.wtree.get_object("subterms"),
 
                            None, show=True)
 
            if makeCurve:
 
                self.curveset.new_curve(newname)
 
            
 
        ns.hide()
 

	
 
    def refreshTheme(self):
 
        gtk.rc_reparse_all()
 
        reactor.callLater(1, self.refreshTheme)
 

	
 
    def onQuit(self, *args):
 
        reactor.crash()
 
        # there's a hang after this, maybe in sem_wait in two
 
        # threads. I don't know whose they are.
 
        os.kill(os.getpid(), signal.SIGKILL)
 

	
 
    def onSeeCurrentTime(self, item):
 
        dispatcher.send("see time")
 
@@ -105,25 +123,26 @@ class Main(object):
 
        dispatcher.send("show all")
 

	
 
    def onPlayPause(self, item):
 
        # since the X coord in a curveview affects the handling, one
 
        # of them may be able to pick this up
 
        results = dispatcher.send("onPlayPause")
 
        times = [t for listener, t in results if t is not None]
 
        self.music.playOrPause(t=times[0] if times else None)
 

	
 
    def onSave(self, *args):
 
        savekey(self.song, self.subterms, self.curveset)
 

	
 
    def add_subterms_for_song(self, song, curveset, subterms, master):
 
    def add_subterms_for_song(self, song, curveset, subterms):
 
        master = self.wtree.get_object("subterms")
 
        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 makeStatusLines(self, master):
 
        """various labels that listen for dispatcher signals"""
 
@@ -177,34 +196,24 @@ class Main(object):
 
                # try to minimize the number of times we redraw
 
                # the curve at startup. If tk is very slow, it's
 
                # ok. You'll just get some wasted redraws.
 
                self.curvesetView.goLive()
 
            except Exception, e:
 
                print "reload failed:", e
 
        if self.opts.reload:
 
            reactor.callLater(1, self.refreshCurveView)
 

	
 
    def onReloadSubs(self, *args): # wants to be ctrl-r  too
 
        dispatcher.send('reload all subs')
 

	
 
    def onAddSubterm(self):
 
        uri = L9['sub/%s' % newname.get()]
 
        graph.add((uri, RDF.type, L9.Subterm))
 
        graph.add((uri, RDFS.label, Literal(newname.get())))
 
        add_one_subterm(graph, uri,
 
                        curveset, subterms, ssv, None)
 
        if evt.state & 4: # control key modifier
 
            curveset.new_curve(newname.get())
 
        newname.set('')
 

	
 

	
 
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')
 
    parser.add_option("--skip-music", action='store_true',
 
                      help="ignore music and smooth_music curve files")
 
    parser.add_option("--debug", action="store_true",
 
                      help="log at DEBUG")
 
    parser.add_option("--reload", action="store_true",
light9/curvecalc/curvecalc.glade
Show inline comments
 
@@ -421,51 +421,41 @@
 
                            <property name="use_action_appearance">False</property>
 
                            <property name="image">image2</property>
 
                            <accelerator key="r" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
 
                            <signal name="clicked" handler="onReloadSubs" swapped="no"/>
 
                          </object>
 
                          <packing>
 
                            <property name="expand">False</property>
 
                            <property name="fill">True</property>
 
                            <property name="position">0</property>
 
                          </packing>
 
                        </child>
 
                        <child>
 
                          <object class="GtkLabel" id="label2">
 
                          <object class="GtkButton" id="button2">
 
                            <property name="label">gtk-add</property>
 
                            <property name="visible">True</property>
 
                            <property name="can_focus">False</property>
 
                            <property name="label" translatable="yes">new subterm named (C-Enter for curve too, C-n for focus):</property>
 
                            <property name="can_focus">True</property>
 
                            <property name="receives_default">True</property>
 
                            <property name="use_action_appearance">False</property>
 
                            <property name="use_stock">True</property>
 
                            <signal name="clicked" handler="onNewSubterm" swapped="no"/>
 
                          </object>
 
                          <packing>
 
                            <property name="expand">False</property>
 
                            <property name="fill">True</property>
 
                            <property name="fill">False</property>
 
                            <property name="position">1</property>
 
                          </packing>
 
                        </child>
 
                        <child>
 
                          <object class="GtkEntry" id="entry1">
 
                            <property name="visible">True</property>
 
                            <property name="can_focus">True</property>
 
                            <property name="invisible_char">●</property>
 
                            <property name="invisible_char_set">True</property>
 
                            <property name="primary_icon_activatable">False</property>
 
                            <property name="secondary_icon_activatable">False</property>
 
                            <property name="primary_icon_sensitive">True</property>
 
                            <property name="secondary_icon_sensitive">True</property>
 
                          </object>
 
                          <packing>
 
                            <property name="expand">False</property>
 
                            <property name="fill">True</property>
 
                            <property name="position">2</property>
 
                          </packing>
 
                          <placeholder/>
 
                        </child>
 
                      </object>
 
                      <packing>
 
                        <property name="expand">False</property>
 
                        <property name="fill">False</property>
 
                        <property name="position">1</property>
 
                      </packing>
 
                    </child>
 
                  </object>
 
                </child>
 
                <child type="label">
 
                  <object class="GtkLabel" id="subtermsLabel">
 
@@ -603,84 +593,85 @@
 
  </object>
 
  <object class="GtkAccelGroup" id="accelgroup1"/>
 
  <object class="GtkTextBuffer" id="help">
 
    <property name="text">Mousewheel zoom; C-p play/pause music at mouse
 
Curve point bindings: B1 drag point; C-B1 curve add point; S-B1 sketch points; 1..5 add point at time; B1 drag select points
 
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</property>
 
  </object>
 
  <object class="GtkImage" id="image2">
 
    <property name="visible">True</property>
 
    <property name="can_focus">False</property>
 
    <property name="stock">gtk-refresh</property>
 
  </object>
 
  <object class="GtkListStore" id="liststore1"/>
 
  <object class="GtkDialog" id="newCurve">
 
    <property name="can_focus">False</property>
 
    <property name="border_width">5</property>
 
    <property name="type">popup</property>
 
    <property name="title" translatable="yes">New curve</property>
 
    <property name="modal">True</property>
 
    <property name="window_position">mouse</property>
 
    <property name="type_hint">normal</property>
 
    <child internal-child="vbox">
 
      <object class="GtkVBox" id="dialog-vbox1">
 
        <property name="visible">True</property>
 
        <property name="can_focus">False</property>
 
        <property name="spacing">2</property>
 
        <child internal-child="action_area">
 
          <object class="GtkHButtonBox" id="dialog-action_area1">
 
            <property name="visible">True</property>
 
            <property name="can_focus">False</property>
 
            <property name="layout_style">end</property>
 
            <child>
 
              <object class="GtkButton" id="button12">
 
              <object class="GtkButton" id="button5">
 
                <property name="label">gtk-cancel</property>
 
                <property name="visible">True</property>
 
                <property name="can_focus">True</property>
 
                <property name="receives_default">True</property>
 
                <property name="use_action_appearance">False</property>
 
                <property name="use_stock">True</property>
 
              </object>
 
              <packing>
 
                <property name="expand">False</property>
 
                <property name="fill">False</property>
 
                <property name="position">0</property>
 
              </packing>
 
            </child>
 
            <child>
 
              <object class="GtkButton" id="button2">
 
              <object class="GtkButton" id="button4">
 
                <property name="label">gtk-add</property>
 
                <property name="visible">True</property>
 
                <property name="can_focus">True</property>
 
                <property name="can_default">True</property>
 
                <property name="has_default">True</property>
 
                <property name="receives_default">True</property>
 
                <property name="use_action_appearance">False</property>
 
                <property name="use_stock">True</property>
 
              </object>
 
              <packing>
 
                <property name="expand">False</property>
 
                <property name="fill">False</property>
 
                <property name="position">1</property>
 
              </packing>
 
            </child>
 
          </object>
 
          <packing>
 
            <property name="expand">False</property>
 
            <property name="fill">True</property>
 
            <property name="pack_type">end</property>
 
            <property name="position">0</property>
 
          </packing>
 
        </child>
 
        <child>
 
          <object class="GtkLabel" id="label11">
 
          <object class="GtkLabel" id="label12">
 
            <property name="visible">True</property>
 
            <property name="can_focus">False</property>
 
            <property name="label" translatable="yes">Name for new curve</property>
 
          </object>
 
          <packing>
 
            <property name="expand">True</property>
 
            <property name="fill">True</property>
 
            <property name="position">1</property>
 
          </packing>
 
        </child>
 
        <child>
 
          <object class="GtkEntry" id="newCurveName">
 
@@ -694,30 +685,148 @@ Available in functions: nsin/ncos period
 
            <property name="primary_icon_sensitive">True</property>
 
            <property name="secondary_icon_sensitive">True</property>
 
          </object>
 
          <packing>
 
            <property name="expand">True</property>
 
            <property name="fill">True</property>
 
            <property name="position">2</property>
 
          </packing>
 
        </child>
 
      </object>
 
    </child>
 
    <action-widgets>
 
      <action-widget response="2">button12</action-widget>
 
      <action-widget response="1">button2</action-widget>
 
      <action-widget response="2">button5</action-widget>
 
      <action-widget response="1">button4</action-widget>
 
    </action-widgets>
 
  </object>
 
  <object class="GtkTextBuffer" id="textbuffer1">
 
    <property name="text" translatable="yes">song01(t)</property>
 
  <object class="GtkDialog" id="newSubterm">
 
    <property name="can_focus">False</property>
 
    <property name="border_width">5</property>
 
    <property name="type">popup</property>
 
    <property name="title" translatable="yes">New curve</property>
 
    <property name="modal">True</property>
 
    <property name="window_position">mouse</property>
 
    <property name="type_hint">normal</property>
 
    <child internal-child="vbox">
 
      <object class="GtkVBox" id="dialog-vbox3">
 
        <property name="visible">True</property>
 
        <property name="can_focus">False</property>
 
        <property name="spacing">2</property>
 
        <child internal-child="action_area">
 
          <object class="GtkHButtonBox" id="dialog-action_area3">
 
            <property name="visible">True</property>
 
            <property name="can_focus">False</property>
 
            <property name="layout_style">end</property>
 
            <child>
 
              <object class="GtkButton" id="button12">
 
                <property name="label">gtk-cancel</property>
 
                <property name="visible">True</property>
 
                <property name="can_focus">True</property>
 
                <property name="receives_default">True</property>
 
                <property name="use_action_appearance">False</property>
 
                <property name="use_stock">True</property>
 
              </object>
 
              <packing>
 
                <property name="expand">False</property>
 
                <property name="fill">False</property>
 
                <property name="position">0</property>
 
              </packing>
 
            </child>
 
            <child>
 
              <object class="GtkButton" id="button3">
 
                <property name="label">gtk-add</property>
 
                <property name="visible">True</property>
 
                <property name="can_focus">True</property>
 
                <property name="can_default">True</property>
 
                <property name="has_default">True</property>
 
                <property name="receives_default">True</property>
 
                <property name="use_action_appearance">False</property>
 
                <property name="use_stock">True</property>
 
              </object>
 
              <packing>
 
                <property name="expand">False</property>
 
                <property name="fill">False</property>
 
                <property name="position">1</property>
 
              </packing>
 
            </child>
 
          </object>
 
          <packing>
 
            <property name="expand">False</property>
 
            <property name="fill">True</property>
 
            <property name="pack_type">end</property>
 
            <property name="position">0</property>
 
          </packing>
 
        </child>
 
        <child>
 
          <object class="GtkLabel" id="label11">
 
            <property name="visible">True</property>
 
            <property name="can_focus">False</property>
 
            <property name="label" translatable="yes">Name for new subterm</property>
 
          </object>
 
          <packing>
 
            <property name="expand">True</property>
 
            <property name="fill">True</property>
 
            <property name="position">1</property>
 
          </packing>
 
        </child>
 
        <child>
 
          <object class="GtkVBox" id="vbox11">
 
            <property name="visible">True</property>
 
            <property name="can_focus">False</property>
 
            <child>
 
              <object class="GtkComboBox" id="newSubtermName">
 
                <property name="visible">True</property>
 
                <property name="can_focus">True</property>
 
                <property name="has_focus">True</property>
 
                <property name="is_focus">True</property>
 
                <property name="model">liststore1</property>
 
                <property name="has_entry">True</property>
 
                <property name="entry_text_column">0</property>
 
              </object>
 
              <packing>
 
                <property name="expand">True</property>
 
                <property name="fill">True</property>
 
                <property name="position">0</property>
 
              </packing>
 
            </child>
 
            <child>
 
              <object class="GtkCheckButton" id="newSubtermMakeCurve">
 
                <property name="label" translatable="yes">_Make new curve with the same name</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="use_underline">True</property>
 
                <property name="active">True</property>
 
                <property name="draw_indicator">True</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">2</property>
 
          </packing>
 
        </child>
 
      </object>
 
    </child>
 
    <action-widgets>
 
      <action-widget response="2">button12</action-widget>
 
      <action-widget response="1">button3</action-widget>
 
    </action-widgets>
 
  </object>
 
  <object class="GtkVBox" id="vbox2">
 
    <property name="visible">True</property>
 
    <property name="can_focus">False</property>
 
    <child>
 
      <object class="GtkImage" id="image1">
 
        <property name="width_request">289</property>
 
        <property name="height_request">120</property>
 
        <property name="visible">True</property>
 
        <property name="can_focus">False</property>
 
        <property name="stock">gtk-missing-image</property>
 
      </object>
 
@@ -733,13 +842,17 @@ Available in functions: nsin/ncos period
 
        <property name="can_focus">False</property>
 
        <property name="yalign">0.4699999988079071</property>
 
        <property name="label" translatable="yes">vidref from Sat 15:30</property>
 
      </object>
 
      <packing>
 
        <property name="expand">True</property>
 
        <property name="fill">True</property>
 
        <property name="position">1</property>
 
      </packing>
 
    </child>
 
  </object>
 
  <object class="GtkSizeGroup" id="sizegroup1"/>
 
  <object class="GtkSizeGroup" id="sizegroup2"/>
 
  <object class="GtkTextBuffer" id="textbuffer1">
 
    <property name="text" translatable="yes">song01(t)</property>
 
  </object>
 
</interface>
light9/curvecalc/subtermview.py
Show inline comments
 
@@ -41,36 +41,37 @@ class Subtermview(object):
 
    """
 
    has .label and .exprView widgets for you to put in a table
 
    """
 
    def __init__(self, graph, st):
 
        self.subterm = st
 

	
 
        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):
 
def add_one_subterm(graph, subUri, curveset, subterms, master, expr=None, show=False):
 
    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, yoptions=0)
 
    master.attach(stv.exprView, 1, 2, y, y + 1, yoptions=0)
 

	
 
    if show:
 
        master.show_all()
 
    return term
 

	
 

	
0 comments (0 inline, 0 general)