eric7/Cooperation/ChatWidget.py

branch
eric7
changeset 8356
68ec9c3d4de5
parent 8350
74a3b2a6a944
child 8358
144a6b854f70
equal deleted inserted replaced
8355:8a7677a63c8d 8356:68ec9c3d4de5
9 9
10 from PyQt6.QtCore import Qt, pyqtSlot, pyqtSignal, QDateTime, QPoint, QFileInfo 10 from PyQt6.QtCore import Qt, pyqtSlot, pyqtSignal, QDateTime, QPoint, QFileInfo
11 from PyQt6.QtGui import QColor 11 from PyQt6.QtGui import QColor
12 from PyQt6.QtWidgets import QWidget, QListWidgetItem, QMenu, QApplication 12 from PyQt6.QtWidgets import QWidget, QListWidgetItem, QMenu, QApplication
13 13
14 from E5Gui.E5Application import e5App 14 from E5Gui.EricApplication import ericApp
15 from E5Gui import E5MessageBox, E5FileDialog 15 from E5Gui import EricMessageBox, EricFileDialog
16 16
17 from Globals import recentNameHosts 17 from Globals import recentNameHosts
18 18
19 from .CooperationClient import CooperationClient 19 from .CooperationClient import CooperationClient
20 20
346 self.hostEdit.setEnabled(not connected) 346 self.hostEdit.setEnabled(not connected)
347 self.serverButton.setEnabled(not connected) 347 self.serverButton.setEnabled(not connected)
348 self.sharingGroup.setEnabled(connected) 348 self.sharingGroup.setEnabled(connected)
349 349
350 if connected: 350 if connected:
351 vm = e5App().getObject("ViewManager") 351 vm = ericApp().getObject("ViewManager")
352 aw = vm.activeWindow() 352 aw = vm.activeWindow()
353 if aw: 353 if aw:
354 self.checkEditorActions(aw) 354 self.checkEditorActions(aw)
355 355
356 def __showErrorMessage(self, message): 356 def __showErrorMessage(self, message):
402 self.editorCommand.emit(hashStr, fileName, message) 402 self.editorCommand.emit(hashStr, fileName, message)
403 403
404 from QScintilla.Editor import Editor 404 from QScintilla.Editor import Editor
405 if (message.startswith(Editor.StartEditToken + Editor.Separator) or 405 if (message.startswith(Editor.StartEditToken + Editor.Separator) or
406 message.startswith(Editor.EndEditToken + Editor.Separator)): 406 message.startswith(Editor.EndEditToken + Editor.Separator)):
407 vm = e5App().getObject("ViewManager") 407 vm = ericApp().getObject("ViewManager")
408 aw = vm.activeWindow() 408 aw = vm.activeWindow()
409 if aw: 409 if aw:
410 self.checkEditorActions(aw) 410 self.checkEditorActions(aw)
411 411
412 @pyqtSlot(bool) 412 @pyqtSlot(bool)
548 """ 548 """
549 Private slot to save the contents of the chat display. 549 Private slot to save the contents of the chat display.
550 """ 550 """
551 txt = self.chatEdit.toPlainText() 551 txt = self.chatEdit.toPlainText()
552 if txt: 552 if txt:
553 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( 553 fname, selectedFilter = EricFileDialog.getSaveFileNameAndFilter(
554 self, 554 self,
555 self.tr("Save Chat"), 555 self.tr("Save Chat"),
556 "", 556 "",
557 self.tr("Text Files (*.txt);;All Files (*)"), 557 self.tr("Text Files (*.txt);;All Files (*)"),
558 None, 558 None,
559 E5FileDialog.DontConfirmOverwrite) 559 EricFileDialog.DontConfirmOverwrite)
560 if fname: 560 if fname:
561 ext = QFileInfo(fname).suffix() 561 ext = QFileInfo(fname).suffix()
562 if not ext: 562 if not ext:
563 ex = selectedFilter.split("(*")[1].split(")")[0] 563 ex = selectedFilter.split("(*")[1].split(")")[0]
564 if ex: 564 if ex:
565 fname += ex 565 fname += ex
566 if QFileInfo(fname).exists(): 566 if QFileInfo(fname).exists():
567 res = E5MessageBox.yesNo( 567 res = EricMessageBox.yesNo(
568 self, 568 self,
569 self.tr("Save Chat"), 569 self.tr("Save Chat"),
570 self.tr("<p>The file <b>{0}</b> already exists." 570 self.tr("<p>The file <b>{0}</b> already exists."
571 " Overwrite it?</p>").format(fname), 571 " Overwrite it?</p>").format(fname),
572 icon=E5MessageBox.Warning) 572 icon=EricMessageBox.Warning)
573 if not res: 573 if not res:
574 return 574 return
575 fname = Utilities.toNativeSeparators(fname) 575 fname = Utilities.toNativeSeparators(fname)
576 576
577 try: 577 try:
578 with open(fname, "w", encoding="utf-8") as f: 578 with open(fname, "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 E5MessageBox.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(

eric ide

mercurial