commit e402bc719aaff0467c1f4e3cd7ff9ae3efc4e6ac
Author: Pavel <murglm@seznam.cz>
Date:   Thu Jun 3 11:57:31 2021 +0200

    Re: #8998 - refactoring, comments

diff --git a/aswi2021vochomurka/view/logger_view.py b/aswi2021vochomurka/view/logger_view.py
index 2ed4231..0649bc2 100644
--- a/aswi2021vochomurka/view/logger_view.py
+++ b/aswi2021vochomurka/view/logger_view.py
@@ -5,9 +5,15 @@ from PyQt5.QtWidgets import QPlainTextEdit
 
 
 class LoggerView(logging.Handler, QObject):
+    """
+    LoggerView represents console in gui application.
+    """
     append = pyqtSignal(str)
 
     def __init__(self, parent):
+        """
+        Constructor
+        """
         super().__init__()
         super(QObject, self).__init__()
 
@@ -19,10 +25,18 @@ class LoggerView(logging.Handler, QObject):
         )
 
     def emit(self, record):
+        """
+        Emit message from record
+        :param record: record
+        """
         msg = self.format(record)
         self.append.emit(msg)
 
     def appendMessage(self, msg):
+        """
+        Append message
+        :param msg: message
+        """
         self.widget.appendPlainText(msg)
         self.widget.verticalScrollBar().setValue(self.widget.verticalScrollBar().maximum())
 
diff --git a/aswi2021vochomurka/view/main_view.py b/aswi2021vochomurka/view/main_view.py
index 4b86d1b..227444e 100644
--- a/aswi2021vochomurka/view/main_view.py
+++ b/aswi2021vochomurka/view/main_view.py
@@ -19,6 +19,9 @@ from aswi2021vochomurka.view.settings import SettingsDialog, DEFAULT_HOST, DEFAU
 
 
 class Worker(QObject, SubscriberCallback):
+    """
+    Worker representing thread
+    """
     connected = pyqtSignal()
     disconnected = pyqtSignal()
     error = pyqtSignal(Exception)
@@ -28,62 +31,83 @@ class Worker(QObject, SubscriberCallback):
     params: SubscriberParams
 
     def __init__(self, params: SubscriberParams) -> None:
+        """
+        Constructor
+        """
         super().__init__()
         self.params = params
 
     def start(self):
+        """
+        Start worker
+        """
         self.subscriber = MQTTSubscriber(self, self.params)
         self.subscriber.start()
 
     def stop(self):
+        """
+        Stop worker
+        """
         self.subscriber.stop()
 
     def onConnected(self):
+        """
+        Emit connection signal
+        """
         self.connected.emit()
 
     def onDisconnected(self):
+        """
+        Emit disconnection signal
+        """
         self.disconnected.emit()
 
     def onError(self):
         pass
 
     def onMessage(self, message: Message):
+        """
+        Emit message signal
+        :param message: message
+        """
         self.newMessage.emit(message)
 
     def onCloseTopic(self, topic: str):
+        """
+        Emit close topic signal
+        :param topic: topic
+        """
         print("Close topic")
         self.closeTopic.emit(topic)
-        #pass
 
 
 class MainView(QMainWindow):
+    """
+    Main window of application.
+    Displays all parts of the application.
+    """
     worker: Worker = None
     workerThread: QThread = None
 
     def __init__(self):
+        """
+        Constructor - displays all parts of the application.
+        """
         super(MainView, self).__init__()
 
         self.chartsNum = 0
-        self.arrayData = []
-
-        self.dataIndex = 0
         self.dataDict = {}
         self.canvasDict = {}
         self.figureDict = {}
         self.widgetDict = {}
-
         self.widgetList = []
 
-        # self.toolbar = NavigationToolbar(self.canvas, self)
-
-        # self.setMinimumSize(QSize(440, 240))
         self.setMinimumSize(QSize(1200, 800))
         self.setWindowTitle("MQTT client")
 
         logger = self._createLoggerView()
         layout = QVBoxLayout()
         layout.addWidget(logger.widget)
-        # layout.addWidget(self.toolbar)
 
         widget = QWidget()
         widget.setLayout(layout)
@@ -100,6 +124,9 @@ class MainView(QMainWindow):
         self.init_subscriber()
 
     def _createLoggerView(self):
+        """
+        Create logger view
+        """
         logger = LoggerView(self)
         formatter = logging.Formatter('%(asctime)s %(message)s', '%H:%M')
         logger.setFormatter(formatter)
