def test_suggestions(self): squares = [['.', '.', ' ', ' ', ' '], ['B', 'E', 'E', 'C', 'H'], ['A', 'S', 'A', 'H', 'I'], ['T', 'A', 'C', 'O', 'S'], ['H', 'U', 'H', '.', '.']] model = Model(squares) model.update_focus(0, 2) across, down = model.get_suggestions()
def test_suggestions(self): squares = [['.', '.', '', '', ''], ['B', 'E', 'E', 'C', 'H'], ['A', 'S', 'A', 'H', 'I'], ['T', 'A', 'C', 'O', 'S'], ['H', 'U', 'H', '.', '.']] model = Model(squares) suggestions = model._get_suggestions((0, 2), grid.Mode.ACROSS) print(suggestions[:10])
def test_get_square_info(self, square, text, background, focused): model = Model(squares, dictionary_path=dictionary_path) model.update_focus(2, 3) actual = model.get_square(square[0], square[1]) self.assertEqual(actual.text, text) self.assertEqual(actual.background, background) self.assertEqual(actual.focused, focused)
def test_fill(self): squares = [['.', '.', '', '', ''], ['B', 'E', 'E', 'C', 'H'], ['A', 'S', 'A', 'H', 'I'], ['T', 'A', 'C', 'O', 'S'], ['H', 'U', 'H', '.', '.']] model = Model(squares) model.fill() self.assertEqual(['.', '.', 'P', 'E', 'C'], model.grid.squares[0])
def __init__(self): super().__init__() self.title = 'Crossword Creator' self.left = 2000 self.top = 10 self.width = 1000 self.height = 480 self.model = Model(filename=FILENAME, size=15) self.init_ui() self.update_views()
def test_update_square_block_symmetry(self): model = Model(squares, dictionary_path=dictionary_path) model.update_square(4, 0, grid.BLOCK) self.assertEqual(model.get_square(4, 0).text, grid.BLOCK) self.assertEqual(model.get_square(0, 4).text, grid.BLOCK) model.update_square(0, 4, 'A') self.assertEqual(model.get_square(4, 0).text, '') self.assertEqual(model.get_square(0, 4).text, 'A')
def test_toggle(self): model = Model(squares, dictionary_path=dictionary_path) model.mode = grid.Mode.ACROSS model.focus = (3, 1) model.toggle_orientation() self.assertEqual(model.mode, grid.Mode.DOWN) self.assertEqual(model.highlight, [(3, 1), (4, 1)])
def test_movement(self): model = Model(squares, dictionary_path=dictionary_path) model.focus = (2, 2) model.move_up() self.assertEqual(model.focus, (1, 2)) model.move_left() self.assertEqual(model.focus, (1, 1)) model.move_down() self.assertEqual(model.focus, (2, 1)) model.move_right() self.assertEqual(model.focus, (2, 2))
def test_get_next_focus(self, current_focus, text, mode, new_focus): model = Model(squares, dictionary_path=dictionary_path) model.mode = mode model.focus = current_focus model.get_next_focus(text) self.assertEqual(model.focus, new_focus)
def test_update_highlighted_squares(self, focus, mode, highlight): model = Model(squares, dictionary_path=dictionary_path) model.mode = mode model.update_focus(focus[0], focus[1]) self.assertEqual(model.focus, focus) self.assertEqual(model.highlight, highlight)
def test_create_from_size(self): model = Model(size=8, dictionary_path=dictionary_path) self.assertEqual(model.size, 8)
def test_create_from_file(self): model = Model(filename="test/crossword.txt", dictionary_path=dictionary_path) self.assertEqual(model.size, 15)
def test_create_from_squares(self): model = Model(squares, dictionary_path=dictionary_path) self.assertEqual(model.size, 5)
class App(QWidget): def __init__(self): super().__init__() self.title = 'Crossword Creator' self.left = 2000 self.top = 10 self.width = 1000 self.height = 480 self.model = Model(filename=FILENAME, size=15) self.init_ui() self.update_views() def init_ui(self): self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.create_grid_layout() self.create_options_layout() self.across_suggestions = SuggestionBox("Across") self.down_suggestions = SuggestionBox("Down") window_layout = QHBoxLayout() window_layout.addWidget(self.grid_group_box) window_layout.addWidget(self.across_suggestions) window_layout.addWidget(self.down_suggestions) window_layout.addWidget(self.options_group_box) self.setLayout(window_layout) self.show() def create_grid_layout(self): self.grid_group_box = QGroupBox() self.grid_group_box.setMaximumSize(450, 450) layout = QGridLayout() layout.setSpacing(0) layout.setRowStretch(0, 0) for row in range(0, 15): for col in range(0, 15): text_box = CrosswordLineEdit() text_box.setObjectName(get_box_name(row, col)) text_box.edited.connect(self.on_box_edited) text_box.focused.connect(self.on_box_focused) text_box.installEventFilter(self) layout.addWidget(text_box, row, col) self.grid_group_box.setLayout(layout) def create_options_layout(self): self.options_group_box = QGroupBox() layout = QVBoxLayout() save = QPushButton("Save") save.clicked.connect(self.save_crossword) layout.addWidget(save) fill = QPushButton("Fill") fill.clicked.connect(self.fill) layout.addWidget(fill) self.options_group_box.setLayout(layout) def keyPressEvent(self, event): if event.key() == Qt.Key_Shift: self.model.toggle_orientation() self.update_views() def eventFilter(self, obj, event): # filter to keep LineEdits from consuming arrow keys if event.type() == QEvent.KeyPress: if event.key() in [ Qt.Key_Up, Qt.Key_Down, Qt.Key_Right, Qt.Key_Left ]: if event.key() == Qt.Key_Up: self.model.move_up() elif event.key() == Qt.Key_Down: self.model.move_down() elif event.key() == Qt.Key_Left: self.model.move_left() elif event.key() == Qt.Key_Right: self.model.move_right() self.update_views() return True return False def save_crossword(self): self.model.save(FILENAME) def fill(self): self.model.fill() self.update_views() def on_box_edited(self, name, text): coords = get_coords_from_name(name) self.model.update_square(coords[0], coords[1], text) self.update_views() def on_box_focused(self, name): row, col = get_coords_from_name(name) self.model.update_focus(row, col) self.update_views() def update_views(self): for row in range(0, self.model.size): for col in range(0, self.model.size): square = self.model.get_square(row, col) name = get_box_name(row, col) self.grid_group_box.findChild(CrosswordLineEdit, name).update(square) self.update_suggestions() def update_suggestions(self): across, down = self.model.get_suggestions() self.across_suggestions.update_suggestions(across) self.down_suggestions.update_suggestions(down)