src/eric7/Network/IRC/IrcNetworkWidget.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
--- a/src/eric7/Network/IRC/IrcNetworkWidget.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/Network/IRC/IrcNetworkWidget.py	Wed Jul 13 14:55:47 2022 +0200
@@ -28,7 +28,7 @@
 class IrcNetworkWidget(QWidget, Ui_IrcNetworkWidget):
     """
     Class implementing the network part of the IRC widget.
-    
+
     @signal connectNetwork(str,bool,bool) emitted to connect or disconnect from
         a network
     @signal editNetwork(str) emitted to edit a network configuration
@@ -38,6 +38,7 @@
     @signal away(bool) emitted to indicate the away status
     @signal autoConnected() emitted after an automatic connection was initiated
     """
+
     connectNetwork = pyqtSignal(str, bool, bool)
     editNetwork = pyqtSignal(str)
     joinChannel = pyqtSignal(str)
@@ -45,52 +46,52 @@
     sendData = pyqtSignal(str)
     away = pyqtSignal(bool)
     autoConnected = pyqtSignal()
-    
+
     def __init__(self, parent=None):
         """
         Constructor
-        
+
         @param parent reference to the parent widget (QWidget)
         """
         super().__init__(parent)
         self.setupUi(self)
-        
+
         self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect"))
         self.editButton.setIcon(UI.PixmapCache.getIcon("ircConfigure"))
         self.joinButton.setIcon(UI.PixmapCache.getIcon("ircJoinChannel"))
         self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserPresent"))
-        
+
         self.joinButton.setEnabled(False)
         self.nickCombo.setEnabled(False)
         self.awayButton.setEnabled(False)
-        
-        self.channelCombo.lineEdit().returnPressed.connect(
-            self.on_joinButton_clicked)
+
+        self.channelCombo.lineEdit().returnPressed.connect(self.on_joinButton_clicked)
         self.nickCombo.lineEdit().returnPressed.connect(
-            self.on_nickCombo_currentIndexChanged)
-        
+            self.on_nickCombo_currentIndexChanged
+        )
+
         self.setConnected(False)
-        
+
         self.__initMessagesMenu()
-        
+
         self.__manager = None
         self.__connected = False
         self.__registered = False
         self.__away = False
-    
+
     def initialize(self, manager):
         """
         Public method to initialize the widget.
-        
+
         @param manager reference to the network manager (IrcNetworkManager)
         """
         self.__manager = manager
-        
+
         self.networkCombo.addItems(self.__manager.getNetworkNames())
-        
+
         self.__manager.networksChanged.connect(self.__refreshNetworks)
         self.__manager.identitiesChanged.connect(self.__refreshNetworks)
-    
+
     def autoConnect(self):
         """
         Public method to perform the IRC auto connection.
@@ -101,7 +102,7 @@
         userInterface.onlineStateChanged.connect(self.__onlineStateChanged)
         if online:
             self.__autoConnect()
-    
+
     def __autoConnect(self):
         """
         Private method to perform the IRC auto connection.
@@ -113,12 +114,12 @@
                 self.on_connectButton_clicked()
                 self.autoConnected.emit()
                 break
-    
+
     @pyqtSlot(bool)
     def __onlineStateChanged(self, online):
         """
         Private slot handling online state changes.
-        
+
         @param online online state
         @type bool
         """
@@ -131,7 +132,7 @@
         else:
             network = self.networkCombo.currentText()
             self.connectNetwork.emit(network, online, True)
-    
+
     @pyqtSlot()
     def __refreshNetworks(self):
         """
@@ -152,7 +153,7 @@
         self.nickCombo.setEditText(currentNick)
         self.nickCombo.blockSignals(blocked)
         self.channelCombo.setEditText(currentChannel)
-    
+
     @pyqtSlot()
     def on_connectButton_clicked(self):
         """
@@ -160,7 +161,7 @@
         """
         network = self.networkCombo.currentText()
         self.connectNetwork.emit(network, not self.__connected, False)
-    
+
     @pyqtSlot()
     def on_awayButton_clicked(self):
         """
@@ -170,21 +171,19 @@
             self.handleAwayCommand("")
         else:
             networkName = self.networkCombo.currentText()
