def draw_on(self, canvas, top_left): x, y = top_left # pins for r in xrange(2): for c in xrange(4): pin_x = x + c * (CONNECTOR_SIZE + CONNECTOR_SPACING) pin_y = y + r * (CONNECTOR_SIZE + VERTICAL_SEPARATION) canvas.create_rectangle(pin_x, pin_y, pin_x + CONNECTOR_SIZE, pin_y + CONNECTOR_SIZE, fill='black') # body width = 4 * CONNECTOR_SIZE + 3 * CONNECTOR_SPACING height = 2 * CONNECTOR_SIZE + VERTICAL_SEPARATION h_offset = 2 v_offset = 2 * CONNECTOR_SIZE / 3 canvas.create_rectangle(x - h_offset, y + v_offset, x + width + h_offset, y + height - v_offset, fill=OP_AMP_BODY_COLOR) # dot dot_dx = (OP_AMP_DOT_OFFSET - h_offset) if self.dot_bottom_left else ( width - OP_AMP_DOT_OFFSET + h_offset) dot_dy = ((height - OP_AMP_DOT_OFFSET - CONNECTOR_SIZE / 2) if self.dot_bottom_left else (OP_AMP_DOT_OFFSET + CONNECTOR_SIZE / 2)) create_circle(canvas, x + dot_dx, y + dot_dy, OP_AMP_DOT_RADIUS, fill=OP_AMP_DOT_COLOR) if self.jfet: create_circle(canvas, x + width / 2, y + height / 2, 10, fill='white') canvas.create_text(x + width / 2, y + height / 2, text='J', justify=CENTER, fill='red', font=BOLD_FONT)
def draw_on(self, canvas, top_left): x, y = top_left size = 3 * CONNECTOR_SIZE + 2 * CONNECTOR_SPACING offset = 2 canvas.create_rectangle(x - offset, y - offset, x + size + offset, y + size + offset, fill=POT_FILL, outline=POT_OUTLINE) create_circle(canvas, x + size / 2, y + size / 2, POT_CIRCLE_RADIUS, fill=POT_CIRCLE_FILL) for (r, c) in ([(0, 1), (2, 0), (2, 2)] if self.directed_up else [(0, 0), (0, 2), (2, 1)]): pin_x = x + c * (CONNECTOR_SIZE + CONNECTOR_SPACING) pin_y = y + r * (CONNECTOR_SIZE + CONNECTOR_SPACING) canvas.create_rectangle(pin_x, pin_y, pin_x + CONNECTOR_SIZE, pin_y + CONNECTOR_SIZE, fill='#777', outline='black')
def draw_on(self, canvas, top_left): x, y = top_left # pins for r in xrange(2): for c in xrange(4): pin_x = x + c * (CONNECTOR_SIZE + CONNECTOR_SPACING) pin_y = y + r * (CONNECTOR_SIZE + VERTICAL_SEPARATION) canvas.create_rectangle(pin_x, pin_y, pin_x + CONNECTOR_SIZE, pin_y + CONNECTOR_SIZE, fill='black') # body width = 4 * CONNECTOR_SIZE + 3 * CONNECTOR_SPACING height = 2 * CONNECTOR_SIZE + VERTICAL_SEPARATION h_offset = 2 v_offset = 2 * CONNECTOR_SIZE / 3 canvas.create_rectangle(x - h_offset, y + v_offset, x + width + h_offset, y + height - v_offset, fill=OP_AMP_BODY_COLOR) # dot dot_dx = (OP_AMP_DOT_OFFSET - h_offset) if self.dot_bottom_left else (width - OP_AMP_DOT_OFFSET + h_offset) dot_dy = ((height - OP_AMP_DOT_OFFSET - CONNECTOR_SIZE / 2) if self.dot_bottom_left else (OP_AMP_DOT_OFFSET + CONNECTOR_SIZE / 2)) create_circle(canvas, x + dot_dx, y + dot_dy, OP_AMP_DOT_RADIUS, fill=OP_AMP_DOT_COLOR) if self.jfet: create_circle(canvas, x + width / 2, y + height / 2, 10, fill='white') canvas.create_text(x + width / 2, y + height / 2, text='J', justify=CENTER, fill='red', font=BOLD_FONT)
def draw_on(self, canvas, offset=(0, 0)): Pin_Drawable.draw_on(self, canvas, offset) ox, oy = offset w, h = self.width, self.height cx, cy = ox + w / 2, oy + h / 2 left_x, left_y, common_x, common_y, right_x, right_y = self._pin_positions( offset) self.parts.add(canvas.create_text(left_x + LABEL_PADDING * sign(cx - left_x), left_y + LABEL_PADDING * sign(cy - left_y), text='l', fill='white', justify=CENTER, font=FONT)) self.parts.add(canvas.create_text(common_x + LABEL_PADDING * sign(cx - common_x), common_y + LABEL_PADDING * sign(cy - common_y), text='c', fill='white', justify=CENTER, font=FONT)) self.parts.add(canvas.create_text(right_x + LABEL_PADDING * sign(cx - right_x), right_y + LABEL_PADDING * sign(cy - right_y), text='r', fill='white', justify=CENTER, font=FONT)) # draw the button that shows whether a signal file has been selected lamp_cx = ox + LAMP_BOX_PADDING + LAMP_BOX_SIZE / 2 lamp_cy = oy + LAMP_BOX_PADDING + LAMP_BOX_SIZE / 2 lamp_box = canvas.create_rectangle(lamp_cx - LAMP_BOX_SIZE / 2, lamp_cy - LAMP_BOX_SIZE / 2, lamp_cx + LAMP_BOX_SIZE / 2, lamp_cy + LAMP_BOX_SIZE / 2, fill=LAMP_BOX_COLOR) lamp = create_circle(canvas, lamp_cx, lamp_cy, LAMP_RADIUS, fill=LAMP_COLOR if self.signal_file else LAMP_EMPTY_COLOR) def set_signal_file(): """ Opens a window to let the user choose a lamp signal file. """ new_signal_file = askopenfilename(title=OPEN_LAMP_SIGNAL_FILE_TITLE, filetypes=[('%s files' % LAMP_SIGNAL_FILE_TYPE, LAMP_SIGNAL_FILE_EXTENSION)], initialfile=self.signal_file) if new_signal_file and new_signal_file != self.signal_file: self.signal_file = relpath(new_signal_file) canvas.itemconfig(lamp, fill=LAMP_COLOR) self.on_signal_file_changed() self.set_signal_file = set_signal_file self.parts.add(lamp_box) self.parts.add(lamp)