annotate bin/tracker @ 1859:f066d6e874db

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