diff --git a/simframe/frame/heartbeat.py b/simframe/frame/heartbeat.py index 2116623..0c87d99 100644 --- a/simframe/frame/heartbeat.py +++ b/simframe/frame/heartbeat.py @@ -1,4 +1,5 @@ from simframe.frame.updater import Updater +from simframe.utils.color import colorize class Heartbeat(object): @@ -35,7 +36,28 @@ def __str__(self): return "{}".format(str(self.__name__)) def __repr__(self): - return self.__str__() + s = self.__str__() + "\n" + s += (len(s)-1)*"-" + "\n" + s += "\n" + s += "{} {}".format(colorize("Systole: ", color="red"), + str(self.systole._func)) + "\n" + s += "{} {}".format(colorize("Updater: ", color="red"), + str(self.updater._func)) + "\n" + s += "{} {}".format(colorize("Diastole:", color="red"), + str(self.diastole._func)) + "\n" + s += "\n" + s += "Docstrings" + "\n" + s += 10*"-" + "\n" + s += "\n" + s += colorize("Systole:", color="red") + "\n" + s += str(self.systole._func.__doc__ or None) + "\n" + s += "\n" + s += colorize("Updater:", color="red") + "\n" + s += str(self.updater._func.__doc__ or None) + "\n" + s += "\n" + s += colorize("Diastole:", color="red") + "\n" + s += str(self.diastole._func.__doc__ or None) + return s @property def systole(self): diff --git a/simframe/frame/updater.py b/simframe/frame/updater.py index 1ea1a43..f2ccff5 100644 --- a/simframe/frame/updater.py +++ b/simframe/frame/updater.py @@ -1,3 +1,7 @@ +import inspect +from simframe.utils.color import colorize + + class Updater(): """Class that manages how a ``Group`` or ``Field`` is updated.""" @@ -25,7 +29,37 @@ def update(self, owner, *args, **kwargs): return self._func(owner, *args, **kwargs) def __str__(self): - return "{}".format(str(self.__name__)) + s = "{}".format(str(self.__name__)) + "\n" + s += (len(s)-1)*"-" + "\n" + s += "\n" + # Signature + try: + sig = "{}{}".format(self._func.__name__, + inspect.signature(self._func)) + s += "{} {}".format(colorize("Signature:", + color="red"), str(sig)) + "\n" + except: + pass + # Source/Docstring + try: + source = inspect.getsource(self._func) + cat = colorize("Source:", color="red") + "\n" + except: + source = self._func.__doc__ + cat = colorize("Docstring:", color="red") + "\n" + if source is not None: + s += cat + s += source + # File + try: + fn = inspect.getfile(self._func) + s += "{} {}".format(colorize("File:", color="red"), fn) + "\n" + except: + pass + # Type + cls = self._func.__class__.__name__ + s += "{} {}".format(colorize("Type:", color="red"), cls) + return s def __repr__(self): return self.__str__()