SimpleCalc Full Code Example

import logging
from utils.MetaModel import MetaModel
from utils.LogDecorator import log

class SimpleCalcModel(MetaModel):
    """
    Simple calculator model to store and compute values.
    Supports addition (+) and subtraction (-) operations.
    """
    logger = logging.getLogger(__name__)

    @log(logger=logger)
    def _init(self):
        self.results = []

    @log(logger=logger)
    def compute(self, left, operator, right):
        if len(self.results) >= 5:
            return None
        if operator == "+":
            result = left + right
        elif operator == "-":
            result = left - right
        else:
            return None
        self.results.append(result)
        return result

    @log(logger=logger)
    def get_results(self):
        return self.results

    @log(logger=logger)
    def reset(self):
        self.results = []

Pro Tip

You may have noticed the @log(logger=logger) tags above some functions.

This is Poriscope’s way of automatically keeping track of what happens in your plugin — like when a function starts, ends, or runs into a problem.

It helps with troubleshooting and understanding how everything runs behind the scenes — without needing to write a lot of extra code.

If you want to log your own messages inside the function (like notes or warnings), you can still do that using lines like self.logger.info("Your message here").

For more details, see Logging.