Sun, 25 Apr 2021 17:57:07 +0200
Implemented some code simplifications.
--- a/ChangeLog Sun Apr 25 17:41:32 2021 +0200 +++ b/ChangeLog Sun Apr 25 17:57:07 2021 +0200 @@ -2,6 +2,7 @@ --------- Version 3.0.0: - removed support for obsolete eric6 versions +- implemented some code simplifications Version 2.1.0: - changed exec_() into exec()
--- a/MqttMonitor/MqttConnectionOptionsDialog.py Sun Apr 25 17:41:32 2021 +0200 +++ b/MqttMonitor/MqttConnectionOptionsDialog.py Sun Apr 25 17:57:07 2021 +0200 @@ -37,7 +37,7 @@ @param parent reference to the parent widget @type QWidget """ - super(MqttConnectionOptionsDialog, self).__init__(parent) + super().__init__(parent) self.setupUi(self) self.__client = client
--- a/MqttMonitor/MqttConnectionProfilesDialog.py Sun Apr 25 17:41:32 2021 +0200 +++ b/MqttMonitor/MqttConnectionProfilesDialog.py Sun Apr 25 17:57:07 2021 +0200 @@ -44,7 +44,7 @@ @param parent reference to the parent widget @type QWidget """ - super(MqttConnectionProfilesDialog, self).__init__(parent) + super().__init__(parent) self.setupUi(self) self.__client = client @@ -127,18 +127,21 @@ self.minusButton.setEnabled(current is not None) self.copyButton.setEnabled(current is not None) - if current is not previous: - if not self.__deletingProfile and self.__isChangedProfile(): - # modified profile belongs to previous - yes = E5MessageBox.yesNo( - self, - self.tr("Changed Connection Profile"), - self.tr("""The current profile has unsaved changes.""" - """ Shall these be saved?"""), - icon=E5MessageBox.Warning, - yesDefault=True) - if yes: - self.__applyProfile() + if ( + current is not previous and + not self.__deletingProfile and + self.__isChangedProfile() + ): + # modified profile belongs to previous + yes = E5MessageBox.yesNo( + self, + self.tr("Changed Connection Profile"), + self.tr("""The current profile has unsaved changes.""" + """ Shall these be saved?"""), + icon=E5MessageBox.Warning, + yesDefault=True) + if yes: + self.__applyProfile() if current: profileName = current.text() @@ -472,16 +475,16 @@ bool(self.brokerAddressEdit.text())) # condition 2: if client ID is empty, clean session must be selected - if not self.__populatingProfile: - if ( - self.clientIdEdit.text() == "" and - not self.cleanSessionCheckBox.isChecked() - ): - enable = False - E5MessageBox.critical( - self, - self.tr("Invalid Connection Parameters"), - self.tr("An empty Client ID requires a clean session.")) + if ( + not self.__populatingProfile and + self.clientIdEdit.text() == "" and + not self.cleanSessionCheckBox.isChecked() + ): + enable = False + E5MessageBox.critical( + self, + self.tr("Invalid Connection Parameters"), + self.tr("An empty Client ID requires a clean session.")) if self.tlsGroupBox.isChecked(): if self.tlsCertsFileButton.isChecked(): @@ -680,12 +683,12 @@ E5MessageBox.Save), E5MessageBox.Save) if button == E5MessageBox.Save: - super(MqttConnectionProfilesDialog, self).accept() + super().accept() return elif button == E5MessageBox.Abort: return - super(MqttConnectionProfilesDialog, self).reject() + super().reject() @pyqtSlot() def accept(self): @@ -703,4 +706,4 @@ if yes: self.__applyProfile() - super(MqttConnectionProfilesDialog, self).accept() + super().accept()
--- a/MqttMonitor/MqttMonitorWidget.py Sun Apr 25 17:41:32 2021 +0200 +++ b/MqttMonitor/MqttMonitorWidget.py Sun Apr 25 17:57:07 2021 +0200 @@ -10,6 +10,7 @@ import os import collections import copy +import contextlib from PyQt5.QtCore import pyqtSlot, Qt, QTimer, QFileInfo from PyQt5.QtGui import QFont, QTextCursor, QBrush @@ -47,7 +48,7 @@ @param parent reference to the parent widget @type QWidget """ - super(MqttMonitorWidget, self).__init__(parent) + super().__init__(parent) self.setupUi(self) self.__plugin = plugin @@ -248,10 +249,11 @@ # ensure, the client loop is stopped self.__client.stopLoop() - if rc > 0: - msg = mqttErrorMessage(rc) - else: - msg = self.tr("Connection to Broker shut down cleanly.") + msg = ( + mqttErrorMessage(rc) + if rc > 0 else + self.tr("Connection to Broker shut down cleanly.") + ) self.__flashBrokerStatusLabel(msg) self.connectButton.setIcon(UI.PixmapCache.getIcon("ircConnect.png")) @@ -279,13 +281,10 @@ @param message log message @type str """ - try: + with contextlib.suppress(KeyError): if MqttClient.LogLevelMap[level] < self.logLevelComboBox.itemData( self.logLevelComboBox.currentIndex()): return - except KeyError: - # always show unknown log levels - pass scrollbarValue = self.logEdit.verticalScrollBar().value() @@ -372,13 +371,10 @@ """ if mid in self.__topicQueue: topic = self.__topicQueue.pop(mid) - try: + with contextlib.suppress(ValueError): self.__subscribedTopics.remove(topic) self.__updateUnsubscribeTopicComboBox() self.__updatePublishTopicComboBox() - except ValueError: - # ignore it - pass ####################################################################### ## Slots handling UI interactions @@ -725,7 +721,7 @@ fn = Utilities.toNativeSeparators(fn) try: with open(fn, "w") as f: - f.write(self.logEdit.toPlainText()) + f.write(self.logEdit.toPlainText()) except EnvironmentError as err: E5MessageBox.critical( self, @@ -788,20 +784,14 @@ self.brokerPortComboBox.clear() # step 2a: populate the broker name list - if brokerPortList: - currentBroker = brokerPortList[0][0] - else: - currentBroker = "" + currentBroker = brokerPortList[0][0] if brokerPortList else "" brokerSet = {b[0].strip() for b in brokerPortList} self.brokerComboBox.addItems(sorted(brokerSet)) index = self.brokerComboBox.findText(currentBroker) self.brokerComboBox.setCurrentIndex(index) # step 2b: populate the broker ports list - if brokerPortList: - currentPort = brokerPortList[0][1] - else: - currentPort = 1883 + currentPort = brokerPortList[0][1] if brokerPortList else 1883 currentPortStr = "{0:5}".format(currentPort) portsSet = {b[1] for b in brokerPortList} portsSet.update({1883, 8883}) @@ -917,12 +907,9 @@ if topic.startswith(MqttMonitorWidget.BrokerStatusTopicLoadPrefix): self.__handleBrokerLoadStatusMessage(topic, payloadStr) else: - try: + with contextlib.suppress(KeyError): label = self.__statusLabelMapping[topic] label.setText(payloadStr) - except KeyError: - # ignore topics not shown in display - pass def __handleBrokerLoadStatusMessage(self, topic, payloadStr): """ @@ -937,27 +924,25 @@ subtopic, topicElement = topic.rsplit("/", 1) self.__statusLoadValues[subtopic][topicElement] = payloadStr - try: + with contextlib.suppress(KeyError): label = self.__statusLabelMapping[subtopic] label.setText("{0} / {1} / {2}".format( self.__statusLoadValues[subtopic]["1min"], self.__statusLoadValues[subtopic]["5min"], self.__statusLoadValues[subtopic]["15min"], )) - except KeyError: - # ignore topics not shown in display - pass def __clearBrokerStatusLabels(self): """ Private method to clear the broker status labels. """ for statusLabelKey in self.__statusLabelMapping: - if statusLabelKey.startswith( - MqttMonitorWidget.BrokerStatusTopicLoadPrefix): - label = "- / - / -" - else: - label = "-" + label = ( + "- / - / -" + if statusLabelKey.startswith( + MqttMonitorWidget.BrokerStatusTopicLoadPrefix) else + "-" + ) self.__statusLabelMapping[statusLabelKey].setText(label) def __loadDefaultDictFactory(self):
--- a/PluginMqttMonitor.epj Sun Apr 25 17:41:32 2021 +0200 +++ b/PluginMqttMonitor.epj Sun Apr 25 17:57:07 2021 +0200 @@ -8,8 +8,21 @@ "CHECKERSPARMS": { "Pep8Checker": { "AnnotationsChecker": { + "AllowUntypedDefs": false, + "AllowUntypedNested": false, + "DispatchDecorators": [ + "singledispatch", + "singledispatchmethod" + ], "MaximumComplexity": 3, - "MinimumCoverage": 75 + "MaximumLength": 7, + "MinimumCoverage": 75, + "MypyInitReturn": false, + "OverloadDecorators": [ + "overload" + ], + "SuppressDummyArgs": false, + "SuppressNoneReturning": true }, "BlankLines": [ 2, @@ -27,20 +40,35 @@ ] }, "CommentedCodeChecker": { - "Aggressive": false + "Aggressive": false, + "WhiteList": [ + "pylint", + "pyright", + "noqa", + "type:\\s*ignore", + "fmt:\\s*(on|off)", + "TODO", + "FIXME", + "WARNING", + "NOTE", + "TEST", + "DOCU", + "XXX", + "- " + ] }, "CopyrightAuthor": "", "CopyrightMinFileSize": 0, "DocstringType": "eric", - "EnabledCheckerCategories": "C, D, E, M, N, S, W", + "EnabledCheckerCategories": "C, D, E, M, N, S, Y, W", "ExcludeFiles": "*/Ui_*.py, */*_rc.py", - "ExcludeMessages": "C101,E265,E266,E305,E402,M201,M811,N802,N803,N807,N808,N821,W293,W504", + "ExcludeMessages": "C101,E265,E266,E305,E402,M201,M301,M302,M303,M304,M305,M306,M307,M308,M311,M312,M313,M314,M315,M321,M701,M702,M811,M834,N802,N803,N807,N808,N821,W293,W504,Y119,Y401,Y402", "FixCodes": "", "FixIssues": false, "FutureChecker": "", "HangClosing": false, "IncludeMessages": "", - "LineComplexity": 20, + "LineComplexity": 25, "LineComplexityScore": 10, "MaxCodeComplexity": 10, "MaxDocLineLength": 79,
--- a/PluginMqttMonitor.py Sun Apr 25 17:41:32 2021 +0200 +++ b/PluginMqttMonitor.py Sun Apr 25 17:57:07 2021 +0200 @@ -87,7 +87,7 @@ @param ui reference to the user interface object @type UI.UserInterface """ - super(MqttMonitorPlugin, self).__init__(ui) + super().__init__(ui) self.__ui = ui self.__initialize() @@ -128,14 +128,12 @@ try: usesDarkPalette = e5App().usesDarkPalette() except AttributeError: + # eric6 < 20.4 from PyQt5.QtGui import QPalette palette = e5App().palette() lightness = palette.color(QPalette.Window).lightness() usesDarkPalette = lightness <= 128 - if usesDarkPalette: - iconSuffix = "dark" - else: - iconSuffix = "light" + iconSuffix = "dark" if usesDarkPalette else "light" self.__widget = MqttMonitorWidget(self, iconSuffix) self.__ui.addSideWidget(