Does the Viewer State Browser support colored text?

   799   1   0
User Avatar
Member
4 posts
Joined: July 2019
Offline
Does the Viewer State Browser support colored text?

It'd be great to be able to use some color for debug information in the Viewer State Browser. Usually I do this in python like this:

class bcolors:
    HEADER = '\033[95m'
    OKBLUE = '\033[94m'
    OKCYAN = '\033[96m'
    OKGREEN = '\033[92m'
    WARNING = '\033[93m'
    FAIL = '\033[91m'
    ENDC = '\033[0m'
    BOLD = '\033[1m'
    UNDERLINE = '\033[4m'

print(bcolors.WARNING + "Warning: No active frommets remain. Continue?" + bcolors.ENDC)

But using self.log and bcolors doesn't work.

self.log(bcolors.OKBLUE + "blue text" + bcolors.ENDC)
Just prints 'blue text' to the viewer state browser
User Avatar
Member
122 posts
Joined: June 2019
Offline
State browser is qt based so it's not your usual shell.

It does support rich text however. For log viewer you can use qt html subset for formatting which can do much more than colors actually: https://doc.qt.io/qt-5/richtext-html-subset.html [doc.qt.io]

Basically this:
self.log("<span style='font-weight:bold; color:#00FF00;'>== Enter ==</span>")

gives you this entry:


Also for usual logging messages logger provides standard levels: https://www.sidefx.com/docs/houdini/hom/hou/severityType.html [www.sidefx.com] that you can pass like this:
self.log("Input doesn't have name attribute", severity=hou.severityType.Warning)


These modules (additional python utils like resourceutils or viewerstates.utils) aren't documented but you can check their source, they have many other useful things

Attachments:
state_log.png (4.2 KB)
state_warn.png (8.6 KB)

  • Quick Links