Changeset - 013cbd7a0f08
[Not reviewed]
default
0 6 0
Drew Perttula - 8 years ago 2017-06-03 09:20:04
drewp@bigasterisk.com
choice-type attrs in live
Ignore-this: 6c762ec4b8f93c4700edbb080990eb5f
6 files changed with 30 insertions and 21 deletions:
0 comments (0 inline, 0 general)
bin/collector
Show inline comments
 
@@ -23,25 +23,29 @@ from run_local import log
 
from lib.cycloneerr import PrettyErrorHandler
 
from light9.collector.output import EnttecDmx, Udmx
 
from light9.collector.collector import Collector
 
from light9.namespaces import L9
 
from light9 import networking
 
from light9.rdfdb.syncedgraph import SyncedGraph
 
from light9.greplin_cyclone import StatsForCyclone
 

	
 
def parseJsonMessage(msg):
 
    body = json.loads(msg)
 
    settings = []
 
    for device, attr, value in body['settings']:
 
        settings.append((URIRef(device), URIRef(attr), Literal(value)))
 
        if isinstance(value, basestring) and value.startswith('http'):
 
            value = URIRef(value)
 
        else:
 
            value = Literal(value)
 
        settings.append((URIRef(device), URIRef(attr), value))
 
    return body['client'], body['clientSession'], settings, body['sendTime']
 

	
 
def startZmq(port, collector):
 
    stats = scales.collection('/zmqServer',
 
                              scales.PmfStat('setAttr'))
 
    
 
    zf = ZmqFactory()
 
    addr = 'tcp://*:%s' % port
 
    log.info('creating zmq endpoint at %r', addr)
 
    e = ZmqEndpoint('bind', addr)
 
    s = ZmqPullConnection(zf, e)
 
    def onPull(message):
light9/collector/device.py
Show inline comments
 
