Mots croisés fonctionnel

This commit is contained in:
François Pelletier 2023-12-26 18:47:53 -05:00
parent 9549eed355
commit 0c4220d848
4 changed files with 13 additions and 9 deletions

0
__init__.py Normal file
View file

View file

@ -10,9 +10,8 @@ paper, if you're one of those people.
import argparse
# Custom imports
import file_ops
import grid_generator
from grid_generator import GridGenerator
import crossword_generator.file_ops as file_ops
from crossword_generator.grid_generator import GridGenerator
def parse_cmdline_args():

View file

@ -1,4 +1,5 @@
import os
import pathlib
import pprint
import shutil
import subprocess
@ -23,7 +24,7 @@ def read_word_list(filename, min_length=2, min_different_letters=2):
return words
def write_grid_to_file(grid, out_file="table.tex", out_pdf="out.pdf", keep_tex=True, words=[]):
def write_grid_to_file(grid, out_file="table.tex", out_pdf="out.pdf", keep_tex=True, words=None):
""" This function receives the generated grid and writes it to the file (or
to the screen, if that's what we want). The grid is expected to be a list
of lists, as used by the remaining functions.
@ -32,6 +33,8 @@ def write_grid_to_file(grid, out_file="table.tex", out_pdf="out.pdf", keep_tex=T
is printed as such.
"""
# Print grid to the file and compile
if words is None:
words = []
with open(out_file, "w") as texfile:
# Write preamble
texfile.write("\documentclass[a4paper]{article}" + "\n")
@ -123,13 +126,13 @@ def write_grid_to_file(grid, out_file="table.tex", out_pdf="out.pdf", keep_tex=T
print("\n=== Compiling the generated latex file! ===")
with tempfile.TemporaryDirectory() as tmpdir:
# Save current directory
original_dir = os.getcwd()
original_dir = pathlib.Path(os.getcwd())
# Copy the latex source to the temporary directory
shutil.copy(out_file, tmpdir)
# Copy logo to the temporary directory
shutil.copy("logo.png", tmpdir)
shutil.copy("../crossword_generator/logo.png", tmpdir)
# Move to the temp directory
os.chdir(tmpdir)
@ -138,10 +141,10 @@ def write_grid_to_file(grid, out_file="table.tex", out_pdf="out.pdf", keep_tex=T
os.rename(out_file, "out.tex")
# Compile
proc = subprocess.call(['pdflatex', "out.tex"])
subprocess.call(['pdflatex', "out.tex"])
# Copy PDF back to the original directory
shutil.copy("out.pdf", original_dir+"/"+out_pdf)
shutil.copy("out.pdf", str(original_dir / out_pdf))
# Move back to the original directory
os.chdir(original_dir)

View file

@ -1,8 +1,10 @@
import basic_ops
import crossword_generator.basic_ops as basic_ops
class GridGenerator:
def __init__(self, word_list, dimensions, n_loops, timeout, target_occupancy):
self.words_in_grid = None
self.grid = None
self.word_list = word_list
self.dimensions = dimensions
self.n_loops = n_loops