7 Module implementing the IRC channel widget. |
7 Module implementing the IRC channel widget. |
8 """ |
8 """ |
9 |
9 |
10 from itertools import zip_longest |
10 from itertools import zip_longest |
11 |
11 |
|
12 import pathlib |
12 import re |
13 import re |
13 |
14 |
14 from PyQt6.QtCore import ( |
15 from PyQt6.QtCore import ( |
15 pyqtSlot, pyqtSignal, QDateTime, QPoint, QFileInfo, QTimer, QUrl, |
16 pyqtSlot, pyqtSignal, QDateTime, QPoint, QTimer, QUrl, QCoreApplication |
16 QCoreApplication |
|
17 ) |
17 ) |
18 from PyQt6.QtGui import QIcon, QPainter, QTextCursor, QDesktopServices |
18 from PyQt6.QtGui import QIcon, QPainter, QTextCursor, QDesktopServices |
19 from PyQt6.QtWidgets import ( |
19 from PyQt6.QtWidgets import ( |
20 QWidget, QListWidgetItem, QMenu, QApplication, QInputDialog, QLineEdit |
20 QWidget, QListWidgetItem, QMenu, QApplication, QInputDialog, QLineEdit |
21 ) |
21 ) |
1373 "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)") |
1373 "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)") |
1374 .format(htmlExtension), |
1374 .format(htmlExtension), |
1375 None, |
1375 None, |
1376 EricFileDialog.DontConfirmOverwrite) |
1376 EricFileDialog.DontConfirmOverwrite) |
1377 if fname: |
1377 if fname: |
1378 ext = QFileInfo(fname).suffix() |
1378 fpath = pathlib.Path(fname) |
1379 if not ext: |
1379 if not fpath.suffix: |
1380 ex = selectedFilter.split("(*")[1].split(")")[0] |
1380 ex = selectedFilter.split("(*")[1].split(")")[0] |
1381 if ex: |
1381 if ex: |
1382 fname += ex |
1382 fpath = fpath.with_suffix(ex) |
1383 ext = QFileInfo(fname).suffix() |
1383 if fpath.exists(): |
1384 if QFileInfo(fname).exists(): |
|
1385 res = EricMessageBox.yesNo( |
1384 res = EricMessageBox.yesNo( |
1386 self, |
1385 self, |
1387 self.tr("Save Messages"), |
1386 self.tr("Save Messages"), |
1388 self.tr("<p>The file <b>{0}</b> already exists." |
1387 self.tr("<p>The file <b>{0}</b> already exists." |
1389 " Overwrite it?</p>").format(fname), |
1388 " Overwrite it?</p>").format(str(fpath)), |
1390 icon=EricMessageBox.Warning) |
1389 icon=EricMessageBox.Warning) |
1391 if not res: |
1390 if not res: |
1392 return |
1391 return |
1393 fname = Utilities.toNativeSeparators(fname) |
|
1394 |
1392 |
1395 try: |
1393 try: |
1396 txt = ( |
1394 txt = ( |
1397 self.messages.toHtml() |
1395 self.messages.toHtml() |
1398 if ext.lower() in ["htm", "html"] else |
1396 if fpath.suffix.lower() in [".htm", ".html"] else |
1399 self.messages.toPlainText() |
1397 self.messages.toPlainText() |
1400 ) |
1398 ) |
1401 with open(fname, "w", encoding="utf-8") as f: |
1399 with fpath.open("w", encoding="utf-8") as f: |
1402 f.write(txt) |
1400 f.write(txt) |
1403 except OSError as err: |
1401 except OSError as err: |
1404 EricMessageBox.critical( |
1402 EricMessageBox.critical( |
1405 self, |
1403 self, |
1406 self.tr("Error saving Messages"), |
1404 self.tr("Error saving Messages"), |
1407 self.tr( |
1405 self.tr( |
1408 """<p>The messages contents could not be written""" |
1406 """<p>The messages contents could not be written""" |
1409 """ to <b>{0}</b></p><p>Reason: {1}</p>""") |
1407 """ to <b>{0}</b></p><p>Reason: {1}</p>""") |
1410 .format(fname, str(err))) |
1408 .format(str(fpath), str(err))) |
1411 |
1409 |
1412 def __initMessagesMenu(self): |
1410 def __initMessagesMenu(self): |
1413 """ |
1411 """ |
1414 Private slot to initialize the context menu of the messages pane. |
1412 Private slot to initialize the context menu of the messages pane. |
1415 """ |
1413 """ |