@@ -95,24 +95,25 @@ def toOutputAttrs(deviceType, deviceAttr
 
    def fine16Attr(attr, scale=1.0):
 
        x = floatAttr(attr) * scale
 
        hi = _8bit(x)
 
        lo = _8bit((x * 255) % 1.0)
 
        return hi, lo
 

	
 
    def choiceAttr(attr):
 
        # todo
 
        if deviceAttrSettings.get(attr) == L9['g1']:
 
            return 3
 
        if deviceAttrSettings.get(attr) == L9['g2']:
 
            return 10
 
        return 0
 
        
 
    if deviceType == L9['ChauvetColorStrip']:
 
        r, g, b = rgbAttr(L9['color'])
 
        return {
 
            L9['mode']: 215,
 
            L9['red']: r,
 
            L9['green']: g,
 
            L9['blue']: b
 
            }
 
    elif deviceType == L9['SimpleDimmer']:
 
        return {L9['level']: _8bit(floatAttr(L9['brightness']))}
 
    elif deviceType == L9['Mini15']:
light9/web/graph.coffee
Show inline comments
 
@@ -244,24 +244,31 @@ class window.SyncedGraph
 
    return hit if hit != undefined
 

	
 
    ret = parseFloat(N3.Util.getLiteralValue(@_singleValue(s, p)))
 
    @cachedFloatValues.set(key, ret)
 
    return ret
 
    
 
  stringValue: (s, p) ->
 
    N3.Util.getLiteralValue(@_singleValue(s, p))
 
    
 
  uriValue: (s, p) ->
 
    @_singleValue(s, p)
 

	
 
  labelOrTail: (uri) ->
 
    try
 
      @graph.stringValue(uri, @graph.Uri('rdfs:label'))
 
    catch
 
      words = uri.split('/')
 
      words[words.length-1]
 

	
 
  objects: (s, p) ->
 
    @_autoDeps.askedFor(s, p, null, null)
 
    quads = @graph.findByIRI(s, p)
 
    return (q.object for q in quads)
 

	
 
  subjects: (p, o) ->
 
    @_autoDeps.askedFor(null, p, o, null)
 
    quads = @graph.findByIRI(null, p, o)
 
    return (q.subject for q in quads)
 

	
 
  items: (list) ->
 
    out = []
light9/web/live/index.html
Show inline comments
 
@@ -34,27 +34,28 @@
 
                        content-type="application/json"
 
                        immediate-value="{{immediateSlider}}"></paper-slider>
 
        </template>
 
        <template is="dom-if" if="{{deviceAttr.useColor}}">
 
          <input type="color"
 
                 id="col"
 
                 on-input="onPickedColor"
 
                 value="{{pickedColor}}">
 
          <button on-click="goWhite">white</button>
 
          <button on-click="goBlack">black</button>
 
        </template>
 
        <template is="dom-if" if="{{deviceAttr.useChoice}}">
 
          <select size="10">
 
          <select size$="{{deviceAttr.choiceSize}}" value="{{pickedChoice::change}}">
 
            <option value="">None</option>
 
            <template is="dom-repeat" items="{{deviceAttr.choices}}">
 
              <option>item {{item}}</option>
 
              <option value="{{item.uri}}">{{item.label}}</option>
 
            </template>
 
          </select>
 
        </template>
 

	
 
      </template>
 
     
 
    </dom-module>
 

	
 
    <dom-module id="light9-live-device-control">
 
      <template>
 
        <style>
 
         .device {
light9/web/live/live.coffee
Show inline comments
 
log = console.log
 

	
 
Polymer
 
  is: 'light9-live-control'
 
  properties:
 
    device: { type: String }
 
    deviceAttr: { type: Object }
 
    max: { type: Number, value: 1 }
 
    value: { type: Object, notify: true }
 
    
 
    immediateSlider: { notify: true, observer: 'onSlider' }
 
    pickedColor: { observer: 'onPickedColor' }
 
    pickedChoice: { observer: 'onChange' }
 
  observers: [
 
    'onChange(value)'
 
    ]
 
  ready: ->
 
    
 
  onPickedColor: (ev) -> @value = ev.target.value
 
  onSlider: -> @value = @immediateSlider
 
  goWhite: -> @value = "#ffffff"
 
  goBlack: -> @value = "#000000"
 
  onChoice: (ev) ->
 
    console.log('ch', ev)
 
  
 
  onChange: (value) ->
 
    @lastSent = [[@device, @deviceAttr.uri, value]]
 
    @resend()
 
  resend: ->
 
    window.gather(@lastSent)
 
  clear: ->
 
    if @deviceAttr.useColor
 
      @value = '#000000'
 
    else
 
      @value = @immediateSlider = 0
 

	
 
Polymer
 
  is: "light9-live-device-control"
 
  properties:
 
    graph: { type: Object, notify: true }
 
    uri: { type: String, notify: true }
 
    label: { type: String, notify: true }
 
    deviceClass: { type: String, notify: true }
 
    deviceAttrs: { type: Array, notify: true }
 
  observers: [
 
    'onGraph(graph)'
 
    ]
 
  onGraph: ->
 
    @graph.runHandler(@update.bind(@), "#{@uri} update")
 
  update: ->
 
    U = (x) => @graph.Uri(x)
 

	
 
    @zlabel = (try
 
        @graph.stringValue(@uri, U('rdfs:label'))
 
      catch
 
        words = @uri.split('/')
 
        words[words.length-1]
 
        )
 
    
 
    @deviceClass = @graph.uriValue(@uri, U('rdf:type'))
 
    
 
    @deviceAttrs = []
 
    for da in _.unique(_.sortBy(@graph.objects(@deviceClass, U(':deviceAttr'))))
 
      dataType = @graph.uriValue(da, U(':dataType'))
 
      daRow = {
 
        uri: da
 
        dataType: dataType
 
        showColorPicker: dataType == U(':color')
 
        }
 
      if dataType == 'http://light9.bigasterisk.com/color'
 
        daRow.useColor = true
 

	
 
      else if dataType == U(':choice')
 
        daRow.useChoice = true
 
        daRow.choices = @graph.objects(da, U(':choice'))
 
        choiceUris = _.sortBy(@graph.objects(da, U(':choice')))
 
        daRow.choices = ({uri: x, label: @graph.labelOrTail(x)} for x in choiceUris)
 
        daRow.choiceSize = Math.min(choiceUris.length + 1, 10)
 
      else
 

	
 
        daRow.useSlider = true
 
        daRow.max = 1
 
        if dataType == U(':angle')
 
          # varies
 
          daRow.max = 1
 

	
 
      @push('deviceAttrs', daRow)
 

	
 
    
 
Polymer
 
  is: "light9-live-controls"
 
  properties:
light9/web/resource-display.html
Show inline comments
 
@@ -29,38 +29,42 @@
 
        <div class="buttons">
 
          <paper-button dialog-dismiss>Cancel</paper-button>
 
          <paper-button dialog-confirm>OK</paper-button>
 
        </div>
 
      </paper-dialog>
 
      
 
    </template>
 
  </template>
 
  <script>
 
   Polymer({
 
       is: "resource-display",
 
       properties: {
 
           graph: { type: Object },
 
           uri: { type: String },
 
           graph: { type: Object, notify: true },
 
           uri: { type: String, notify: true },
 
           label: { type: String },
 
           rename: { type: Boolean },
 
           renameTo: { type: String, notify: true },
 
       },
 
       ready: function() {
 
           this.graph.runHandler(this.setLabel.bind(this), `label ${this.uri}`);
 
       },
 
       setLabel: function() {
 
           this.label = this.graph.stringValue(this.uri,
 
                                               this.graph.Uri('rdfs:label'));
 
           try {
 
             this.label = this.graph.stringValue(this.uri,
 
                                                 this.graph.Uri('rdfs:label'));
 
           } catch(e) {
 
               this.label = null;
 
           }
 
           if (!this.label) {
 
               this.label = this.uri;
 
               this.label = this.uri || "<no uri>";
 
           }
 
       },
 
       onRename: function() {
 
           this.renameTo = this.label;
 
           this.querySelector("#renameDialog").open();
 
           this.querySelector("#renameTo").setSelectionRange(0, -1);
 
       },
 
       onRenameKey: function(ev) {
 
           if (ev.key == 'Enter') {
 
               this.querySelector("[dialog-confirm]").click();
 
           }
 
           if (ev.key == 'Escape') {
0 comments (0 inline, 0 general)