<gh_stars>0
#!/usr/bin/python3

import tkinter as tk
from tkinter import ttk
import socket
import picamera
import time
import datetime
import RPi.GPIO as GPIO
import os
import timeit
from fractions import Fraction
from rpi_ws281x import *
import numpy as np
import subprocess


# LED strip configuration:
LED_COUNT = 35  # Number of LED pixels.
LED_PIN = 18  # GPIO pin connected to the pixels (real nuber is 12) (must support PWM!).
LED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)
LED_DMA = 10  # DMA channel to use for generating signal (try 10)
LED_BRIGHTNESS = 255  # Set to 0 for darkest and 255 for brightest
LED_INVERT = False  # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL = 0
LED_STRIP = ws.SK6812W_STRIP

# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL,
                          LED_STRIP)
# Intialize the library (must be called once before other functions).
strip.begin()

# IR LEDs configuration
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.OUT)  # inderpendent IR board # 37
GPIO.setup(23, GPIO.OUT)  # second IR board # 16


def get_ip():
    '''function to get and show IP in the status bar'''
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        # doesn't even have to be reachable
        s.connect(('10.255.255.255', 1))
        IP = s.getsockname()[0]
    except Exception:
        IP = '127.0.1.1'
    finally:
        s.close()
    return IP


def print_selection():
    # Text widget - info text selection ###
    if (pre_light.get() == 1):
        pretreatment = True

    if (ah_choice.get() == 1) & (ph_choice.get() == 0):
        w1.config(font=("Arial", 12, 'bold'), label="Length of the apical hook experiment (hours):", bg='white')
    elif (ah_choice.get() == 1) & (ph_choice.get() == 1):
        w1.config(font=("Arial", 12, 'bold'), label="Length of the apical hook experiment (hours):", bg='white')
    elif (ah_choice.get() == 0) & (ph_choice.get() == 1):
        w1.config(font=("Arial", 12, 'bold'), label="Length of the initial dark period (hours):", bg='white')


def show_values():
    # Showing values on sliders
    print(w1.get(), w2.get(), w3.get())


def color_switcher():
    global color_var
    color_var[-1] = white_choice.get()
    color_var[0] = red_choice.get()
    color_var[1] = green_choice.get()
    color_var[2] = blue_choice.get()


def open_username(username_dict):
    ''' Keyboard and username/experiment name selection'''
    global username
    username[username_dict] = ""

    def press(num):
        global username
        username[username_dict] = username[username_dict] + str(num)
        equation.set(username[username_dict])

    # end

    # function clear button

    def clear():
        global username
        username[username_dict] = ""
        equation.set(username[username_dict])

    # end

    # closing window without closing the app
    def popup():
        global username
        if username[username_dict] == "":
            username[username_dict] = 'default_{}'.format(username_dict[:-5])
        p = tk.Toplevel(key)
        p.configure(bg='white')
        p.geometry('600x225+100+50')
        p_label = tk.Label(p, text='{} is set as the {}.'.format(username[username_dict], username_dict), bg='white')
        p_label.config(font=("Arial", 15, 'bold'))
        p_label.grid(row=0, column=0, ipadx=1, ipady=15)
        p.after(3000, key.destroy)

    key = tk.Toplevel(window)  # key window name
    key.title('Cool custom keyboard')  # title Name

    # Size window size
    key.geometry('800x450')  # normal size
    key.maxsize(width=800, height=450)  # maximum size
    key.minsize(width=800, height=450)  # minimum size
    # end window size

    key.configure(bg='grey')  # add background color

    # label
    username_label = tk.Label(key, text="Type your {} below:".format(username_dict), bg='grey')
    username_label.config(font=("Arial", 18, 'bold'), anchor="center")
    username_label.grid(rowspan=1, columnspan=7, column=0, ipadx=1, ipady=15)

    # entry box
    equation = tk.StringVar()
    Dis_entry = ttk.Entry(key, state='readonly', textvariable=equation)
    Dis_entry.grid(row=1, columnspan=300, ipadx=800, ipady=30)
    # end entry box

    # add all button line wise

    q = ttk.Button(key, text='Q', width=4, command=lambda: press('Q'))
    q.grid(row=3, column=0, ipadx=10, ipady=25)

    w = ttk.Button(key, text='W', width=4, command=lambda: press('W'))
    w.grid(row=3, column=1, ipadx=10, ipady=25)

    E = ttk.Button(key, text='E', width=4, command=lambda: press('E'))
    E.grid(row=3, column=2, ipadx=10, ipady=25)

    R = ttk.Button(key, text='R', width=4, command=lambda: press('R'))
    R.grid(row=3, column=3, ipadx=10, ipady=25)

    T = ttk.Button(key, text='T', width=4, command=lambda: press('T'))
    T.grid(row=3, column=4, ipadx=10, ipady=25)

    Y = ttk.Button(key, text='Y', width=4, command=lambda: press('Y'))
    Y.grid(row=3, column=5, ipadx=10, ipady=25)

    U = ttk.Button(key, text='U', width=4, command=lambda: press('U'))
    U.grid(row=3, column=6, ipadx=10, ipady=25)

    I = ttk.Button(key, text='I', width=4, command=lambda: press('I'))
    I.grid(row=3, column=7, ipadx=10, ipady=25)

    O = ttk.Button(key, text='O', width=4, command=lambda: press('O'))
    O.grid(row=3, column=8, ipadx=10, ipady=25)

    P = ttk.Button(key, text='P', width=4, command=lambda: press('P'))
    P.grid(row=3, column=9, ipadx=10, ipady=25)

    clear = ttk.Button(key, text='Clear', width=4, command=clear)
    clear.grid(row=2, column=10, ipadx=45, ipady=25)

    # Second Line Button

    A = ttk.Button(key, text='A', width=4, command=lambda: press('A'))
    A.grid(row=4, column=0, ipadx=10, ipady=25)

    S = ttk.Button(key, text='S', width=4, command=lambda: press('S'))
    S.grid(row=4, column=1, ipadx=10, ipady=25)

    D = ttk.Button(key, text='D', width=4, command=lambda: press('D'))
    D.grid(row=4, column=2, ipadx=10, ipady=25)

    F = ttk.Button(key, text='F', width=4, command=lambda: press('F'))
    F.grid(row=4, column=3, ipadx=10, ipady=25)

    G = ttk.Button(key, text='G', width=4, command=lambda: press('G'))
    G.grid(row=4, column=4, ipadx=10, ipady=25)

    H = ttk.Button(key, text='H', width=4, command=lambda: press('H'))
    H.grid(row=4, column=5, ipadx=10, ipady=25)

    J = ttk.Button(key, text='J', width=4, command=lambda: press('J'))
    J.grid(row=4, column=6, ipadx=10, ipady=25)

    K = ttk.Button(key, text='K', width=4, command=lambda: press('K'))
    K.grid(row=4, column=7, ipadx=10, ipady=25)

    L = ttk.Button(key, text='L', width=4, command=lambda: press('L'))
    L.grid(row=4, column=8, ipadx=10, ipady=25)

    Ⱈ = ttk.Button(key, text='Ⱈ', width=4, command=lambda: press('Ⱈ'))
    Ⱈ.grid(row=4, column=9, ipadx=10, ipady=25)

    enter = ttk.Button(key, text='Enter', width=4, command=popup)
    enter.grid(row=4, column=10, ipadx=45, ipady=25)

    # third line Button

    Z = ttk.Button(key, text='Z', width=4, command=lambda: press('Z'))
    Z.grid(row=5, column=0, ipadx=10, ipady=25)

    X = ttk.Button(key, text='X', width=4, command=lambda: press('X'))
    X.grid(row=5, column=1, ipadx=10, ipady=25)

    C = ttk.Button(key, text='C', width=4, command=lambda: press('C'))
    C.grid(row=5, column=2, ipadx=10, ipady=25)

    V = ttk.Button(key, text='V', width=4, command=lambda: press('V'))
    V.grid(row=5, column=3, ipadx=10, ipady=25)

    B = ttk.Button(key, text='B', width=4, command=lambda: press('B'))
    B.grid(row=5, column=4, ipadx=10, ipady=25)

    N = ttk.Button(key, text='N', width=4, command=lambda: press('N'))
    N.grid(row=5, column=5, ipadx=10, ipady=25)

    M = ttk.Button(key, text='M', width=4, command=lambda: press('M'))
    M.grid(row=5, column=6, ipadx=10, ipady=25)

    space = ttk.Button(key, text='_', width=4, command=lambda: press('_'))
    space.grid(row=5, columnspan=150, ipadx=145, ipady=25)

    # number row

    one = ttk.Button(key, text='1', width=4, command=lambda: press('1'))
    one.grid(row=2, column=0, ipadx=10, ipady=25)

    two = ttk.Button(key, text='2', width=4, command=lambda: press('2'))
    two.grid(row=2, column=1, ipadx=10, ipady=25)

    three = ttk.Button(key, text='3', width=4, command=lambda: press('3'))
    three.grid(row=2, column=2, ipadx=10, ipady=25)

    four = ttk.Button(key, text='4', width=4, command=lambda: press('4'))
    four.grid(row=2, column=3, ipadx=10, ipady=25)

    five = ttk.Button(key, text='5', width=4, command=lambda: press('5'))
    five.grid(row=2, column=4, ipadx=10, ipady=25)

    six = ttk.Button(key, text='6', width=4, command=lambda: press('6'))
    six.grid(row=2, column=5, ipadx=10, ipady=25)

    seven = ttk.Button(key, text='7', width=4, command=lambda: press('7'))
    seven.grid(row=2, column=6, ipadx=10, ipady=25)

    eight = ttk.Button(key, text='8', width=4, command=lambda: press('8'))
    eight.grid(row=2, column=7, ipadx=10, ipady=25)

    nine = ttk.Button(key, text='9', width=4, command=lambda: press('9'))
    nine.grid(row=2, column=8, ipadx=10, ipady=25)

    zero = ttk.Button(key, text='0', width=4, command=lambda: press('0'))
    zero.grid(row=2, column=9, ipadx=10, ipady=25)

    no_button = ttk.Button(key, text='Does nothing\n(enjoy pushing it)', width=4, command=lambda: press(''))
    no_button.grid(row=3, column=10, ipadx=45, ipady=18)


