grapher/gui.py

113 lines
4.3 KiB
Python
Raw Normal View History

2025-01-31 14:34:57 +01:00
"""
Student Analyzer Application
This script initializes and runs the Student Analyzer application, which provides an interface for
managing student data, class records, and submissions. It uses the Hello ImGui framework for UI rendering
and integrates a database to store and manipulate student information.
Modules:
- Custom Imports: Imports internal models and application state.
- Layouts: Defines different UI layouts for the analyzer and database editor.
- External Libraries: Uses imgui_bundle and Hello ImGui for UI rendering.
- Built-in Libraries: Uses shelve for persistent state storage and typing for type hints.
"""
2025-01-24 12:33:03 +01:00
# Custom
2025-01-31 14:34:57 +01:00
from model import * # Importing database models like Class, Student, Lecture, and Submission
from appstate import AppState, LOG_ERROR # Application state management
2025-01-24 12:33:03 +01:00
# Layouts
2025-01-31 14:34:57 +01:00
from analyzer import analyzer_layout # Main layout for the analyzer
from database import database_editor_layout # Alternative layout for database editing
2025-01-24 12:33:03 +01:00
# External
2025-01-31 14:34:57 +01:00
from imgui_bundle import imgui, immapp, hello_imgui, ImVec2 # ImGui-based UI framework
2025-01-24 12:33:03 +01:00
2025-01-31 14:34:57 +01:00
# Built-in
import shelve # Persistent key-value storage
from typing import List # Type hinting
2025-01-05 01:01:39 +01:00
2025-01-24 12:33:03 +01:00
def menu_bar(runner_params: hello_imgui.RunnerParams) -> None:
2025-01-31 14:34:57 +01:00
"""Defines the application's menu bar."""
try:
hello_imgui.show_app_menu(runner_params)
hello_imgui.show_view_menu(runner_params)
if imgui.begin_menu("File"):
clicked, _ = imgui.menu_item("Open", "", False)
if clicked:
pass # TODO: Implement file opening logic
imgui.end_menu()
except Exception as e:
LOG_ERROR(f"menu_bar {e}")
2025-01-05 01:01:39 +01:00
2025-01-24 12:33:03 +01:00
def status_bar(app_state: AppState) -> None:
2025-01-31 14:34:57 +01:00
"""Displays the status bar information."""
try:
imgui.text("Student Analyzer by @DerGrumpf")
except Exception as e:
LOG_ERROR(f"status_bar {e}")
2025-01-24 12:33:03 +01:00
def main() -> None:
2025-01-31 14:34:57 +01:00
"""Main function to initialize and run the application."""
2025-01-24 12:33:03 +01:00
app_state = AppState()
2025-01-31 14:34:57 +01:00
# Load Database
try:
with shelve.open("state") as state:
v = state.get("DB") # Retrieve stored database connection info
if v:
db.init(v)
db.connect()
db.create_tables([Class, Student, Lecture, Submission, Group]) # Ensure tables exist
app_state.update()
except Exception as e:
LOG_ERROR(f"Database Initialization {e}")
2025-01-05 01:01:39 +01:00
2025-01-31 14:34:57 +01:00
# Set Window Parameters
2025-01-24 12:33:03 +01:00
runner_params = hello_imgui.RunnerParams()
runner_params.app_window_params.window_title = "Analyzer"
runner_params.imgui_window_params.menu_app_title = "Analyzer"
runner_params.app_window_params.window_geometry.size = (1000, 900)
runner_params.app_window_params.restore_previous_geometry = True
runner_params.app_window_params.borderless = True
runner_params.app_window_params.borderless_movable = True
runner_params.app_window_params.borderless_resizable = True
runner_params.app_window_params.borderless_closable = True
2025-01-05 01:01:39 +01:00
2025-01-31 14:34:57 +01:00
# Configure UI Elements
2025-01-24 12:33:03 +01:00
runner_params.imgui_window_params.show_menu_bar = True
runner_params.imgui_window_params.show_menu_app = False
runner_params.imgui_window_params.show_menu_view = False
runner_params.imgui_window_params.show_status_bar = True
runner_params.callbacks.show_menus = lambda: menu_bar(runner_params)
runner_params.callbacks.show_status = lambda: status_bar(app_state)
2025-01-31 14:34:57 +01:00
2025-01-24 12:33:03 +01:00
# Application layout
runner_params.imgui_window_params.default_imgui_window_type = (
hello_imgui.DefaultImGuiWindowType.provide_full_screen_dock_space
2025-01-09 22:33:04 +01:00
)
2025-01-31 14:34:57 +01:00
runner_params.imgui_window_params.enable_viewports = True
2025-01-24 12:33:03 +01:00
runner_params.docking_params = analyzer_layout(app_state)
runner_params.alternative_docking_layouts = [
database_editor_layout(app_state)
]
# Save App Settings
runner_params.ini_folder_type = hello_imgui.IniFolderType.app_user_config_folder
runner_params.ini_filename = "Analyzer/Analyzer.ini"
runner_params.docking_params.layout_condition = hello_imgui.DockingLayoutCondition.application_start
2025-01-31 14:34:57 +01:00
# Run the Application
2025-01-24 12:33:03 +01:00
add_ons_params = immapp.AddOnsParams()
add_ons_params.with_markdown = True
add_ons_params.with_implot = True
add_ons_params.with_implot3d = True
2025-01-31 14:34:57 +01:00
2025-01-24 12:33:03 +01:00
immapp.run(runner_params, add_ons_params)
2025-01-31 14:34:57 +01:00
2025-01-24 12:33:03 +01:00
if __name__ == "__main__":
main()