MqttMonitor/MqttConnectionProfilesDialog.py

branch
eric7
changeset 92
2fb5c08019fd
parent 86
620022b14cb4
child 95
d830314cca87
--- a/MqttMonitor/MqttConnectionProfilesDialog.py	Sun May 30 17:40:40 2021 +0200
+++ b/MqttMonitor/MqttConnectionProfilesDialog.py	Sun May 30 18:21:40 2021 +0200
@@ -9,14 +9,14 @@
 
 import collections
 
-from PyQt5.QtCore import pyqtSlot, Qt, QUuid
-from PyQt5.QtWidgets import (
+from PyQt6.QtCore import pyqtSlot, Qt, QUuid
+from PyQt6.QtWidgets import (
     QDialog, QDialogButtonBox, QAbstractButton, QListWidgetItem, QInputDialog,
     QLineEdit
 )
 
-from E5Gui import E5MessageBox
-from E5Gui.E5PathPicker import E5PathPickerModes
+from EricWidgets import EricMessageBox
+from EricWidgets.EricPathPicker import EricPathPickerModes
 
 from .Ui_MqttConnectionProfilesDialog import Ui_MqttConnectionProfilesDialog
 
@@ -53,23 +53,23 @@
         self.__profiles.update(profiles)
         self.__profilesChanged = False
         
-        self.plusButton.setIcon(UI.PixmapCache.getIcon("plus.png"))
-        self.copyButton.setIcon(UI.PixmapCache.getIcon("editCopy.png"))
-        self.minusButton.setIcon(UI.PixmapCache.getIcon("minus.png"))
+        self.plusButton.setIcon(UI.PixmapCache.getIcon("plus"))
+        self.copyButton.setIcon(UI.PixmapCache.getIcon("editCopy"))
+        self.minusButton.setIcon(UI.PixmapCache.getIcon("minus"))
         
-        self.tlsCertsFilePicker.setMode(E5PathPickerModes.OpenFileMode)
+        self.tlsCertsFilePicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
         self.tlsCertsFilePicker.setFilters(
             self.tr("Certificate Files (*.crt *.pem);;All Files (*)"))
         self.tlsSelfSignedCertsFilePicker.setMode(
-            E5PathPickerModes.OpenFileMode)
+            EricPathPickerModes.OPEN_FILE_MODE)
         self.tlsSelfSignedCertsFilePicker.setFilters(
             self.tr("Certificate Files (*.crt *.pem);;All Files (*)"))
         self.tlsSelfSignedClientCertFilePicker.setMode(
-            E5PathPickerModes.OpenFileMode)
+            EricPathPickerModes.OPEN_FILE_MODE)
         self.tlsSelfSignedClientCertFilePicker.setFilters(
             self.tr("Certificate Files (*.crt *.pem);;All Files (*)"))
         self.tlsSelfSignedClientKeyFilePicker.setMode(
-            E5PathPickerModes.OpenFileMode)
+            EricPathPickerModes.OPEN_FILE_MODE)
         self.tlsSelfSignedClientKeyFilePicker.setFilters(
             self.tr("Key Files (*.key *.pem);;All Files (*)"))
         