@@ -108,6 +135,9 @@ class MainView(QMainWindow):
         return logger
 
     def _createMenuBar(self):
+        """
+        Creates menu bar
+        """
         menuBar = QMenuBar(self)
         settingsAction = QAction("&Settings", self)
         settingsAction.triggered.connect(self.settings)
@@ -115,7 +145,12 @@ class MainView(QMainWindow):
         self.setMenuBar(menuBar)
 
     def plot(self, message: Message):
+        """
+        Plots new charts or updates old ones
+        :param message: message
+        """
         if message.topic in self.dataDict:
+            # topic already exists
             self.dataDict[message.topic].append(message.value)
 
             figure = self.figureDict[message.topic]
@@ -127,6 +162,7 @@ class MainView(QMainWindow):
 
             self.canvasDict[message.topic].draw()
         else:
+            # new topic
             self.dataDict[message.topic] = [message.value]
 
             figure = plt.figure(figsize=[500, 500])
@@ -155,6 +191,10 @@ class MainView(QMainWindow):
             self.chartsNum += 1
 
     def deletePlot(self, topic: str):
+        """
+        Deletes plot
+        :param topic: topic
+        """
         widget = self.widgetDict[topic]
         self.widgetList.remove(widget)
         widget.setParent(None)
@@ -167,6 +207,9 @@ class MainView(QMainWindow):
         self.reorganizePlots()
 
     def reorganizePlots(self):
+        """
+        Reorganize plots
+        """
         count = 0
         for widget in self.widgetList:
             self.grid.addWidget(widget, int(count / 2), count % 2)
@@ -178,21 +221,33 @@ class MainView(QMainWindow):
         self.worker.stop()
 
     def settings(self):
+        """
+        Opens settings dialog
+        """
         dialog = SettingsDialog()
         if dialog.exec_():
             self.reconnect()
 
     def disconnect(self):
+        """
+        Disconnect
+        """
         self.worker.stop()
         self.workerThread.quit()
         self.workerThread.wait()
 
     def reconnect(self):
+        """
+        Reconnect
+        """
         self.disconnect()
         self.worker.params = self.getConfigParams()
         self.workerThread.start()
 
     def init_subscriber(self):
+        """
+        Initialization of subscriber
+        """
         self.workerThread = QThread()
         self.worker = Worker(self.getConfigParams())
         self.worker.moveToThread(self.workerThread)
@@ -207,6 +262,10 @@ class MainView(QMainWindow):
         self.workerThread.start()
 
     def getConfigParams(self) -> SubscriberParams:
+        """
+        Returns config parameters
+        :return: config parameters
+        """
         settings = get_settings()
 
         connection = ConnectionParams(
diff --git a/aswi2021vochomurka/view/settings.py b/aswi2021vochomurka/view/settings.py
index f76d693..e6e2153 100644
--- a/aswi2021vochomurka/view/settings.py
+++ b/aswi2021vochomurka/view/settings.py
@@ -19,9 +19,16 @@ def get_settings():
 
 
 class SettingsDialog(QDialog):
+    """
+    Settings dialog.
+    In settings dialog is possible to change settings of application.
+    """
     topics = DEFAULT_TOPICS
 
     def __init__(self):
+        """
+        Constructor
+        """
         super(SettingsDialog, self).__init__(None,
                                              QtCore.Qt.WindowCloseButtonHint | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint)
         self.settings = get_settings()
@@ -96,20 +103,32 @@ class SettingsDialog(QDialog):
         self.setLayout(mainLayout)
 
     def addTopic(self):
+        """
+        Add topic
+        """
         item = QListWidgetItem()
         item.setText("/topic")
         item.setFlags(item.flags() | QtCore.Qt.ItemIsEditable)
         self.topicsListWidget.addItem(item)
 
     def removeTopic(self):
+        """
+        Remove topic
+        """
         for item in self.topicsListWidget.selectedItems():
             self.topicsListWidget.takeItem(self.topicsListWidget.row(item))
 
     def anonymousChanged(self):
+        """
+        Changing anonymous/user status
+        """
         self.usernameInput.setEnabled(not self.anonymousInput.isChecked())
         self.passwordInput.setEnabled(not self.anonymousInput.isChecked())
 
     def accept(self) -> None:
+        """
+        Accept changes
+        """
         super().accept()
         self.topics = []
         for index in range(self.topicsListWidget.count()):
