# SYSC 1005 A Fall 2017 Lab 7

import sys  # get_image calls exit
from Cimpl import *
from filters import *

def get_image():
    """
    Interactively select an image file and return a Cimpl Image object
    containing the image loaded from the file.
    """

    # Pop up a dialogue box to select a file
    file = choose_file()

    # Exit the program if the Cancel button is clicked.
    if file == "":
        sys.exit("File Open cancelled, exiting program")

    # Open the file containing the image and load it
    img = load_image(file)

    return img

# A bit of code to demonstrate how to use get_image().

if __name__ == "__main__":
    test_img = False
    done = False
    while not done:
        command = input('L)oad Image\nN)egative G)rayscale X)treme contrast S)epia tint E)dge detect \nQ)uit \n: ')

        
        if command == 'L' :
            test_img = True
            img = get_image()
            show(img)
            
        elif command == 'Q' :
            done = True
        elif command == 'N' :
            
            if test_img == False:
                print('No image loaded\n')
            else :
                negative(img)
                show(img)
           
        elif command == 'G' :
            if test_img == False:
                print('No image loaded\n')            
            else :
                grayscale(img)
                show(img)
        elif command == 'X' :
            if test_img == False:
                print('No image loaded\n')       
            else:
                extreme_contrast(img)
                show(img)
        elif command == 'S' :
            if test_img == False:
                print('No image loaded\n')            
            else:
                sepia_tint(img)
                show(img)
        elif command == 'E' :
            if test_img == False:
                print('No image loaded\n')           
            else:
                threshold = float(input('Threshold? : '))
                detect_edges_better(img, threshold)
                show(img)
                
        else:
            print('No such command\n')
            
        
            
