Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ You can also use `draw_tree` as a Python library:
```python
from draw_tree import generate_tex, generate_pdf, generate_png
generate_tex('games/example.ef') # Creates example.tex
generate_tex('games/example.ef', output_tex='custom.tex') # Creates custom.tex
generate_tex('games/example.ef', save_to='custom') # Creates custom.tex
generate_pdf('games/example.ef') # Creates example.pdf
generate_png('games/example.ef') # Creates example.png
generate_png('games/example.ef', dpi=600) # Creates high-res example.png (72-2400, default: 300)
generate_png('games/example.ef', output_png='mygame.png', scale_factor=0.8) # Creates mygame.png with 0.8 scaling (0.01 to 100)
generate_png('games/example.ef', save_to='mygame', scale_factor=0.8) # Creates mygame.png with 0.8 scaling (0.01 to 100)
```

### Rendering in Jupyter Notebooks
Expand All @@ -108,6 +108,19 @@ Check out the `pygambit` documentation which contains tutorials that use `draw_t
- [Tutorial 2: Extensive-form games](https://gambitproject.readthedocs.io/en/latest/tutorials/02_extensive_form.html)
- [Tutorial 3: Stripped-down poker](https://gambitproject.readthedocs.io/en/latest/tutorials/03_stripped_down_poker.html)

In short, you can do:
```python
import pygambit as gbt
from draw_tree import draw_tree, generate_tex, generate_pdf, generate_png
g = gbt.read_efg('somegame.efg')
draw_tree(g)
generate_tex(g)
generate_pdf(g)
generate_png(g)
```

> Note: Without setting the `save_to` parameter, the saved file will be based on the title field of the pygambit game object.

## Developer docs: Testing

The project includes a comprehensive test suite using pytest. To run the tests:
Expand Down
42 changes: 23 additions & 19 deletions src/draw_tree/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,49 +50,53 @@ def main():
current_grid = core.grid

try:
# Use default PDF filename if none specified
if output_file is None:
output_file = Path(current_ef_file).stem
if output_mode == "pdf":
print(f"Generating PDF: {output_file}")
if output_file.endswith(".pdf"):
print(f"Generating PDF: {output_file}")
else:
print(f"Generating PDF: {output_file}.pdf")
pdf_path = generate_pdf(
ef_file=current_ef_file,
output_pdf=output_file,
game=current_ef_file,
save_to=output_file,
scale_factor=current_scale,
show_grid=current_grid
)
print(f"PDF generated successfully: {pdf_path}")

elif output_mode == "png":
# Use default PNG filename if none specified
if output_file is None:
base_name = Path(current_ef_file).stem
output_file = f"{base_name}.png"
print(f"Generating PNG: {output_file}")
if output_file.endswith(".png"):
print(f"Generating PNG: {output_file}")
else:
print(f"Generating PNG: {output_file}.png")
png_path = generate_png(
ef_file=current_ef_file,
output_png=output_file,
game=current_ef_file,
save_to=output_file,
scale_factor=current_scale,
show_grid=current_grid,
dpi=dpi if dpi is not None else 300
)
print(f"PNG generated successfully: {png_path}")

elif output_mode == "tex":
# Use default TEX filename if none specified
if output_file is None:
base_name = Path(current_ef_file).stem
output_file = f"{base_name}.tex"
print(f"Generating LaTeX: {output_file}")
if output_file.endswith(".tex"):
print(f"Generating LaTeX: {output_file}")
else:
print(f"Generating LaTeX: {output_file}.tex")
tex_path = generate_tex(
ef_file=current_ef_file,
output_tex=output_file,
game=current_ef_file,
save_to=output_file,
scale_factor=current_scale,
show_grid=current_grid
show_grid=current_grid,
)
print(f"LaTeX generated successfully: {tex_path}")

else:
# Generate TikZ code (original behavior)
tikz_code = draw_tree(
ef_file=current_ef_file,
game=current_ef_file,
scale_factor=current_scale,
show_grid=current_grid
)
Expand Down
Loading