Cooperation/ChatWidget.py

changeset 945
8cd4d08fa9f6
parent 882
34b86be88bf0
child 1131
7781e396c903
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
22 from .Ui_ChatWidget import Ui_ChatWidget 22 from .Ui_ChatWidget import Ui_ChatWidget
23 23
24 import Preferences 24 import Preferences
25 import Utilities 25 import Utilities
26 import UI.PixmapCache 26 import UI.PixmapCache
27
27 28
28 class ChatWidget(QWidget, Ui_ChatWidget): 29 class ChatWidget(QWidget, Ui_ChatWidget):
29 """ 30 """
30 Class implementing the chat dialog. 31 Class implementing the chat dialog.
31 32
44 shareEditor = pyqtSignal(bool) 45 shareEditor = pyqtSignal(bool)
45 startEdit = pyqtSignal() 46 startEdit = pyqtSignal()
46 sendEdit = pyqtSignal() 47 sendEdit = pyqtSignal()
47 cancelEdit = pyqtSignal() 48 cancelEdit = pyqtSignal()
48 49
49 def __init__(self, port = -1, parent = None): 50 def __init__(self, port=-1, parent=None):
50 """ 51 """
51 Constructor 52 Constructor
52 53
53 @param port port to be used for the cooperation server (integer) 54 @param port port to be used for the cooperation server (integer)
54 @param parent reference to the parent widget (QWidget) 55 @param parent reference to the parent widget (QWidget)
174 self.chatEdit.append(self.trUtf8("* {0} has joined.\n").format(nick)) 175 self.chatEdit.append(self.trUtf8("* {0} has joined.\n").format(nick))
175 self.chatEdit.setTextColor(color) 176 self.chatEdit.setTextColor(color)
176 177
177 QListWidgetItem( 178 QListWidgetItem(
178 UI.PixmapCache.getIcon( 179 UI.PixmapCache.getIcon(
179 "chatUser{0}.png".format(1 + self.usersList.count() % 6)), 180 "chatUser{0}.png".format(1 + self.usersList.count() % 6)),
180 nick, self.usersList) 181 nick, self.usersList)
181 182
182 if not self.__connected: 183 if not self.__connected:
183 self.__setConnected(True) 184 self.__setConnected(True)
184 185
466 Private slot to initialize the chat edit context menu. 467 Private slot to initialize the chat edit context menu.
467 """ 468 """
468 self.__chatMenu = QMenu(self) 469 self.__chatMenu = QMenu(self)
469 self.__cutChatAct = \ 470 self.__cutChatAct = \
470 self.__chatMenu.addAction( 471 self.__chatMenu.addAction(
471 UI.PixmapCache.getIcon("editCut.png"), 472 UI.PixmapCache.getIcon("editCut.png"),
472 self.trUtf8("Cut"), self.__cutChat) 473 self.trUtf8("Cut"), self.__cutChat)
473 self.__copyChatAct = \ 474 self.__copyChatAct = \
474 self.__chatMenu.addAction( 475 self.__chatMenu.addAction(
475 UI.PixmapCache.getIcon("editCopy.png"), 476 UI.PixmapCache.getIcon("editCopy.png"),
476 self.trUtf8("Copy"), self.__copyChat) 477 self.trUtf8("Copy"), self.__copyChat)
477 self.__chatMenu.addSeparator() 478 self.__chatMenu.addSeparator()
478 self.__cutAllChatAct = \ 479 self.__cutAllChatAct = \
479 self.__chatMenu.addAction( 480 self.__chatMenu.addAction(
480 UI.PixmapCache.getIcon("editCut.png"), 481 UI.PixmapCache.getIcon("editCut.png"),
481 self.trUtf8("Cut all"), self.__cutAllChat) 482 self.trUtf8("Cut all"), self.__cutAllChat)
482 self.__copyAllChatAct = \ 483 self.__copyAllChatAct = \
483 self.__chatMenu.addAction( 484 self.__chatMenu.addAction(
484 UI.PixmapCache.getIcon("editCopy.png"), 485 UI.PixmapCache.getIcon("editCopy.png"),
485 self.trUtf8("Copy all"), self.__copyAllChat) 486 self.trUtf8("Copy all"), self.__copyAllChat)
486 self.__chatMenu.addSeparator() 487 self.__chatMenu.addSeparator()
487 self.__clearChatAct = \ 488 self.__clearChatAct = \
488 self.__chatMenu.addAction( 489 self.__chatMenu.addAction(
489 UI.PixmapCache.getIcon("editDelete.png"), 490 UI.PixmapCache.getIcon("editDelete.png"),
490 self.trUtf8("Clear"), self.__clearChat) 491 self.trUtf8("Clear"), self.__clearChat)
491 self.__chatMenu.addSeparator() 492 self.__chatMenu.addSeparator()
492 self.__saveChatAct = \ 493 self.__saveChatAct = \
493 self.__chatMenu.addAction( 494 self.__chatMenu.addAction(
494 UI.PixmapCache.getIcon("fileSave.png"), 495 UI.PixmapCache.getIcon("fileSave.png"),
495 self.trUtf8("Save"), self.__saveChat) 496 self.trUtf8("Save"), self.__saveChat)
496 497
497 @pyqtSlot(bool) 498 @pyqtSlot(bool)
498 def on_chatEdit_copyAvailable(self, yes): 499 def on_chatEdit_copyAvailable(self, yes):
499 """ 500 """
545 if QFileInfo(fname).exists(): 546 if QFileInfo(fname).exists():
546 res = E5MessageBox.yesNo(self, 547 res = E5MessageBox.yesNo(self,
547 self.trUtf8("Save Chat"), 548 self.trUtf8("Save Chat"),
548 self.trUtf8("<p>The file <b>{0}</b> already exists." 549 self.trUtf8("<p>The file <b>{0}</b> already exists."
549 " Overwrite it?</p>").format(fname), 550 " Overwrite it?</p>").format(fname),
550 icon = E5MessageBox.Warning) 551 icon=E5MessageBox.Warning)
551 if not res: 552 if not res:
552 return 553 return
553 fname = Utilities.toNativeSeparators(fname) 554 fname = Utilities.toNativeSeparators(fname)
554 555
555 try: 556 try:
556 f = open(fname, "w", encoding = "utf-8") 557 f = open(fname, "w", encoding="utf-8")
557 f.write(txt) 558 f.write(txt)
558 f.close() 559 f.close()
559 except IOError as err: 560 except IOError as err:
560 E5MessageBox.critical(self, 561 E5MessageBox.critical(self,
561 self.trUtf8("Error saving Chat"), 562 self.trUtf8("Error saving Chat"),
599 Private slot to initialize the users list context menu. 600 Private slot to initialize the users list context menu.
600 """ 601 """
601 self.__usersMenu = QMenu(self) 602 self.__usersMenu = QMenu(self)
602 self.__kickUserAct = \ 603 self.__kickUserAct = \
603 self.__usersMenu.addAction( 604 self.__usersMenu.addAction(
604 UI.PixmapCache.getIcon("chatKickUser.png"), 605 UI.PixmapCache.getIcon("chatKickUser.png"),
605 self.trUtf8("Kick User"), self.__kickUser) 606 self.trUtf8("Kick User"), self.__kickUser)
606 self.__banUserAct = \ 607 self.__banUserAct = \
607 self.__usersMenu.addAction( 608 self.__usersMenu.addAction(
608 UI.PixmapCache.getIcon("chatBanUser.png"), 609 UI.PixmapCache.getIcon("chatBanUser.png"),
609 self.trUtf8("Ban User"), self.__banUser) 610 self.trUtf8("Ban User"), self.__banUser)
610 self.__banKickUserAct = \ 611 self.__banKickUserAct = \
611 self.__usersMenu.addAction( 612 self.__usersMenu.addAction(
612 UI.PixmapCache.getIcon("chatBanKickUser.png"), 613 UI.PixmapCache.getIcon("chatBanKickUser.png"),
613 self.trUtf8("Ban and Kick User"), self.__banKickUser) 614 self.trUtf8("Ban and Kick User"), self.__banKickUser)
614 615
615 @pyqtSlot(QPoint) 616 @pyqtSlot(QPoint)
616 def on_usersList_customContextMenuRequested(self, pos): 617 def on_usersList_customContextMenuRequested(self, pos):
617 """ 618 """

eric ide

mercurial