-            identityName = (
-                self.__manager.getNetwork(networkName).getIdentityName()
-            )
+            identityName = self.__manager.getNetwork(networkName).getIdentityName()
             identity = self.__manager.getIdentity(identityName)
             if identity:
                 awayMessage = identity.getAwayMessage()
             else:
                 awayMessage = ""
             self.handleAwayCommand(awayMessage)
-    
+
     @pyqtSlot(str)
     def handleAwayCommand(self, awayMessage):
         """
         Public slot to process an away command.
-        
+
         @param awayMessage message to be set for being away
         @type str
         """
@@ -198,11 +197,10 @@
         elif not awayMessage and self.__away:
             # cancel being away
             self.sendData.emit("AWAY")
-            self.awayButton.setIcon(
-                UI.PixmapCache.getIcon("ircUserPresent"))
+            self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserPresent"))
             self.__away = False
             self.away.emit(self.__away)
-    
+
     @pyqtSlot()
     def on_editButton_clicked(self):
         """
@@ -210,17 +208,17 @@
         """
         network = self.networkCombo.currentText()
         self.editNetwork.emit(network)
-    
+
     @pyqtSlot(str)
     def on_channelCombo_editTextChanged(self, txt):
         """
         Private slot to react upon changes of the channel.
-        
+
         @param txt current text of the channel combo (string)
         """
         on = bool(txt) and self.__registered
         self.joinButton.setEnabled(on)
-    
+
     @pyqtSlot()
     def on_joinButton_clicked(self):
         """
@@ -228,12 +226,12 @@
         """
         channel = self.channelCombo.currentText()
         self.joinChannel.emit(channel)
-    
+
     @pyqtSlot(int)
     def on_networkCombo_currentIndexChanged(self, index):
         """
         Private slot to handle selections of a network.
-        
+
         @param index index of the selected entry
         @type int
         """
@@ -245,70 +243,67 @@
             channels = network.getChannelNames()
             self.channelCombo.addItems(channels)
             self.channelCombo.setEnabled(True)
-            identity = self.__manager.getIdentity(
-                network.getIdentityName())
+            identity = self.__manager.getIdentity(network.getIdentityName())
             if identity:
                 self.nickCombo.addItems(identity.getNickNames())
         else:
             self.channelCombo.setEnabled(False)
-    
+
     def getNetworkChannels(self):
         """
         Public method to get the list of channels associated with the
         selected network.
-        
+
         @return associated channels (list of IrcChannel)
         """
         networkName = self.networkCombo.currentText()
         network = self.__manager.getNetwork(networkName)
         return network.getChannels()
-    
+
     @pyqtSlot(int)
     @pyqtSlot()
     def on_nickCombo_currentIndexChanged(self, nick=0):
         """
         Private slot to use another nick name.
-        
+
         @param nick index of the selected nick name (unused)
         """
         if self.__connected:
             self.nickChanged.emit(self.nickCombo.currentText())
-    
+
     def getNickname(self):
         """
         Public method to get the currently selected nick name.
-        
+
         @return selected nick name (string)
         """
         return self.nickCombo.currentText()
-    
+
     def setNickName(self, nick):
         """
         Public slot to set the nick name in use.
-        
+
         @param nick nick name in use (string)
         """
         self.nickCombo.blockSignals(True)
         self.nickCombo.setEditText(nick)
         self.nickCombo.blockSignals(False)
-    
+
     def addMessage(self, msg):
         """
         Public method to add a message.
-        
+
         @param msg message to be added (string)
         """
         s = '<font color="{0}">{1} {2}</font>'.format(
-            Preferences.getIrc("NetworkMessageColour"),
-            ircTimestamp(),
-            msg
+            Preferences.getIrc("NetworkMessageColour"), ircTimestamp(), msg
         )
         self.messages.append(s)
