# Author: Abisai Ramos
#! /usr/bin/env python
#
# Support module generated by PAGE version 4.5
# In conjunction with Tcl version 8.6
#    Apr 14, 2015 02:34:09 AM


import sys

try:
    from FilterLibs import *
    from tkinter.filedialog import askopenfilename
    from tkinter.messagebox import showinfo
    from Tkinter import *
except ImportError:
    from tkinter import *


try:
    import ttk
    py3 = 0
except ImportError:
    import tkinter.ttk as ttk
    py3 = 1

def set_Tk_var():
    # These are Tk variables used passed to Tkinter and must be
    # defined before the widgets using them are created.
    global inputText
    inputText = StringVar()
    global filterType
    filterType = StringVar()


def fileChooser():
    filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
    inputText.set(filename)
    sys.stdout.flush()
    
def run():
    if(inputText.get()==""):
        noPathErrorMessage()
    elif(filterType.get()==""):
        showinfo("Error","Select a filter")
    elif(filterType.get()=="Median"):
        cresponce(2)
        #print('median')
    elif(filterType.get()=="Min"):
        cresponce(4)
        #print('Min')
    elif(filterType.get()=="Max"):
        cresponce(5)
        #print('Max')
    elif(filterType.get()=="Mean"):
        cresponce(1)
        #print('Mean')
    elif(filterType.get()=="Min_Max"):
        cresponce(6)
        #print('Min_Max')
    elif(filterType.get()=="Marr/Hildreth Edge Detector"):
        cresponce(0)
        #print('Marr/Hildreth Edge Detector')
    elif(filterType.get()=="Mid Point"):
        cresponce(3)
        #print('Marr/Hildreth Edge Detector')
    sys.stdout.flush()

def init(top, gui, arg=None):
    global w, top_level, root
    w = gui
    top_level = top
    root = top

def destroy_window():
    # Function which closes the window.
    global top_level
    top_level.destroy()
    top_level = None

def noPathErrorMessage():
    showinfo("Error","Select an image")

def cresponce(filterID):
    responce = applyFilter(inputText.get(),filterID)
    if(responce <0):
           noPathErrorMessage()