eric6/Preferences/ConfigurationPages/EmailPage.py

changeset 7771
787a6b3f8c9f
parent 7360
9190402e4505
child 7780
41420f82c0ac
--- a/eric6/Preferences/ConfigurationPages/EmailPage.py	Fri Oct 09 17:19:29 2020 +0200
+++ b/eric6/Preferences/ConfigurationPages/EmailPage.py	Sat Oct 10 12:20:51 2020 +0200
@@ -12,12 +12,11 @@
 import socket
 import sys
 
-from PyQt5.QtCore import pyqtSlot, Qt
-from PyQt5.QtGui import QCursor
-from PyQt5.QtWidgets import QApplication
+from PyQt5.QtCore import pyqtSlot
 
 from E5Gui import E5MessageBox
 from E5Gui.E5Application import e5App
+from E5Gui.E5OverrideCursor import E5OverrideCursor
 
 from E5Network.E5GoogleMailHelpers import getInstallCommand, RequiredPackages
 
@@ -200,49 +199,26 @@
         """
         Private slot to test the mail server login data.
         """
-        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
-        QApplication.processEvents()
         try:
-            if self.useSslButton.isChecked():
-                server = smtplib.SMTP_SSL(self.mailServerEdit.text(),
+            with E5OverrideCursor():
+                if self.useSslButton.isChecked():
+                    server = smtplib.SMTP_SSL(self.mailServerEdit.text(),
+                                              self.portSpin.value(),
+                                              timeout=10)
+                else:
+                    server = smtplib.SMTP(self.mailServerEdit.text(),
                                           self.portSpin.value(),
                                           timeout=10)
-            else:
-                server = smtplib.SMTP(self.mailServerEdit.text(),
-                                      self.portSpin.value(),
-                                      timeout=10)
-                if self.useTlsButton.isChecked():
-                    server.starttls()
-            try:
+                    if self.useTlsButton.isChecked():
+                        server.starttls()
                 server.login(self.mailUserEdit.text(),
                              self.mailPasswordEdit.text())
-                QApplication.restoreOverrideCursor()
-                E5MessageBox.information(
-                    self,
-                    self.tr("Login Test"),
-                    self.tr("""The login test succeeded."""))
-            except (smtplib.SMTPException, socket.error) as e:
-                QApplication.restoreOverrideCursor()
-                if isinstance(e, smtplib.SMTPResponseException):
-                    errorStr = e.smtp_error.decode()
-                elif isinstance(e, socket.timeout):
-                    errorStr = str(e)
-                elif isinstance(e, socket.error):
-                    try:
-                        errorStr = e[1]
-                    except TypeError:
-                        errorStr = str(e)
-                else:
-                    errorStr = str(e)
-                E5MessageBox.critical(
-                    self,
-                    self.tr("Login Test"),
-                    self.tr(
-                        """<p>The login test failed.<br>Reason: {0}</p>""")
-                    .format(errorStr))
-            server.quit()
+                server.quit()
+            E5MessageBox.information(
+                self,
+                self.tr("Login Test"),
+                self.tr("""The login test succeeded."""))
         except (smtplib.SMTPException, socket.error) as e:
-            QApplication.restoreOverrideCursor()
             if isinstance(e, smtplib.SMTPResponseException):
                 errorStr = e.smtp_error.decode()
             elif isinstance(e, socket.timeout):
@@ -257,7 +233,8 @@
             E5MessageBox.critical(
                 self,
                 self.tr("Login Test"),
-                self.tr("""<p>The login test failed.<br>Reason: {0}</p>""")
+                self.tr(
+                    """<p>The login test failed.<br>Reason: {0}</p>""")
                 .format(errorStr))
     
     @pyqtSlot()

eric ide

mercurial