text_extensions_for_pandas/jupyter/widget/table.py
def DataFrameTableColumnComponent(
    widget,
    is_interactive,
    column,
    SpanOnBeginChange,
    SpanOnEndChange,
    TokenSpanOnBeginChange,
    TokenSpanOnEndChange,
):
    """Constructs the widget component representing a single column of data within the
    table."""

    column_items = []

    # Begin with the column header.
    column_items.append(ipw.HTML(f"<b>{column.name}</b>"))

    # Branch to create either a static or interactive version of the column.
    if is_interactive:
        # Build an interactive column.
        for column_index in range(len(column)):
            # Call handler to handle columns of different data types
            # Checks if column is a categorical type and passes in the list of all possible categories as an additional argument if it is
            if str(column.dtype) == "category":
                data = DataTypeHandler(
                    column, column[column_index], categories=column.cat.categories
                )
                data.observe(
                    lambda change, column_index=column_index, column_name=column.name, widget=widget: (
                        CategoricalHandler(change, column_index, column_name, widget)
                    ),
                    names="value",
                )

            elif str(column.dtype) == "SpanDtype":
                data_begin, data_end, text = SpanHandler(
                    column, column_index, SpanOnBeginChange, SpanOnEndChange
                )

            elif str(column.dtype) == "TokenSpanDtype":
                data_begin, data_end, text = TokenSpanHandler(
                    column, column_index, TokenSpanOnBeginChange, TokenSpanOnEndChange
                )

            else:
                data = DataTypeHandler(column, column[column_index])
                data.observe(
                    lambda change, column_name=column.name, index=column_index, widget=widget: GenericInteractHandler(
                        widget, change["new"], column_name, index
                    ),
                    names="value",
                )

            # Create a single container for all widget components.
            if (
                str(column.dtype) == "SpanDtype"
                or str(column.dtype) == "TokenSpanDtype"
            ):
                widget_ui = ipw.HBox([data_begin, data_end, text])
            else:
                widget_ui = ipw.HBox([data])
            widget_ui.add_class("tep--dfwidget--table-widget")

            # Adds interactive widgets to table.
            cell_widget = ipw.HBox(
                children=[widget_ui],
                layout=ipw.Layout(justify_content="flex-end", margin="0"),
            )
            cell_widget.add_class(f"tep--dfwidget--row-{column_index}")

            column_items.append(cell_widget)
    else:
        # Build a static column
        for column_index in range(len(column)):
            item = column[column_index]

            cell_widget = ipw.HBox(
                children=[ipw.HTML(f"<div>{str(item)}</div>")],
                layout=ipw.Layout(justify_content="flex-end", margin="0"),
            )
            cell_widget.add_class(f"tep--dfwidget--row-{column_index}")
            column_items.append(cell_widget)

    return ipw.VBox(children=column_items, layout=ipw.Layout(border="0px solid black"))
Constructs the widget component representing a single column of data within the
    table.
Constructs the widget component representing a single column of data within the
table.
Constructs the widget component representing a single column of data within the table .
def DataFrameTableColumnComponent(
    widget,
    is_interactive,
    column,
    SpanOnBeginChange,
    SpanOnEndChange,
    TokenSpanOnBeginChange,
    TokenSpanOnEndChange,
):
    column_items = []
    column_items.append(ipw.HTML(f"<b>{column.name}</b>"))
    if is_interactive:
        for column_index in range(len(column)):
            if str(column.dtype) == "category":
                data = DataTypeHandler(
                    column, column[column_index], categories=column.cat.categories
                )
                data.observe(
                    lambda change, column_index=column_index, column_name=column.name, widget=widget: (
                        CategoricalHandler(change, column_index, column_name, widget)
                    ),
                    names="value",
                )
            elif str(column.dtype) == "SpanDtype":
                data_begin, data_end, text = SpanHandler(
                    column, column_index, SpanOnBeginChange, SpanOnEndChange
                )
            elif str(column.dtype) == "TokenSpanDtype":
                data_begin, data_end, text = TokenSpanHandler(
                    column, column_index, TokenSpanOnBeginChange, TokenSpanOnEndChange
                )
            else:
                data = DataTypeHandler(column, column[column_index])
                data.observe(
                    lambda change, column_name=column.name, index=column_index, widget=widget: GenericInteractHandler(
                        widget, change["new"], column_name, index
                    ),
                    names="value",
                )
            if (
                str(column.dtype) == "SpanDtype"
                or str(column.dtype) == "TokenSpanDtype"
            ):
                widget_ui = ipw.HBox([data_begin, data_end, text])
            else:
                widget_ui = ipw.HBox([data])
            widget_ui.add_class("tep--dfwidget--table-widget")
            cell_widget = ipw.HBox(
                children=[widget_ui],
                layout=ipw.Layout(justify_content="flex-end", margin="0"),
            )
            cell_widget.add_class(f"tep--dfwidget--row-{column_index}")
            column_items.append(cell_widget)
    else:
        for column_index in range(len(column)):
            item = column[column_index]
            cell_widget = ipw.HBox(
                children=[ipw.HTML(f"<div>{str(item)}</div>")],
                layout=ipw.Layout(justify_content="flex-end", margin="0"),
            )
            cell_widget.add_class(f"tep--dfwidget--row-{column_index}")
            column_items.append(cell_widget)
    return ipw.VBox(children=column_items, layout=ipw.Layout(border="0px solid black"))
