# The code for changing pages was derived from: http://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter
# License: http://creativecommons.org/licenses/by-sa/3.0/	

from analogPressure.sdpArray import SdpArray
from digitalPressure.spd610Array import Spd610Array
from wirelessLoadCell.loadCells import LoadCells
from ui import *

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

import tkinter as tk
import tk_tools
from time import *

LARGE_FONT= ("Verdana", 12)
style.use("ggplot")
       

class Main(tk.Tk):
  def __init__(self, *args, **kwargs):
    tk.Tk.__init__(self, *args, **kwargs)
    tk.Tk.wm_title(self, "Windkanal-Tool")
    
    
    container = tk.Frame(self)
    container.pack(side="top", fill="both", expand = True)
    container.grid_rowconfigure(0, weight=1)
    container.grid_columnconfigure(0, weight=1)


    menubar = tk.Menu(container)
    filemenu = tk.Menu(menubar, tearoff=0)
    filemenu.add_command(label="Save settings", command = lambda: self.popupmsg("Not supported just yet!"))
    filemenu.add_separator()
    filemenu.add_command(label="Exit", command=quit)
    menubar.add_cascade(label="File", menu=filemenu)

    tk.Tk.config(self, menu=menubar)

    self.frames = {}

    for F in (Page_1, Page_2, Page_3, Page_4):

      frame = F(container, self)

      self.frames[F] = frame

      frame.grid(row=0, column=0, sticky="nsew")

    self.show_frame(Page_1)

  def show_frame(self, cont):
    frame = self.frames[cont]
    frame.tkraise()

  def popupmsg(self, msg=""):
      popup = tk.Toplevel(self.master)
      popup.wm_title("Error!")
      label = tk.Label(popup, text=msg, font=LARGE_FONT)
      label.pack(side="top", fill="x", pady=10)
      b1 = tk.Button(popup, text="Okay", command=popup.destroy)
      b1.pack()
  def interval(self):
    
    for frame in self.frames:
      frame.update()

    self.after(300,self.interval)

          