Cooperation/ChatWidget.py

changeset 2986
cd4e2cab7eb2
parent 2953
703452a2876f
child 3020
542e97d4ecb3
child 3057
10516539f238
equal deleted inserted replaced
2985:177b1858245f 2986:cd4e2cab7eb2
28 """ 28 """
29 Class implementing the chat dialog. 29 Class implementing the chat dialog.
30 30
31 @signal connected(connected) emitted to signal a change of the connected 31 @signal connected(connected) emitted to signal a change of the connected
32 state (bool) 32 state (bool)
33 @signal editorCommand(hash, filename, message) emitted when an editor command 33 @signal editorCommand(hash, filename, message) emitted when an editor
34 has been received (string, string, string) 34 command has been received (string, string, string)
35 @signal shareEditor(share) emitted to signal a share is requested (bool) 35 @signal shareEditor(share) emitted to signal a share is requested (bool)
36 @signal startEdit() emitted to start a shared edit session 36 @signal startEdit() emitted to start a shared edit session
37 @signal sendEdit() emitted to send a shared edit session 37 @signal sendEdit() emitted to send a shared edit session
38 @signal cancelEdit() emitted to cancel a shared edit session 38 @signal cancelEdit() emitted to cancel a shared edit session
39 """ 39 """
146 if text == "": 146 if text == "":
147 return 147 return
148 148
149 if text.startswith("/"): 149 if text.startswith("/"):
150 self.__showErrorMessage( 150 self.__showErrorMessage(
151 self.trUtf8("! Unknown command: {0}\n").format(text.split()[0])) 151 self.trUtf8("! Unknown command: {0}\n")
152 .format(text.split()[0]))
152 else: 153 else:
153 self.__client.sendMessage(text) 154 self.__client.sendMessage(text)
154 self.appendMessage(self.__myNickName, text) 155 self.appendMessage(self.__myNickName, text)
155 156
156 self.messageEdit.clear() 157 self.messageEdit.clear()
165 return 166 return
166 167
167 color = self.chatEdit.textColor() 168 color = self.chatEdit.textColor()
168 self.chatEdit.setTextColor(Qt.gray) 169 self.chatEdit.setTextColor(Qt.gray)
169 self.chatEdit.append( 170 self.chatEdit.append(
170 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") 171 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
172 ":")
171 self.chatEdit.append(self.trUtf8("* {0} has joined.\n").format(nick)) 173 self.chatEdit.append(self.trUtf8("* {0} has joined.\n").format(nick))
172 self.chatEdit.setTextColor(color) 174 self.chatEdit.setTextColor(color)
173 175
174 QListWidgetItem( 176 QListWidgetItem(
175 UI.PixmapCache.getIcon( 177 UI.PixmapCache.getIcon(
178 180
179 if not self.__connected: 181 if not self.__connected:
180 self.__setConnected(True) 182 self.__setConnected(True)
181 183
182 if not self.isVisible(): 184 if not self.isVisible():
183 self.__ui.showNotification(UI.PixmapCache.getPixmap("cooperation48.png"), 185 self.__ui.showNotification(
184 self.trUtf8("New User"), self.trUtf8("{0} has joined.").format(nick)) 186 UI.PixmapCache.getPixmap("cooperation48.png"),
185 187 self.trUtf8("New User"), self.trUtf8("{0} has joined.")
188 .format(nick))
186 def __participantLeft(self, nick): 189 def __participantLeft(self, nick):
187 """ 190 """
188 Private slot handling a participant leaving the session. 191 Private slot handling a participant leaving the session.
189 192
190 @param nick nick name of the participant (string) 193 @param nick nick name of the participant (string)
198 del item 201 del item
199 202
200 color = self.chatEdit.textColor() 203 color = self.chatEdit.textColor()
201 self.chatEdit.setTextColor(Qt.gray) 204 self.chatEdit.setTextColor(Qt.gray)
202 self.chatEdit.append( 205 self.chatEdit.append(
203 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") 206 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
207 ":")
204 self.chatEdit.append(self.trUtf8("* {0} has left.\n").format(nick)) 208 self.chatEdit.append(self.trUtf8("* {0} has left.\n").format(nick))
205 self.chatEdit.setTextColor(color) 209 self.chatEdit.setTextColor(color)
206 210
207 if not self.__client.hasConnections(): 211 if not self.__client.hasConnections():
208 self.__setConnected(False) 212 self.__setConnected(False)
209 213
210 if not self.isVisible(): 214 if not self.isVisible():
211 self.__ui.showNotification(UI.PixmapCache.getPixmap("cooperation48.png"), 215 self.__ui.showNotification(
212 self.trUtf8("User Left"), self.trUtf8("{0} has left.").format(nick)) 216 UI.PixmapCache.getPixmap("cooperation48.png"),
217 self.trUtf8("User Left"), self.trUtf8("{0} has left.")
218 .format(nick))
213 219
214 def appendMessage(self, from_, message): 220 def appendMessage(self, from_, message):
215 """ 221 """
216 Public slot to append a message to the display. 222 Public slot to append a message to the display.
217 223
227 self.chatEdit.append(message + "\n") 233 self.chatEdit.append(message + "\n")
228 bar = self.chatEdit.verticalScrollBar() 234 bar = self.chatEdit.verticalScrollBar()
229 bar.setValue(bar.maximum()) 235 bar.setValue(bar.maximum())
230 236
231 if not self.isVisible(): 237 if not self.isVisible():
232 self.__ui.showNotification(UI.PixmapCache.getPixmap("cooperation48.png"), 238 self.__ui.showNotification(
239 UI.PixmapCache.getPixmap("cooperation48.png"),
233 self.trUtf8("Message from <{0}>").format(from_), message) 240 self.trUtf8("Message from <{0}>").format(from_), message)
234 241
235 @pyqtSlot(str) 242 @pyqtSlot(str)
236 def on_hostEdit_editTextChanged(self, host): 243 def on_hostEdit_editTextChanged(self, host):
237 """ 244 """
293 """ 300 """
294 if self.__client.isListening(): 301 if self.__client.isListening():
295 self.__client.close() 302 self.__client.close()
296 self.serverButton.setText(self.trUtf8("Start Server")) 303 self.serverButton.setText(self.trUtf8("Start Server"))
297 self.serverPortSpin.setEnabled(True) 304 self.serverPortSpin.setEnabled(True)
298 if self.serverPortSpin.value() != Preferences.getCooperation("ServerPort"): 305 if (self.serverPortSpin.value() !=
299 self.serverPortSpin.setValue(Preferences.getCooperation("ServerPort")) 306 Preferences.getCooperation("ServerPort")):
307 self.serverPortSpin.setValue(
308 Preferences.getCooperation("ServerPort"))
300 self.serverLed.setColor(QColor(Qt.red)) 309 self.serverLed.setColor(QColor(Qt.red))
301 else: 310 else:
302 res, port = self.__client.startListening(self.serverPortSpin.value()) 311 res, port = self.__client.startListening(
312 self.serverPortSpin.value())
303 if res: 313 if res:
304 self.serverButton.setText(self.trUtf8("Stop Server")) 314 self.serverButton.setText(self.trUtf8("Stop Server"))
305 self.serverPortSpin.setValue(port) 315 self.serverPortSpin.setValue(port)
306 self.serverPortSpin.setEnabled(False) 316 self.serverPortSpin.setEnabled(False)
307 self.serverLed.setColor(QColor(Qt.green)) 317 self.serverLed.setColor(QColor(Qt.green))
346 @param message error message to show (string) 356 @param message error message to show (string)
347 """ 357 """
348 color = self.chatEdit.textColor() 358 color = self.chatEdit.textColor()
349 self.chatEdit.setTextColor(Qt.red) 359 self.chatEdit.setTextColor(Qt.red)
350 self.chatEdit.append( 360 self.chatEdit.append(
351 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") 361 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
362 ":")
352 self.chatEdit.append(message + "\n") 363 self.chatEdit.append(message + "\n")
353 self.chatEdit.setTextColor(color) 364 self.chatEdit.setTextColor(color)
354 365
355 def __initialConnectionRefused(self): 366 def __initialConnectionRefused(self):
356 """ 367 """
361 def preferencesChanged(self): 372 def preferencesChanged(self):
362 """ 373 """
363 Public slot to handle a change of preferences. 374 Public slot to handle a change of preferences.
364 """ 375 """
365 if not self.__client.isListening(): 376 if not self.__client.isListening():
366 self.serverPortSpin.setValue(Preferences.getCooperation("ServerPort")) 377 self.serverPortSpin.setValue(
378 Preferences.getCooperation("ServerPort"))
367 if Preferences.getCooperation("AutoStartServer"): 379 if Preferences.getCooperation("AutoStartServer"):
368 self.on_serverButton_clicked() 380 self.on_serverButton_clicked()
369 381
370 def getClient(self): 382 def getClient(self):
371 """ 383 """
467 self.shareButton.setIcon( 479 self.shareButton.setIcon(
468 UI.PixmapCache.getIcon("sharedEditDisconnected.png")) 480 UI.PixmapCache.getIcon("sharedEditDisconnected.png"))
469 self.startEditButton.setChecked(editing) 481 self.startEditButton.setChecked(editing)
470 482
471 self.shareButton.setEnabled(shareable and not editing) 483 self.shareButton.setEnabled(shareable and not editing)
472 self.startEditButton.setEnabled(sharing and not editing and not remoteEditing) 484 self.startEditButton.setEnabled(
485 sharing and not editing and not remoteEditing)
473 self.sendEditButton.setEnabled(editing) 486 self.sendEditButton.setEnabled(editing)
474 self.cancelEditButton.setEnabled(editing) 487 self.cancelEditButton.setEnabled(editing)
475 488
476 def __initChatMenu(self): 489 def __initChatMenu(self):
477 """ 490 """
566 f.write(txt) 579 f.write(txt)
567 f.close() 580 f.close()
568 except IOError as err: 581 except IOError as err:
569 E5MessageBox.critical(self, 582 E5MessageBox.critical(self,
570 self.trUtf8("Error saving Chat"), 583 self.trUtf8("Error saving Chat"),
571 self.trUtf8("""<p>The chat contents could not be written""" 584 self.trUtf8("""<p>The chat contents could not be"""
572 """ to <b>{0}</b></p><p>Reason: {1}</p>""")\ 585 """ written to <b>{0}</b></p>"""
573 .format(fname, str(err))) 586 """<p>Reason: {1}</p>""") .format(
587 fname, str(err)))
574 588
575 def __copyChat(self): 589 def __copyChat(self):
576 """ 590 """
577 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.
578 """ 592 """
636 self.__client.kickUser(itm.text()) 650 self.__client.kickUser(itm.text())
637 651
638 color = self.chatEdit.textColor() 652 color = self.chatEdit.textColor()
639 self.chatEdit.setTextColor(Qt.darkYellow) 653 self.chatEdit.setTextColor(Qt.darkYellow)
640 self.chatEdit.append( 654 self.chatEdit.append(
641 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") 655 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
656 ":")
642 self.chatEdit.append(self.trUtf8("* {0} has been kicked.\n").format( 657 self.chatEdit.append(self.trUtf8("* {0} has been kicked.\n").format(
643 itm.text().split("@")[0])) 658 itm.text().split("@")[0]))
644 self.chatEdit.setTextColor(color) 659 self.chatEdit.setTextColor(color)
645 660
646 def __banUser(self): 661 def __banUser(self):
651 self.__client.banUser(itm.text()) 666 self.__client.banUser(itm.text())
652 667
653 color = self.chatEdit.textColor() 668 color = self.chatEdit.textColor()
654 self.chatEdit.setTextColor(Qt.darkYellow) 669 self.chatEdit.setTextColor(Qt.darkYellow)
655 self.chatEdit.append( 670 self.chatEdit.append(
656 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") 671 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
672 ":")
657 self.chatEdit.append(self.trUtf8("* {0} has been banned.\n").format( 673 self.chatEdit.append(self.trUtf8("* {0} has been banned.\n").format(
658 itm.text().split("@")[0])) 674 itm.text().split("@")[0]))
659 self.chatEdit.setTextColor(color) 675 self.chatEdit.setTextColor(color)
660 676
661 def __banKickUser(self): 677 def __banKickUser(self):
666 self.__client.banKickUser(itm.text()) 682 self.__client.banKickUser(itm.text())
667 683
668 color = self.chatEdit.textColor() 684 color = self.chatEdit.textColor()
669 self.chatEdit.setTextColor(Qt.darkYellow) 685 self.chatEdit.setTextColor(Qt.darkYellow)
670 self.chatEdit.append( 686 self.chatEdit.append(
671 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) + ":") 687 QDateTime.currentDateTime().toString(Qt.SystemLocaleLongDate) +
672 self.chatEdit.append(self.trUtf8("* {0} has been banned and kicked.\n").format( 688 ":")
673 itm.text().split("@")[0])) 689 self.chatEdit.append(
690 self.trUtf8("* {0} has been banned and kicked.\n")
691 .format( itm.text().split("@")[0]))
674 self.chatEdit.setTextColor(color) 692 self.chatEdit.setTextColor(color)
675 693
676 def shutdown(self): 694 def shutdown(self):
677 """ 695 """
678 Public method to shut down the cooperation system. 696 Public method to shut down the cooperation system.

eric ide

mercurial