コード例 #1
0
    def create(self):
        """
        Create the log viewer.
        """
        from ipywidgets import HTML, HBox, VBox
        html = HTML()

        html.value = """<div style="max-height: 400px; overflow-y: auto; width: 100%";>"""

        buttons = []
        for type in self.log_levels:
            buttons.append(
                HTML(
                    self.toggle_button_line.format(type_lower=type.lower(),
                                                   type_upper=type.upper())))

        buttons_view = HBox(buttons)
        buttons_view.margin = "10px 0px"

        html.value += """<table style="word-break: break-all; margin: 10px;">"""

        for line in self.log_content.split("\n"):
            found = False
            for type in self.log_levels:
                type_upper = type.upper()
                type_lower = type.lower()
                color = self.log_color_codes[type_upper]
                if line.startswith(
                        "[{type_upper}]".format(type_upper=type_upper)):
                    html.value += self.log_line.format(content=line,
                                                       type_lower=type_lower,
                                                       color=color)
                    found = True
                    break

            if not found:
                html.value += self.log_line.format(
                    content=line,
                    type_lower="default",
                    color=self.log_color_codes["DEFAULT"])

        html.value += "</table></div>"
        html.width = "100%"
        html.margin = "5px"

        result_vbox = VBox((buttons_view, html))

        return result_vbox