eric7/Network/IRC/IrcNetworkWidget.py

branch
eric7
changeset 9152
8a68afaf1ba2
parent 8881
54e42bc2437a
child 9153
506e35e424d5
equal deleted inserted replaced
9151:8c5296fe3056 9152:8a68afaf1ba2
5 5
6 """ 6 """
7 Module implementing the network part of the IRC widget. 7 Module implementing the network part of the IRC widget.
8 """ 8 """
9 9
10 from PyQt6.QtCore import pyqtSlot, pyqtSignal, QPoint, QFileInfo, QUrl, QThread 10 import pathlib
11
12 from PyQt6.QtCore import pyqtSlot, pyqtSignal, QPoint, QUrl, QThread
11 from PyQt6.QtGui import QDesktopServices 13 from PyQt6.QtGui import QDesktopServices
12 from PyQt6.QtWidgets import QWidget, QApplication, QMenu 14 from PyQt6.QtWidgets import QWidget, QApplication, QMenu
13 15
14 from EricWidgets import EricMessageBox, EricFileDialog 16 from EricWidgets import EricMessageBox, EricFileDialog
15 from EricWidgets.EricApplication import ericApp 17 from EricWidgets.EricApplication import ericApp
430 "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)") 432 "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)")
431 .format(htmlExtension), 433 .format(htmlExtension),
432 None, 434 None,
433 EricFileDialog.DontConfirmOverwrite) 435 EricFileDialog.DontConfirmOverwrite)
434 if fname: 436 if fname:
435 ext = QFileInfo(fname).suffix() 437 fpath = pathlib.Path(fname)
436 if not ext: 438 if not fpath.suffix:
437 ex = selectedFilter.split("(*")[1].split(")")[0] 439 ex = selectedFilter.split("(*")[1].split(")")[0]
438 if ex: 440 if ex:
439 fname += ex 441 fpath = fpath.with_suffix(ex)
440 ext = QFileInfo(fname).suffix() 442 if fpath.exists():
441 if QFileInfo(fname).exists():
442 res = EricMessageBox.yesNo( 443 res = EricMessageBox.yesNo(
443 self, 444 self,
444 self.tr("Save Messages"), 445 self.tr("Save Messages"),
445 self.tr("<p>The file <b>{0}</b> already exists." 446 self.tr("<p>The file <b>{0}</b> already exists."
446 " Overwrite it?</p>").format(fname), 447 " Overwrite it?</p>").format(str(fpath)),
447 icon=EricMessageBox.Warning) 448 icon=EricMessageBox.Warning)
448 if not res: 449 if not res:
449 return 450 return
450 fname = Utilities.toNativeSeparators(fname)
451 451
452 try: 452 try:
453 txt = ( 453 txt = (
454 self.messages.toHtml() 454 self.messages.toHtml()
455 if ext.lower() in ["htm", "html"] else 455 if fpath.suffix.lower() in [".htm", ".html"] else
456 self.messages.toPlainText() 456 self.messages.toPlainText()
457 ) 457 )
458 with open(fname, "w", encoding="utf-8") as f: 458 with fpath.open("w", encoding="utf-8") as f:
459 f.write(txt) 459 f.write(txt)
460 except OSError as err: 460 except OSError as err:
461 EricMessageBox.critical( 461 EricMessageBox.critical(
462 self, 462 self,
463 self.tr("Error saving Messages"), 463 self.tr("Error saving Messages"),
464 self.tr( 464 self.tr(
465 """<p>The messages contents could not be written""" 465 """<p>The messages contents could not be written"""
466 """ to <b>{0}</b></p><p>Reason: {1}</p>""") 466 """ to <b>{0}</b></p><p>Reason: {1}</p>""")
467 .format(fname, str(err))) 467 .format(str(fpath), str(err)))
468 468
469 def __initMessagesMenu(self): 469 def __initMessagesMenu(self):
470 """ 470 """
471 Private slot to initialize the context menu of the messages pane. 471 Private slot to initialize the context menu of the messages pane.
472 """ 472 """

eric ide

mercurial