def warning_message(message):
    popup_mess = tk.Toplevel(window)
    popup_mess.configure(bg='white')
    popup_mess.geometry('600x225+100+50')
    popup_mess_label = tk.Label(popup_mess, text='No {} selected.'.format(message), bg='white')
    popup_mess_label.config(font=("Arial", 15, 'bold'))
    popup_mess_label.grid(row=0, column=0, ipadx=1, ipady=15)
    popup_mess.after(3000, popup_mess.destroy)


def launch():
    def meta_data_file_create(meta_loc='meta_data.txt'):
        f = open(meta_loc, "w+")
        f.write("# Experiment info\r\n")
        f.close()
        f = open(meta_loc, "a+")
        f.write(f"total_experiment_length={total_experiment_length}\r\n")
        f.write(f"apical_decision={apical_decision}\r\n")
        f.write(f"apical_hours={total_hours}\r\n")
        f.write(f"ph_decision={ph_decision}\r\n")
        f.write(f"light={[int(color[0]), int(color[1]), int(color[2]), int(color[3])]}\r\n")
        f.write(f"location='{os.getcwd()}'")
        f.close()


    ''' masterfunction where all data recorded before should go into motion'''
    if ah_choice.get() == 0 and ph_choice.get() == 0:
        warning_message('experiment')
    elif color_var == [0, 0, 0, 0]:
        warning_message('color settings')
    else:

        ''' Controlling part'''
        apical_decision = ah_choice.get()  # argument which turns off apical hook opening tracing (making pictures of it)
        total_hours = ah_value.get()  # how many hours before the light on (hours)
        period_min = freq_value.get()  # period between pictures (min)
        total_hours_blue = ph_value.get()  # for how long we want blue LEDs on (hours)
        total_experiment_length = total_hours + total_hours_blue

        # intensity of the light
        light_intensity = light_power.get()
        # color of the color strip
        ph_decision = ph_choice.get()

        # period_hours = round(period_min/60)
        total_minutes = total_hours * 60  # necessary for counting number of pictures		initial value is 60
        period_sec = period_min * 60  # (universal) sleep counts time in secs
        pic_num = int(total_minutes // period_min)  # takes only int part of quotient

        # unilateral light (blue)
        total_minutes_blue = total_hours_blue * 60  # initial value is 60
        pic_num_blue = int(total_minutes_blue // period_min)
        color = list(np.array(color_var) * light_intensity)
        print(color, color)

        """ Creating a window with a progress bar and info of the experiment stage"""

        # Setting user name and folder name
        subprocess.call('python3 /home/pi/camera/Apps/experiment_status.py &', shell=True)
        users_folders()
        meta_data_file_create()
        meta_data_file_create("/home/pi/camera/Apps/meta_data.py")
        # init colored photo
        init_photo(int(color[0]), int(color[1]), int(color[2]), int(color[3]), 'init_photo')
        # starting AH cycle
        ah_cycle(pic_num, apical_decision, period_sec)
        # starting ph cycle (or not starting)
        bending_cycle(color, total_hours_blue, ph_decision, pic_num_blue, period_sec)
        # final white photo
        init_photo(0, 0, 0, 10, 'final_photo')


def colorWipe(strip, palette, wait_ms=50):
    """Wipe color across display a pixel at a time."""
    for i in range(strip.numPixels()):
        strip.setPixelColor(i, palette)
        strip.show()
        time.sleep(wait_ms / 1000.0)


def users_folders():
    ''' creating experiment and user folder'''
    folder_name = str(datetime.date.today()).replace('-', '.') + '_PI3_' + '_' + username['experiment name']
    user_name = username['user name']
    os.chdir("/home/pi/camera/Experiments")

    if os.path.isdir("{}".format(user_name)):
        os.chdir("{}".format(user_name))
    else:
        os.mkdir("{}".format(user_name))
        os.chdir("{}".format(user_name))

    # that will release us from constant deleting of already existing folders
    if os.path.isdir("{}".format(folder_name)):
        folder_name = folder_name + "copy"
        os.mkdir("{}".format(folder_name))
        os.chdir("{}".format(folder_name))
    else:
        os.mkdir("{}".format(folder_name))
        os.chdir("{}".format(folder_name))


def init_photo(r, g, b, w, text):
    ''' Creating a single photo with given LED parameters'''
    colorWipe(strip, Color(r, g, b, w), 0)  # White wipe
    with picamera.PiCamera() as camera:
        camera.resolution = (3280, 2464)
        camera.framerate = 0.2
        camera.shutter_speed = 700000
        camera.exposure_mode = 'off'
        camera.iso = 200
        time.sleep(5)
        camera.capture('{}.jpg'.format(text))
    # Switching off LED strip
    colorWipe(strip, Color(0, 0, 0, 0), 0)


def ah_cycle(pic_num, apical_decision, period_sec):
    """ Running an apical hook stage/dark stage """
    # the cycle itself
    for i in range(pic_num):
        start_time = timeit.default_timer()  # when making of picture starts
        if int(apical_decision) == 1:  # by this, we disarm the whole cycle
            GPIO.output(23, GPIO.HIGH)
            GPIO.output(26, GPIO.HIGH)
            with picamera.PiCamera() as camera:
                camera.color_effects = (128, 128)  # b/w mode
                camera.resolution = (3280, 2464)
                camera.framerate = 0.2
                camera.shutter_speed = 400000  # exposure length, can be ajusted (max 6000000 - 6 sec)
                camera.exposure_mode = 'off'  # turning off of autoexposure
                camera.iso = 100
                # Give the camera a good long time to measure AWB
                # (you may wish to use fixed AWB instead)
                camera.awb_mode = 'off'
                camera.awb_gains = (Fraction(2), Fraction(1))
                camera.capture("./{}_cycle_{}h_dark.jpg".format(i, i*round(period_sec/3600, 2)))   # updated 2020.08.25
            GPIO.output(23, GPIO.LOW)
            GPIO.output(26, GPIO.LOW)
        # Making image of current state, while dark stage is ongoing
        else:
            # Image of current plant look
            GPIO.output(23, GPIO.HIGH)
            GPIO.output(26, GPIO.HIGH)
            with picamera.PiCamera() as camera:
                camera.color_effects = (128, 128)  # b/w mode
                camera.resolution = (3280, 2464)
                camera.framerate = 0.2
                camera.shutter_speed = 400000  # exposure length, can be ajusted (max 6000000 - 6 sec)
                camera.exposure_mode = 'off'  # turning off autoexposure
                camera.iso = 100
                # Give the camera a good long time to measure AWB
                # (you may wish to use fixed AWB instead)
                camera.awb_mode = 'off'
                camera.awb_gains = (Fraction(2), Fraction(1))
                camera.capture("./current_look_{}(dark_stage).jpg".format(i))
            GPIO.output(23, GPIO.LOW)
            GPIO.output(26, GPIO.LOW)
            # current photo should be only one
            exists = os.path.isfile("./current_look_{}(dark_stage).jpg".format(i-1))
            if exists:
                os.remove("./current_look_{}(dark_stage).jpg".format(i-1))
        elapsed = timeit.default_timer() - start_time
        time.sleep(float(period_sec) - elapsed)
    GPIO.cleanup()


def bending_cycle(color, total_hours_blue, ph_decision, pic_num_blue, period_sec):
    ''' Running a phototropic stage'''
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(23, GPIO.OUT)  # IR left
    # GPIO.setup(18, GPIO.OUT)  # blue LEDs
    GPIO.setup(26, GPIO.OUT)  # IR right

    # that will release us from constant deleting of already existing folders
    if total_hours_blue != 0 or ph_decision != 0:
        for i in range(pic_num_blue):
            start_time = timeit.default_timer()  # when making of picture starts
            colorWipe(strip, Color(0, 0, 0, 0), 0)  # switch off light
            GPIO.output(23, GPIO.HIGH)
            GPIO.output(26, GPIO.HIGH)
            with picamera.PiCamera() as camera:
                camera.color_effects = (128, 128)  # b/w mode
                camera.resolution = (3280, 2464)
                camera.framerate = 0.2
                camera.shutter_speed = 400000  # exposure length, can be ajusted (max 6000000 - 6 sec)
                camera.exposure_mode = 'off'  # turning off of autoexposure
                camera.iso = 100
                # Give the camera a good long time to measure AWB
                # (you may wish to use fixed AWB instead)
                camera.awb_mode = 'off'
                camera.awb_gains = (Fraction(2), Fraction(1))

                camera.capture("./{}_{}_irradiated.jpg".format(i, color))
            colorWipe(strip, Color(int(color[0]),int(color[1]), int(color[2]), int(color[3])), 0)
            GPIO.output(23, GPIO.LOW)
            GPIO.output(26, GPIO.LOW)
            # adjustment of total time(cause it tends to run forward for ~45 sec per cycle
            elapsed = timeit.default_timer() - start_time
            time.sleep(float(period_sec) - elapsed)
        colorWipe(strip, Color(0, 0, 0, 0), 0)
    GPIO.cleanup()



# Variables
username = {'experiment name': '', 'user name': ''}  # global variable

### This creates the main window of an application
window = tk.Tk()
SIGNATURE = socket.getfqdn() + " " + get_ip()
window.title("RaPiDBox v 1" + "  (" + SIGNATURE + ")")
window.geometry("800x450")
window.configure(background='white')

# ### Navigation buttons
# run
launch_button = tk.Button(window, text="Launch", width=16, command=launch)
launch_button.grid(row=1, column=3, ipady=10, ipadx=5, sticky='e')
launch_button.config(font=("Arial", 14, 'bold'), bg='white')
# close
close_butt = tk.Button(window, text="Close", width=16, bg='white', command=window.destroy)
close_butt.grid(row=1, column=0, ipadx=5, ipady=10, sticky='w')
close_butt.config(font=("Arial", 14, 'bold'), bg='white')
# user
usr_name = tk.Button(window, text="Select user", width=16, bg='white', command=lambda: open_username('user name'))
usr_name.grid(row=1, column=1, ipadx=5, ipady=10, sticky='w')
usr_name.config(font=("Arial", 14, 'bold'), bg='white')
# experiment_name
exp_name = tk.Button(window, text="Experiment name", width=16, bg='white',
                     command=lambda: open_username('experiment name'))
exp_name.grid(row=1, column=2, ipadx=5, ipady=10, sticky='w')
exp_name.config(font=("Arial", 14, 'bold'), bg='white')

### Checkboxes ###

pre_light = tk.IntVar()
ah_choice = tk.IntVar()
ph_choice = tk.IntVar()

c1 = tk.Checkbutton(window, text='6h white light pretreatment', width=26, variable=pre_light, onvalue=1, offvalue=0,
                    command=print_selection)
c1.grid(row=2, column=0, ipadx=25, ipady=15, columnspan=2)
c1.config(font=("Arial", 16, 'bold'), bg='white', anchor='w')

c2 = tk.Checkbutton(window, text='Apical hook development', width=26, variable=ah_choice, onvalue=1, offvalue=0,
                    command=print_selection)
c2.grid(row=3, column=0, ipadx=25, ipady=15, columnspan=2)
c2.config(font=("Arial", 16, 'bold'), bg='white', anchor='w')

c3 = tk.Checkbutton(window, text='Phototropic bending', width=26, variable=ph_choice, onvalue=1, offvalue=0,
                    command=print_selection)
c3.grid(row=4, column=0, ipadx=25, ipady=15, columnspan=2)
c3.config(font=("Arial", 16, 'bold'), bg='white', anchor='w')

### Sliders ###

ah_value = tk.IntVar()
ph_value = tk.IntVar()
freq_value = tk.IntVar()
light_power = tk.IntVar()

# AH/Dark experiment length

AH_label = "Apical hook experiment length (hours):"
w1 = tk.Scale(window, from_=0, to=350, width=26, tickinterval=50, label=AH_label, variable=ah_value,
              orient='horizontal')
w1.set(90)
w1.grid(row=5, column=0, ipadx=147, ipady=1, columnspan=2)
w1.config(font=("Arial", 12, 'bold'), bg='white')

# phototrop experiment length
PH_label = "Phototropic bending experiment length (hours):"
w2 = tk.Scale(window, from_=0, to=80, width=26, tickinterval=10, label=PH_label, variable=ph_value, orient='horizontal')
w2.set(20)
w2.grid(row=6, column=0, ipadx=147, ipady=1, columnspan=2)
w2.config(font=("Arial", 12, 'bold'), bg='white')

# Frequency of imaging
freq_label = "Interval between images (minutes):"
w3 = tk.Scale(window, from_=0, to=240, width=26, tickinterval=50, label=freq_label, variable=freq_value,
              orient='horizontal')
w3.set(20)
w3.grid(row=5, columnspan=2, column=2, rowspan=1, ipadx=144, ipady=1, sticky='w')
w3.config(font=("Arial", 12, 'bold'), bg='white')

# Light intencity
light_power_label = "Light intensity:"
w4 = tk.Scale(window, from_=0, to=255, width=26, tickinterval=50, label=light_power_label, variable=light_power,
              orient='horizontal')
w4.set(10)
w4.grid(row=6, columnspan=2, column=2, rowspan=1, ipadx=144, ipady=1, sticky='w')
w4.config(font=("Arial", 12, 'bold'), bg='white')

''' Make possible to combine simultaneous buttons press + add clear button to unselect all'''

# Color label
color_label = tk.Label(window, text="Select LED color", bg='white')
color_label.config(font=("Arial", 18, 'bold'))
color_label.grid(row=2, column=2, columnspan=2, ipadx=10, ipady=15)

color_var = [0, 0, 0, 0]

# LED
white_choice = tk.IntVar()
red_choice = tk.IntVar()
green_choice = tk.IntVar()
blue_choice = tk.IntVar()

white = tk.Checkbutton(window, text="White", font=('Arial', 14, 'bold'), bg='white', width=5, variable=white_choice,
                       command=color_switcher, onvalue=1, offvalue=0)
white.grid(row=3, column=2, ipadx=55, ipady=15)

# Red LED
red = tk.Checkbutton(window, text="Red", font=('Arial', 14, 'bold'), bg='red', activebackground='pink', width=5,
                     variable=red_choice, command=color_switcher, onvalue=1, offvalue=0)
red.grid(row=3, column=3, ipadx=55, ipady=15)

# Green LED
green = tk.Checkbutton(window, text="Green", font=('Arial', 14, 'bold'), bg='#6df565',
                       activebackground='#c0f6bd', width=5,
                       variable=green_choice, command=color_switcher, onvalue=1, offvalue=0)
green.grid(row=4, column=2, ipadx=55, ipady=15)

# blue LED
blue = tk.Checkbutton(window, text="Blue", font=('Arial', 14, 'bold'),
                      activebackground='#bdc9f6', bg='#6c89fb', width=5,
                      variable=blue_choice, command=color_switcher, onvalue=1, offvalue=0)
blue.grid(row=4, column=3, ipadx=55, ipady=15)

tk.Button(window, text='Show', command=show_values)


window.mainloop()

#!/usr/bin/python3

import tkinter as tk
from tkinter import ttk
import socket
import picamera
import time
import datetime
import RPi.GPIO as GPIO
import os
import timeit
from fractions import Fraction
from rpi_ws281x import *
import numpy as np
import subprocess


# LED strip configuration:
LED_COUNT = 35  # Number of LED pixels.
LED_PIN = 18  # GPIO pin connected to the pixels (real nuber is 12) (must support PWM!).
LED_FREQ_HZ = 800000  # LED signal frequency in hertz (usually 800khz)
LED_DMA = 10  # DMA channel to use for generating signal (try 10)
LED_BRIGHTNESS = 255  # Set to 0 for darkest and 255 for brightest
LED_INVERT = False  # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL = 0
LED_STRIP = ws.SK6812W_STRIP

# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL,
                          LED_STRIP)
# Intialize the library (must be called once before other functions).
strip.begin()

# IR LEDs configuration
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.OUT)  # inderpendent IR board # 37
GPIO.setup(23, GPIO.OUT)  # second IR board # 16


