def __init__(self): GCompound.__init__(self) self.add(SudokuDigitSelectorSubcell(1), 0, 0) self.add(SudokuDigitSelectorSubcell(2), SUBCELL_WIDTH, 0) self.add(SudokuDigitSelectorSubcell(3), 0, SUBCELL_WIDTH) self.add(SudokuDigitSelectorSubcell(4), SUBCELL_WIDTH, SUBCELL_WIDTH) self.add(ClearCell(), SUBCELL_WIDTH, SUBCELL_WIDTH)
def __init__(self, boxes): GCompound.__init__(self) self.boxes = boxes assert len(boxes) == 4 self.add(boxes[0], 0, 0) self.add(boxes[1], BOX_WIDTH, 0) self.add(boxes[2], 0, BOX_WIDTH) self.add(boxes[3], BOX_WIDTH, BOX_WIDTH)
def __init__(self, cells): GCompound.__init__(self) assert len(cells) == 4 self.cells = cells self.add(cells[0], 0, 0) self.add(cells[1], CELL_WIDTH, 0) self.add(cells[2], 0, CELL_WIDTH) self.add(cells[3], CELL_WIDTH, CELL_WIDTH)
def __init__(self): GCompound.__init__(self) box1 = construct_box(0,0,0,0) box2 = construct_box(0,0,0,0) box3 = construct_box(0,0,0,0) box4 = construct_box(0,0,0,0) self.board = VisualSudokuBoard([box1, box2, box3, box4]) self.add(self.board, 0, 0) self.menu = MenuBar() self.add(self.menu, 0, GWINDOW_WIDTH)
def __init__(self, name): """Creates a new node with the specified name.""" GCompound.__init__(self) self._name = name r = ArpanetNode.SIZE / 2 oval = GOval(-r, -r, 2 * r, 2 * r) oval.setFilled(True) self.add(oval) self._routingTable = None self._active = True self._neighbors = set()
def __init__(self, letter): GCompound.__init__(self) lamp = GOval(LAMP_RADIUS * 2, LAMP_RADIUS * 2) lamp.setColor(LAMP_BORDER_COLOR) lamp.setFillColor(LAMP_BGCOLOR) self.add(lamp, -LAMP_RADIUS, -LAMP_RADIUS) # create design for lamps self.ch = GLabel(letter) self.ch.setColor(LAMP_OFF_COLOR) self.ch.setFont(LAMP_FONT) self.add(self.ch, -self.ch.getWidth() / 2, LAMP_LABEL_DY)
def __init__(self): GCompound.__init__(self) bar = GRect(GWINDOW_WIDTH, MENU_BAR_HEIGHT) bar.setFilled(True) bar.setColor(CELL_BORDER_COLOR) bar.setFillColor(MENU_BAR_BGCOLOR) self.add(bar, 0, 0) self.label = GLabel("Y O U D O K U") self.label.setFont(MENU_TITLE_FONT) self.label.setColor(MENU_TITLE_COLOR) self.add(self.label, GWINDOW_WIDTH//2 - self.label.getWidth()//2, MENU_BAR_HEIGHT//2 + self.label.getAscent()//2 - 5)
def __init__(self, letter): GCompound.__init__(self) key = GOval(KEY_RADIUS * 2, KEY_RADIUS * 2) key.setLineWidth(KEY_BORDER) key.setColor(KEY_BORDER_COLOR) key.setFillColor(KEY_BGCOLOR) self.add(key, -KEY_RADIUS, -KEY_RADIUS) # create design for keys self.ch = GLabel(letter) self.ch.setColor(KEY_UP_COLOR) self.ch.setFont(KEY_FONT) self.add(self.ch, -self.ch.getWidth() / 2, KEY_LABEL_DY)
def __init__(self, digit): GCompound.__init__(self) self.digit = str(digit) cell = GRect(0, 0, SUBCELL_WIDTH, SUBCELL_WIDTH) cell.setColor(CELL_BORDER_COLOR) cell.setFillColor(SUBCELL_FILL_COLOR) cell.setFilled(True) self.add(cell, 0, 0) self.label = GLabel(digit) self.label.setFont(SUBCELL_FONT) self.label.setColor(SUBCELL_TEXT_COLOR) self.add(self.label, SUBCELL_WIDTH//2 - self.label.getWidth()//2, SUBCELL_WIDTH//2 + self.label.getAscent()//2 - 3)
def __init__(self, digit): GCompound.__init__(self) if digit != 0: self.digit = str(digit) else: self.digit = None self.cell = GRect(0, 0, CELL_WIDTH, CELL_WIDTH) self.cell.setColor(CELL_BORDER_COLOR) self.cell.setFillColor(CELL_GOOD_COLOR) self.cell.setFilled(True) self.add(self.cell, 0, 0) self.label = None self.only_a_suggestion = True self.render_label() self.selector = None
def __init__(self, text, fn=None): GCompound.__init__(self) label = GLabel(text) label.set_font(self.BUTTON_FONT) width = max(self.BUTTON_MIN_WIDTH, 2 * self.BUTTON_MARGIN + label.get_width()) frame = GRect(width, self.BUTTON_DEFAULT_HEIGHT) frame.set_filled(True) frame.set_fill_color("White") self.add(frame) self.add(label) self.text = text self.label = label self.frame = frame self.fn = fn self._recenter()
def __init__(self, letter): ''' The constructor initalizes the key for a given letter. ''' GCompound.__init__(self) button = createFilledCircle(0, 0, KEY_RADIUS, fill=KEY_BGCOLOR, border=KEY_BORDER_COLOR) button.setLineWidth(KEY_BORDER) key = GLabel(letter) key.setFont(KEY_FONT) self.key = key key.setColor(KEY_UP_COLOR) self.add(button) self.add(key, -key.getWidth() / 2, KEY_LABEL_DY)
def __init__(self): ''' The constructor creates a return button on the enigma. ''' GCompound.__init__(self) button = createFilledRect(-RETURN_WIDTH / 2, -RETURN_HEIGHT / 2, RETURN_WIDTH, RETURN_HEIGHT, fill=RETURN_BGCOLOR, border=RETURN_BORDER_COLOR) button.setLineWidth(RETURN_BORDER) label = GLabel('RETURN') label.setFont(RETURN_FONT) label.setColor(RETURN_COLOR) self.add(button) self.add(label, -label.getWidth() / 2, RETURN_LABEL_DY)
def __init__(self): GCompound.__init__(self) self.digit = "" outer = GOval(-20, -20, 40, 40) outer.setFilled(True) outer.setFillColor("red") outer.setColor("red") self.add(outer) outer = GOval(-16, -16, 32, 32) outer.setFilled(True) outer.setFillColor("white") outer.setColor("white") self.add(outer) strikethrough = GLine(15, -15, -15, 15) strikethrough.setLineWidth(6) strikethrough.setColor("red") self.add(strikethrough)
def __init__(self, nRows, nCols, sqSize): """ Creates a new Maze object with the specified number of rows and columns and in which each square has the specified size. The return value is a single graphical object descended from GCompound that can be added to a GWindow. In keeping with the conventions of the Portable Graphics Library, the reference point for the Maze object is its upper left corner. """ GCompound.__init__(self) self._nRows = nRows self._nCols = nCols self._sqSize = sqSize self._addGrid(nRows, nCols, sqSize) self._addVerticalWalls(nRows, nCols, sqSize) self._addHorizontalWalls(nRows, nCols, sqSize) self._addBorders(nRows, nCols, sqSize) self._addIntersections(nRows, nCols, sqSize)
def __init__(self, letter, perm, inverse): GCompound.__init__(self) rotor = GRect(ROTOR_WIDTH, ROTOR_HEIGHT) rotor.setColor(ROTOR_BGCOLOR) rotor.setFilled(True) self.add(rotor, -ROTOR_WIDTH / 2, -ROTOR_HEIGHT / 2) # create design for rotors self.ch = GLabel(letter) self.ch.setColor(ROTOR_COLOR) self.ch.setFont(ROTOR_FONT) self.add(self.ch, -self.ch.getWidth() / 2, ROTOR_LABEL_DY) self.perm = perm self.inverse = inverse self.offset = 0 self.rotor = rotor
def __init__(self, letter): ''' The constructor creates a lamp for a given letter. ''' GCompound.__init__(self) self.letter = letter lamp = createFilledCircle(0, 0, LAMP_RADIUS, fill=LAMP_BGCOLOR, border=LAMP_BORDER_COLOR) lamp = GLabel(letter) lamp.setFont(LAMP_FONT) self.lamp = lamp self.state = False lamp.setColor(LAMP_OFF_COLOR) self.add(lamp) self.add(lamp, -lamp.getWidth() / 2, LAMP_LABEL_DY)
def __init__(self, permuation): ''' The constructor initalizes the rotor in the base setting. ''' GCompound.__init__(self) self.permuation = permuation self.inversion = invertKey(permuation) self.offset = 0 rotor = createFilledRect(-ROTOR_WIDTH / 2, -ROTOR_HEIGHT / 2, ROTOR_WIDTH, ROTOR_HEIGHT, fill=ROTOR_BGCOLOR) setting = GLabel(ALPHABET[self.offset]) setting.setColor(ROTOR_COLOR) setting.setFont(ROTOR_FONT) self.setting = setting self.add(rotor) self.add(setting, -setting.getWidth() / 2, ROTOR_LABEL_DY)
def __init__(self, node): GCompound.__init__(self) self._node = node frame = GRect(ArpanetMonitor.WIDTH, ArpanetMonitor.MAX_NODES * ArpanetMonitor.VSPACE) self.add(frame, 0, ArpanetMonitor.VSPACE) label = GLabel(node.getName()) label.setFont(ArpanetMonitor.FONT) x = ArpanetMonitor.MARGIN y = label.getAscent() self.add(label, x, y) self._label = label self._lines = [] for i in range(ArpanetMonitor.MAX_NODES): y += ArpanetMonitor.VSPACE label = GLabel("") label.setFont(ArpanetMonitor.FONT) self.add(label, x, y) self._lines.append(label) self.update()
def __init__(self, rotor): ''' The constructor initalizes the selector in the standard setting in the three rotor model. ''' GCompound.__init__(self) self.offset = rotor self.rotor = rotor button = createFilledRect(-SELECTOR_WIDTH / 2, -SELECTOR_HEIGHT / 2, SELECTOR_WIDTH, SELECTOR_HEIGHT, fill=SELECTOR_BGCOLOR, border=SELECTOR_COLOR) button.setLineWidth(3) setting = GLabel(str(self.offset)) setting.setFont(SELECTOR_FONT) setting.setColor(SELECTOR_COLOR) self.setting = setting self.add(button) self.add(setting, -setting.getWidth() / 2, SELECTOR_LABEL_DY)
def __init__(self, color, level, puzzle): """Creates a piece with the indicated color and initial level""" GCompound.__init__(self) self._level = level self._puzzle = puzzle self.setColor(color) frame = GRect(PIECE_WIDTH, PIECE_HEIGHT) frame.setFilled(True) frame.setColor(PIECE_COLOR) self.add(frame, -PIECE_WIDTH / 2, 0) poly = GPolygon() dw = PIECE_WIDTH / puzzle.getNLevels() w0 = (level - 1) * dw w1 = level * dw poly.addVertex(-w0 / 2, 0) poly.addVertex(w0 / 2, 0) poly.addVertex(w1 / 2, PIECE_HEIGHT) poly.addVertex(-w1 / 2, PIECE_HEIGHT) poly.setFilled(True) poly.setColor(color) self.add(poly) border = GRect(PIECE_WIDTH, PIECE_HEIGHT) border.setColor(BORDER_COLOR) self.add(border, -PIECE_WIDTH / 2, 0)
def __init__(self, edge, order): GCompound.__init__(self) self.addSierpinskiTriangle(edge, order)