6 """ |
6 """ |
7 Module implementing the UI Previewer main window. |
7 Module implementing the UI Previewer main window. |
8 """ |
8 """ |
9 |
9 |
10 import contextlib |
10 import contextlib |
11 |
11 import pathlib |
12 from PyQt6.QtCore import QDir, QFileInfo, QEvent, QSize, Qt |
12 |
|
13 from PyQt6.QtCore import QDir, QEvent, QSize, Qt |
13 from PyQt6.QtGui import QAction, QKeySequence, QImageWriter, QPainter |
14 from PyQt6.QtGui import QAction, QKeySequence, QImageWriter, QPainter |
14 from PyQt6.QtWidgets import ( |
15 from PyQt6.QtWidgets import ( |
15 QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, QWhatsThis, QDialog, |
16 QSizePolicy, QSpacerItem, QWidget, QHBoxLayout, QWhatsThis, QDialog, |
16 QScrollArea, QApplication, QStyleFactory, QFrame, QMainWindow, |
17 QScrollArea, QApplication, QStyleFactory, QFrame, QMainWindow, |
17 QComboBox, QVBoxLayout, QLabel |
18 QComboBox, QVBoxLayout, QLabel |
467 self.tr("Save Image"), |
468 self.tr("Save Image"), |
468 "", |
469 "", |
469 fileFilter) |
470 fileFilter) |
470 if not fname: |
471 if not fname: |
471 return |
472 return |
472 |
473 |
473 ext = QFileInfo(fname).suffix().upper() |
474 fpath = pathlib.Path(fname) |
|
475 ext = fpath.suffix.upper().replace(".", "") |
474 if not ext: |
476 if not ext: |
475 ext = defaultExt |
477 ext = defaultExt |
476 fname.append(".{0}".format(defaultExt.lower())) |
478 fpath = fpath.with_suffix(".{0}".format(defaultExt.lower())) |
477 |
479 |
478 pix = self.mainWidget.grab() |
480 pix = self.mainWidget.grab() |
479 self.__updateChildren(self.lastStyle) |
481 self.__updateChildren(self.lastStyle) |
480 if not pix.save(fname, str(ext)): |
482 if not pix.save(str(fpath), str(ext)): |
481 EricMessageBox.critical( |
483 EricMessageBox.critical( |
482 self, |
484 self, |
483 self.tr("Save Image"), |
485 self.tr("Save Image"), |
484 self.tr( |
486 self.tr( |
485 """<p>The file <b>{0}</b> could not be saved.</p>""") |
487 """<p>The file <b>{0}</b> could not be saved.</p>""") |
486 .format(fname)) |
488 .format(str(fpath))) |
487 |
489 |
488 def __copyImageToClipboard(self): |
490 def __copyImageToClipboard(self): |
489 """ |
491 """ |
490 Private slot to handle the Copy Image menu action. |
492 Private slot to handle the Copy Image menu action. |
491 """ |
493 """ |