Skip to content

Commit

Permalink
Merge pull request #317 from pfafflabatuiuc/save_figure_bugfix
Browse files Browse the repository at this point in the history
Save figure bugfix.
  • Loading branch information
wpfff committed Jul 29, 2022
2 parents 1fa3537 + 7e1755e commit 75991e0
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions plottr/plot/pyqtgraph/autoplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def __init__(self, parent: Optional[PlotWidgetContainer]) -> None:
self.fmWidget: Optional[FigureWidget] = None
self.figConfig: Optional[FigureConfigToolBar] = None
self.figOptions: FigureOptions = FigureOptions()
self.title : Optional[str] = None

layout = QtWidgets.QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
Expand Down Expand Up @@ -309,6 +310,7 @@ def _plotData(self, **kwargs: Any) -> None:

if self.data.has_meta('title'):
self.fmWidget.setTitle(self.data.meta_val('title'))
self.title = self.data.meta_val('title')

@Slot()
def _refreshPlot(self) -> None:
Expand All @@ -335,12 +337,16 @@ def onfigSaved(self) -> None:
assert isinstance(self.fmWidget, FigureWidget)
assert isinstance(self.data, DataDictBase)
screenshot = self.fmWidget.grab(rectangle=QtCore.QRect(QtCore.QPoint(0, 0), QtCore.QSize(-1, -1)))
path = Path(self.data.meta_val('title'))
# add a timestamp here
t = time.localtime()
time_str = time.strftime(TIMESTRFORMAT, t)
filename = time_str+'_'+str(path.stem)+'.png'
screenshot.save(str(path.parent)+'/'+filename, format='PNG')
if self.title is not None:
path = Path(self.title)
# add a timestamp here
t = time.localtime()
time_str = time.strftime(TIMESTRFORMAT, t)
filename = time_str+'_'+str(path.stem)+'.png'
screenshot.save(str(path.parent)+'/'+filename, format='PNG')
return

logger.error("Could not find the path of the figuer. Figure has not been saved")

# TODO: Allow for the option to choose filetypes and the name/directory

Expand Down

0 comments on commit 75991e0

Please sign in to comment.