Core Module

Core application module for the GUI-based multiple-arithmetic interpolation project for EAN on CS-Sem2.

This module defines the main App class that handles the GUI structure and properties, user input, arithmetic modes, and computation using interpolation algorithms. It also holds a utility function make_focusable().

Classes:

App: Main project structure and event manager for inputs, computation and output.

Functions:

make_focusable(widget): Makes any Tkinter widget focusable by clicking on it.

class gui.core.App(root_window: tkinter.Tk)

Bases: object

The main class managing all components of the project, used as the main project structure.

This class manages all pieces of the project and connects them into a working structure. It initializes the UI components, structures them correctly within the root window, manages writing outputs and handling user inputs such as button clicks and entry field interactions.

build()

Structure the contents of the app using tkinter’s grid geometry manager, set correct properties for specific widgets.

Returns:

None

calculate_button_func() None

Process input data from entry fields, perform interpolation algorithms, and display results.

This method:
  1. Retrieves values from X, Y and Z entry fields.

  2. Validates that all fields are filled and correctly formatted.

  3. Checks that X and Y lists have the same length and that X contains no duplicate values.

  4. Performs Lagrange and Neville interpolations and calculates Lagrange polynomial coefficients.

  5. Outputs the results using self.write_output().

Returns:

None

Raises:

Exception – If the input data cannot be parsed correctly.

Side effects:

Updates the contents of the output text widget (self.output_box).

debug_mode()

Enable debug mode by coloring the backgrounds of key widgets to clearly show the app layout.

This method must be called explicitly to activate the debug mode. It changes the background colors of main UI elements for debugging purposes.

Returns:

None

Side effects:

Updates the background colors of multiple (but not all) widgets.

display()

Place all the app’s elements in the root window and run the window.

Returns:

None

update_mode()

Update the arithmetic mode for the program’s computations.

This method updates the parser and modifies the input placeholders, as well as allowed character masks for all relevant input fields (X, Y, Z) according to the currently selected mode.

Raises:

Exception – If the current mode key is not valid.

Returns:

None

write_output(output: str)

Overwrite all contents of the output text widget with the given string.

This method clears any existing text in self.output_box and inserts the new content. The widget is temporarily set to editable and then returned to the disabled state to prevent user interaction.

Parameters:

output (str) – The string to display in the output text widget

Returns:

None

gui.core.make_focusable(widget: tkinter.Widget) None

Make any tkinter widget focusable.

Makes any Tkinter widget focusable by clicking on any area that shows it as the topmost layer. Used for allowing defocusing of entry widgets by clicking outside of them.

Parameters:

widget (tk.Widget) – Any tkinter widget

Returns:

None