@@ -103,15 +103,20 @@
         @param button reference to the pressed button
         @type QAbstractButton
         """
-        if button == self.profileButtonBox.button(QDialogButtonBox.Apply):
+        if button == self.profileButtonBox.button(
+            QDialogButtonBox.StandardButton.Apply
+        ):
             currentProfile = self.__applyProfile()
             self.__populateProfilesList(currentProfile)
         
-        elif button == self.profileButtonBox.button(QDialogButtonBox.Reset):
+        elif button == self.profileButtonBox.button(
+            QDialogButtonBox.StandardButton.Reset
+        ):
             self.__resetProfile()
         
         elif button == self.profileButtonBox.button(
-                QDialogButtonBox.RestoreDefaults):
+                QDialogButtonBox.StandardButton.RestoreDefaults
+        ):
             self.__populateProfileDefault()
     
     @pyqtSlot(QListWidgetItem, QListWidgetItem)
@@ -133,12 +138,12 @@
             self.__isChangedProfile()
         ):
             # modified profile belongs to previous
-            yes = E5MessageBox.yesNo(
+            yes = EricMessageBox.yesNo(
                 self,
                 self.tr("Changed Connection Profile"),
                 self.tr("""The current profile has unsaved changes."""
                         """ Shall these be saved?"""),
-                icon=E5MessageBox.Warning,
+                icon=EricMessageBox.Warning,
                 yesDefault=True)
             if yes:
                 self.__applyProfile()
@@ -158,10 +163,10 @@
             self,
             self.tr("New Connection Profile"),
             self.tr("Enter name for the new Connection Profile:"),
-            QLineEdit.Normal)
+            QLineEdit.EchoMode.Normal)
         if ok and bool(profileName):
             if profileName in self.__profiles:
-                E5MessageBox.warning(
+                EricMessageBox.warning(
                     self,
                     self.tr("New Connection Profile"),
                     self.tr("""<p>A connection named <b>{0}</b> exists"""
@@ -170,7 +175,8 @@
             else:
                 itm = QListWidgetItem(profileName, self.profilesList)
                 self.profilesList.setCurrentItem(itm)
-                self.brokerAddressEdit.setFocus(Qt.OtherFocusReason)
+                self.brokerAddressEdit.setFocus(
+                    Qt.FocusReason.OtherFocusReason)
     
     @pyqtSlot()
     def on_copyButton_clicked(self):
@@ -184,10 +190,10 @@
                 self,
                 self.tr("Copy Connection Profile"),
                 self.tr("Enter name for the copied Connection Profile:"),
-                QLineEdit.Normal)
+                QLineEdit.EchoMode.Normal)
             if ok and bool(newProfileName):
                 if newProfileName in self.__profiles:
-                    E5MessageBox.warning(
+                    EricMessageBox.warning(
                         self,
                         self.tr("Copy Connection Profile"),
                         self.tr("""<p>A connection named <b>{0}</b> exists"""
@@ -200,7 +206,8 @@
                     
                     itm = QListWidgetItem(newProfileName, self.profilesList)
                     self.profilesList.setCurrentItem(itm)
-                    self.brokerAddressEdit.setFocus(Qt.OtherFocusReason)
+                    self.brokerAddressEdit.setFocus(
+                        Qt.FocusReason.OtherFocusReason)
     
     @pyqtSlot()
     def on_minusButton_clicked(self):
@@ -210,7 +217,7 @@
         itm = self.profilesList.currentItem()
         if itm:
             profileName = itm.text()
-            yes = E5MessageBox.yesNo(
+            yes = EricMessageBox.yesNo(
                 self,
                 self.tr("Delete Connection Profile"),
                 self.tr("""<p>Shall the Connection Profile <b>{0}</b>"""
@@ -223,7 +230,7 @@
                 self.__populateProfilesList()
                 self.__deletingProfile = False
         
-        self.profilesList.setFocus(Qt.OtherFocusReason)
+        self.profilesList.setFocus(Qt.FocusReason.OtherFocusReason)
     
     def getProfiles(self):
         """
@@ -316,7 +323,7 @@
         
         if currentProfile:
             items = self.profilesList.findItems(
-                currentProfile, Qt.MatchExactly)
+                currentProfile, Qt.MatchFlag.MatchExactly)
             if items:
                 self.profilesList.setCurrentItem(items[0])
         
@@ -481,7 +488,7 @@
             not self.cleanSessionCheckBox.isChecked()
         ):
             enable = False
-            E5MessageBox.critical(
+            EricMessageBox.critical(
                 self,
                 self.tr("Invalid Connection Parameters"),
                 self.tr("An empty Client ID requires a clean session."))
@@ -500,7 +507,8 @@
                     bool(self.tlsSelfSignedClientKeyFilePicker.text())
                 )
         
-        self.profileButtonBox.button(QDialogButtonBox.Apply).setEnabled(enable)
+        self.profileButtonBox.button(
+            QDialogButtonBox.StandardButton.Apply).setEnabled(enable)
     
     @pyqtSlot(str)
     def on_brokerAddressEdit_textChanged(self, address):
