Network/IRC/IrcNetworkWidget.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2791
a9577f248f04
parent 2960
9453efa25fd5
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
25 25
26 class IrcNetworkWidget(QWidget, Ui_IrcNetworkWidget): 26 class IrcNetworkWidget(QWidget, Ui_IrcNetworkWidget):
27 """ 27 """
28 Class implementing the network part of the IRC widget. 28 Class implementing the network part of the IRC widget.
29 29
30 @signal connectNetwork(str,bool) emitted to connect or disconnect from a network 30 @signal connectNetwork(str,bool) emitted to connect or disconnect from
31 a network
31 @signal editNetwork(str) emitted to edit a network configuration 32 @signal editNetwork(str) emitted to edit a network configuration
32 @signal joinChannel(str) emitted to join a channel 33 @signal joinChannel(str) emitted to join a channel
33 @signal nickChanged(str) emitted to change the nick name 34 @signal nickChanged(str) emitted to change the nick name
34 @signal sendData(str) emitted to send a message to the channel 35 @signal sendData(str) emitted to send a message to the channel
35 @signal away(bool) emitted to indicate the away status 36 @signal away(bool) emitted to indicate the away status
59 60
60 self.joinButton.setEnabled(False) 61 self.joinButton.setEnabled(False)
61 self.nickCombo.setEnabled(False) 62 self.nickCombo.setEnabled(False)
62 self.awayButton.setEnabled(False) 63 self.awayButton.setEnabled(False)
63 64
64 self.channelCombo.lineEdit().returnPressed.connect(self.on_joinButton_clicked) 65 self.channelCombo.lineEdit().returnPressed.connect(
66 self.on_joinButton_clicked)
65 self.nickCombo.lineEdit().returnPressed.connect( 67 self.nickCombo.lineEdit().returnPressed.connect(
66 self.on_nickCombo_currentIndexChanged) 68 self.on_nickCombo_currentIndexChanged)
67 69
68 self.setConnected(False) 70 self.setConnected(False)
69 71
133 """ 135 """
134 Private slot to toggle the away status. 136 Private slot to toggle the away status.
135 """ 137 """
136 if self.__away: 138 if self.__away:
137 self.sendData.emit("AWAY") 139 self.sendData.emit("AWAY")
138 self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserPresent.png")) 140 self.awayButton.setIcon(
141 UI.PixmapCache.getIcon("ircUserPresent.png"))
139 self.__away = False 142 self.__away = False
140 else: 143 else:
141 networkName = self.networkCombo.currentText() 144 networkName = self.networkCombo.currentText()
142 identityName = self.__manager.getNetwork(networkName).getIdentityName() 145 identityName = self.__manager.getNetwork(networkName)\
143 awayMessage = self.__manager.getIdentity(identityName).getAwayMessage() 146 .getIdentityName()
147 awayMessage = self.__manager.getIdentity(identityName)\
148 .getAwayMessage()
144 self.sendData.emit("AWAY :" + awayMessage) 149 self.sendData.emit("AWAY :" + awayMessage)
145 self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserAway.png")) 150 self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserAway.png"))
146 self.__away = True 151 self.__away = True
147 self.away.emit(self.__away) 152 self.away.emit(self.__away)
148 153
284 289
285 @param connected flag indicating the connection state (boolean) 290 @param connected flag indicating the connection state (boolean)
286 """ 291 """
287 self.__connected = connected 292 self.__connected = connected
288 if self.__connected: 293 if self.__connected:
289 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircDisconnect.png")) 294 self.connectButton.setIcon(
295 UI.PixmapCache.getIcon("ircDisconnect.png"))
290 self.connectButton.setToolTip( 296 self.connectButton.setToolTip(
291 self.trUtf8("Press to disconnect from the network")) 297 self.trUtf8("Press to disconnect from the network"))
292 else: 298 else:
293 self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect.png")) 299 self.connectButton.setIcon(
300 UI.PixmapCache.getIcon("ircConnect.png"))
294 self.connectButton.setToolTip( 301 self.connectButton.setToolTip(
295 self.trUtf8("Press to connect to the selected network")) 302 self.trUtf8("Press to connect to the selected network"))
296 303
297 def isConnected(self): 304 def isConnected(self):
298 """ 305 """
304 311
305 def setRegistered(self, registered): 312 def setRegistered(self, registered):
306 """ 313 """
307 Public slot to set the registered state. 314 Public slot to set the registered state.
308 315
309 @param connected flag indicating the connection state (boolean) 316 @param registered flag indicating the registration state (boolean)
310 """ 317 """
311 self.__registered = registered 318 self.__registered = registered
312 on = bool(self.channelCombo.currentText()) and self.__registered 319 on = bool(self.channelCombo.currentText()) and self.__registered
313 self.joinButton.setEnabled(on) 320 self.joinButton.setEnabled(on)
314 self.nickCombo.setEnabled(registered) 321 self.nickCombo.setEnabled(registered)
315 self.awayButton.setEnabled(registered) 322 self.awayButton.setEnabled(registered)
316 if registered: 323 if registered:
317 self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserPresent.png")) 324 self.awayButton.setIcon(
325 UI.PixmapCache.getIcon("ircUserPresent.png"))
318 self.__away = False 326 self.__away = False
319 327
320 def __clearMessages(self): 328 def __clearMessages(self):
321 """ 329 """
322 Private slot to clear the contents of the messages display. 330 Private slot to clear the contents of the messages display.
323 """ 331 """
324 self.messages.clear() 332 self.messages.clear()
325 333
326 def __copyMessages(self): 334 def __copyMessages(self):
327 """ 335 """
328 Private slot to copy the selection of the messages display to the clipboard. 336 Private slot to copy the selection of the messages display to
337 the clipboard.
329 """ 338 """
330 self.messages.copy() 339 self.messages.copy()
331 340
332 def __copyAllMessages(self): 341 def __copyAllMessages(self):
333 """ 342 """
334 Private slot to copy the contents of the messages display to the clipboard. 343 Private slot to copy the contents of the messages display to
344 the clipboard.
335 """ 345 """
336 txt = self.messages.toPlainText() 346 txt = self.messages.toPlainText()
337 if txt: 347 if txt:
338 cb = QApplication.clipboard() 348 cb = QApplication.clipboard()
339 cb.setText(txt) 349 cb.setText(txt)
340 350
341 def __cutAllMessages(self): 351 def __cutAllMessages(self):
342 """ 352 """
343 Private slot to cut the contents of the messages display to the clipboard. 353 Private slot to cut the contents of the messages display to
354 the clipboard.
344 """ 355 """
345 txt = self.messages.toPlainText() 356 txt = self.messages.toPlainText()
346 if txt: 357 if txt:
347 cb = QApplication.clipboard() 358 cb = QApplication.clipboard()
348 cb.setText(txt) 359 cb.setText(txt)
361 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( 372 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
362 self, 373 self,
363 self.trUtf8("Save Messages"), 374 self.trUtf8("Save Messages"),
364 "", 375 "",
365 self.trUtf8( 376 self.trUtf8(
366 "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)").format( 377 "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)")
367 htmlExtension), 378 .format(htmlExtension),
368 None, 379 None,
369 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) 380 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
370 if fname: 381 if fname:
371 ext = QFileInfo(fname).suffix() 382 ext = QFileInfo(fname).suffix()
372 if not ext: 383 if not ext:
393 f.write(txt) 404 f.write(txt)
394 f.close() 405 f.close()
395 except IOError as err: 406 except IOError as err:
396 E5MessageBox.critical(self, 407 E5MessageBox.critical(self,
397 self.trUtf8("Error saving Messages"), 408 self.trUtf8("Error saving Messages"),
398 self.trUtf8("""<p>The messages contents could not be written""" 409 self.trUtf8(
399 """ to <b>{0}</b></p><p>Reason: {1}</p>""")\ 410 """<p>The messages contents could not be written"""
411 """ to <b>{0}</b></p><p>Reason: {1}</p>""")\
400 .format(fname, str(err))) 412 .format(fname, str(err)))
401 413
402 def __initMessagesMenu(self): 414 def __initMessagesMenu(self):
403 """ 415 """
404 Private slot to initialize the context menu of the messages pane. 416 Private slot to initialize the context menu of the messages pane.
431 self.on_messages_copyAvailable(False) 443 self.on_messages_copyAvailable(False)
432 444
433 @pyqtSlot(bool) 445 @pyqtSlot(bool)
434 def on_messages_copyAvailable(self, yes): 446 def on_messages_copyAvailable(self, yes):
435 """ 447 """
436 Private slot to react to text selection/deselection of the messages edit. 448 Private slot to react to text selection/deselection of the
449 messages edit.
437 450
438 @param yes flag signaling the availability of selected text (boolean) 451 @param yes flag signaling the availability of selected text (boolean)
439 """ 452 """
440 self.__copyMessagesAct.setEnabled(yes) 453 self.__copyMessagesAct.setEnabled(yes)
441 454
442 @pyqtSlot(QPoint) 455 @pyqtSlot(QPoint)
443 def on_messages_customContextMenuRequested(self, pos): 456 def on_messages_customContextMenuRequested(self, pos):
444 """ 457 """
445 Private slot to show the context menu of the messages pane. 458 Private slot to show the context menu of the messages pane.
459
460 @param pos position the menu should be opened at (QPoint)
446 """ 461 """
447 enable = not self.messages.document().isEmpty() 462 enable = not self.messages.document().isEmpty()
448 self.__cutAllMessagesAct.setEnabled(enable) 463 self.__cutAllMessagesAct.setEnabled(enable)
449 self.__copyAllMessagesAct.setEnabled(enable) 464 self.__copyAllMessagesAct.setEnabled(enable)
450 self.__saveMessagesAct.setEnabled(enable) 465 self.__saveMessagesAct.setEnabled(enable)
452 467
453 @pyqtSlot(QUrl) 468 @pyqtSlot(QUrl)
454 def on_messages_anchorClicked(self, url): 469 def on_messages_anchorClicked(self, url):
455 """ 470 """
456 Private slot to open links in the default browser. 471 Private slot to open links in the default browser.
472
473 @param url URL to be opened (QUrl)
457 """ 474 """
458 QDesktopServices.openUrl(url) 475 QDesktopServices.openUrl(url)

eric ide

mercurial