51 ToggleItem.__init__(self)
53 self.
id = self.canvas.create_text(x, y, text=text)
62 self.
id = self.canvas.create_text(self.
x, self.
y, text=self.
text)
71 self.canvas.delete(self.
id)
76 ToggleItem.__init__(self)
88 self.
id[0] = self.canvas.create_line(0, self.
height/2,
90 self.
id[1] = self.canvas.create_text(self.
width - 10,
93 self.
id[2] = self.canvas.create_line(self.
width/2, 0,
95 self.
id[3] = self.canvas.create_text(self.
width/2 + 10,
101 self.canvas.delete(i)
104 def __init__(self, canvas, x, y, width, height, pitch):
105 ToggleItem.__init__(self)
122 circrange = range(circnum)
125 x0 = self.
x - self.
pitch * i
126 y0 = self.
y - self.
pitch * i
127 x1 = self.
x + self.
pitch * i
128 y1 = self.
y + self.
pitch * i
133 id = self.canvas.create_oval(x0, y0, x1, y1, fill=color,
139 self.canvas.tag_lower(i)
143 self.canvas.delete(c)
150 def __init__(self, canvas, x0, y0, x1, y1, color, width):
151 ToggleItem.__init__(self)
159 self.
id = self.canvas.create_line(self.
x0, self.
y0, self.
x1, self.
y1,
166 self.
id = self.canvas.create_line(self.
x0, self.
y0, self.
x1, self.
y1,
176 self.canvas.delete(self.
id)
183 self.
id = self.canvas.create_oval(x-r, y-r, x+r, y+r, **key)
222 self.canvas.tag_bind(self.
id,
'<Button1-Motion>', self.
dragging)
223 self.canvas.tag_bind(self.
id,
'<Button1-ButtonRelease>', self.
drag_end)
243 dx = (x1 - self.
x) - self.
coffx 244 dy = (y1 - self.
y) - self.
coffy 247 self.canvas.move(self.
id, dx, dy)
248 self.canvas.tag_raise(self.
id)
266 self.canvas.move(self.
id, -dx, -dy)
281 th = math.acos((x * 1.0) / (r * 1.0)) * 180.0 / math.pi
283 th = math.acos((x * 1.0) / (r * 1.0)) * -180.0 / math.pi
293 def __init__(self, r=10, width=300, height=300, master=None):
294 Frame.__init__(self, master)
318 self.scale_var.set(1.0)
322 self.vline_check.set(
"on")
324 self.axis_check.set(
"on")
326 self.circ_check.set(
"on")
328 self.xy_check.set(
"on")
330 self.pol_check.set(
"on")
334 self.xentry.set(
"0.0")
336 self.yentry.set(
"0.0")
340 self.rentry.set(
"0.0")
342 self.thentry.set(
"0.0")
365 self.canvas.pack(side=LEFT)
376 text =
'x: %4d, y: %4d' % (0, 0)
381 text =
'r: %4.2f, th: NaN' % (0.0)
392 fill=
"#999999", width=1)
400 self.frame.pack(side=LEFT, fill=Y, padx=3, pady=3)
408 f = Frame(frame, bd=2, relief=GROOVE)
409 dummy = Frame(f, width=self.
wd)
411 sl = Scale(f, from_=0, to=10, resolution=0.01,
412 label=
"Scale Factor", command=self.
on_scale,
413 variable=self.
scale_var, orient=HORIZONTAL)
414 bt = Button(f, text=
"Reset Scale", command=self.
reset_scale)
415 sl.pack(side=TOP, fill=X)
416 bt.pack(side=TOP, fill=X)
425 self.can_circle.set_pitch(pitch)
428 f = Frame(frame, bd=2, relief=GROOVE)
429 dummy = Frame(f, width=self.
wd)
431 vec = Checkbutton(f, text=
"Vector Line",
432 onvalue=
"on", offvalue=
"off",
433 justify=LEFT, anchor=W,
435 command=self.can_vline.toggle)
436 axis = Checkbutton(f, text=
"Axis",
437 onvalue=
"on", offvalue=
"off",
438 justify=LEFT, anchor=W,
440 command=self.can_axis.toggle)
441 circ = Checkbutton(f, text=
"Background",
442 onvalue=
"on", offvalue=
"off",
443 justify=LEFT, anchor=W,
445 command=self.can_circle.toggle)
446 xy = Checkbutton(f, text=
"X-Y position",
447 onvalue=
"on", offvalue=
"off",
448 justify=LEFT, anchor=W,
450 command=self.can_xytext.toggle)
451 pol = Checkbutton(f, text=
"Polar postion",
452 onvalue=
"on", offvalue=
"off",
453 justify=LEFT, anchor=W,
455 command=self.can_poltext.toggle)
456 for w
in [vec, axis, circ, xy, pol]:
457 w.pack(side=TOP, anchor=W, fill=X)
462 dummy = Frame(f, width=self.
wd)
464 xl = Label(f, text=
"x: ", width=3)
466 justify=RIGHT, relief=GROOVE)
467 yl = Label(f, text=
"y: ", width=3)
469 justify=RIGHT, relief=GROOVE)
471 for w
in [ye, yl, xe, xl]:
472 w.pack(side=RIGHT, fill=X)
476 f = Frame(frame, width=self.
wd)
477 dummy = Frame(f, width=self.
wd)
479 rl = Label(f, text=
"r: ", width=3)
481 justify=RIGHT, relief=GROOVE)
482 thl = Label(f, text=
"th:", width=3)
484 justify=RIGHT, relief=GROOVE)
485 for w
in [the, thl, re, rl]:
486 w.pack(side=RIGHT, fill=X)
490 self.scale_var.set(1.)
492 self.can_circle.set_pitch(pitch)
498 self.
pos_x = pos[0] * self.scale_var.get()
499 self.
pos_y = pos[1] * self.scale_var.get()
500 self.
pol_r = pol[0] * self.scale_var.get()
503 xt =
'%4d' % (self.
pos_x)
504 yt =
'%4d' % (self.
pos_y)
505 rt =
'%5.2f' % (self.
pol_r)
506 if pol[1] > 360: tht =
'NaN' 507 else: tht =
'%5.2f' % self.
pol_th 512 self.thentry.set(tht)
514 text =
'x: %4d, y: %4d' % (pos[0], pos[1])
517 text =
'r: %5.2f, th: NaN' % (pol[0])
519 text =
'r: %5.2f, th: %5.2f' % (pol[0], pol[1])
522 self.can_vline.draw_line(self.
x0, self.
y0,
541 if __name__ ==
'__main__':
test()
def __init__(self, canvas, x0, y0, x1, y1, color, width)
def on_pos_update(self, pos, pol)
def dragging(self, event)
def __init__(self, canvas, width, height)
def create_pollabel(self, frame)
def set_on_drag_start(self, func)
def drag_start(self, event)
def set_pitch(self, pitch)
def create_checkbutton(self, frame)
def __init__(self, canvas, x, y, width, height, pitch)
def set_on_dragging(self, func)
def __init__(self, canvas, x, y, r, key)
def set_on_update(self, func)
def create_xylabel(self, frame)
def __init__(self, canvas, text, x, y)
def __init__(self, r=10, width=300, height=300, master=None)
def set_on_drag_end(self, func)
def create_scale(self, frame)
def draw_text(self, x, y, text)
def draw_line(self, x0, y0, x1, y1)
def drag_end(self, event)