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
 
@@ -29,13 +29,17 @@ from light9.rdfdb.syncedgraph import Syn
 
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'))
 
    
light9/collector/device.py
Show inline comments
 
@@ -101,12 +101,13 @@ def toOutputAttrs(deviceType, deviceAttr
 
    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,
light9/web/graph.coffee
Show inline comments
 
@@ -250,12 +250,19 @@ class window.SyncedGraph
 
  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) ->
light9/web/live/index.html
Show inline comments
 
@@ -40,15 +40,16 @@
 
                 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>
 
     
light9/web/live/live.coffee
Show inline comments
 
@@ -7,24 +7,22 @@ Polymer
 
    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: ->
 
@@ -35,29 +33,22 @@ Polymer
 

	
 
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 = {
 
@@ -67,15 +58,16 @@ Polymer
 
        }
 
      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
 

	
light9/web/resource-display.html
Show inline comments
 
@@ -35,26 +35,30 @@
 
    </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);
0 comments (0 inline, 0 general)