{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: IMPORTS\n",
    "Code block: import statemants.\n",
    "'''\n",
    "\n",
    "import io\n",
    "import codecs\n",
    "\n",
    "import ipywidgets as ipw\n",
    "from pandas import set_option as set_option\n",
    "from pprint import pprint\n",
    "\n",
    "import geomacc as gma\n",
    "\n",
    "%matplotlib widget"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: DEFAULT APP LAYOUT\n",
    "Codeblock: default objects of main window are defined\n",
    "    here. Mainly for development purposes.\n",
    "\n",
    "## Docasna definice boxu v AppLayout\n",
    "Abych si na zacatku mel vubec co zobrazit,\n",
    "definuju si tady (zbytecnou) funkci pro\n",
    "vyrobu tlacitek a nasledne tlacitka, kterymi\n",
    "zaplnim prostor v AppLayout.\n",
    "'''\n",
    "\n",
    "def create_button(description, button_style):\n",
    "    return ipw.Button(\n",
    "        description=description,\n",
    "        button_style=button_style,\n",
    "        layout=ipw.Layout(height='auto', width='auto'),)\n",
    "\n",
    "header = create_button(\"Here shall be the HEADER\", 'info')\n",
    "footer = create_button(\"FOOTER\", 'info')\n",
    "left = create_button(\"LEFT PANE\", 'success')\n",
    "right = create_button(\"RIGHT PANE\", 'danger')\n",
    "\n",
    "with open(\"static/images/mesh_surface_low_res.jpg\", \"rb\") as f:\n",
    "    center_image = f.read()\n",
    "center = ipw.Image(\n",
    "    value=center_image,\n",
    "    format='jpg',\n",
    "    width='auto',\n",
    "    height='auto',\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: MAIN BOX - HEADER\n",
    "Code block: V tomto bloku je kompletni definice okna header\n",
    "    na pozici header v main boxu.\n",
    "\n",
    "## DEFINICE 'HEADER' V MAIN_BOX\n",
    "\n",
    "V teto bunce je definovana konecna podoba headeru.\n",
    "'''\n",
    "\n",
    "# Docasna podoba - TO DO HERE\n",
    "file_header = open('static/images/header.png', 'rb')\n",
    "image_header = file_header.read()\n",
    "\n",
    "header_box_layout = ipw.Layout(\n",
    "    display='flex',\n",
    "    flex_flow='column',\n",
    "    align_items='stretch',\n",
    "    width='100%',\n",
    "    height='100%',\n",
    "    border='solid 1px',\n",
    "    grid_area='header',\n",
    ")\n",
    "header_box = ipw.Image(\n",
    "    value=image_header,\n",
    "    format='png',\n",
    "    width='auto',\n",
    "    height=44,\n",
    "    layout=header_box_layout\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: MAIN BOX - FOOTER\n",
    "Code block: V tomto bloku je kompletni definice okna footer\n",
    "    na pozici footer v main boxu.\n",
    "\n",
    "## DEFINICE 'FOOTER' V MAIN_BOX\n",
    "\n",
    "V teto bunce je definovana konecna podoba footer.\n",
    "'''\n",
    "\n",
    "# Docasna podoba - TO DO HERE\n",
    "file_footer = open('static/images/footer.png', 'rb')\n",
    "image_footer = file_footer.read()\n",
    "\n",
    "footer_box_layout = ipw.Layout(\n",
    "    display='flex',\n",
    "    flex_flow='column',\n",
    "    align_items='stretch',\n",
    "    width='100%',\n",
    "    height='100%',\n",
    "    border='solid 1px',\n",
    "    grid_area='footer',\n",
    ")\n",
    "footer_box = ipw.Image(\n",
    "    value=image_footer,\n",
    "    format='png',\n",
    "    width='auto',\n",
    "    height='auto',\n",
    "    layout=footer_box_layout\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: MAIN BOX - LEFT SIDEBAR\n",
    "Code block: V tomto bloku je kompletni definice okna left sidebar\n",
    "    na pozici left sidebar v main boxu.\n",
    "\n",
    "## DEFINICE LEFT_BOX NA POZICI LEFT_SIDEBAR V APPLAYOUT\n",
    "\n",
    "V teto bunce je definovana konecna podoba okna LEFT_BOX.\n",
    "'''\n",
    "button_lb_home = ipw.Button(\n",
    "    description='Home Screen',\n",
    "    disabled=False,\n",
    "    button_style='', # 'success', 'info', 'warning', 'danger' or ''\n",
    "    tooltip='Go to home screen for initial information.',\n",
    "    icon='home',\n",
    ")\n",
    "\n",
    "button_lb_data_load = ipw.Button(\n",
    "    description='Data Load',\n",
    "    disabled=False,\n",
    "    button_style='', # 'success', 'info', 'warning', 'danger' or ''\n",
    "    tooltip='Load data from file <name>.rtl exported from \"Carto Explore\"',\n",
    "    icon='folder',\n",
    ")\n",
    "\n",
    "button_lb_data_view = ipw.Button(\n",
    "    description='Data View',\n",
    "    disabled=False,\n",
    "    button_style='',\n",
    "    tooltip='View imported data. Filtr, what should be calculated.',\n",
    "    icon='table',\n",
    ")\n",
    "\n",
    "button_lb_compute = ipw.Button(\n",
    "    description='Compute',\n",
    "    disabled=False,\n",
    "    button_style='',\n",
    "    tooltip='Compute geometric accuracy data/statistics.',\n",
    "    icon='bar-chart',\n",
    ")\n",
    "\n",
    "button_lb_compensate = ipw.Button(\n",
    "    description='Compensate',\n",
    "    disabled=False,\n",
    "    button_style='',\n",
    "    tooltip='Compute compensation table and export it to machine ready file.',\n",
    "    icon='calculator',\n",
    ")\n",
    "\n",
    "button_lb_history = ipw.Button(\n",
    "    description='History',\n",
    "    disabled=False,\n",
    "    button_style='',\n",
    "    tooltip='Browse history.',\n",
    "    icon='history',\n",
    ")\n",
    "\n",
    "out = ipw.Output()\n",
    "\n",
    "def home_on_click(_):\n",
    "    with out:\n",
    "        #update_main_box(center=window_data_load)\n",
    "        update_main_box(position='center', new_window=window_home)\n",
    "        \n",
    "def data_load_on_click(_):\n",
    "    with out:\n",
    "        #update_main_box(center=window_data_load)\n",
    "        update_main_box(position='center', new_window=window_data_load)\n",
    "\n",
    "def data_view_on_click(_):\n",
    "    with out:\n",
    "        #update_main_box(center=window_data_view)\n",
    "        update_main_box(position='center', new_window=window_data_view)\n",
    "\n",
    "def compute_on_click(_):\n",
    "    with out:\n",
    "        #update_main_box(center=window_compute)\n",
    "        update_main_box(position='center', new_window=window_compute)\n",
    "\n",
    "def compensate_on_click(_):\n",
    "    with out:\n",
    "        #update_main_box(center=window_compensate)\n",
    "        update_main_box(position='center', new_window=window_compensate)\n",
    "\n",
    "def history_on_click(_):\n",
    "    with out:\n",
    "        #update_main_box(center=window_history)\n",
    "        update_main_box(position='center', new_window=window_history)\n",
    "\n",
    "\n",
    "#button_lb_data_load.on_click(update_main_box_on_click(window_data_load))\n",
    "button_lb_home.on_click(home_on_click)\n",
    "button_lb_data_load.on_click(data_load_on_click)\n",
    "button_lb_data_view.on_click(data_view_on_click)\n",
    "button_lb_compute.on_click(compute_on_click)\n",
    "button_lb_compensate.on_click(compensate_on_click)\n",
    "button_lb_history.on_click(history_on_click)\n",
    "\n",
    "# Konstrukce left_box, ktery je umisten v left_sidebar.\n",
    "left_box_layout = ipw.Layout(\n",
    "    display='flex',\n",
    "    flex_flow='column',\n",
    "    overflow='auto',\n",
    "    align_items='stretch',\n",
    "    width='160px',\n",
    "    height='100%',\n",
    "    grid_area='left_sidebar',\n",
    ")\n",
    "\n",
    "left_box = ipw.VBox(\n",
    "    [\n",
    "        button_lb_home,\n",
    "        button_lb_data_load,\n",
    "        button_lb_data_view,\n",
    "        button_lb_compute,\n",
    "        button_lb_compensate,\n",
    "        button_lb_history,\n",
    "    ],\n",
    "    layout=left_box_layout,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: CENTER = HOME\n",
    "Code block: V tomto bloku je kompletni definice PODokna Home Screen\n",
    "    na pozici center v main boxu.\n",
    "\n",
    "## DEFINICE OKNA NA POZICI CENTER PRO HOME\n",
    "\n",
    "V teto bunce je definovana konecna podoba okna DATA LOAD.\n",
    "'''\n",
    "\n",
    "window_home = ipw.Image(\n",
    "    value=center_image,\n",
    "    format='jpg',\n",
    "    width='auto',\n",
    "    height='auto',\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: CENTER = DATA LOAD\n",
    "Code block: V tomto bloku je kompletni definice PODokna Data Load\n",
    "    na pozici center v main boxu.\n",
    "\n",
    "## DEFINICE OKNA NA POZICI CENTER PRO DATA LOAD\n",
    "\n",
    "V teto bunce je definovana konecna podoba okna DATA LOAD.\n",
    "'''\n",
    "\n",
    "# Docasna podoba - TO DO HERE\n",
    "button_data_load_1 = ipw.Button(\n",
    "    description='Load File',\n",
    "    disabled=False,\n",
    "    button_style='',\n",
    "    tooltip='Opens up a browse window to locate <name>.rtl file.',\n",
    "    icon='file',\n",
    ")\n",
    "\n",
    "button_data_load_1_out = ipw.Output()\n",
    "\n",
    "\n",
    "def button_data_load_1_click(_):\n",
    "    \"\"\"\n",
    "    \n",
    "    \"\"\"\n",
    "\n",
    "    source_path = gma.core.dialog()\n",
    "    global varfile_str, varfile_list\n",
    "    varfile_str, varfile_list = gma.core.load_into_var(source_path)\n",
    "\n",
    "    def load_to_df():\n",
    "        Norm_0.data_raw = gma.core.ReadFromRTL.extract_section(\n",
    "            varfile_list,\n",
    "            'Run Target Data:',\n",
    "            '\\n',\n",
    "        )\n",
    "        data_df = gma.core.load_to_df(Norm_0.data_raw)\n",
    "        return data_df\n",
    "\n",
    "    Norm_0.tabulka= load_to_df()\n",
    "    set_option('display.max_rows', 999)\n",
    "    set_option('display.min_rows', 30)\n",
    "    button_data_load_1_out.clear_output()\n",
    "\n",
    "    with button_data_load_1_out:\n",
    "        print(\"Data successfully loaded\")\n",
    "        display(Norm_0.tabulka)\n",
    "\n",
    "\n",
    "button_data_load_1.on_click(button_data_load_1_click)\n",
    "\n",
    "\n",
    "# Upload Button\n",
    "file_picker = ipw.FileUpload(\n",
    "    accept='.rtl',  # Accepted file extension e.g. '.txt', '.pdf', 'image/*', 'image/*,.pdf'\n",
    "    multiple=False,  # True to accept multiple files upload else False\n",
    ")\n",
    "\n",
    "\n",
    "def change_input(change):\n",
    "    \"\"\"\n",
    "    \n",
    "    \"\"\"\n",
    "    \n",
    "    test_uploaded_data = file_picker.value['example_short.rtl']['content']\n",
    "    global varfile_list\n",
    "    varfile_list = io.StringIO(codecs.decode(test_uploaded_data, encoding='utf-8-sig'))\n",
    "    \n",
    "    def load_to_df():\n",
    "        Norm_0.data_raw = gma.core.ReadFromRTL.extract_section(\n",
    "            varfile_list,\n",
    "            'Run Target Data:',\n",
    "            '\\n',\n",
    "        )\n",
    "        data_df = gma.core.load_to_df(Norm_0.data_raw)\n",
    "        return data_df\n",
    "\n",
    "    Norm_0.tabulka= load_to_df()\n",
    "    set_option('display.max_rows', 999)\n",
    "    set_option('display.min_rows', 30)\n",
    "    button_data_load_1_out.clear_output()\n",
    "\n",
    "    with button_data_load_1_out:\n",
    "        print(\"Data successfully loaded\")\n",
    "        display(Norm_0.tabulka)\n",
    "    \n",
    "\n",
    "file_picker.observe(change_input, 'value')\n",
    "\n",
    "\n",
    "windows_data_load_layout = ipw.Layout(\n",
    "    display='flex',\n",
    "    flex_flow='row',\n",
    "    align_items='stretch',\n",
    "    width='100%',\n",
    "    height='100%',\n",
    "    border='solid 1px',\n",
    "    grid_area='center',\n",
    ")\n",
    "window_data_load = ipw.Box([\n",
    "    ipw.HBox([\n",
    "        button_data_load_1,\n",
    "        button_data_load_1_out,\n",
    "        file_picker,\n",
    "    ], layout=windows_data_load_layout)\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: CENTER = DATA VIEW\n",
    "Code block: V tomto bloku je kompletni definice PODokna Data View\n",
    "    na pozici center v main boxu.\n",
    "\n",
    "## DEFINICE OKNA NA POZICI CENTER PRO DATA VIEW\n",
    "\n",
    "V teto bunce je definovana konecna podoba okna DATA VIEW.\n",
    "'''\n",
    "\n",
    "# Docasna podoba - TO DO HERE\n",
    "'''\n",
    "window_data_view = ipw.Button(\n",
    "    description='Data View Window.',\n",
    "    disabled=False,\n",
    "    button_style='',\n",
    "    tooltip='Browse history.',\n",
    "    icon='victory',\n",
    ")\n",
    "'''\n",
    "window_data_view = ipw.Textarea(\n",
    "    value='Tady bude okno pro interaktivni prohlizeni \\\n",
    "    nactenych dat. Bude mozne hodnoty seskupovat, filtrovat \\\n",
    "    mozna i editovat.',\n",
    "    description='TO DO:',\n",
    "    disabled=False\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: COMPUTE HEADER\n",
    "Code block: V tomto bloku je kompletni definice PODokna Header\n",
    "    na pozici header okna Compute, ktere je na pozici center\n",
    "    v main boxu.\n",
    "'''\n",
    "\n",
    "\n",
    "compute_header_status = ipw.Text(\n",
    "    value='Ready',\n",
    "    placeholder='',\n",
    "    description='Computation Status:',\n",
    "    disabled=False,\n",
    ")\n",
    "\n",
    "\n",
    "### BUTTON START\n",
    "button_compute_header_run = ipw.Button(\n",
    "    description='Run',\n",
    "    disabled=False,\n",
    "    button_style='', # 'success', 'info', 'warning', 'danger' or ''\n",
    "    tooltip='Run the calculation.',\n",
    "    icon='',\n",
    ")\n",
    "\n",
    "\n",
    "def button_compute_run_onclick(b):\n",
    "    compute_proccess()\n",
    "    with out_iso230x2x2014:\n",
    "        display(Norm_0.fig)\n",
    "    with out_iso230x2x2014:\n",
    "        pprint(Norm_0.stats.main_stats)\n",
    "    update_iso230x2x2014(out_iso230x2x2014)\n",
    "\n",
    "\n",
    "button_compute_header_run.on_click(button_compute_run_onclick)\n",
    "### BUTTON END\n",
    "\n",
    "\n",
    "compute_header_layout = ipw.Layout(\n",
    "    display='flex',\n",
    "    flex_flow='row',\n",
    "    align_items='stretch',\n",
    "    width='100%',\n",
    "    height='100%',\n",
    "    border='solid 1px',\n",
    "    grid_area='compute_header',\n",
    ")\n",
    "\n",
    "compute_header = ipw.HBox([\n",
    "    compute_header_status,\n",
    "    button_compute_header_run,\n",
    "    ], layout=compute_header_layout,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: COMPUTE LEFT SIDEBAR\n",
    "Code block: V tomto bloku je kompletni definice PODokna Left Sidebar\n",
    "    na pozici left sidebar okna Compute, ktere je na pozici center\n",
    "    v main boxu.\n",
    "'''\n",
    "\n",
    "compute_left_sidebar_iso230_2 = ipw.Button(\n",
    "    description='ISO 230-2:2014',\n",
    "    disabled=False,\n",
    "    button_style='', # 'success', 'info', 'warning', 'danger' or ''\n",
    "    tooltip='Calculation according to ISO 230-2:2014',\n",
    "    icon='lightbulb-o',\n",
    ")\n",
    "\n",
    "\n",
    "def update_compute_center(**kwargs):\n",
    "    set_position = kwargs['position']\n",
    "    set_new_window = kwargs['new_window']\n",
    "    '''\n",
    "    V nasledujici IF funkci odpovidaji prirazena\n",
    "    cisla radkum v definici main_box:\n",
    "        0 = 0. radek = compute_header\n",
    "        1 = 1. radek = compute_left_sidebar\n",
    "        2 = 2. radek = compute_center\n",
    "    '''\n",
    "    if set_position == 'header': i = 0\n",
    "    elif set_position == 'left_sidebar': i = 1\n",
    "    elif set_position == 'center': i = 2\n",
    "    temp = list(window_compute.children)\n",
    "    temp[i] = set_new_window\n",
    "    window_compute.children = tuple(temp)\n",
    "    display(window_compute)\n",
    "\n",
    "\n",
    "def compute_left_sidebar_iso230_2_onclick(_):\n",
    "    update_compute_center(position='center', new_window=compute_center_iso230x2x2014)\n",
    "\n",
    "    \n",
    "compute_left_sidebar_iso230_2.on_click(compute_left_sidebar_iso230_2_onclick)\n",
    "\n",
    "compute_left_sidebar_layout = ipw.Layout(\n",
    "    display='flex',\n",
    "    flex_flow='row',\n",
    "    align_items='stretch',\n",
    "    width='100%',\n",
    "    height='100%',\n",
    "    border='solid 1px',\n",
    "    grid_area='compute_left_sidebar',\n",
    ")\n",
    "compute_left_sidebar = ipw.VBox(\n",
    "    [\n",
    "        compute_left_sidebar_iso230_2\n",
    "    ],\n",
    "    layout=compute_left_sidebar_layout,\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: COMPUTE CENTER iso230x2x2014\n",
    "Code block: V tomto bloku je kompletni definice PODokna Center\n",
    "    pro normu iso230x2x2014\n",
    "    na pozici center okna Compute, ktere je na pozici center\n",
    "    v main boxu.\n",
    "'''\n",
    "\n",
    "\n",
    "# TO DO !!!!!!!!!!!!\n",
    "# norm0 je identifikator pro normu iso 230-2:2014\n",
    "# presunout nekam do samostatne bunky\n",
    "class Norm_0(object):\n",
    "    \"\"\"\n",
    "    Container for variables only = NAMESPACE HERE\n",
    "    \"\"\"\n",
    "    pass\n",
    "\n",
    "\n",
    "def compute_proccess():\n",
    "    # namerena data\n",
    "    Norm_0.meta_data = gma.core.MetaDictConst.const_measure_data(varfile_list)\n",
    "    Norm_0.runs_all, Norm_0.runs_odd, Norm_0.runs_even = gma.core.run_all(Norm_0.tabulka, Norm_0.meta_data)\n",
    "    Norm_0.fig = gma.core.figs(Norm_0.runs_all, Norm_0.meta_data)\n",
    "\n",
    "    # vypocet dle normy\n",
    "    Norm_0.stats = gma.norms.DefineData(\n",
    "        Norm_0.meta_data['Run-count'],\n",
    "        Norm_0.meta_data['Target-count'],\n",
    "    )\n",
    "    # Norm_0.stats.transformTable(Norm_0.data_raw)\n",
    "    # Norm_0.stats.load_data(source='var', value=Norm_0.tabulka)\n",
    "    Norm_0.stats.preprocess_data(Norm_0.tabulka)\n",
    "    Norm_0.stats.def_all()\n",
    "    Norm_0.stats.main_stats()\n",
    "\n",
    "\n",
    "out_iso230x2x2014 = ipw.Output(layout={'border': '1px solid black'})\n",
    "\n",
    "\n",
    "compute_center_test = ipw.Text(\n",
    "    value='Ready',\n",
    "    placeholder='',\n",
    "    description='Computation Status:',\n",
    "    disabled=False,\n",
    ")\n",
    "\n",
    "\n",
    "def update_iso230x2x2014(new_window):\n",
    "    '''\n",
    "    compute_center_iso230x2x2014:\n",
    "    0 = 0. radek = compute_header\n",
    "    '''\n",
    "    temp = list(compute_center_iso230x2x2014.children)\n",
    "    temp[0] = new_window\n",
    "    compute_center_iso230x2x2014.children = tuple(temp)\n",
    "    display(compute_center_iso230x2x2014)\n",
    "\n",
    "    \n",
    "compute_center_iso230x2x2014_layout = ipw.Layout(\n",
    "    display='flex',\n",
    "    flex_flow='row',\n",
    "    align_items='stretch',\n",
    "    width='100%',\n",
    "    height='100%',\n",
    "    border='solid 1px',\n",
    "    grid_area='compute_center',\n",
    ")\n",
    "\n",
    "compute_center_iso230x2x2014 = ipw.VBox(\n",
    "    [\n",
    "        compute_center_test\n",
    "    ],\n",
    "    layout=compute_center_iso230x2x2014_layout,\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: COMPUTE CENTER\n",
    "Code block: V tomto bloku je kompletni definice PODokna Center\n",
    "    na pozici center okna Compute, ktere je na pozici center\n",
    "    v main boxu.\n",
    "'''\n",
    "\n",
    "with open(\"static/images/mesh_surface_low_res.jpg\", \"rb\") as fx:\n",
    "    center_imagex = fx.read()\n",
    "compute_center = ipw.Image(\n",
    "    value=center_imagex,\n",
    "    format='jpg',\n",
    "    width='auto',\n",
    "    height='auto',\n",
    "    grid_area='compute_center',\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: CENTER = COMPUTE\n",
    "Code block: V tomto bloku je kompletni definice PODokna Compute\n",
    "    na pozici center v main boxu.\n",
    "\n",
    "## DEFINICE OKNA NA POZICI CENTER PRO COMPUTE\n",
    "\n",
    "V teto bunce je definovana konecna podoba okna COMPUTE.\n",
    "'''\n",
    "\n",
    "'''\n",
    "# Docasna podoba - TO DO HERE\n",
    "window_compute = ipw.Button(\n",
    "    description='Compute Window.',\n",
    "    disabled=False,\n",
    "    button_style='',\n",
    "    tooltip='Browse history.',\n",
    "    icon='victory',\n",
    ")\n",
    "'''\n",
    "\n",
    "window_compute_layout = ipw.Layout(\n",
    "    height='100%',  # viewport height, 1vh = 1% of browser’s height!!!!!!!!!!!\n",
    "    width='100%',\n",
    "    grid_gap='5px',\n",
    "    overflow='auto',\n",
    "    overflow_x='auto',\n",
    "    align_items='stretch',\n",
    "    #align_content='stretch',\n",
    "    margin='0px',\n",
    "    border='0px',\n",
    "    padding='0px',\n",
    "    display='grid',\n",
    "    grid_template_rows='5% 95%',\n",
    "    grid_template_columns='10% 90%',\n",
    "    grid_template_areas='''\n",
    "        \"compute_left_sidebar compute_header\"\n",
    "        \"compute_left_sidebar compute_center\"\n",
    "    ''',\n",
    "    grid_area='center',  # toto okno se vykresluje na pozici 'center'\n",
    ")\n",
    "\n",
    "window_compute = ipw.GridBox(\n",
    "    children=[\n",
    "        compute_header,\n",
    "        compute_left_sidebar,\n",
    "        compute_center,\n",
    "    ],\n",
    "    layout=window_compute_layout,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: CENTER = COMPENSATE\n",
    "Code block: V tomto bloku je kompletni definice PODokna Compensate\n",
    "    na pozici center v main boxu.\n",
    "\n",
    "## DEFINICE OKNA NA POZICI CENTER PRO COMPENSATE\n",
    "\n",
    "V teto bunce je definovana konecna podoba okna COMPENSATE.\n",
    "'''\n",
    "\n",
    "# Docasna podoba - TO DO HERE\n",
    "window_compensate = ipw.Button(\n",
    "    description='Compensate Windows.',\n",
    "    disabled=False,\n",
    "    button_style='',\n",
    "    tooltip='Browse history.',\n",
    "    icon='victory',\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "'''\n",
    "ID: CENTER = HISTORY\n",
    "Code block: V tomto bloku je kompletni definice PODokna History\n",
    "    na pozici center v main boxu.\n",
    "\n",
    "## DEFINICE OKNA NA POZICI CENTER PRO HISTORY\n",
    "\n",
    "V teto bunce je definovana konecna podoba okna HISTORY.\n",
    "'''\n",
    "\n",
    "# Docasna podoba - TO DO HERE\n",
    "window_history = ipw.Button(\n",
    "    description='History Window.',\n",
    "    disabled=False,\n",
    "    button_style='',\n",
    "    tooltip='Browse history.',\n",
    "    icon='victory',\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "ceeadf7309304766a267ea37cd2614f7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "GridBox(children=(Image(value=b'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00\\x07K\\x00\\x00\\x00,\\x08\\x06\\x00\\x00\\…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "'''\n",
    "ID: MAIN BOX DEFINITION\n",
    "Code block: V tomto bloku je konstrukce hlavniho okna (main box)\n",
    "    a pomocne funkce pro jeho chod.\n",
    "\n",
    "## KONSTRUKCE A DEFINICE HLAVNIHO OKNA APPLAYOUT\n",
    "\n",
    "\n",
    "'''\n",
    "'''\n",
    "main_box_layout = ipw.Layout(\n",
    "    #height='1080px',\n",
    "    #width='1920px',\n",
    "    height='900px',\n",
    "    width='100%',\n",
    "    grid_gap='0px',\n",
    "    overflow='auto',\n",
    "    #align_items='stretch',\n",
    "    #align_content='stretch',\n",
    ")\n",
    "\n",
    "# Docasna podoba - TO DO HERE\n",
    "main_box = ipw.AppLayout(\n",
    "    header=header_box,\n",
    "    footer=footer_box,\n",
    "    center=center,\n",
    "    left_sidebar=left_box,\n",
    "    right_sidebar=None,\n",
    "    layout=main_box_layout,\n",
    ")\n",
    "'''\n",
    "\n",
    "main_box_layout = ipw.Layout(\n",
    "    height='96vh',  # viewport height, 1vh = 1% of browser’s height!!!!!!!!!!!\n",
    "    width='99.5%',\n",
    "    grid_gap='5px',\n",
    "    overflow='visible',\n",
    "    align_items='stretch',\n",
    "    #align_content='stretch',\n",
    "    margin='0px',\n",
    "    border='0px',\n",
    "    padding='0px',\n",
    "    display='grid',\n",
    "    grid_template_rows='5% 90% 3%',\n",
    "    grid_template_columns='8% 92%',\n",
    "    grid_template_areas='''\n",
    "        \"header header\"\n",
    "        \"left_sidebar center\"\n",
    "        \"footer footer\"\n",
    "    ''',\n",
    ")\n",
    "\n",
    "main_box = ipw.GridBox(\n",
    "    children=[\n",
    "        header_box,\n",
    "        footer_box,\n",
    "        left_box,\n",
    "        center,\n",
    "    ],\n",
    "    layout=main_box_layout,\n",
    ")\n",
    "\n",
    "display(main_box)\n",
    "\n",
    "'''\n",
    "def update_main_box(**kwargs):\n",
    "    for item in kwargs.items():\n",
    "        key, value = item\n",
    "    setattr(main_box, key, value)\n",
    "'''\n",
    "\n",
    "def update_main_box(**kwargs):\n",
    "    set_position = kwargs['position']\n",
    "    set_new_window = kwargs['new_window']\n",
    "    '''\n",
    "    V nasledujici IF funkci odpovidaji prirazena\n",
    "    cisla radkum v definici main_box:\n",
    "        0 = 0. radek = header_box\n",
    "        1 = 1. radek = footer_box\n",
    "        2 = 2. radek = left_box\n",
    "        3 = 3. radek = center\n",
    "    '''\n",
    "    if set_position == 'header': i = 0\n",
    "    elif set_position == 'footer': i = 1\n",
    "    elif set_position == 'left_sidebar': i = 2\n",
    "    elif set_position == 'center': i = 3\n",
    "    temp = list(main_box.children)\n",
    "    temp[i] = set_new_window\n",
    "    main_box.children = tuple(temp)\n",
    "    display(main_box)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.6 64-bit ('voila': conda)",
   "language": "python",
   "name": "python37664bitvoilacondadbc3819297864011bc316b8ba426a99e"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
