-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
58 lines (46 loc) · 1.84 KB
/
functions.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
##############################################################################
##
# This file is part of SHG data fitting
##
# SHG data fitting is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
##
##############################################################################
__author__ = ["Aymen Mahmoudi"]
__license__ = "GPL"
__date__ = "01/02/2023"
import numpy as np
from PyQt5.QtWidgets import QMainWindow, QApplication, QFileDialog
from PyQt5 import uic
import sys
def openFileNameDialog(self):
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
fileName, _ = QFileDialog.getOpenFileName(self,"QFileDialog.getOpenFileName()", "","All Files (*);;Python Files (*.py)", options=options)
if fileName:
print(fileName)
def write_to_file(self, file_path, data):
"""
Write data to a file.
Parameters:
- file_path (str): The path to the file.
- data (str): The data to be written to the file.
Returns:
- bool: True if the write operation is successful, False otherwise.
"""
try:
with open(file_path, 'w') as file:
file.write(data)
print(f"Data successfully written to {file_path}")
return True
except Exception as e:
print(f"Error writing to {file_path}: {e}")
return False
def open_save_dialog(self):
option = QFileDialog.Options()
option |= QFileDialog.DontUseNativeDialog
file = QFileDialog.getSaveFileName(self, "Save File Name Title", "default.txt", "All Files (*)", options=option)
self.write_to_file(file[0], "Hello Aymen")