50 ToggleItem.__init__(self)
52 self.
id = self.canvas.create_text(x, y, text=text)
61 self.
id = self.canvas.create_text(self.
x, self.
y, text=self.
text)
70 self.canvas.delete(self.
id)
75 ToggleItem.__init__(self)
87 self.
id[0] = self.canvas.create_line(0, self.
height/2,
89 self.
id[1] = self.canvas.create_text(self.
width - 10,
92 self.
id[2] = self.canvas.create_line(self.
width/2, 0,
94 self.
id[3] = self.canvas.create_text(self.
width/2 + 10,
100 self.canvas.delete(i)
103 def __init__(self, canvas, x, y, width, height, pitch):
104 ToggleItem.__init__(self)
121 circrange = range(
int(circnum))
124 x0 = self.
x - self.
pitch * i
125 y0 = self.
y - self.
pitch * i
126 x1 = self.
x + self.
pitch * i
127 y1 = self.
y + self.
pitch * i
132 id = self.canvas.create_oval(x0, y0, x1, y1, fill=color,
138 self.canvas.tag_lower(i)
142 self.canvas.delete(c)
149 def __init__(self, canvas, x0, y0, x1, y1, color, width):
150 ToggleItem.__init__(self)
158 self.
id = self.canvas.create_line(self.
x0, self.
y0, self.
x1, self.
y1,
165 self.
id = self.canvas.create_line(self.
x0, self.
y0, self.
x1, self.
y1,
175 self.canvas.delete(self.
id)
182 self.
id = self.canvas.create_oval(x-r, y-r, x+r, y+r, **key)
220 self.canvas.tag_bind(self.
id,
'<Button1-Motion>', self.
dragging)
221 self.canvas.tag_bind(self.
id,
'<Button1-ButtonRelease>', self.
drag_end)
241 dx = (x1 - self.
x) - self.
coffx 242 dy = (y1 - self.
y) - self.
coffy 245 self.canvas.move(self.
id, dx, dy)
246 self.canvas.tag_raise(self.
id)
264 self.canvas.move(self.
id, -dx, -dy)
279 th = math.acos((x * 1.0) / (r * 1.0)) * 180.0 / math.pi
281 th = math.acos((x * 1.0) / (r * 1.0)) * -180.0 / math.pi
291 def __init__(self, r=10, width=300, height=300, master=None):
292 Frame.__init__(self, master)
316 self.scale_var.set(1.0)
320 self.vline_check.set(
"on")
322 self.axis_check.set(
"on")
324 self.circ_check.set(
"on")
326 self.xy_check.set(
"on")
328 self.pol_check.set(
"on")
332 self.xentry.set(
"0.0")
334 self.yentry.set(
"0.0")
338 self.rentry.set(
"0.0")
340 self.thentry.set(
"0.0")
363 self.canvas.pack(side=LEFT)
374 text =
'x: %4d, y: %4d' % (0, 0)
379 text =
'r: %4.2f, th: NaN' % (0.0)
390 fill=
"#999999", width=1)
398 self.frame.pack(side=LEFT, fill=Y, padx=3, pady=3)
406 f = Frame(frame, bd=2, relief=GROOVE)
407 dummy = Frame(f, width=self.
wd)
409 sl = Scale(f, from_=0, to=10, resolution=0.01,
410 label=
"Scale Factor", command=self.
on_scale,
411 variable=self.
scale_var, orient=HORIZONTAL)
412 bt = Button(f, text=
"Reset Scale", command=self.
reset_scale)
413 sl.pack(side=TOP, fill=X)
414 bt.pack(side=TOP, fill=X)
423 self.can_circle.set_pitch(pitch)
426 f = Frame(frame, bd=2, relief=GROOVE)
427 dummy = Frame(f, width=self.
wd)
429 vec = Checkbutton(f, text=
"Vector Line",
430 onvalue=
"on", offvalue=
"off",
431 justify=LEFT, anchor=W,
433 command=self.can_vline.toggle)
434 axis = Checkbutton(f, text=
"Axis",
435 onvalue=
"on", offvalue=
"off",
436 justify=LEFT, anchor=W,
438 command=self.can_axis.toggle)
439 circ = Checkbutton(f, text=
"Background",
440 onvalue=
"on", offvalue=
"off",
441 justify=LEFT, anchor=W,
443 command=self.can_circle.toggle)
444 xy = Checkbutton(f, text=
"X-Y position",
445 onvalue=
"on", offvalue=
"off",
446 justify=LEFT, anchor=W,
448 command=self.can_xytext.toggle)
449 pol = Checkbutton(f, text=
"Polar postion",
450 onvalue=
"on", offvalue=
"off",
451 justify=LEFT, anchor=W,
453 command=self.can_poltext.toggle)
454 for w
in [vec, axis, circ, xy, pol]:
455 w.pack(side=TOP, anchor=W, fill=X)
460 dummy = Frame(f, width=self.
wd)
462 xl = Label(f, text=
"x: ", width=3)
463 xe = Entry(f, width=7, textvariable=self.
xentry,
464 justify=RIGHT, relief=GROOVE)
465 yl = Label(f, text=
"y: ", width=3)
466 ye = Entry(f, width=7, textvariable=self.
yentry,
467 justify=RIGHT, relief=GROOVE)
469 for w
in [ye, yl, xe, xl]:
470 w.pack(side=RIGHT, fill=X)
474 f = Frame(frame, width=self.
wd)
475 dummy = Frame(f, width=self.
wd)
477 rl = Label(f, text=
"r: ", width=3)
478 re = Entry(f, width=7, textvariable=self.
rentry,
479 justify=RIGHT, relief=GROOVE)
480 thl = Label(f, text=
"th:", width=3)
481 the = Entry(f, width=7, textvariable=self.
thentry,
482 justify=RIGHT, relief=GROOVE)
483 for w
in [the, thl, re, rl]:
484 w.pack(side=RIGHT, fill=X)
488 self.scale_var.set(1.)
490 self.can_circle.set_pitch(pitch)
496 self.
pos_x = pos[0] * self.scale_var.get()
497 self.
pos_y = pos[1] * self.scale_var.get()
498 self.
pol_r = pol[0] * self.scale_var.get()
501 xt =
'%4d' % (self.
pos_x)
502 yt =
'%4d' % (self.
pos_y)
503 rt =
'%5.2f' % (self.
pol_r)
504 if pol[1] > 360: tht =
'NaN' 505 else: tht =
'%5.2f' % self.
pol_th 510 self.thentry.set(tht)
512 text =
'x: %4d, y: %4d' % (pos[0], pos[1])
515 text =
'r: %5.2f, th: NaN' % (pol[0])
517 text =
'r: %5.2f, th: %5.2f' % (pol[0], pol[1])
520 self.can_vline.draw_line(self.
x0, self.
y0,
539 if __name__ ==
'__main__':
test()
def set_on_update(self, func)
def on_pos_update(self, pos, pol)
def __init__(self, canvas, text, x, y)
def set_on_drag_end(self, func)
def create_xylabel(self, frame)
def __init__(self, canvas, x, y, width, height, pitch)
def create_scale(self, frame)
def set_on_drag_start(self, func)
def drag_start(self, event)
def create_checkbutton(self, frame)
def dragging(self, event)
def draw_line(self, x0, y0, x1, y1)
def drag_end(self, event)
def set_pitch(self, pitch)
def __init__(self, canvas, x0, y0, x1, y1, color, width)
def __init__(self, r=10, width=300, height=300, master=None)
def create_pollabel(self, frame)
def draw_text(self, x, y, text)
def __init__(self, canvas, width, height)
def __init__(self, canvas, x, y, r, key)
def set_on_dragging(self, func)
static int max(int a, int b)