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
 
@@ -15,15 +15,13 @@ 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
 
@@ -65,15 +63,13 @@ class Main(object):
 
        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")
 
@@ -82,12 +78,34 @@ class Main(object):
 
        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()
 
@@ -111,13 +129,14 @@ class Main(object):
 
        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,
 
@@ -183,22 +202,12 @@ class Main(object):
 
        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',
light9/curvecalc/curvecalc.glade
Show inline comments
 
@@ -427,39 +427,29 @@
 
                            <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>
 
@@ -609,12 +599,13 @@ Available in functions: nsin/ncos period
 
  </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>
 
@@ -628,13 +619,13 @@ Available in functions: nsin/ncos period
 
        <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>
 
@@ -643,13 +634,13 @@ Available in functions: nsin/ncos period
 
                <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>
 
@@ -668,13 +659,13 @@ Available in functions: nsin/ncos period
 
            <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>
 
@@ -700,18 +691,136 @@ Available in functions: nsin/ncos period
 
            <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">
 
@@ -739,7 +848,11 @@ Available in functions: nsin/ncos period
 
        <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
 
@@ -47,13 +47,13 @@ class Subtermview(object):
 
        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)
 
@@ -67,10 +67,11 @@ def add_one_subterm(graph, subUri, curve
 

	
 
    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)