annotate light9/dmxchanedit.py @ 1922:11e2f63bb2f2

more stats to measure sequencer framerate better Ignore-this: 5df74b41a9847296432a31d248b31857
author Drew Perttula <drewp@bigasterisk.com>
date Sat, 01 Jun 2019 23:43:44 +0000
parents 3c523c71da29
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
1 """
45b12307c695 Initial revision
drewp
parents:
diff changeset
2
45b12307c695 Initial revision
drewp
parents:
diff changeset
3 widget to show all dmx channel levels and allow editing. levels might
45b12307c695 Initial revision
drewp
parents:
diff changeset
4 not actually match what dmxserver is outputting.
45b12307c695 Initial revision
drewp
parents:
diff changeset
5
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
6 proposal for new focus and edit system:
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
7 - rows can be selected
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
8 - the chan number or label can be used to select rows. dragging over rows brings all of them into or out of the current selection
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
9 - numbers drag up and down (like today)
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
10 - if you drag a number in a selected row, all the selected numbers change
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
11 - if you start dragging a number in an unselected row, your row becomes the new selection and then the edit works
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
12
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
13
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
14 proposal for new attribute system:
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
15 - we always want to plan some attributes for each light: where to center; what stage to cover; what color gel to apply; whether the light is burned out
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
16 - we have to stop packing these into the names. Names should be like 'b33' or 'blue3' or just '44'. maybe 'blacklight'.
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
17
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
18 """
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
19
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
20 import tkinter as tk
1866
3c523c71da29 pyflakes cleanups and some refactors
Drew Perttula <drewp@bigasterisk.com>
parents: 1859
diff changeset
21 from rdflib import RDF
1157
dc86936969d8 SC don't break so much on corrupt subs (but we don't yet remove their dangling graph links)
drewp@bigasterisk.com
parents: 979
diff changeset
22 import math, logging
910
3a15fb921b9c more tripleFilter speedups. accept Decimals coming in from n3 files, which happens with the 2012 code
Drew Perttula <drewp@bigasterisk.com>
parents: 838
diff changeset
23 from decimal import Decimal
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
24 from light9.namespaces import L9
1157
dc86936969d8 SC don't break so much on corrupt subs (but we don't yet remove their dangling graph links)
drewp@bigasterisk.com
parents: 979
diff changeset
25 log = logging.getLogger('dmxchanedit')
1264
74de46bdac56 tk font sizes
drewp@bigasterisk.com
parents: 1157
diff changeset
26 stdfont = ('Arial', 7)
231
2c02748847f0 refactor gradient() from dmxchanedit
drewp@bigasterisk.com
parents: 210
diff changeset
27
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
28
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
29 def gradient(lev, low=(80, 80, 180), high=(255, 55, 50)):
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
30 out = [int(l + lev * (h - l)) for h, l in zip(high, low)]
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
31 col = "#%02X%02X%02X" % tuple(out)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
32 return col
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
33
231
2c02748847f0 refactor gradient() from dmxchanedit
drewp@bigasterisk.com
parents: 210
diff changeset
34
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
35 class Onelevel(tk.Frame):
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
36 """a name/level pair
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
37
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
38 source data is like this:
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
39 ch:b11-c a :Channel;
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
40 :output dmx:c54;
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
41 rdfs:label "b11-c" .
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
42
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
43 and the level is like this:
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
44
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
45 ?editor :currentSub ?sub .
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
46 ?sub :lightLevel [:channel ?ch; :level ?level] .
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
47
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
48 levels come in with self.setTo and go out by the onLevelChange
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
49 callback. This object does not use the graph for level values,
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
50 which I'm doing for what I think is efficiency. Unclear why I
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
51 didn't use Observable for that API.
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
52 """
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
53
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
54 def __init__(self, parent, graph, channelUri, onLevelChange):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
55 tk.Frame.__init__(self, parent, height=20)
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
56 self.graph = graph
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
57 self.onLevelChange = onLevelChange
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
58 self.uri = channelUri
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
59 self.currentLevel = 0 # the level we're displaying, 0..1
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
60
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
61 # no statement yet
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
62 self.channelnum = int(
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
63 self.graph.value(self.uri, L9['output']).rsplit('/c')[-1])
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
64
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
65 # 3 widgets, left-to-right:
45b12307c695 Initial revision
drewp
parents:
diff changeset
66
45b12307c695 Initial revision
drewp
parents:
diff changeset
67 # channel number -- will turn yellow when being altered
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
68 self.num_lab = tk.Label(self,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
69 text=str(self.channelnum),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
70 width=3,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
71 bg='grey40',
334
42e4c4728a66 ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents: 320
diff changeset
72 fg='white',
42e4c4728a66 ascoltami, subcomposer, keyboardcomposer use rdf show data; raise channel count to 270
drewp@bigasterisk.com
parents: 320
diff changeset
73 font=stdfont,
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
74 padx=0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
75 pady=0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
76 bd=0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
77 height=1)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
78 self.num_lab.pack(side='left')
45b12307c695 Initial revision
drewp
parents:
diff changeset
79
45b12307c695 Initial revision
drewp
parents:
diff changeset
80 # text description of channel
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
81 self.desc_lab = tk.Label(self,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
82 width=14,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
83 font=stdfont,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
84 anchor='w',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
85 padx=0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
86 pady=0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
87 bd=0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
88 height=1,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
89 bg='black',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
90 fg='white')
805
54732a2f9935 SC more specific handler for faster chan label updates
drewp@bigasterisk.com
parents: 804
diff changeset
91 self.graph.addHandler(self.updateLabel)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
92 self.desc_lab.pack(side='left')
210
f41004d5a507 factored out some networking, new show/ layout, curvecalc works
drewp@bigasterisk.com
parents: 209
diff changeset
93
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
94 # current level of channel, shows intensity with color
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
95 self.level_lab = tk.Label(self,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
96 width=3,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
97 bg='lightBlue',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
98 anchor='e',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
99 font=stdfont,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
100 padx=1,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
101 pady=0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
102 bd=0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
103 height=1)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
104 self.level_lab.pack(side='left')
45b12307c695 Initial revision
drewp
parents:
diff changeset
105
45b12307c695 Initial revision
drewp
parents:
diff changeset
106 self.setupmousebindings()
805
54732a2f9935 SC more specific handler for faster chan label updates
drewp@bigasterisk.com
parents: 804
diff changeset
107
54732a2f9935 SC more specific handler for faster chan label updates
drewp@bigasterisk.com
parents: 804
diff changeset
108 def updateLabel(self):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
109 self.desc_lab.config(text=self.graph.label(self.uri))
821
295b867fd810 just whitespace (hopefully)
drewp@bigasterisk.com
parents: 805
diff changeset
110
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
111 def setupmousebindings(self):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
112
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
113 def b1down(ev):
45b12307c695 Initial revision
drewp
parents:
diff changeset
114 self.desc_lab.config(bg='cyan')
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
115 self._start_y = ev.y
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
116 self._start_lev = self.currentLevel
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
117
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
118 def b1motion(ev):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
119 delta = self._start_y - ev.y
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
120 self.setlevel(max(0, min(1, self._start_lev + delta * .005)))
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
121
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
122 def b1up(ev):
45b12307c695 Initial revision
drewp
parents:
diff changeset
123 self.desc_lab.config(bg='black')
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
124
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 201
diff changeset
125 def b3up(ev):
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
126 self.setlevel(0.0)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
127
205
3905d3c92aaa twisted mainloop, more row-change keys, xmlrpc fadesub command on port 8050
drewp
parents: 201
diff changeset
128 def b3down(ev):
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
129 self.setlevel(1.0)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
130
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
131 def b2down(ev): # same thing for now
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
132 self.setlevel(1.0)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
133
45b12307c695 Initial revision
drewp
parents:
diff changeset
134 # make the buttons work in the child windows
45b12307c695 Initial revision
drewp
parents:
diff changeset
135 for w in self.winfo_children():
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
136 for e, func in (('<ButtonPress-1>',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
137 b1down), ('<B1-Motion>',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
138 b1motion), ('<ButtonRelease-1>', b1up),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
139 ('<ButtonPress-2>',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
140 b2down), ('<ButtonRelease-3>',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
141 b3up), ('<ButtonPress-3>', b3down)):
320
fd06667e00e1 b2 light setting in subcomposer
Drew Perttula <drewp@bigasterisk.com>
parents: 231
diff changeset
142
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
143 w.bind(e, func)
821
295b867fd810 just whitespace (hopefully)
drewp@bigasterisk.com
parents: 805
diff changeset
144
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
145 def colorlabel(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
146 """color the level label based on its own text (which is 0..100)"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
147 txt = self.level_lab['text'] or "0"
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
148 lev = float(txt) / 100
231
2c02748847f0 refactor gradient() from dmxchanedit
drewp@bigasterisk.com
parents: 210
diff changeset
149 self.level_lab.config(bg=gradient(lev))
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
150
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
151 def setlevel(self, newlev):
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
152 """UI received a level change, which we put in the graph"""
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
153 self.onLevelChange(self.uri, newlev)
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
154
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
155 def setTo(self, newLevel):
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
156 """levelbox saw a change in the graph"""
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
157 self.currentLevel = min(1, max(0, newLevel))
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
158 newLevel = "%d" % (self.currentLevel * 100)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
159 olddisplay = self.level_lab.cget('text')
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
160 if newLevel != olddisplay:
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
161 self.level_lab.config(text=newLevel)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
162 self.colorlabel()
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
163
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
164
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
165 class Levelbox(tk.Frame):
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
166 """
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
167 this also watches all the levels in the sub and sets the boxes when they change
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
168 """
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
169
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
170 def __init__(self, parent, graph, currentSub):
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
171 """
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
172 currentSub is an Observable(PersistentSubmaster)
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
173 """
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
174 tk.Frame.__init__(self, parent)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
175
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
176 self.currentSub = currentSub
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
177 self.graph = graph
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
178 graph.addHandler(self.updateChannels)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
179
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
180 self.currentSub.subscribe(lambda _: graph.addHandler(self.
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
181 updateLevelValues))
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
182
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
183 def updateChannels(self):
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
184 """(re)make Onelevel boxes for the defined channels"""
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
185
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
186 [ch.destroy() for ch in self.winfo_children()]
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
187 self.levelFromUri = {} # channel : OneLevel
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
188
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
189 chans = list(self.graph.subjects(RDF.type, L9.Channel))
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
190 chans.sort(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
191 key=lambda c: int(self.graph.value(c, L9.output).rsplit('/c')[-1]))
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
192 cols = 2
979
c1f3cc23b51b subcomposer wouldn't draw right if there is an odd number of channels
drewp@bigasterisk.com
parents: 910
diff changeset
193 rows = int(math.ceil(len(chans) / cols))
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
194
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
195 def make_frame(parent):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
196 f = tk.Frame(parent, bd=0, bg='black')
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
197 f.pack(side='left')
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
198 return f
821
295b867fd810 just whitespace (hopefully)
drewp@bigasterisk.com
parents: 805
diff changeset
199
803
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
200 columnFrames = [make_frame(self) for x in range(cols)]
ce4fffe8e413 update SC to read rdf graph
drewp@bigasterisk.com
parents: 450
diff changeset
201
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
202 for i, channel in enumerate(chans): # sort?
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
203 # frame for this channel
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
204 f = Onelevel(columnFrames[i // rows], self.graph, channel,
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
205 self.onLevelChange)
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
206
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
207 self.levelFromUri[channel] = f
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
208 f.pack(side='top')
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
209
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
210 def updateLevelValues(self):
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
211 """set UI level from graph"""
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
212 submaster = self.currentSub()
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
213 if submaster is None:
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
214 return
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
215 sub = submaster.uri
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
216 if sub is None:
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
217 raise ValueError("currentSub is %r" % submaster)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
218
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
219 remaining = set(self.levelFromUri.keys())
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
220 for ll in self.graph.objects(sub, L9['lightLevel']):
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
221 chan = self.graph.value(ll, L9['channel'])
1157
dc86936969d8 SC don't break so much on corrupt subs (but we don't yet remove their dangling graph links)
drewp@bigasterisk.com
parents: 979
diff changeset
222 try:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
223 lev = self.graph.value(ll, L9['level']).toPython()
1157
dc86936969d8 SC don't break so much on corrupt subs (but we don't yet remove their dangling graph links)
drewp@bigasterisk.com
parents: 979
diff changeset
224 except AttributeError as e:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
225 log.error('on lightlevel %r:', ll)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
226 log.exception(e)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
227 continue
910
3a15fb921b9c more tripleFilter speedups. accept Decimals coming in from n3 files, which happens with the 2012 code
Drew Perttula <drewp@bigasterisk.com>
parents: 838
diff changeset
228 if isinstance(lev, Decimal):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
229 lev = float(lev)
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
230 assert isinstance(lev, (int, float)), repr(lev)
1157
dc86936969d8 SC don't break so much on corrupt subs (but we don't yet remove their dangling graph links)
drewp@bigasterisk.com
parents: 979
diff changeset
231 try:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
232 self.levelFromUri[chan].setTo(lev)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
233 remaining.remove(chan)
1157
dc86936969d8 SC don't break so much on corrupt subs (but we don't yet remove their dangling graph links)
drewp@bigasterisk.com
parents: 979
diff changeset
234 except KeyError as e:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 1264
diff changeset
235 log.exception(e)
838
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
236 for channel in remaining:
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
237 self.levelFromUri[channel].setTo(0)
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
238
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
239 def onLevelChange(self, chan, newLevel):
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
240 """UI received a change which we put in the graph"""
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
241 if self.currentSub() is None:
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
242 raise ValueError("no currentSub in Levelbox")
321fc6150ee3 subcomposer's nice currently-editing DnD box
drewp@bigasterisk.com
parents: 821
diff changeset
243 self.currentSub().editLevel(chan, newLevel)