annotate bin/attic/tracker @ 2376:4556eebe5d73

topdir reorgs; let pdm have its src/ dir; separate vite area from light9/
author drewp@bigasterisk.com
date Sun, 12 May 2024 19:02:10 -0700
parents bin/tracker@5bcb950024af
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
1 #!/usr/bin/python
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
2
154
e3a92ccea4be add cuisine path
dmcc
parents: 152
diff changeset
3 import sys
e3a92ccea4be add cuisine path
dmcc
parents: 152
diff changeset
4 sys.path.append("../../editor/pour")
159
5aa7cffe68d0 talks dmx
drewp
parents: 156
diff changeset
5 sys.path.append("../light8")
154
e3a92ccea4be add cuisine path
dmcc
parents: 152
diff changeset
6
159
5aa7cffe68d0 talks dmx
drewp
parents: 156
diff changeset
7 from Submaster import Submaster
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
8 from skim.zooming import Zooming, Pair
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
9 from math import sqrt, sin, cos
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
10 from pygame.rect import Rect
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
11 from xmlnodebase import xmlnodeclass, collectiveelement, xmldocfile
195
8c7f136120a9 update dispatcher import
drewp
parents: 193
diff changeset
12 from dispatch import dispatcher
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
13
159
5aa7cffe68d0 talks dmx
drewp
parents: 156
diff changeset
14 import dmxclient
5aa7cffe68d0 talks dmx
drewp
parents: 156
diff changeset
15
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
16 import tkinter as tk
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
17
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
18 defaultfont = "arial 8"
156
224505b0c21e smaller text
drewp
parents: 154
diff changeset
19
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
20
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
21 def pairdist(pair1, pair2):
193
e16b8ca470d8 distance calc change
drewp
parents: 159
diff changeset
22 return pair1.dist(pair2)
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
23
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
24
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
25 def canvashighlighter(canvas, obj, attribute, normalval, highlightval):
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
26 """creates bindings on a canvas obj that make attribute go
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
27 from normal to highlight when the mouse is over the obj"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
28 canvas.tag_bind(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
29 obj, "<Enter>", lambda ev: canvas.itemconfig(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
30 obj, **{attribute: highlightval}))
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
31 canvas.tag_bind(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
32 obj,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
33 "<Leave>", lambda ev: canvas.itemconfig(obj, **{attribute: normalval}))
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
34
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
35
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
36 class Field(xmlnodeclass):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
37 """one light has a field of influence. for any point on the
45b12307c695 Initial revision
drewp
parents:
diff changeset
38 canvas, you can ask this field how strong it is. """
45b12307c695 Initial revision
drewp
parents:
diff changeset
39
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
40 def name(self, newval=None):
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
41 """light/sub name"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
42 return self._getorsetattr("name", newval)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
43
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
44 def center(self, x=None, y=None):
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
45 """x,y float coords for the center of this light in the field. returns
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
46 a Pair, although it accepts x,y"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
47 return Pair(self._getorsettypedattr("x", float, x),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
48 self._getorsettypedattr("y", float, y))
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
49
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
50 def falloff(self, dist=None):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
51 """linear falloff from 1 at center, to 0 at dist pixels away
45b12307c695 Initial revision
drewp
parents:
diff changeset
52 from center"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
53 return self._getorsettypedattr("falloff", float, dist)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
54
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
55 def getdistforintensity(self, intens):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
56 """returns the distance you'd have to be for the given intensity (0..1)"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
57 return (1 - intens) * self.falloff()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
58
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
59 def calc(self, x, y):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
60 """returns field strength at point x,y"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
61 dist = pairdist(Pair(x, y), self.center())
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
62 return max(0, (self.falloff() - dist) / self.falloff())
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
63
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
64
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
65 class Fieldset(collectiveelement):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
66 """group of fields. persistent."""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
67
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
68 def childtype(self):
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
69 return Field
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
70
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
71 def version(self):
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
72 """read-only version attribute on fieldset tag"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
73 return self._getorsetattr("version", None)
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
74
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
75 def report(self, x, y):
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
76 """reports active fields and their intensities"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
77 active = 0
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
78 for f in self.getall():
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
79 name = f.name()
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
80 intens = f.calc(x, y)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
81 if intens > 0:
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
82 print(name, intens, end=' ')
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
83 active += 1
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
84 if active > 0:
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
85 print()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
86 self.dmxsend(x, y)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
87
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
88 def dmxsend(self, x, y):
159
5aa7cffe68d0 talks dmx
drewp
parents: 156
diff changeset
89 """output lights to dmx"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
90 levels = dict([(f.name(), f.calc(x, y)) for f in self.getall()])
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
91 dmxlist = Submaster(None, levels).get_dmx_list()
159
5aa7cffe68d0 talks dmx
drewp
parents: 156
diff changeset
92 dmxclient.outputlevels(dmxlist)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
93
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
94 def getbounds(self):
45b12307c695 Initial revision
drewp
parents:
diff changeset
95 """returns xmin,xmax,ymin,ymax for the non-zero areas of this field"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
96 r = None
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
97 for f in self.getall():
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
98 rad = f.getdistforintensity(0)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
99 fx, fy = f.center()
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
100 fieldrect = Rect(fx - rad, fy - rad, rad * 2, rad * 2)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
101 if r is None:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
102 r = fieldrect
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
103 else:
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
104 r = r.union(fieldrect)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
105 return r.left, r.right, r.top, r.bottom
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
106
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
107
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
108 class Fieldsetfile(xmldocfile):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
109
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
110 def __init__(self, filename):
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
111 self._openornew(filename, topleveltype=Fieldset)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
112
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
113 def fieldset(self):
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
114 return self._gettoplevel()
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
115
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
116
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
117 ########################################################################
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
118 ########################################################################
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
119
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
120
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
121 class FieldDisplay:
45b12307c695 Initial revision
drewp
parents:
diff changeset
122 """the view for a Field."""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
123
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
124 def __init__(self, canvas, field):
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
125 self.canvas = canvas
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
126 self.field = field
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
127 self.tags = [str(id(self))] # canvas tag to id our objects
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
128
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
129 def setcoords(self):
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
130 """adjust canvas obj coords to match the field"""
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
131 # this uses the canvas object ids saved by makeobjs
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
132 f = self.field
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
133 c = self.canvas
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
134 w2c = self.canvas.world2canvas
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
135
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
136 # rings
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
137 for intens, ring in list(self.rings.items()):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
138 rad = f.getdistforintensity(intens)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
139 p1 = w2c(*(f.center() - Pair(rad, rad)))
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
140 p2 = w2c(*(f.center() + Pair(rad, rad)))
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
141 c.coords(ring, p1[0], p1[1], p2[0], p2[1])
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
142
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
143 # text
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
144 p1 = w2c(*f.center())
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
145 c.coords(self.txt, *p1)
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
146
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
147 def makeobjs(self):
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
148 """(re)create the canvas objs (null coords) and make their bindings"""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
149 c = self.canvas
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
150 f = self.field
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
151 c.delete(self.tags)
45b12307c695 Initial revision
drewp
parents:
diff changeset
152
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
153 w2c = self.canvas.world2canvas
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
154
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
155 # make rings
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
156 self.rings = {} # rad,canvasobj
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
157 for intens, color in ( #(1,'white'),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
158 (.8, 'gray90'), (.6, 'gray80'), (.4, 'gray60'), (.2, 'gray50'),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
159 (0, '#000080')):
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
160 self.rings[intens] = c.create_oval(0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
161 0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
162 0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
163 0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
164 outline=color,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
165 width=2,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
166 tags=self.tags,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
167 outlinestipple='gray50')
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
168
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
169 # make text
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
170 self.txt = c.create_text(0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
171 0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
172 text=f.name(),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
173 font=defaultfont + " bold",
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
174 fill='white',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
175 anchor='c',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
176 tags=self.tags)
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
177
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
178 # highlight text bindings
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
179 canvashighlighter(c,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
180 self.txt,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
181 'fill',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
182 normalval='white',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
183 highlightval='red')
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
184
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
185 # position drag bindings
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
186 def press(ev):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
187 self._lastmouse = ev.x, ev.y
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
188
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
189 def motion(ev):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
190 dcan = Pair(*[a - b for a, b in zip((ev.x, ev.y), self._lastmouse)])
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
191 dworld = c.canvas2world_vector(*dcan)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
192 self.field.center(*(self.field.center() + dworld))
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
193 self._lastmouse = ev.x, ev.y
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
194 self.setcoords() # redraw
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
195
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
196 def release(ev):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
197 if hasattr(self, '_lastmouse'):
156
224505b0c21e smaller text
drewp
parents: 154
diff changeset
198 del self._lastmouse
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
199 dispatcher.send("field coord changed") # updates bounds
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
200
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
201 c.tag_bind(self.txt, "<ButtonPress-1>", press)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
202 c.tag_bind(self.txt, "<B1-Motion>", motion)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
203 c.tag_bind(self.txt, "<B1-ButtonRelease>", release)
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
204
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
205 # radius drag bindings
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
206 outerring = self.rings[0]
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
207 canvashighlighter(c,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
208 outerring,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
209 'outline',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
210 normalval='#000080',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
211 highlightval='#4040ff')
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
212
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
213 def motion(ev):
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
214 worldmouse = self.canvas.canvas2world(ev.x, ev.y)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
215 currentdist = pairdist(worldmouse, self.field.center())
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
216 self.field.falloff(currentdist)
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
217 self.setcoords()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
218
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
219 c.tag_bind(outerring, "<B1-Motion>", motion)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
220 c.tag_bind(outerring, "<B1-ButtonRelease>", release) # from above
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
221
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
222 self.setcoords()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
223
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
224
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
225 class Tracker(tk.Frame):
45b12307c695 Initial revision
drewp
parents:
diff changeset
226 """whole tracker widget, which is mostly a view for a
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
227 Fieldset. tracker makes its own fieldset"""
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
228
45b12307c695 Initial revision
drewp
parents:
diff changeset
229 # world coords of the visible canvas (preserved even in window resizes)
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
230 xmin = 0
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
231 xmax = 100
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
232 ymin = 0
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
233 ymax = 100
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
234
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
235 fieldsetfile = None
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
236 displays = None # Field : FieldDisplay. we keep these in sync with the fieldset
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
237
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
238 def __init__(self, master):
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
239 tk.Frame.__init__(self, master)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
240
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
241 self.displays = {}
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
242
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
243 c = self.canvas = Zooming(self, bg='black', closeenough=5)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
244 c.pack(fill='both', exp=1)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
245
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
246 # preserve edge coords over window resize
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
247 c.bind("<Configure>", self.configcoords)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
248
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
249 c.bind("<Motion>", lambda ev: self._fieldset().report(*c.canvas2world(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
250 ev.x, ev.y)))
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
251
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
252 def save(ev):
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
253 print("saving")
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
254 self.fieldsetfile.save()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
255
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
256 master.bind("<Key-s>", save)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
257 dispatcher.connect(self.autobounds, "field coord changed")
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
258
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
259 def _fieldset(self):
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
260 return self.fieldsetfile.fieldset()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
261
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
262 def load(self, filename):
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
263 self.fieldsetfile = Fieldsetfile(filename)
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
264 self.displays.clear()
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
265 for f in self.fieldsetfile.fieldset().getall():
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
266 self.displays[f] = FieldDisplay(self.canvas, f)
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
267 self.displays[f].makeobjs()
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
268 self.autobounds()
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
269
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
270 def configcoords(self, *args):
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
271 # force our canvas coords to stay at the edges of the window
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
272 c = self.canvas
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
273 cornerx, cornery = c.canvas2world(0, 0)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
274 c.move(cornerx - self.xmin, cornery - self.ymin)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
275 c.setscale(0, 0,
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
276 c.winfo_width() / (self.xmax - self.xmin),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
277 c.winfo_height() / (self.ymax - self.ymin))
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
278
45b12307c695 Initial revision
drewp
parents:
diff changeset
279 def autobounds(self):
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
280 """figure out our bounds from the fieldset, and adjust the display zooms.
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
281 writes the corner coords onto the canvas."""
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
282 self.xmin, self.xmax, self.ymin, self.ymax = self._fieldset().getbounds(
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
283 )
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
284
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
285 self.configcoords()
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
286
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
287 c = self.canvas
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
288 c.delete('cornercoords')
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
289 for x, anc2 in ((self.xmin, 'w'), (self.xmax, 'e')):
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
290 for y, anc1 in ((self.ymin, 'n'), (self.ymax, 's')):
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
291 pos = c.world2canvas(x, y)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
292 c.create_text(pos[0],
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
293 pos[1],
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
294 text="%s,%s" % (x, y),
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
295 fill='white',
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
296 anchor=anc1 + anc2,
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
297 tags='cornercoords')
1859
f066d6e874db 2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents: 1858
diff changeset
298 [d.setcoords() for d in list(self.displays.values())]
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
299
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
300
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
301 ########################################################################
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
302 ########################################################################
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
303
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
304 root = tk.Tk()
156
224505b0c21e smaller text
drewp
parents: 154
diff changeset
305 root.wm_geometry('700x350')
1858
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
306 tra = Tracker(root)
7772cc48e016 reformat all python
drewp@bigasterisk.com
parents: 303
diff changeset
307 tra.pack(fill='both', exp=1)
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
308
152
e6ca7c1f0b1e loads and saves as xml now
drewp
parents: 150
diff changeset
309 tra.load("fieldsets/demo")
0
45b12307c695 Initial revision
drewp
parents:
diff changeset
310
45b12307c695 Initial revision
drewp
parents:
diff changeset
311 root.mainloop()