Exemplo n.º 1
0
 def __init__(self, wdw, r, c):
     """
     Determines layout of the canvas,
     number of rows and colums is r and c.
     """
     wdw.title('a 4-bar mechanism')
     self.fbr = FourBar()
     self.rows = r
     self.cols = c
     self.ox = c/3
     self.oy = 3*r/4
     # print "A =" , (self.ox, self.oy)
     self.togo = False
     # the canvas and start, stop, and clear buttons
     self.c = Canvas(wdw, width=self.cols, height=self.rows, bg='green')
     self.c.grid(row=1, column=2, columnspan=2)
     self.startbut = Button(wdw, text='start', command = self.start)
     self.startbut.grid(row=3, column=2, sticky=W+E)
     self.stopbut = Button(wdw, text='stop', command = self.stop)
     self.stopbut.grid(row=3, column=3, sticky=W+E)
     self.clearbut = Button(wdw, text='clear', command = self.clear)
     self.clearbut.grid(row=3, column=4, columnspan=3, sticky=W+E)
     # the length of the crank
     self.crank_lbl = Label(wdw, text='crank', justify=LEFT)
     self.crank_lbl.grid(row=0, column=0)
     self.crank_bar = IntVar()
     self.L = Scale(wdw, orient='vertical', from_=0, to=self.rows/2, \
         tickinterval=20, resolution=1, length=self.rows, \
         variable=self.crank_bar, command=self.draw_mechanism)
     self.L.set(self.fbr.crank)
     self.L.grid(row=1, column=0)
     # the angle that drives the crank
     self.angle_lbl = Label(wdw, text='angle', justify=LEFT)
     self.angle_lbl.grid(row=0, column=1)
     self.angle = DoubleVar()
     self.t = Scale(wdw, orient='vertical', from_=0, to=6.30, \
         tickinterval=0.30, resolution=0.01, length=self.rows, \
         variable=self.angle, command=self.draw_mechanism)
     self.t.grid(row=1, column=1)
     self.angle.set(self.fbr.angle)
     # the bar at the right
     self.right_bar_lbl = Label(wdw, text='right bar', justify=LEFT)
     self.right_bar_lbl.grid(row=0, column=4)
     self.right_bar = IntVar()
     self.r = Scale(wdw, orient='vertical', from_=0, to=self.rows/2, \
         tickinterval=20, resolution=1, length=self.rows, \
         variable=self.right_bar, command=self.draw_mechanism)
     self.r.grid(row=1, column=4)
     self.right_bar.set(self.fbr.right)
     # the top bar attached to the crank
     self.top_bar_lbl = Label(wdw, text='top bar', justify=LEFT)
     self.top_bar_lbl.grid(row=0, column=5)
     self.r_top_bar = IntVar()
     self.R = Scale(wdw, orient='vertical', from_=0, to=self.rows/2, \
         tickinterval=20, resolution=1, length=self.rows, \
         variable=self.r_top_bar, command=self.draw_mechanism)
     self.R.grid(row=1, column=5)
     self.r_top_bar.set(self.fbr.top)
     # the scale for the coupler bar
     self.coupler_bar_lbl = Label(wdw, text='coupler', justify=LEFT)
     self.coupler_bar_lbl.grid(row=0, column=6)
     self.coupler_bar = IntVar()
     self.cpl = Scale(wdw, orient='vertical', from_=0, to=self.rows/2, \
         tickinterval=20, resolution=1, length=self.rows, \
         variable=self.coupler_bar, command=self.draw_mechanism)
     self.cpl.grid(row=1, column=6)
     self.coupler_bar.set(self.fbr.coupler)
     # the horizontal bottom bar
     self.flat_lbl = Label(wdw, text='right joint', justify=RIGHT)
     self.flat_lbl.grid(row=2, column=1)
     self.flat = IntVar()
     self.f = Scale(wdw, orient='horizontal', from_=0, to=self.rows/2, \
         tickinterval=50, resolution=1, length=self.cols, \
         variable=self.flat, command=self.draw_mechanism)
     self.f.grid(row=2, column=2, columnspan=2)
     self.flat.set(self.fbr.flat)
     # coordinates of the coupler point appear on top
     self.ex = Entry(wdw) # for x value
     self.ex.grid(row=0, column=2)
     self.ex.insert(INSERT, "x = ")
     self.ey = Entry(wdw) # for y value
     self.ey.grid(row=0, column=3)
     self.ey.insert(INSERT,"y = ")
     # check button for drawing of coupler curve
     self.curve = IntVar()
     self.cb = Checkbutton(wdw, text='coupler', \
         variable=self.curve, onvalue=1, offvalue=0)
     self.curve.set(1)
     self.cb.grid(row=3, column=0)
     # draw the mechanism on canvas
     self.draw_mechanism(0)