Changeset - 1692e8aba9f5
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 7 years ago 2018-06-09 01:59:39
drewp@bigasterisk.com
optimize KC output to collector, hopefully
Ignore-this: 6378404614fe9ac95e5d1d8819c16772
2 files changed with 8 insertions and 14 deletions:
0 comments (0 inline, 0 general)
bin/keyboardcomposer
Show inline comments
 
@@ -451,13 +451,13 @@ class KeyboardComposer(tk.Frame, SubClie
 

	
 
    def get_levels(self):
 
        return dict([(uri, box.slider_var.get())
 
            for uri, box in self.subbox.items()])
 

	
 
    def get_output_settings(self, _graph=None):
 
        _graph = _graph or graph
 
        _graph = _graph or self.graph
 
        outputSettings = []
 
        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()
 
@@ -469,34 +469,28 @@ class KeyboardComposer(tk.Frame, SubClie
 
                outputSettings.append(out)
 

	
 
        return DeviceSettings.fromList(_graph, outputSettings)
 

	
 
    def save_current_stage(self, subname):
 
        log.info("saving current levels as %s", subname)
 
        with graph.currentState() as g:
 
        with self.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),
 
            ])
 

	
 
        graph.suggestPrefixes(ctx, {'eff': effect + '/'})
 
        graph.patch(Patch(addQuads=stmts, delQuads=[]))
 
        self.graph.suggestPrefixes(ctx, {'eff': effect + '/'})
 
        self.graph.patch(Patch(addQuads=stmts, delQuads=[]))
 
              
 
        self.sub_name.delete(0, tk.END)
 

	
 
    def send_frequent_updates(self):
 
        """called when we get a fade -- send events as quickly as possible"""
 
        if time.time() <= self.stop_frequent_update_time:
 
            self.send_levels()
 
            self.after(10, self.send_frequent_updates)
 

	
 
    def alltozero(self):
 
        for uri, subbox in self.subbox.items():
 
            if subbox.scale.scale_var.get() != 0:
 
                subbox.scale.fade(value=0.0, length=0)
 

	
 
# move to web lib
light9/subclient.py
Show inline comments
 
@@ -11,19 +11,19 @@ class SubClient:
 

	
 
    def get_levels_as_sub(self):
 
        """Subclasses must implement this method and return a Submaster
 
        object."""
 

	
 
    def send_levels(self):
 
        # shouldn't be handler- should be immediate mode!
 
        self.graph.addHandler(self._send_sub)
 
        self._send_sub()
 

	
 
    def send_levels_loop(self, delay=1000):
 
        task.LoopingCall(lambda: self.graph.addHandler(self.send_levels)).start(delay)
 
        task.LoopingCall(self.send_levels).start(delay)
 

	
 
    def _send_sub(self):
 
        try:
 
            outputSettings = self.get_output_settings()
 
            with self.graph.currentState() as g:
 
                outputSettings = self.get_output_settings(_graph=g)
 
        except:
 
            traceback.print_exc()
 
            return
 
        sendToCollector('subclient', self.session, outputSettings)
0 comments (0 inline, 0 general)