5 |
5 |
6 """ |
6 """ |
7 Module implementing a subclass of EricGraphicsView for our diagrams. |
7 Module implementing a subclass of EricGraphicsView for our diagrams. |
8 """ |
8 """ |
9 |
9 |
|
10 import pathlib |
|
11 |
10 from PyQt6.QtCore import ( |
12 from PyQt6.QtCore import ( |
11 pyqtSignal, Qt, QSignalMapper, QFileInfo, QEvent, QRectF, QMarginsF |
13 pyqtSignal, Qt, QSignalMapper, QEvent, QRectF, QMarginsF |
12 ) |
14 ) |
13 from PyQt6.QtGui import QAction, QPageLayout |
15 from PyQt6.QtGui import QAction, QPageLayout |
14 from PyQt6.QtWidgets import QGraphicsView, QToolBar, QDialog |
16 from PyQt6.QtWidgets import QGraphicsView, QToolBar, QDialog |
15 from PyQt6.QtPrintSupport import QPrinter, QPrintDialog |
17 from PyQt6.QtPrintSupport import QPrinter, QPrintDialog |
16 |
18 |
365 self.tr("Portable Network Graphics (*.png);;" |
367 self.tr("Portable Network Graphics (*.png);;" |
366 "Scalable Vector Graphics (*.svg)"), |
368 "Scalable Vector Graphics (*.svg)"), |
367 "", |
369 "", |
368 EricFileDialog.DontConfirmOverwrite) |
370 EricFileDialog.DontConfirmOverwrite) |
369 if fname: |
371 if fname: |
370 ext = QFileInfo(fname).suffix() |
372 fpath = pathlib.Path(fname) |
371 if not ext: |
373 if not fpath.suffix: |
372 ex = selectedFilter.split("(*")[1].split(")")[0] |
374 ex = selectedFilter.split("(*")[1].split(")")[0] |
373 if ex: |
375 if ex: |
374 fname += ex |
376 fpath = fpath.with_suffix(ex) |
375 if QFileInfo(fname).exists(): |
377 if fpath.exists(): |
376 res = EricMessageBox.yesNo( |
378 res = EricMessageBox.yesNo( |
377 self, |
379 self, |
378 self.tr("Save Diagram"), |
380 self.tr("Save Diagram"), |
379 self.tr("<p>The file <b>{0}</b> already exists." |
381 self.tr("<p>The file <b>{0}</b> already exists." |
380 " Overwrite it?</p>").format(fname), |
382 " Overwrite it?</p>").format(str(fpath)), |
381 icon=EricMessageBox.Warning) |
383 icon=EricMessageBox.Warning) |
382 if not res: |
384 if not res: |
383 return |
385 return |
384 |
386 |
385 success = super().saveImage( |
387 success = super().saveImage( |
386 fname, QFileInfo(fname).suffix().upper()) |
388 str(fpath), fpath.suffix.upper()) |
387 if not success: |
389 if not success: |
388 EricMessageBox.critical( |
390 EricMessageBox.critical( |
389 self, |
391 self, |
390 self.tr("Save Diagram"), |
392 self.tr("Save Diagram"), |
391 self.tr( |
393 self.tr( |
392 """<p>The file <b>{0}</b> could not be saved.</p>""") |
394 """<p>The file <b>{0}</b> could not be saved.</p>""") |
393 .format(fname)) |
395 .format(str(fpath))) |
394 |
396 |
395 def __relayout(self): |
397 def __relayout(self): |
396 """ |
398 """ |
397 Private slot to handle the re-layout context menu entry. |
399 Private slot to handle the re-layout context menu entry. |
398 """ |
400 """ |