def DataFrameTableColumnComponent ( widget , is_interactive , column , SpanOnBeginChange , SpanOnEndChange , TokenSpanOnBeginChange , TokenSpanOnEndChange , ) : column_items = [ ] column_items . append ( ipw . HTML ( f"<b>{column.name}</b>" ) ) if is_interactive : for column_index in range ( len ( column ) ) : if str ( column . dtype ) == "category" : data = DataTypeHandler ( column , column [ column_index ] , categories = column . cat . categories ) data . observe ( lambda change , column_index = column_index , column_name = column . name , widget = widget : ( CategoricalHandler ( change , column_index , column_name , widget ) ) , names = "value" , ) elif str ( column . dtype ) == "SpanDtype" : data_begin , data_end , text = SpanHandler ( column , column_index , SpanOnBeginChange , SpanOnEndChange ) elif str ( column . dtype ) == "TokenSpanDtype" : data_begin , data_end , text = TokenSpanHandler ( column , column_index , TokenSpanOnBeginChange , TokenSpanOnEndChange ) else : data = DataTypeHandler ( column , column [ column_index ] ) data . observe ( lambda change , column_name = column . name , index = column_index , widget = widget : GenericInteractHandler ( widget , change [ "new" ] , column_name , index ) , names = "value" , ) if ( str ( column . dtype ) == "SpanDtype" or str ( column . dtype ) == "TokenSpanDtype" ) : widget_ui = ipw . HBox ( [ data_begin , data_end , text ] ) else : widget_ui = ipw . HBox ( [ data ] ) widget_ui . add_class ( "tep--dfwidget--table-widget" ) cell_widget = ipw . HBox ( children = [ widget_ui ] , layout = ipw . Layout ( justify_content = "flex-end" , margin = "0" ) , ) cell_widget . add_class ( f"tep--dfwidget--row-{column_index}" ) column_items . append ( cell_widget ) else : for column_index in range ( len ( column ) ) : item = column [ column_index ] cell_widget = ipw . HBox ( children = [ ipw . HTML ( f"<div>{str(item)}</div>" ) ] , layout = ipw . Layout ( justify_content = "flex-end" , margin = "0" ) , ) cell_widget . add_class ( f"tep--dfwidget--row-{column_index}" ) column_items . append ( cell_widget ) return ipw . VBox ( children = column_items , layout = ipw . Layout ( border = "0px solid black" ) )
Constructs the widget component representing a single column of data within the
table.
Constructs the widget component representing a single column of data within the table .
"""Constructs the widget component representing a single column of data within the
    table.""" # Begin with the column header. # Branch to create either a static or interactive version of the column. # Build an interactive column. # Call handler to handle columns of different data types # Checks if column is a categorical type and passes in the list of all possible categories as an additional argument if it is # Create a single container for all widget components. # Adds interactive widgets to table. # Build a static column
widget
is_interactive
column
SpanOnBeginChange
SpanOnEndChange
TokenSpanOnBeginChange
TokenSpanOnEndChange