"""Mockup of multi-camera parameter display.

Designed for 1920x720 area.
"""
import sys
import tkinter as tk
from tkinter import ttk
from tkinter import font

HIGHLIGHT_BACKGROUND = '#2020c0'

class ParamGrid(ttk.Frame):
    def __init__(self, master=None, **kw):
        super().__init__(master, **kw)
        self.master = master
        self.grid_propagate(False)          # use fixed size window specified by caller
        f = font.Font(family='DejaVu Sans', size=38)
        s = ttk.Style()
        s.configure('TLabel', background='black', foreground='white', font=f)
        # s.configure('TLabel', background='#2020c0', foreground='white', font=f)
        s.configure('Status.TLabel', background='green')
        s.configure('Message.TLabel', background='yellow', foreground='black')
        s.configure('Z.TLabel', background=HIGHLIGHT_BACKGROUND)
        self.create_grid()

    def create_grid(self):
        self.cameras_label = ttk.Label(self, text='Cam --')
        self.wb_label = ttk.Label(self, text='WB 6500', style='Z.TLabel')
        self.shutter_label = ttk.Label(self, text='SHUTTER 1/100')
        self.fstop_label = ttk.Label(self, text='F 4.5')
        self.iso_label = ttk.Label(self, text='ISO 2000')
        self.enc_label = ttk.Label(self, text='ProRes 422 LT')
        self.fps_label = ttk.Label(self, text='FPS 59.94')
        self.status_standby_label = ttk.Label(self, text='STANDBY', style='Status.TLabel')
        self.status_recording_label = ttk.Label(self, text='RECORDING', style='Status.TLabel')
        self.error_label = ttk.Label(self, text='ERROR: cam7 shutter', style='Message.TLabel')
        self.noerror_value = ttk.Label(self, text=' ', style='Message.TLabel')

        # minimum sizes for rows and columns
        self.columnconfigure((0,1), minsize=960)

        # padding for labels
        PAD = 10                # padding inside label
        LOFS0 = 300-PAD         # external left padding for column 0
        LOFS1 = 400-PAD         # external left padding for column 1

        # place the labels in the frame: 6 rows, 2 columns
        # row 0: camera number
        self.cameras_label.configure(padding=PAD)
        self.cameras_label.grid(row=0, column=0, columnspan=2)

        # row 1: iso, wb
        self.iso_label.configure(padding=PAD)
        self.iso_label.grid(row=1, column=0, padx=(LOFS0,0), sticky='w')
        self.wb_label.configure(padding=PAD)
        self.wb_label.grid(row=1, column=1, padx=(LOFS1,0), sticky='w')

        # row 2: shutter, fps
        self.shutter_label.configure(padding=PAD)
        self.shutter_label.grid(row=2, column=0, padx=(LOFS0,0), sticky='w')
        self.fps_label.configure(padding=PAD)
        self.fps_label.grid(row=2, column=1, padx=(LOFS1,0), sticky='w')

        # row 3: f-stop, enc
        self.fstop_label.configure(padding=PAD)
        self.fstop_label.grid(row=3, column=0, padx=(LOFS0,0), sticky='w')
        self.enc_label.configure(padding=PAD)
        self.enc_label.grid(row=3, column=1, padx=(LOFS1,0), sticky='w')

        # row 4: status
        self.status_standby_label.configure(padding=(30,20))
        self.status_standby_label.grid(row=4, column=0, columnspan=2)

        # row 5: error message
        self.error_label.grid(row=5, column=0, columnspan=2, sticky='we')
        self.rowconfigure(5, minsize=100)


if __name__ == '__main__':
    root = tk.Tk()
    root.attributes('-fullscreen', True)
    root.configure(background='#cc7722')

    screen_height=1080
    video_height=540
    video_frame = ttk.Frame(root, width=960, height=video_height)
    param_grid = ParamGrid(master=root, width=1920, height=screen_height-video_height)
    ttk.Style().configure('TFrame', background='black')
    video_frame.grid(row=0, column=0)
    param_grid.grid(row=1, column=0)

    print('hello world')
    root.bind('<Escape>', lambda ev: root.destroy())
    root.bind('<Button-1>', lambda ev: root.destroy())
    param_grid.mainloop()
    print('goodbye')
