From 15ebc718f0fe4da8a8a8cb9d8a364eafb9abe97c Mon Sep 17 00:00:00 2001 From: "komment-ai[bot]" <122626893+komment-ai[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 08:50:33 +0000 Subject: [PATCH] Added comments to 8 functions across 1 file --- .../src/genericworker.py | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/cli/robocompdsl/test/resources/reference_components/test_customStateMachinePython/src/genericworker.py b/cli/robocompdsl/test/resources/reference_components/test_customStateMachinePython/src/genericworker.py index 4ee44cf1..d008041c 100644 --- a/cli/robocompdsl/test/resources/reference_components/test_customStateMachinePython/src/genericworker.py +++ b/cli/robocompdsl/test/resources/reference_components/test_customStateMachinePython/src/genericworker.py @@ -53,6 +53,50 @@ class GenericWorker(QtWidgets.QWidget): #------------------------- def __init__(self, mprx): + """ + initializes a `GenericWorker` object by creating and setting up a state + machine, defining five states, and connecting event handlers to trigger + transitions between them. + + Args: + mprx (object reference, without specifying its actual class name.): + xtensor of the PRX class, which is used to initialize the state + machine and its states. + + - `super(GenericWorker, self).__init__()` is called to initialize + the class with a standard __init__ function. + - `self.ui = Ui_guiDlg()` creates an instance of the `Ui_guiDlg` + class and sets it as the UI element of the GenericWorker object. + - `self.ui.setupUi(self)` is called to setup the UI elements + with the necessary properties and attributes. + - `self.show()` is called to show the GenericWorker's UI. + - `self.mutex` is a `QMutex` object used for synchronization purposes. + - `self.Period` is an integer value that determines the duration + of each state machine transition in milliseconds. + - `self.timer` is a `QTimer` object used to trigger state machine + transitions at a specific interval. + - `self.myStateMachine` is a `QStateMachine` object used to + manage the GenericWorker's state machine logic. + - `self.five_state` is a final state of the state machine that + represents the "idle" or "stop" state of the GenericWorker. + - The remaining states (`one_state`, `two_state`, `three_state`, + and `four_state`) are also instances of `QState` objects, which + define the different states that the GenericWorker can be in during + its operation. Each state has its own set of transitions and events + that occur when it is entered or exited. + - The `t_one_to_two`, `t_two_to_three`, `t_three_to_four`, + `t_four_to_one`, and `t_four_to_five` methods are used to define + the transitions between the states, and each transition has a + corresponding event that occurs when the state machine reaches + that transition. + + Overall, the `__init__` function defines the necessary properties + and attributes of the GenericWorker class, as well as setting up + the state machine logic and defining the transitions between the + different states. + + + """ super(GenericWorker, self).__init__() @@ -97,32 +141,62 @@ def __init__(self, mprx): @QtCore.Slot() def sm_two(self): + """ + prints "Error: lack sm_two in Specificworker" and exits with a status code + of -1 when it is called. + + """ print("Error: lack sm_two in Specificworker") sys.exit(-1) @QtCore.Slot() def sm_three(self): + """ + prints "Error: lack sm_three in Specificworker" and exits with a value of + -1 if the named variable 'sm_three' is not defined in the scope of the function. + + """ print("Error: lack sm_three in Specificworker") sys.exit(-1) @QtCore.Slot() def sm_four(self): + """ + prints "Error: lack sm_four in Specificworker" and exits with an error + code -1 when called. + + """ print("Error: lack sm_four in Specificworker") sys.exit(-1) @QtCore.Slot() def sm_one(self): + """ + prints an error message and exits with a non-zero status code if the + `SpecificWorker` class does not have a defined `sm_one` method. + + """ print("Error: lack sm_one in Specificworker") sys.exit(-1) @QtCore.Slot() def sm_five(self): + """ + prints "Error: lack sm_five in Specificworker" and terminates the program + with exit code -1 when it is called. + + """ print("Error: lack sm_five in Specificworker") sys.exit(-1) #------------------------- @QtCore.Slot() def killYourSelf(self): + """ + terminates the current instance by emitting the `kill` signal, causing it + to be deleted or stopped. + + """ rDebug("Killing myself") self.kill.emit() @@ -130,6 +204,16 @@ def killYourSelf(self): # @param per Period in ms @QtCore.Slot(int) def setPeriod(self, p): + """ + changes its argument `p`, then assigns it to the instance attribute ` + Period`, and starts the `timer` with the new period value using the `start()` + method. + + Args: + p (int): period of time to display the message or trigger the event, + and it is used to set the value of `self.Period`. + + """ print("Period changed", p) self.Period = p self.timer.start(self.Period)