def get_ip():
    '''function to get and show IP in the status bar'''
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        # doesn't even have to be reachable
        s.connect(('10.255.255.255', 1))
        IP = s.getsockname()[0]
    except Exception:
        IP = '127.0.1.1'
    finally:
        s.close()
    return IP


def print_selection():
    # Text widget - info text selection ###
    if (pre_light.get() == 1):
        pretreatment = True

    if (ah_choice.get() == 1) & (ph_choice.get() == 0):
        w1.config(font=("Arial", 12, 'bold'), label="Length of the apical hook experiment (hours):", bg='white')
    elif (ah_choice.get() == 1) & (ph_choice.get() == 1):
        w1.config(font=("Arial", 12, 'bold'), label="Length of the apical hook experiment (hours):", bg='white')
    elif (ah_choice.get() == 0) & (ph_choice.get() == 1):
        w1.config(font=("Arial", 12, 'bold'), label="Length of the initial dark period (hours):", bg='white')


def show_values():
    # Showing values on sliders
    print(w1.get(), w2.get(), w3.get())


def color_switcher():
    global color_var
    color_var[-1] = white_choice.get()
    color_var[0] = red_choice.get()
    color_var[1] = green_choice.get()
    color_var[2] = blue_choice.get()


def open_username(username_dict):
    ''' Keyboard and username/experiment name selection'''
    global username
    username[username_dict] = ""

    def press(num):
        global username
        username[username_dict] = username[username_dict] + str(num)
        equation.set(username[username_dict])

    # end

    # function clear button

    def clear():
        global username
        username[username_dict] = ""
        equation.set(username[username_dict])

    # end

    # closing window without closing the app
    def popup():
        global username
        if username[username_dict] == "":
            username[username_dict] = 'default_{}'.format(username_dict[:-5])
        p = tk.Toplevel(key)
        p.configure(bg='white')
        p.geometry('600x225+100+50')
        p_label = tk.Label(p, text='{} is set as the {}.'.format(username[username_dict], username_dict), bg='white')
        p_label.config(font=("Arial", 15, 'bold'))
        p_label.grid(row=0, column=0, ipadx=1, ipady=15)
        p.after(3000, key.destroy)

    key = tk.Toplevel(window)  # key window name
    key.title('Cool custom keyboard')  # title Name

    # Size window size
    key.geometry('800x450')  # normal size
    key.maxsize(width=800, height=450)  # maximum size
    key.minsize(width=800, height=450)  # minimum size
    # end window size

    key.configure(bg='grey')  # add background color

    # label
    username_label = tk.Label(key, text="Type your {} below:".format(username_dict), bg='grey')
    username_label.config(font=("Arial", 18, 'bold'), anchor="center")
    username_label.grid(rowspan=1, columnspan=7, column=0, ipadx=1, ipady=15)

    # entry box
    equation = tk.StringVar()
    Dis_entry = ttk.Entry(key, state='readonly', textvariable=equation)
    Dis_entry.grid(row=1, columnspan=300, ipadx=800, ipady=30)
    # end entry box

    # add all button line wise

    q = ttk.Button(key, text='Q', width=4, command=lambda: press('Q'))
    q.grid(row=3, column=0, ipadx=10, ipady=25)

    w = ttk.Button(key, text='W', width=4, command=lambda: press('W'))
    w.grid(row=3, column=1, ipadx=10, ipady=25)

    E = ttk.Button(key, text='E', width=4, command=lambda: press('E'))
    E.grid(row=3, column=2, ipadx=10, ipady=25)

    R = ttk.Button(key, text='R', width=4, command=lambda: press('R'))
    R.grid(row=3, column=3, ipadx=10, ipady=25)

    T = ttk.Button(key, text='T', width=4, command=lambda: press('T'))
    T.grid(row=3, column=4, ipadx=10, ipady=25)

    Y = ttk.Button(key, text='Y', width=4, command=lambda: press('Y'))
    Y.grid(row=3, column=5, ipadx=10, ipady=25)

    U = ttk.Button(key, text='U', width=4, command=lambda: press('U'))
    U.grid(row=3, column=6, ipadx=10, ipady=25)

    I = ttk.Button(key, text='I', width=4, command=lambda: press('I'))
    I.grid(row=3, column=7, ipadx=10, ipady=25)

    O = ttk.Button(key, text='O', width=4, command=lambda: press('O'))
    O.grid(row=3, column=8, ipadx=10, ipady=25)

    P = ttk.Button(key, text='P', width=4, command=lambda: press('P'))
    P.grid(row=3, column=9, ipadx=10, ipady=25)

    clear = ttk.Button(key, text='Clear', width=4, command=clear)
    clear.grid(row=2, column=10, ipadx=45, ipady=25)

    # Second Line Button

    A = ttk.Button(key, text='A', width=4, command=lambda: press('A'))
    A.grid(row=4, column=0, ipadx=10, ipady=25)

    S = ttk.Button(key, text='S', width=4, command=lambda: press('S'))
    S.grid(row=4, column=1, ipadx=10, ipady=25)

    D = ttk.Button(key, text='D', width=4, command=lambda: press('D'))
    D.grid(row=4, column=2, ipadx=10, ipady=25)

    F = ttk.Button(key, text='F', width=4, command=lambda: press('F'))
    F.grid(row=4, column=3, ipadx=10, ipady=25)

    G = ttk.Button(key, text='G', width=4, command=lambda: press('G'))
    G.grid(row=4, column=4, ipadx=10, ipady=25)

    H = ttk.Button(key, text='H', width=4, command=lambda: press('H'))
    H.grid(row=4, column=5, ipadx=10, ipady=25)

    J = ttk.Button(key, text='J', width=4, command=lambda: press('J'))
    J.grid(row=4, column=6, ipadx=10, ipady=25)

    K = ttk.Button(key, text='K', width=4, command=lambda: press('K'))
    K.grid(row=4, column=7, ipadx=10, ipady=25)

    L = ttk.Button(key, text='L', width=4, command=lambda: press('L'))
    L.grid(row=4, column=8, ipadx=10, ipady=25)

    Ⱈ = ttk.Button(key, text='Ⱈ', width=4, command=lambda: press('Ⱈ'))
    Ⱈ.grid(row=4, column=9, ipadx=10, ipady=25)

    enter = ttk.Button(key, text='Enter', width=4, command=popup)
    enter.grid(row=4, column=10, ipadx=45, ipady=25)

    # third line Button

    Z = ttk.Button(key, text='Z', width=4, command=lambda: press('Z'))
    Z.grid(row=5, column=0, ipadx=10, ipady=25)

    X = ttk.Button(key, text='X', width=4, command=lambda: press('X'))
    X.grid(row=5, column=1, ipadx=10, ipady=25)

    C = ttk.Button(key, text='C', width=4, command=lambda: press('C'))
    C.grid(row=5, column=2, ipadx=10, ipady=25)

    V = ttk.Button(key, text='V', width=4, command=lambda: press('V'))
    V.grid(row=5, column=3, ipadx=10, ipady=25)

    B = ttk.Button(key, text='B', width=4, command=lambda: press('B'))
    B.grid(row=5, column=4, ipadx=10, ipady=25)

    N = ttk.Button(key, text='N', width=4, command=lambda: press('N'))
    N.grid(row=5, column=5, ipadx=10, ipady=25)

    M = ttk.Button(key, text='M', width=4, command=lambda: press('M'))
    M.grid(row=5, column=6, ipadx=10, ipady=25)

    space = ttk.Button(key, text='_', width=4, command=lambda: press('_'))
    space.grid(row=5, columnspan=150, ipadx=145, ipady=25)

    # number row

    one = ttk.Button(key, text='1', width=4, command=lambda: press('1'))
    one.grid(row=2, column=0, ipadx=10, ipady=25)

    two = ttk.Button(key, text='2', width=4, command=lambda: press('2'))
    two.grid(row=2, column=1, ipadx=10, ipady=25)

    three = ttk.Button(key, text='3', width=4, command=lambda: press('3'))
    three.grid(row=2, column=2, ipadx=10, ipady=25)

    four = ttk.Button(key, text='4', width=4, command=lambda: press('4'))
    four.grid(row=2, column=3, ipadx=10, ipady=25)

    five = ttk.Button(key, text='5', width=4, command=lambda: press('5'))
    five.grid(row=2, column=4, ipadx=10, ipady=25)

    six = ttk.Button(key, text='6', width=4, command=lambda: press('6'))
    six.grid(row=2, column=5, ipadx=10, ipady=25)

    seven = ttk.Button(key, text='7', width=4, command=lambda: press('7'))
    seven.grid(row=2, column=6, ipadx=10, ipady=25)

    eight = ttk.Button(key, text='8', width=4, command=lambda: press('8'))
    eight.grid(row=2, column=7, ipadx=10, ipady=25)

    nine = ttk.Button(key, text='9', width=4, command=lambda: press('9'))
    nine.grid(row=2, column=8, ipadx=10, ipady=25)

    zero = ttk.Button(key, text='0', width=4, command=lambda: press('0'))
    zero.grid(row=2, column=9, ipadx=10, ipady=25)

    no_button = ttk.Button(key, text='Does nothing\n(enjoy pushing it)', width=4, command=lambda: press(''))
    no_button.grid(row=3, column=10, ipadx=45, ipady=18)