-    
+
     def addServerMessage(self, msgType, msg, filterMsg=True):
         """
         Public method to add a server message.
-        
+
         @param msgType txpe of the message (string)
         @param msg message to be added (string)
         @param filterMsg flag indicating to filter the message (boolean)
@@ -316,58 +311,52 @@
         if filterMsg:
             msg = ircFilter(msg)
         s = '<font color="{0}">{1} <b>[</b>{2}<b>]</b> {3}</font>'.format(
-            Preferences.getIrc("ServerMessageColour"),
-            ircTimestamp(),
-            msgType,
-            msg
+            Preferences.getIrc("ServerMessageColour"), ircTimestamp(), msgType, msg
         )
         self.messages.append(s)
-    
+
     def addErrorMessage(self, msgType, msg):
         """
         Public method to add an error message.
-        
+
         @param msgType txpe of the message (string)
         @param msg message to be added (string)
         """
         s = '<font color="{0}">{1} <b>[</b>{2}<b>]</b> {3}</font>'.format(
-            Preferences.getIrc("ErrorMessageColour"),
-            ircTimestamp(),
-            msgType,
-            msg
+            Preferences.getIrc("ErrorMessageColour"), ircTimestamp(), msgType, msg
         )
         self.messages.append(s)
-    
+
     def setConnected(self, connected):
         """
         Public slot to set the connection state.
-        
+
         @param connected flag indicating the connection state (boolean)
         """
         self.__connected = connected
         if self.__connected:
-            self.connectButton.setIcon(
-                UI.PixmapCache.getIcon("ircDisconnect"))
+            self.connectButton.setIcon(UI.PixmapCache.getIcon("ircDisconnect"))
             self.connectButton.setToolTip(
-                self.tr("Press to disconnect from the network"))
+                self.tr("Press to disconnect from the network")
+            )
         else:
-            self.connectButton.setIcon(
-                UI.PixmapCache.getIcon("ircConnect"))
+            self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect"))
             self.connectButton.setToolTip(
-                self.tr("Press to connect to the selected network"))
-    
+                self.tr("Press to connect to the selected network")
+            )
+
     def isConnected(self):
         """
         Public method to check, if the network is connected.
-        
+
         @return flag indicating a connected network (boolean)
         """
         return self.__connected
-    
+
     def setRegistered(self, registered):
         """
         Public slot to set the registered state.
-        
+
         @param registered flag indicating the registration state (boolean)
         """
         self.__registered = registered
@@ -376,23 +365,22 @@
         self.nickCombo.setEnabled(registered)
         self.awayButton.setEnabled(registered)
         if registered:
-            self.awayButton.setIcon(
-                UI.PixmapCache.getIcon("ircUserPresent"))
+            self.awayButton.setIcon(UI.PixmapCache.getIcon("ircUserPresent"))
             self.__away = False
-    
+
     def __clearMessages(self):
         """
         Private slot to clear the contents of the messages display.
         """
         self.messages.clear()
-    
+
     def __copyMessages(self):
         """
         Private slot to copy the selection of the messages display to
         the clipboard.
         """
         self.messages.copy()
-    
+
     def __copyAllMessages(self):
         """
         Private slot to copy the contents of the messages display to
@@ -402,7 +390,7 @@
         if txt:
             cb = QApplication.clipboard()
             cb.setText(txt)
-    
+
     def __cutAllMessages(self):
         """
         Private slot to cut the contents of the messages display to
@@ -413,7 +401,7 @@
             cb = QApplication.clipboard()
             cb.setText(txt)
         self.messages.clear()
-    
+
     def __saveMessages(self):
         """
         Private slot to save the contents of the messages display.
@@ -428,11 +416,12 @@
                 self,
                 self.tr("Save Messages"),
                 "",
-                self.tr(
-                    "HTML Files (*.{0});;Text Files (*.txt);;All Files (*)")
-                .format(htmlExtension),
+                self.tr("HTML Files (*.{0});;Text Files (*.txt);;All Files (*)").format(
+                    htmlExtension
+                ),
                 None,
-                EricFileDialog.DontConfirmOverwrite)
+                EricFileDialog.DontConfirmOverwrite,
+            )
             if fname:
                 fpath = pathlib.Path(fname)
                 if not fpath.suffix:
