7 Module implementing a dialog showing UML like diagrams. |
7 Module implementing a dialog showing UML like diagrams. |
8 """ |
8 """ |
9 |
9 |
10 import enum |
10 import enum |
11 import json |
11 import json |
12 |
12 import pathlib |
13 from PyQt6.QtCore import pyqtSlot, Qt, QFileInfo, QCoreApplication |
13 |
|
14 from PyQt6.QtCore import pyqtSlot, Qt, QCoreApplication |
14 from PyQt6.QtGui import QAction |
15 from PyQt6.QtGui import QAction |
15 from PyQt6.QtWidgets import QToolBar, QGraphicsScene |
16 from PyQt6.QtWidgets import QToolBar, QGraphicsScene |
16 |
17 |
17 from EricWidgets import EricMessageBox, EricFileDialog |
18 from EricWidgets import EricMessageBox, EricFileDialog |
18 from EricWidgets.EricMainWindow import EricMainWindow |
19 from EricWidgets.EricMainWindow import EricMainWindow |
247 "All Files (*)"), |
248 "All Files (*)"), |
248 "", |
249 "", |
249 EricFileDialog.DontConfirmOverwrite) |
250 EricFileDialog.DontConfirmOverwrite) |
250 if not fname: |
251 if not fname: |
251 return |
252 return |
252 ext = QFileInfo(fname).suffix() |
253 |
253 if not ext: |
254 fpath = pathlib.Path(fname) |
|
255 if not fpath.suffix: |
254 ex = selectedFilter.split("(*")[1].split(")")[0] |
256 ex = selectedFilter.split("(*")[1].split(")")[0] |
255 if ex: |
257 if ex: |
256 fname += ex |
258 fpath = fpath.with_suffix(ex) |
257 if QFileInfo(fname).exists(): |
259 if fpath.exists(): |
258 res = EricMessageBox.yesNo( |
260 res = EricMessageBox.yesNo( |
259 self, |
261 self, |
260 self.tr("Save Diagram"), |
262 self.tr("Save Diagram"), |
261 self.tr("<p>The file <b>{0}</b> already exists." |
263 self.tr("<p>The file <b>{0}</b> already exists." |
262 " Overwrite it?</p>").format(fname), |
264 " Overwrite it?</p>").format(str(fpath)), |
263 icon=EricMessageBox.Warning) |
265 icon=EricMessageBox.Warning) |
264 if not res: |
266 if not res: |
265 return |
267 return |
266 filename = fname |
268 filename = str(fpath) |
267 |
269 |
268 res = self.__writeJsonGraphicsFile(filename) |
270 res = self.__writeJsonGraphicsFile(filename) |
269 |
271 |
270 if res: |
272 if res: |
271 # save the file name only in case of success |
273 # save the file name only in case of success |