Skip to content

App

App

Bases: CTk

Frontend for evaluating generated BCO domains from BcoRag.

Source code in evaluator/frontend/app.py
class App(ctk.CTk):
    """Frontend for evaluating generated BCO domains from
    BcoRag.
    """

    def __init__(self):
        """Constructor."""
        super().__init__()
        init_data = app_start.initialization()

        self.attributes = init_data

        self.title("BCO RAG Evaluator")
        self.geometry(f"{1920}x{1080}")

        self.grid_columnconfigure(0, weight=1)
        self.grid_rowconfigure(0, weight=1)

        self.login_screen = LoginScreen(
            master=self,
            attributes=self.attributes,
            on_login=login,
            on_login_success=self._login_success,
            on_exit=misc.exit_app,
        )

    def start(self):
        """Start the app main loop."""
        self.mainloop()

    def navigate(
        self, direction: Literal[-1, 1], run_index: int, app_state: AppState
    ) -> None:
        """Callback to execute when the user presses
        the next or previous buttons.

        Parameters
        ----------
        direction : -1 or 1
            Indicates the direction the user is navigating,
            -1 for previous, 1 for next.
        run_index : int
            The new run index being navigated to.
        app_state : AppState
            The current app state.
        """
        self.app_state = app_state
        updated_run_state = state.load_run_state(
            run_index=run_index,
            total_runs=self.run["total_runs"],
            app_state=self.app_state,
        )
        self.view_page.update_state(
            app_state=self.app_state, run_state=updated_run_state
        )

    def _login_success(self, app_state: AppState) -> None:
        """Callback to execute on login success."""
        self.app_state = app_state
        self.login_screen.grid_forget()
        self.intermediate_screen = IntermediateScreen(
            master=self, on_start=self._on_start, app_state=self.app_state
        )

    def _on_start(self, app_state: AppState) -> None:
        """Callback to execute on evaluation start."""
        self.intermediate_screen.grid_forget()
        self.app_state = app_state
        # create init run state
        init_run_state = app_start.create_init_run_state(app_state)
        self.run = init_run_state
        self.view_page = ViewPage(
            master=self,
            app_state=self.app_state,
            run_state=init_run_state,
            navigate=self.navigate,
            on_save=state.save_state,
            on_exit=misc.exit_app,
        )

__init__()

Constructor.

Source code in evaluator/frontend/app.py
def __init__(self):
    """Constructor."""
    super().__init__()
    init_data = app_start.initialization()

    self.attributes = init_data

    self.title("BCO RAG Evaluator")
    self.geometry(f"{1920}x{1080}")

    self.grid_columnconfigure(0, weight=1)
    self.grid_rowconfigure(0, weight=1)

    self.login_screen = LoginScreen(
        master=self,
        attributes=self.attributes,
        on_login=login,
        on_login_success=self._login_success,
        on_exit=misc.exit_app,
    )

start()

Start the app main loop.

Source code in evaluator/frontend/app.py
def start(self):
    """Start the app main loop."""
    self.mainloop()

navigate(direction, run_index, app_state)

Callback to execute when the user presses the next or previous buttons.

Parameters:

Name Type Description Default
direction -1 or 1

Indicates the direction the user is navigating, -1 for previous, 1 for next.

required
run_index int

The new run index being navigated to.

required
app_state AppState

The current app state.

required
Source code in evaluator/frontend/app.py
def navigate(
    self, direction: Literal[-1, 1], run_index: int, app_state: AppState
) -> None:
    """Callback to execute when the user presses
    the next or previous buttons.

    Parameters
    ----------
    direction : -1 or 1
        Indicates the direction the user is navigating,
        -1 for previous, 1 for next.
    run_index : int
        The new run index being navigated to.
    app_state : AppState
        The current app state.
    """
    self.app_state = app_state
    updated_run_state = state.load_run_state(
        run_index=run_index,
        total_runs=self.run["total_runs"],
        app_state=self.app_state,
    )
    self.view_page.update_state(
        app_state=self.app_state, run_state=updated_run_state
    )

_login_success(app_state)

Callback to execute on login success.

Source code in evaluator/frontend/app.py
def _login_success(self, app_state: AppState) -> None:
    """Callback to execute on login success."""
    self.app_state = app_state
    self.login_screen.grid_forget()
    self.intermediate_screen = IntermediateScreen(
        master=self, on_start=self._on_start, app_state=self.app_state
    )

_on_start(app_state)

Callback to execute on evaluation start.

Source code in evaluator/frontend/app.py
def _on_start(self, app_state: AppState) -> None:
    """Callback to execute on evaluation start."""
    self.intermediate_screen.grid_forget()
    self.app_state = app_state
    # create init run state
    init_run_state = app_start.create_init_run_state(app_state)
    self.run = init_run_state
    self.view_page = ViewPage(
        master=self,
        app_state=self.app_state,
        run_state=init_run_state,
        navigate=self.navigate,
        on_save=state.save_state,
        on_exit=misc.exit_app,
    )