changeset 1654:5849146f4eb4

KC can save new effects Ignore-this: 51aa0170af56f90d4baea4aa8aab3faf
author drewp@bigasterisk.com
date Sat, 10 Jun 2017 19:01:19 +0000
parents 8ea61f1fda9c
children 89acc2cf832a
files bin/keyboardcomposer
diffstat 1 files changed, 21 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/bin/keyboardcomposer	Sat Jun 10 18:31:41 2017 +0000
+++ b/bin/keyboardcomposer	Sat Jun 10 19:01:19 2017 +0000
@@ -15,13 +15,14 @@
 from light9.subclient import SubClient
 from light9 import showconfig, networking, prof
 from light9.uihelpers import toplevelat
-from light9.namespaces import L9, RDF
+from light9.namespaces import L9, RDF, RDFS
 from light9.tkdnd import initTkdnd, dragSourceRegister, dropTargetRegister
 from light9.rdfdb import clientsession
 from light9.rdfdb.syncedgraph import SyncedGraph
 from light9.effect.sequencer import CodeWatcher
 import light9.effect.effecteval
 from light9.effect.settings import DeviceSettings
+from light9.rdfdb.patch import Patch
 
 from bcf2000 import BCF2000
 
@@ -451,11 +452,12 @@
         return dict([(uri, box.slider_var.get())
             for uri, box in self.subbox.items()])
 
-    def get_output_settings(self):
+    def get_output_settings(self, _graph=None):
+        _graph = _graph or graph
         outputSettings = []
-        for setting in graph.objects(self.session, L9['subSetting']):
-            effect = graph.value(setting, L9['sub'])
-            strength = graph.value(setting, L9['level'])
+        for setting in _graph.objects(self.session, L9['subSetting']):
+            effect = _graph.value(setting, L9['sub'])
+            strength = _graph.value(setting, L9['level'])
             if strength:
                 now = time.time()
                 outputSettings.append(
@@ -465,23 +467,24 @@
                         # should be counting from when you bumped up from 0
                         noteTime=now))
 
-        return DeviceSettings.fromList(graph, outputSettings)
+        return DeviceSettings.fromList(_graph, outputSettings)
 
     def save_current_stage(self, subname):
-        raise NotImplementedError
         log.info("saving current levels as %s", subname)
-        with self.graph.currentState() as current:
-            sub = self.get_levels_as_sub(graph=current)
-
-        log.debug("new sub for reference: %r", sub)
+        with graph.currentState() as g:
+            ds = self.get_output_settings(_graph=g)
+        effect = L9['effect/%s' % subname]
+        ctx = URIRef(showconfig.showUri() + '/effect/' + subname)
+        stmts = ds.statements(effect, ctx, effect + '/', set())
+        stmts.extend([
+            (effect, RDF.type, L9['Effect'], ctx),
+            (effect, RDFS.label, Literal(subname), ctx),
+            (effect, L9['publishAttr'], L9['strength'], ctx),
+            ])
 
-        newUri = showconfig.showUri() + "/sub/%s" % subname
-        ps = PersistentSubmaster(self.graph, newUri)
-        ps.changeName(subname)
-        for chanName, v in sub.get_levels().items():
-            chan = get_channel_uri(str(chanName))
-            ps.editLevel(chan, v)
-            
+        graph.suggestPrefixes(ctx, {'eff': effect + '/'})
+        graph.patch(Patch(addQuads=stmts, delQuads=[]))
+              
         self.sub_name.delete(0, tk.END)
 
     def send_frequent_updates(self):