5 |
5 |
6 """ |
6 """ |
7 Module implementing the chat dialog. |
7 Module implementing the chat dialog. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt6.QtCore import Qt, pyqtSlot, pyqtSignal, QDateTime, QPoint, QFileInfo |
10 import pathlib |
|
11 |
|
12 from PyQt6.QtCore import Qt, pyqtSlot, pyqtSignal, QDateTime, QPoint |
11 from PyQt6.QtGui import QColor |
13 from PyQt6.QtGui import QColor |
12 from PyQt6.QtWidgets import QWidget, QListWidgetItem, QMenu, QApplication |
14 from PyQt6.QtWidgets import QWidget, QListWidgetItem, QMenu, QApplication |
13 |
15 |
14 from EricWidgets.EricApplication import ericApp |
16 from EricWidgets.EricApplication import ericApp |
15 from EricWidgets import EricMessageBox, EricFileDialog |
17 from EricWidgets import EricMessageBox, EricFileDialog |
556 "", |
557 "", |
557 self.tr("Text Files (*.txt);;All Files (*)"), |
558 self.tr("Text Files (*.txt);;All Files (*)"), |
558 None, |
559 None, |
559 EricFileDialog.DontConfirmOverwrite) |
560 EricFileDialog.DontConfirmOverwrite) |
560 if fname: |
561 if fname: |
561 ext = QFileInfo(fname).suffix() |
562 fpath = pathlib.Path(fname) |
562 if not ext: |
563 if not fpath.suffix: |
563 ex = selectedFilter.split("(*")[1].split(")")[0] |
564 ex = selectedFilter.split("(*")[1].split(")")[0] |
564 if ex: |
565 if ex: |
565 fname += ex |
566 fpath = fpath.with_suffix(ex) |
566 if QFileInfo(fname).exists(): |
567 if fpath.exists(): |
567 res = EricMessageBox.yesNo( |
568 res = EricMessageBox.yesNo( |
568 self, |
569 self, |
569 self.tr("Save Chat"), |
570 self.tr("Save Chat"), |
570 self.tr("<p>The file <b>{0}</b> already exists." |
571 self.tr("<p>The file <b>{0}</b> already exists." |
571 " Overwrite it?</p>").format(fname), |
572 " Overwrite it?</p>").format(str(fpath)), |
572 icon=EricMessageBox.Warning) |
573 icon=EricMessageBox.Warning) |
573 if not res: |
574 if not res: |
574 return |
575 return |
575 fname = Utilities.toNativeSeparators(fname) |
|
576 |
576 |
577 try: |
577 try: |
578 with open(fname, "w", encoding="utf-8") as f: |
578 with fpath.open("w", encoding="utf-8") as f: |
579 f.write(txt) |
579 f.write(txt) |
580 except OSError as err: |
580 except OSError as err: |
581 EricMessageBox.critical( |
581 EricMessageBox.critical( |
582 self, |
582 self, |
583 self.tr("Error saving Chat"), |
583 self.tr("Error saving Chat"), |
584 self.tr("""<p>The chat contents could not be""" |
584 self.tr("""<p>The chat contents could not be""" |
585 """ written to <b>{0}</b></p>""" |
585 """ written to <b>{0}</b></p>""" |
586 """<p>Reason: {1}</p>""") .format( |
586 """<p>Reason: {1}</p>""") .format( |
587 fname, str(err))) |
587 str(fpath), str(err))) |
588 |
588 |
589 def __copyChat(self): |
589 def __copyChat(self): |
590 """ |
590 """ |
591 Private slot to copy the contents of the chat display to the clipboard. |
591 Private slot to copy the contents of the chat display to the clipboard. |
592 """ |
592 """ |