Skip to content

Commit 288b029

Browse files
authored
Add/handle stringio (#3)
* Updated to support StringIO for saving figures * tidy up
1 parent a7babbd commit 288b029

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

mpldxf/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
import mpldxf.backend_dxf
3+
from .backend_dxf import FigureCanvasDxf
4+

mpldxf/backend_dxf.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"""
3636

3737
from __future__ import absolute_import, division, print_function, unicode_literals
38+
from io import BytesIO, StringIO
3839
import os
3940
import sys
4041
import math
@@ -519,12 +520,17 @@ def draw(self):
519520
filetypes = FigureCanvasBase.filetypes.copy()
520521
filetypes["dxf"] = "DXF"
521522

522-
def print_dxf(self, filename, *args, **kwargs):
523+
def print_dxf(self, filename=None, *args, **kwargs):
523524
"""
524525
Write out a DXF file.
525526
"""
526527
drawing = self.draw()
527-
drawing.saveas(filename)
528+
# Check if filename is a BytesIO instance
529+
if isinstance(filename, StringIO):
530+
# ezdxf can only write to a string or a file (not BytesIO directly)
531+
drawing.write(filename)
532+
else:
533+
drawing.saveas(filename) # Use saveas() for file paths
528534

529535
def get_default_filetype(self):
530536
return "dxf"

0 commit comments

Comments
 (0)