Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save figure bugfix. #317

Merged
merged 3 commits into from
Jul 29, 2022
Merged
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
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