def warning_message(message):
    popup_mess = tk.Toplevel(window)
    popup_mess.configure(bg='white')
    popup_mess.geometry('600x225+100+50')
    popup_mess_label = tk.Label(popup_mess, text='No {} selected.'.format(message), bg='white')
    popup_mess_label.config(font=("Arial", 15, 'bold'))
    popup_mess_label.grid(row=0, column=0, ipadx=1, ipady=15)
    popup_mess.after(3000, popup_mess.destroy)


def launch():
    def meta_data_file_create(meta_loc='meta_data.txt'):
        f = open(meta_loc, "w+")
        f.write("# Experiment info\r\n")
        f.close()
        f = open(meta_loc, "a+")
        f.write(f"total_experiment_length={total_experiment_length}\r\n")
        f.write(f"apical_decision={apical_decision}\r\n")
        f.write(f"apical_hours={total_hours}\r\n")
        f.write(f"ph_decision={ph_decision}\r\n")
        f.write(f"light={[int(color[0]), int(color[1]), int(color[2]), int(color[3])]}\r\n")
        f.write(f"location='{os.getcwd()}'")
        f.close()


    ''' masterfunction where all data recorded before should go into motion'''
    if ah_choice.get() == 0 and ph_choice.get() == 0:
        warning_message('experiment')
    elif color_var == [0, 0, 0, 0]:
        warning_message('color settings')
    else:

        ''' Controlling part'''
        apical_decision = ah_choice.get()  # argument which turns off apical hook opening tracing (making pictures of it)
        total_hours = ah_value.get()  # how many hours before the light on (hours)
        period_min = freq_value.get()  # period between pictures (min)
        total_hours_blue = ph_value.get()  # for how long we want blue LEDs on (hours)
        total_experiment_length = total_hours + total_hours_blue

        # intensity of the light
        light_intensity = light_power.get()
        # color of the color strip
        ph_decision = ph_choice.get()

        # period_hours = round(period_min/60)
        total_minutes = total_hours * 60  # necessary for counting number of pictures		initial value is 60
        period_sec = period_min * 60  # (universal) sleep counts time in secs
        pic_num = int(total_minutes // period_min)  # takes only int part of quotient

        # unilateral light (blue)
        total_minutes_blue = total_hours_blue * 60  # initial value is 60
        pic_num_blue = int(total_minutes_blue // period_min)
        color = list(np.array(color_var) * light_intensity)
        print(color, color)

        """ Creating a window with a progress bar and info of the experiment stage"""

        # Setting user name and folder name
        subprocess.call('python3 /home/pi/camera/Apps/experiment_status.py &', shell=True)
        users_folders()
        meta_data_file_create()
        meta_data_file_create("/home/pi/camera/Apps/meta_data.py")
        # init colored photo
        init_photo(int(color[0]), int(color[1]), int(color[2]), int(color[3]), 'init_photo')
        # starting AH cycle
        ah_cycle(pic_num, apical_decision, period_sec)
        # starting ph cycle (or not starting)
        bending_cycle(color, total_hours_blue, ph_decision, pic_num_blue, period_sec)
        # final white photo
        init_photo(0, 0, 0, 10, 'final_photo')


def colorWipe(strip, palette, wait_ms=50):
    """Wipe color across display a pixel at a time."""
    for i in range(strip.numPixels()):
        strip.setPixelColor(i, palette)
        strip.show()
        time.sleep(wait_ms / 1000.0)


def users_folders():
    ''' creating experiment and user folder'''
    folder_name = str(datetime.date.today()).replace('-', '.') + '_PI3_' + '_' + username['experiment name']
    user_name = username['user name']
    os.chdir("/home/pi/camera/Experiments")

    if os.path.isdir("{}".format(user_name)):
        os.chdir("{}".format(user_name))
    else:
        os.mkdir("{}".format(user_name))
        os.chdir("{}".format(user_name))

    # that will release us from constant deleting of already existing folders
    if os.path.isdir("{}".format(folder_name)):
        folder_name = folder_name + "copy"
        os.mkdir("{}".format(folder_name))
        os.chdir("{}".format(folder_name))
    else:
        os.mkdir("{}".format(folder_name))
        os.chdir("{}".format(folder_name))


def init_photo(r, g, b, w, text):
    ''' Creating a single photo with given LED parameters'''
    colorWipe(strip, Color(r, g, b, w), 0)  # White wipe
    with picamera.PiCamera() as camera:
        camera.resolution = (3280, 2464)
        camera.framerate = 0.2
        camera.shutter_speed = 700000
        camera.exposure_mode = 'off'
        camera.iso = 200
        time.sleep(5)
        camera.capture('{}.jpg'.format(text))
    # Switching off LED strip
    colorWipe(strip, Color(0, 0, 0, 0), 0)


def ah_cycle(pic_num, apical_decision, period_sec):
    """ Running an apical hook stage/dark stage """
    # the cycle itself
    for i in range(pic_num):
        start_time = timeit.default_timer()  # when making of picture starts
        if int(apical_decision) == 1:  # by this, we disarm the whole cycle
            GPIO.output(23, GPIO.HIGH)
            GPIO.output(26, GPIO.HIGH)
            with picamera.PiCamera() as camera:
                camera.color_effects = (128, 128)  # b/w mode
                camera.resolution = (3280, 2464)
                camera.framerate = 0.2
                camera.shutter_speed = 400000  # exposure length, can be ajusted (max 6000000 - 6 sec)
                camera.exposure_mode = 'off'  # turning off of autoexposure
                camera.iso = 100
                # Give the camera a good long time to measure AWB
                # (you may wish to use fixed AWB instead)
                camera.awb_mode = 'off'
                camera.awb_gains = (Fraction(2), Fraction(1))
                camera.capture("./{}_cycle_{}h_dark.jpg".format(i, i*round(period_sec/3600, 2)))   # updated 2020.08.25
            GPIO.output(23, GPIO.LOW)
            GPIO.output(26, GPIO.LOW)
        # Making image of current state, while dark stage is ongoing
        else:
            # Image of current plant look
            GPIO.output(23, GPIO.HIGH)
            GPIO.output(26, GPIO.HIGH)
            with picamera.PiCamera() as camera:
                camera.color_effects = (128, 128)  # b/w mode
                camera.resolution = (3280, 2464)
                camera.framerate = 0.2
                camera.shutter_speed = 400000  # exposure length, can be ajusted (max 6000000 - 6 sec)
                camera.exposure_mode = 'off'  # turning off autoexposure
                camera.iso = 100
                # Give the camera a good long time to measure AWB
                # (you may wish to use fixed AWB instead)
                camera.awb_mode = 'off'
                camera.awb_gains = (Fraction(2), Fraction(1))
                camera.capture("./current_look_{}(dark_stage).jpg".format(i))
            GPIO.output(23, GPIO.LOW)
            GPIO.output(26, GPIO.LOW)
            # current photo should be only one
            exists = os.path.isfile("./current_look_{}(dark_stage).jpg".format(i-1))
            if exists:
                os.remove("./current_look_{}(dark_stage).jpg".format(i-1))
        elapsed = timeit.default_timer() - start_time
        time.sleep(float(period_sec) - elapsed)
    GPIO.cleanup()


def bending_cycle(color, total_hours_blue, ph_decision, pic_num_blue, period_sec):
    ''' Running a phototropic stage'''
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(23, GPIO.OUT)  # IR left
    # GPIO.setup(18, GPIO.OUT)  # blue LEDs
    GPIO.setup(26, GPIO.OUT)  # IR right

    # that will release us from constant deleting of already existing folders
    if total_hours_blue != 0 or ph_decision != 0:
        for i in range(pic_num_blue):
            start_time = timeit.default_timer()  # when making of picture starts
            colorWipe(strip, Color(0, 0, 0, 0), 0)  # switch off light
            GPIO.output(23, GPIO.HIGH)
            GPIO.output(26, GPIO.HIGH)
            with picamera.PiCamera() as camera:
                camera.color_effects = (128, 128)  # b/w mode
                camera.resolution = (3280, 2464)
                camera.framerate = 0.2
                camera.shutter_speed = 400000  # exposure length, can be ajusted (max 6000000 - 6 sec)
                camera.exposure_mode = 'off'  # turning off of autoexposure
                camera.iso = 100
                # Give the camera a good long time to measure AWB
                # (you may wish to use fixed AWB instead)
                camera.awb_mode = 'off'
                camera.awb_gains = (Fraction(2), Fraction(1))

                camera.capture("./{}_{}_irradiated.jpg".format(i, color))
            colorWipe(strip, Color(int(color[0]),int(color[1]), int(color[2]), int(color[3])), 0)
            GPIO.output(23, GPIO.LOW)
            GPIO.output(26, GPIO.LOW)
            # adjustment of total time(cause it tends to run forward for ~45 sec per cycle
            elapsed = timeit.default_timer() - start_time
            time.sleep(float(period_sec) - elapsed)
        colorWipe(strip, Color(0, 0, 0, 0), 0)
    GPIO.cleanup()



# Variables
username = {'experiment name': '', 'user name': ''}  # global variable

### This creates the main window of an application
window = tk.Tk()
SIGNATURE = socket.getfqdn() + " " + get_ip()
window.title("RaPiDBox v 1" + "  (" + SIGNATURE + ")")
window.geometry("800x450")
window.configure(background='white')

# ### Navigation buttons
# run
launch_button = tk.Button(window, text="Launch", width=16, command=launch)
launch_button.grid(row=1, column=3, ipady=10, ipadx=5, sticky='e')
launch_button.config(font=("Arial", 14, 'bold'), bg='white')
# close
close_butt = tk.Button(window, text="Close", width=16, bg='white', command=window.destroy)
close_butt.grid(row=1, column=0, ipadx=5, ipady=10, sticky='w')
close_butt.config(font=("Arial", 14, 'bold'), bg='white')
# user
usr_name = tk.Button(window, text="Select user", width=16, bg='white', command=lambda: open_username('user name'))
usr_name.grid(row=1, column=1, ipadx=5, ipady=10, sticky='w')
usr_name.config(font=("Arial", 14, 'bold'), bg='white')
# experiment_name
exp_name = tk.Button(window, text="Experiment name", width=16, bg='white',
                     command=lambda: open_username('experiment name'))
exp_name.grid(row=1, column=2, ipadx=5, ipady=10, sticky='w')
exp_name.config(font=("Arial", 14, 'bold'), bg='white')

### Checkboxes ###

pre_light = tk.IntVar()
ah_choice = tk.IntVar()
ph_choice = tk.IntVar()

c1 = tk.Checkbutton(window, text='6h white light pretreatment', width=26, variable=pre_light, onvalue=1, offvalue=0,
                    command=print_selection)
c1.grid(row=2, column=0, ipadx=25, ipady=15, columnspan=2)
c1.config(font=("Arial", 16, 'bold'), bg='white', anchor='w')

c2 = tk.Checkbutton(window, text='Apical hook development', width=26, variable=ah_choice, onvalue=1, offvalue=0,
                    command=print_selection)
c2.grid(row=3, column=0, ipadx=25, ipady=15, columnspan=2)
c2.config(font=("Arial", 16, 'bold'), bg='white', anchor='w')

c3 = tk.Checkbutton(window, text='Phototropic bending', width=26, variable=ph_choice, onvalue=1, offvalue=0,
                    command=print_selection)
c3.grid(row=4, column=0, ipadx=25, ipady=15, columnspan=2)
c3.config(font=("Arial", 16, 'bold'), bg='white', anchor='w')

### Sliders ###

ah_value = tk.IntVar()
ph_value = tk.IntVar()
freq_value = tk.IntVar()
light_power = tk.IntVar()

# AH/Dark experiment length

AH_label = "Apical hook experiment length (hours):"
w1 = tk.Scale(window, from_=0, to=350, width=26, tickinterval=50, label=AH_label, variable=ah_value,
              orient='horizontal')
w1.set(90)
w1.grid(row=5, column=0, ipadx=147, ipady=1, columnspan=2)
w1.config(font=("Arial", 12, 'bold'), bg='white')

# phototrop experiment length
PH_label = "Phototropic bending experiment length (hours):"
w2 = tk.Scale(window, from_=0, to=80, width=26, tickinterval=10, label=PH_label, variable=ph_value, orient='horizontal')
w2.set(20)
w2.grid(row=6, column=0, ipadx=147, ipady=1, columnspan=2)
w2.config(font=("Arial", 12, 'bold'), bg='white')

# Frequency of imaging
freq_label = "Interval between images (minutes):"
w3 = tk.Scale(window, from_=0, to=240, width=26, tickinterval=50, label=freq_label, variable=freq_value,
              orient='horizontal')
w3.set(20)
w3.grid(row=5, columnspan=2, column=2, rowspan=1, ipadx=144, ipady=1, sticky='w')
w3.config(font=("Arial", 12, 'bold'), bg='white')

# Light intencity
light_power_label = "Light intensity:"
w4 = tk.Scale(window, from_=0, to=255, width=26, tickinterval=50, label=light_power_label, variable=light_power,
              orient='horizontal')
w4.set(10)
w4.grid(row=6, columnspan=2, column=2, rowspan=1, ipadx=144, ipady=1, sticky='w')
w4.config(font=("Arial", 12, 'bold'), bg='white')

''' Make possible to combine simultaneous buttons press + add clear button to unselect all'''

# Color label
color_label = tk.Label(window, text="Select LED color", bg='white')
color_label.config(font=("Arial", 18, 'bold'))
color_label.grid(row=2, column=2, columnspan=2, ipadx=10, ipady=15)

color_var = [0, 0, 0, 0]

# LED
white_choice = tk.IntVar()
red_choice = tk.IntVar()
green_choice = tk.IntVar()
blue_choice = tk.IntVar()

white = tk.Checkbutton(window, text="White", font=('Arial', 14, 'bold'), bg='white', width=5, variable=white_choice,
                       command=color_switcher, onvalue=1, offvalue=0)
white.grid(row=3, column=2, ipadx=55, ipady=15)

# Red LED
red = tk.Checkbutton(window, text="Red", font=('Arial', 14, 'bold'), bg='red', activebackground='pink', width=5,
                     variable=red_choice, command=color_switcher, onvalue=1, offvalue=0)
red.grid(row=3, column=3, ipadx=55, ipady=15)

# Green LED
green = tk.Checkbutton(window, text="Green", font=('Arial', 14, 'bold'), bg='#6df565',
                       activebackground='#c0f6bd', width=5,
                       variable=green_choice, command=color_switcher, onvalue=1, offvalue=0)
green.grid(row=4, column=2, ipadx=55, ipady=15)

# blue LED
blue = tk.Checkbutton(window, text="Blue", font=('Arial', 14, 'bold'),
                      activebackground='#bdc9f6', bg='#6c89fb', width=5,
                      variable=blue_choice, command=color_switcher, onvalue=1, offvalue=0)
blue.grid(row=4, column=3, ipadx=55, ipady=15)

tk.Button(window, text='Show', command=show_values)


window.mainloop()
#!/usr/bin/python3 # LED strip configuration: # Number of LED pixels. # GPIO pin connected to the pixels (real nuber is 12) (must support PWM!). # LED signal frequency in hertz (usually 800khz) # DMA channel to use for generating signal (try 10) # Set to 0 for darkest and 255 for brightest # True to invert the signal (when using NPN transistor level shift) # Create NeoPixel object with appropriate configuration. # Intialize the library (must be called once before other functions). # IR LEDs configuration # inderpendent IR board # 37 # second IR board # 16 function to get and show IP in the status bar # doesn't even have to be reachable # Text widget - info text selection ### # Showing values on sliders Keyboard and username/experiment name selection # end # function clear button # end # closing window without closing the app # key window name # title Name # Size window size # normal size # maximum size # minimum size # end window size # add background color # label # entry box # end entry box # add all button line wise # Second Line Button # third line Button # number row masterfunction where all data recorded before should go into motion Controlling part # argument which turns off apical hook opening tracing (making pictures of it) # how many hours before the light on (hours) # period between pictures (min) # for how long we want blue LEDs on (hours) # intensity of the light # color of the color strip # period_hours = round(period_min/60) # necessary for counting number of pictures		initial value is 60 # (universal) sleep counts time in secs # takes only int part of quotient # unilateral light (blue) # initial value is 60 Creating a window with a progress bar and info of the experiment stage # Setting user name and folder name # init colored photo # starting AH cycle # starting ph cycle (or not starting) # final white photo Wipe color across display a pixel at a time. creating experiment and user folder # that will release us from constant deleting of already existing folders Creating a single photo with given LED parameters # White wipe # Switching off LED strip Running an apical hook stage/dark stage # the cycle itself # when making of picture starts # by this, we disarm the whole cycle # b/w mode # exposure length, can be ajusted (max 6000000 - 6 sec) # turning off of autoexposure # Give the camera a good long time to measure AWB # (you may wish to use fixed AWB instead) # updated 2020.08.25 # Making image of current state, while dark stage is ongoing # Image of current plant look # b/w mode # exposure length, can be ajusted (max 6000000 - 6 sec) # turning off autoexposure # Give the camera a good long time to measure AWB # (you may wish to use fixed AWB instead) # current photo should be only one Running a phototropic stage # IR left # GPIO.setup(18, GPIO.OUT)  # blue LEDs # IR right # that will release us from constant deleting of already existing folders # when making of picture starts # switch off light # b/w mode # exposure length, can be ajusted (max 6000000 - 6 sec) # turning off of autoexposure # Give the camera a good long time to measure AWB # (you may wish to use fixed AWB instead) # adjustment of total time(cause it tends to run forward for ~45 sec per cycle # Variables # global variable ### This creates the main window of an application # ### Navigation buttons # run # close # user # experiment_name ### Checkboxes ### ### Sliders ### # AH/Dark experiment length # phototrop experiment length # Frequency of imaging # Light intencity Make possible to combine simultaneous buttons press + add clear button to unselect all # Color label # LED # Red LED # Green LED # blue LED