-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveFig.py
More file actions
31 lines (25 loc) · 830 Bytes
/
Copy pathSaveFig.py
File metadata and controls
31 lines (25 loc) · 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import os
import CheckCreateDirectory
from PyQt5.QtWidgets import (
QFileDialog,
QMessageBox,
)
def save_fig(self, fig, name):
"""
Saves the current figure as a PNG image.
This method prompts the user to select a file name and location to save the
figure as a PNG image.
"""
path = ".\\Results"
CheckCreateDirectory.check_create_dir(path)
file_name, _ = QFileDialog.getSaveFileName(
self, "Save Figure", os.path.join(os.getcwd(), "Results", name), "PNG (*.png)"
)
if file_name:
try:
fig.savefig(file_name)
QMessageBox.information(self, "Success", "Figure saved successfully.")
except Exception as e:
QMessageBox.warning(
self, "Error", f"An error occurred while saving the figure: {e}"
)