changeset 706:16042667ab51

ui for making a new subterm Ignore-this: 88632c01c5e8ffb6bca4159160b7b40
author Drew Perttula <drewp@bigasterisk.com>
date Sun, 10 Jun 2012 08:47:19 +0000
parents ed50631cf333
children c4a38a247b26
files bin/curvecalc light9/curvecalc/curvecalc.glade light9/curvecalc/subtermview.py
diffstat 3 files changed, 168 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/bin/curvecalc	Sun Jun 10 08:06:54 2012 +0000
+++ b/bin/curvecalc	Sun Jun 10 08:47:19 2012 +0000
@@ -18,9 +18,7 @@
 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()
 
@@ -68,9 +66,7 @@
         # 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"))
@@ -85,6 +81,28 @@
             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)
@@ -114,7 +132,8 @@
     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,
@@ -186,16 +205,6 @@
     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()
--- a/light9/curvecalc/curvecalc.glade	Sun Jun 10 08:06:54 2012 +0000
+++ b/light9/curvecalc/curvecalc.glade	Sun Jun 10 08:47:19 2012 +0000
@@ -430,33 +430,23 @@
                           </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>
@@ -612,6 +602,7 @@
     <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>
@@ -631,7 +622,7 @@
             <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>
@@ -646,7 +637,7 @@
               </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>
@@ -671,7 +662,7 @@
           </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>
@@ -703,12 +694,130 @@
       </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>
@@ -742,4 +851,8 @@
     </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>
--- a/light9/curvecalc/subtermview.py	Sun Jun 10 08:06:54 2012 +0000
+++ b/light9/curvecalc/subtermview.py	Sun Jun 10 08:47:19 2012 +0000
@@ -50,7 +50,7 @@
         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
@@ -70,7 +70,8 @@
     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