@@ -518,7 +526,8 @@
         Private slot to generate a client ID.
         """
         uuid = QUuid.createUuid()
-        self.clientIdEdit.setText(uuid.toString(QUuid.WithoutBraces))
+        self.clientIdEdit.setText(
+            uuid.toString(QUuid.StringFormat.WithoutBraces))
     
     @pyqtSlot(str)
     def on_clientIdEdit_textChanged(self, clientId):
@@ -590,7 +599,7 @@
         """
         if checked and self.brokerPortSpinBox.value() == 1883:
             # port is still standard non-TLS port
-            yes = E5MessageBox.yesNo(
+            yes = EricMessageBox.yesNo(
                 self,
                 self.tr("SSL/TLS Enabled"),
                 self.tr(
@@ -598,13 +607,13 @@
                     """ However, the broker port is still the default"""
                     """ unencrypted port (port 1883). Shall this be"""
                     """ changed?"""),
-                icon=E5MessageBox.Warning,
+                icon=EricMessageBox.Warning,
                 yesDefault=True)
             if yes:
                 self.brokerPortSpinBox.setValue(8883)
         elif not checked and self.brokerPortSpinBox.value() == 8883:
             # port is still standard TLS port
-            yes = E5MessageBox.yesNo(
+            yes = EricMessageBox.yesNo(
                 self,
                 self.tr("SSL/TLS Disabled"),
                 self.tr(
@@ -612,7 +621,7 @@
                     """ However, the broker port is still the default"""
                     """ encrypted port (port 8883). Shall this be"""
                     """ changed?"""),
-                icon=E5MessageBox.Warning,
+                icon=EricMessageBox.Warning,
                 yesDefault=True)
             if yes:
                 self.brokerPortSpinBox.setValue(1883)
@@ -658,34 +667,32 @@
         Public slot to reject the dialog changes.
         """
         if self.__isChangedProfile():
-            button = E5MessageBox.warning(
+            button = EricMessageBox.warning(
                 self,
                 self.tr("Changed Connection Profile"),
                 self.tr("""The current profile has unsaved changes. Shall"""
                         """ these be saved?"""),
-                E5MessageBox.StandardButtons(
-                    E5MessageBox.Discard |
-                    E5MessageBox.Save),
-                E5MessageBox.Save)
-            if button == E5MessageBox.Save:
+                EricMessageBox.Discard |
+                EricMessageBox.Save,
+                EricMessageBox.Save)
+            if button == EricMessageBox.Save:
                 self.__applyProfile()
                 return
         
         if self.__profilesChanged:
-            button = E5MessageBox.warning(
+            button = EricMessageBox.warning(
                 self,
                 self.tr("Changed Connection Profiles"),
                 self.tr("""The list of connection profiles has unsaved"""
                         """ changes."""),
-                E5MessageBox.StandardButtons(
-                    E5MessageBox.Abort |
-                    E5MessageBox.Discard |
-                    E5MessageBox.Save),
-                E5MessageBox.Save)
-            if button == E5MessageBox.Save:
+                EricMessageBox.Abort |
+                EricMessageBox.Discard |
+                EricMessageBox.Save,
+                EricMessageBox.Save)
+            if button == EricMessageBox.Save:
                 super().accept()
                 return
-            elif button == E5MessageBox.Abort:
+            elif button == EricMessageBox.Abort:
                 return
         
         super().reject()
@@ -696,12 +703,12 @@
         Public slot to accept the dialog.
         """
         if self.__isChangedProfile():
-            yes = E5MessageBox.yesNo(
+            yes = EricMessageBox.yesNo(
                 self,
                 self.tr("Changed Connection Profile"),
                 self.tr("""The current profile has unsaved changes. Shall"""
                         """ these be saved?"""),
-                icon=E5MessageBox.Warning,
+                icon=EricMessageBox.Warning,
                 yesDefault=True)
             if yes:
                 self.__applyProfile()

eric ide

mercurial