Source code for interface.home

"""
Frontend Home Page File for AGE-ABM Visual Interface
@Author Meghan Ireland
@Co-Authors Max Hall and Matthew Fleischman

"""

import tkinter as tk
import customtkinter
import backend.backend as bk
from visuals import visual
from math import ceil, floor
[docs] class Home: """Defines the home page functionality. """ def __init__(self, ec_app_ui): """Creates widgets for the home class. """ self.ec_app_ui = ec_app_ui ### Labels ### self.label_home_project_name = tk.Label(self.ec_app_ui.page_frame , text = "Enter Project Name:", font = self.ec_app_ui.font2 , bg = self.ec_app_ui.frame_colour, fg = self.ec_app_ui.label_text_colour) self.label_home_welcome = tk.Label(self.ec_app_ui.title_frame, text="Welcome to ECApp!", font=self.ec_app_ui.font1, fg=self.ec_app_ui.label_text_colour ,bg=self.ec_app_ui.title_colour) ### Entry ### self.entry_home_model_name = customtkinter.CTkEntry(self.ec_app_ui.page_frame , font = self.ec_app_ui.font2, height=self.ec_app_ui.entry_height , width=self.ec_app_ui.entry_height*8,fg_color = self.ec_app_ui.entry_colour , text_color = self.ec_app_ui.entry_text_colour) ### Buttons ### self.button_home_make_model = customtkinter.CTkButton(self.ec_app_ui.page_frame , hover_color=self.ec_app_ui.highlight_colour, text="Start\nNew Project" , command=self.btn_home_make_model, fg_color=self.ec_app_ui.comp_btn_colour , font = self.ec_app_ui.font2 , height=2*self.ec_app_ui.entry_height, width=self.ec_app_ui.entry_width) self.button_home_make_exist_model = customtkinter.CTkButton(self.ec_app_ui.page_frame , hover_color=self.ec_app_ui.highlight_colour, text="Upload\nExisting Project" , command=self.btn_home_make_exist_model, fg_color=self.ec_app_ui.comp_btn_colour , font = self.ec_app_ui.font2, height=2*self.ec_app_ui.entry_height , width=self.ec_app_ui.entry_width) self.canvas = tk.Canvas(self.ec_app_ui.title_frame, width=1000, height=3) ### Home Tab ###
[docs] def clear_home(self): """Clears home page. """ self.label_home_welcome.grid_forget() self.label_home_project_name.grid_forget() self.entry_home_model_name.grid_forget() self.button_home_make_model.grid_forget() self.button_home_make_exist_model.grid_forget() self.canvas.grid_forget()
[docs] def home_tab_btn(self): """Places widgets for the home page. """ self.ec_app_ui.clear_all() self.label_home_welcome.grid(row = 0, column = 0) self.label_home_project_name.grid(row = 0, column = 0, pady=40) self.entry_home_model_name.delete(0,'end') self.entry_home_model_name.grid(row = 0, column = 2) self.button_home_make_model.grid(row = 1, column = 2, pady=5) self.button_home_make_exist_model.grid(row = 2, column = 2, pady=5)
[docs] def btn_home_make_model(self): """Saves model into the backend. """ self.ec_app_ui.new_model = bk.ModelEnv(self.entry_home_model_name.get()) self.ec_app_ui.visual = visual.VisualEnv(self.ec_app_ui.new_model) self.clear_home() self.ec_app_ui.home_save_button.configure(state = "normal" , command = self.ec_app_ui.new_model.store_model) self.ec_app_ui.home_tab_button.configure(state = "disabled") self.ec_app_ui.libraries.libraries_tab_btn() self.ec_app_ui.enable()
[docs] def btn_home_make_exist_model(self): """Loads new model into the backend. """ filename = tk.filedialog.askopenfilename() if filename != "": self.ec_app_ui.new_model = bk.ModelEnv(exist_proj = filename) self.ec_app_ui.visual = visual.VisualEnv(self.ec_app_ui.new_model) self.ec_app_ui.home_tab_button.configure(state = "disabled") self.clear_home() self.ec_app_ui.libraries.libraries_tab_btn() self.ec_app_ui.home_save_button.configure(state = "normal" , command = self.ec_app_ui.new_model.store_model) self.ec_app_ui.enable()