@@ -443,17 +432,20 @@
                     res = EricMessageBox.yesNo(
                         self,
                         self.tr("Save Messages"),
-                        self.tr("<p>The file <b>{0}</b> already exists."
-                                " Overwrite it?</p>").format(fpath),
-                        icon=EricMessageBox.Warning)
+                        self.tr(
+                            "<p>The file <b>{0}</b> already exists."
+                            " Overwrite it?</p>"
+                        ).format(fpath),
+                        icon=EricMessageBox.Warning,
+                    )
                     if not res:
                         return
-                
+
                 try:
                     txt = (
                         self.messages.toHtml()
-                        if fpath.suffix.lower() in [".htm", ".html"] else
-                        self.messages.toPlainText()
+                        if fpath.suffix.lower() in [".htm", ".html"]
+                        else self.messages.toPlainText()
                     )
                     with fpath.open("w", encoding="utf-8") as f:
                         f.write(txt)
@@ -463,50 +455,53 @@
                         self.tr("Error saving Messages"),
                         self.tr(
                             """<p>The messages contents could not be written"""
-                            """ to <b>{0}</b></p><p>Reason: {1}</p>""")
-                        .format(fpath, str(err)))
-    
+                            """ to <b>{0}</b></p><p>Reason: {1}</p>"""
+                        ).format(fpath, str(err)),
+                    )
+
     def __initMessagesMenu(self):
         """
         Private slot to initialize the context menu of the messages pane.
         """
         self.__messagesMenu = QMenu(self)
         self.__copyMessagesAct = self.__messagesMenu.addAction(
-            UI.PixmapCache.getIcon("editCopy"),
-            self.tr("Copy"), self.__copyMessages)
+            UI.PixmapCache.getIcon("editCopy"), self.tr("Copy"), self.__copyMessages
+        )
         self.__messagesMenu.addSeparator()
         self.__cutAllMessagesAct = self.__messagesMenu.addAction(
-            UI.PixmapCache.getIcon("editCut"),
-            self.tr("Cut all"), self.__cutAllMessages)
+            UI.PixmapCache.getIcon("editCut"), self.tr("Cut all"), self.__cutAllMessages
+        )
         self.__copyAllMessagesAct = self.__messagesMenu.addAction(
             UI.PixmapCache.getIcon("editCopy"),
-            self.tr("Copy all"), self.__copyAllMessages)
+            self.tr("Copy all"),
+            self.__copyAllMessages,
+        )
         self.__messagesMenu.addSeparator()
         self.__clearMessagesAct = self.__messagesMenu.addAction(
-            UI.PixmapCache.getIcon("editDelete"),
-            self.tr("Clear"), self.__clearMessages)
+            UI.PixmapCache.getIcon("editDelete"), self.tr("Clear"), self.__clearMessages
+        )
         self.__messagesMenu.addSeparator()
         self.__saveMessagesAct = self.__messagesMenu.addAction(
-            UI.PixmapCache.getIcon("fileSave"),
-            self.tr("Save"), self.__saveMessages)
-        
+            UI.PixmapCache.getIcon("fileSave"), self.tr("Save"), self.__saveMessages
+        )
+
         self.on_messages_copyAvailable(False)
-    
+
     @pyqtSlot(bool)
     def on_messages_copyAvailable(self, yes):
         """
         Private slot to react to text selection/deselection of the
         messages edit.
-        
+
         @param yes flag signaling the availability of selected text (boolean)
         """
         self.__copyMessagesAct.setEnabled(yes)
-    
+
     @pyqtSlot(QPoint)
     def on_messages_customContextMenuRequested(self, pos):
         """
         Private slot to show the context menu of the messages pane.
-        
+
         @param pos position the menu should be opened at (QPoint)
         """
         enable = not self.messages.document().isEmpty()
@@ -514,12 +509,12 @@
         self.__copyAllMessagesAct.setEnabled(enable)
         self.__saveMessagesAct.setEnabled(enable)
         self.__messagesMenu.popup(self.messages.mapToGlobal(pos))
-    
+
     @pyqtSlot(QUrl)
     def on_messages_anchorClicked(self, url):
         """
         Private slot to open links in the default browser.
-        
+
         @param url URL to be opened (QUrl)
         """
         QDesktopServices.openUrl(url)

eric ide

mercurial