"""This module manages the GUI settings menu that appears when the program is first run."""
# C:\Users\alda_ik\Documents\04_PROGRAMMING\02_FINAL_PROJECT\gui.py
from tkinter import ttk
from typing import Tuple
from datetime import datetime
import tkinter as tk
import matplotlib.pyplot as plt
[docs]
def update_entry(variable: tk.StringVar, entry: tk.ttk.Entry) -> None:
"""Checks for the parsed state of a variable to enable
or disable its text box.
Args:
variable (tk.StringVar): Container of the variable to check.
entry (tk.ttk.Entry): Container of the value and its state.
"""
if variable.get() == "Auto" or variable.get() == "Full":
# If exposure is automatic, the button will be greyed-out
entry.config(state="disabled")
else:
entry.config(state="normal")
[docs]
def create_graph(
elevation_in, payload
) -> Tuple[plt.figure, plt.axes, plt.hlines, list, list]:
"""Creates the live graph displayed in the GUI:
1. Creates the plot with an specific size, position, title and labels.
2. If a payload with full elevation range has been chosen, the graph will be smaller
to acomodate the link budget graph.
3. Initializes the data for the graph.
Args:
elevation_in (tk.StringVar): Container of the elevation mode (Individual or Full).
payload (tk.StringVar): Container of the payload used (None, KIODO, OsirisV1, Osiris4CubeSat, CubeCat).
Returns:
tuple[plt.figure, plt.axes, plt.hlines, list, list]: fig (plt.figure): Figure of the created plot.
ax (plt.axes): Axes of the created plot.
line (plt.hlines): Lines of the created plot.
xdata (list): X-axis data from the created plot.
ydata (list): Y-axis data from the created plot.
"""
# Create figure and axis objects
fig, ax = plt.subplots()
if elevation_in.get() == "Full" and payload.get() != "None":
# Size and position of the intensity graph.
fig.set_size_inches(5.38, 3.3)
fig.canvas.manager.window.wm_geometry("+5+290")
fig.subplots_adjust(left=0.11, right=0.95, top=0.92, bottom=0.13)
else:
fig.set_size_inches(8.9, 3.3)
fig.canvas.manager.window.wm_geometry("+5+290")
fig.subplots_adjust(left=0.08, right=0.97, top=0.92, bottom=0.13)
(line,) = ax.plot([], [], lw=2)
ax.set_ylim(0, 255)
ax.grid()
if payload.get() != "None":
ax.set_title(
f"{payload.get()} downlink on {datetime.now().strftime('%Y-%m-%d')}"
)
else:
ax.set_title(f"Downlink on {datetime.now().strftime('%Y-%m-%d')}")
ax.set_xlabel("Time [UTC]")
ax.set_ylabel("Brightness")
# Initialize empty data
xdata, ydata = [], []
return fig, ax, line, xdata, ydata