import tkinter as tk
import tk_tools
from .Plot import Plot
from .globals import *

import matplotlib
from matplotlib.backends.backend_tkagg import (
    FigureCanvasTkAgg, NavigationToolbar2Tk)
from matplotlib.figure import Figure
from matplotlib import style


class Page_1(tk.Frame):
  def __init__(self, parent, controller):
    tk.Frame.__init__(self, parent)
    self.t = 0
    self.controller = controller

    # graph
    self.serialPlot = Plot(20)
    canvas = FigureCanvasTkAgg(self.serialPlot.fig, self)
    canvas.draw()
    canvas.get_tk_widget().pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
    canvas._tkcanvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
    # right menu
    left = tk.Frame(self, borderwidth=2, relief="solid")
    container = tk.Frame(left, borderwidth=2, relief="solid")
    label1 = tk.Label(container, text="I could be a canvas, but I'm a label right now")

    self.label4 = tk.Label(self,font=("Arial","30"),fg="red")
    self.label4.pack()
    self.label4.config(text=str(self.t))

    SendButton = tk.Button(left, text='Quit', command=quit)
    label2 = tk.Label(left, text="I could be a button")
    label3 = tk.Label(left, text="So could I")

    left.pack(side="left", expand=True, fill="both")
    container.pack(expand=True, fill="both", padx=7, pady=5)
    SendButton.pack()

    label1.pack()
    label2.pack()
    label3.pack()

    controller.pid.SetPoint = 0.4 # m/s

  def update(self):
    self.serialPlot.update(self.controller.getLastValue("force_X_1"))
    self.label4.config(text="{:3d} Nm".format(3))