#!/usr/bin/env python

# NOTICE... this file is generated by tk_happy.
# Any code or comments added by the user must be in designated areas ONLY.
# User additions will be lost if they are placed in code-generated areas.

# tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "imports"
from Tkinter import *
import tkMessageBox
import tkFileDialog
import tkColorChooser
# >>>>>>insert any user code below this comment for section "imports"
# Place any user import statements here

# tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "top_of_init"


class _Temp:
    def __init__(self, master):
        self.initComplete = 0
        frame = Frame(master, width=555, height=546)
        frame.pack()
        self.master = master
        self.x, self.y, self.w, self.h = -1,-1,-1,-1
        
        # bind master to <Configure> in order to handle any resizing, etc.
        # postpone self.master.bind("<Configure>", self.Master_Configure)
        self.master.bind('<Enter>', self.bindConfigure)
        

        self.master.title("temp")

        self.Plot_Canvas = Canvas(self.master,width="313", height="362")
        self.Plot_Canvas.place(x=216, y=36)
        self.Plot_Canvas.bind("<ButtonRelease-1>", self.Plot_Canvas_Click)

        self.Defined_Points_Label = Label(self.master,text="Defined Points", width="15")
        self.Defined_Points_Label.place(x=48, y=12, width=112, height=22)


        lbframe = Frame( self.master )
        self.Defined_Points_Listbox_frame = lbframe
        scrollbar = Scrollbar(lbframe, orient=VERTICAL)
        self.Defined_Points_Listbox = Listbox(lbframe, width="15", selectmode="extended", yscrollcommand=scrollbar.set)
        scrollbar.config(command=self.Defined_Points_Listbox.yview)
        scrollbar.pack(side=RIGHT, fill=Y)
        self.Defined_Points_Listbox.pack(side=LEFT, fill=BOTH, expand=1)

        self.Defined_Points_Listbox_frame.place(x=24, y=36, width=179, height=365)
        self.Defined_Points_Listbox.bind("<ButtonRelease-1>", self.Defined_Points_Listbox_Click)
        
        # make a Status Bar
        self.statusMessage = StringVar()
        self.statusMessage.set("")
        self.statusbar = Label(self.master, textvariable=self.statusMessage, bd=1, relief=SUNKEN)
        self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)


        # >>>>>>insert any user code below this comment for section "top_of_init"
        self.statusMessage.set("Welcome to temp")
        # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "menuStructure"
        self.menuBar = Menu(master, relief = "raised", bd=2)

        top_File = Menu(self.menuBar, tearoff=0)

        top_File.add("command", label = "Import Image", command = self.menu_File_Import_Image)
        top_File.add("command", label = "Save CSV", command = self.menu_File_Save_CSV)
        self.menuBar.add("cascade", label="File", menu=top_File)

        top_Anchor_Plot = Menu(self.menuBar, tearoff=0)

        top_Anchor_Plot.add("command", label = "Set Xmin", command = self.menu_Anchor_Plot_Set_Xmin)
        top_Anchor_Plot.add("command", label = "Set Xmax", command = self.menu_Anchor_Plot_Set_Xmax)
        top_Anchor_Plot.add("command", label = "Set Ymin", command = self.menu_Anchor_Plot_Set_Ymin)
        top_Anchor_Plot.add("command", label = "Set Ymax", command = self.menu_Anchor_Plot_Set_Ymax)
        self.menuBar.add("cascade", label="Anchor Plot", menu=top_Anchor_Plot)
        self.menuBar.add("command", label = "Help", command = self.menu_Help)

        top_Exit = Menu(self.menuBar, tearoff=0)

        top_Exit.add("command", label = "Quit", command = self.menu_Exit_Quit)
        self.menuBar.add("cascade", label="Exit", menu=top_Exit)

        master.config(menu=self.menuBar)

        # >>>>>>insert any user code below this comment for section "menuStructure"


    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "menu_File_Import_Image"
    def menu_File_Import_Image(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_File_Import_Image"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_File_Import_Image")
        print "called menu_File_Import_Image"


    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "menu_File_Save_CSV"
    def menu_File_Save_CSV(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_File_Save_CSV"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_File_Save_CSV")
        print "called menu_File_Save_CSV"


    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "menu_Anchor_Plot_Set_Xmin"
    def menu_Anchor_Plot_Set_Xmin(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_Anchor_Plot_Set_Xmin"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_Anchor_Plot_Set_Xmin")
        print "called menu_Anchor_Plot_Set_Xmin"


    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "menu_Anchor_Plot_Set_Xmax"
    def menu_Anchor_Plot_Set_Xmax(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_Anchor_Plot_Set_Xmax"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_Anchor_Plot_Set_Xmax")
        print "called menu_Anchor_Plot_Set_Xmax"


    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "menu_Anchor_Plot_Set_Ymin"
    def menu_Anchor_Plot_Set_Ymin(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_Anchor_Plot_Set_Ymin"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_Anchor_Plot_Set_Ymin")
        print "called menu_Anchor_Plot_Set_Ymin"


    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "menu_Anchor_Plot_Set_Ymax"
    def menu_Anchor_Plot_Set_Ymax(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_Anchor_Plot_Set_Ymax"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_Anchor_Plot_Set_Ymax")
        print "called menu_Anchor_Plot_Set_Ymax"


    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "menu_Help"
    def menu_Help(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_Help"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_Help")
        print "called menu_Help"


    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "menu_Exit_Quit"
    def menu_Exit_Quit(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_Exit_Quit"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_Exit_Quit")
        print "called menu_Exit_Quit"


    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "Master_Configure"
    def bindConfigure(self, event):
        if not self.initComplete:
            self.master.bind("<Configure>", self.Master_Configure)
            self.initComplete = 1


    def Master_Configure(self, event):
        pass
        # >>>>>>insert any user code below this comment for section "Master_Configure"
        # replace, delete, or comment-out the following
        if event.widget != self.master:
            if self.w != -1:
                return
        x = int(self.master.winfo_x())
        y = int(self.master.winfo_y())
        w = int(self.master.winfo_width())
        h = int(self.master.winfo_height())
        if (self.x, self.y, self.w, self.h) == (-1,-1,-1,-1):
            self.x, self.y, self.w, self.h = x,y,w,h


        if self.w!=w or self.h!=h:
            print "Master reconfigured... make resize adjustments"
            self.w=w
            self.h=h
    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "compID=1"
    def Plot_Canvas_Click(self, event): #click method for component ID=1
        pass
        # >>>>>>insert any user code below this comment for section "compID=1"
        # replace, delete, or comment-out the following
        print "executed method Plot_Canvas_Click"
        self.statusMessage.set("executed method Plot_Canvas_Click")
        print "clicked in canvas at x,y =",event.x,event.y
        w = int(self.Plot_Canvas.cget("width"))
        h = int(self.Plot_Canvas.cget("height"))
        self.Plot_Canvas.create_rectangle((2, 2, w+1, h+1), outline="blue")
        self.Plot_Canvas.create_line(0, 0, w+2, h+2, fill="red")
        x = int(event.x)
        y = int(event.y)
        print "event x,y=",x,y
        self.Plot_Canvas.create_text(x,y, text="NE", fill="green", anchor=NE)
        self.Plot_Canvas.create_text(x,y, text="SW", fill="magenta", anchor=SW)

    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "compID=2"
    def Defined_Points_Listbox_Click(self, event): #click method for component ID=2
        pass
        # >>>>>>insert any user code below this comment for section "compID=2"
        # replace, delete, or comment-out the following
        print "executed method Defined_Points_Listbox_Click"
        self.statusMessage.set("executed method Defined_Points_Listbox_Click")
        print "current selection(s) =",self.Defined_Points_Listbox.curselection()
        labelL = []
        for i in self.Defined_Points_Listbox.curselection():
            labelL.append( self.Defined_Points_Listbox.get(i))
        print "current label(s) =",labelL
        # use self.Defined_Points_Listbox.insert(0, "item zero")
        #     self.Defined_Points_Listbox.insert(index, "item i")
        #            OR
        #     self.Defined_Points_Listbox.insert(END, "item end")
        #   to insert items into the list box

    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "standard_message_dialogs"

    # standard message dialogs... showinfo, showwarning, showerror
    def ShowInfo(self, title='Title', message='your message here.'):
        tkMessageBox.showinfo( title, message )
        return
    def ShowWarning(self, title='Title', message='your message here.'):
        tkMessageBox.showwarning( title, message )
        return
    def ShowError(self, title='Title', message='your message here.'):
        tkMessageBox.showerror( title, message )
        return
        
    # standard question dialogs... askquestion, askokcancel, askyesno, or askretrycancel
    # return True for OK, Yes, Retry, False for Cancel or No
    def AskYesNo(self, title='Title', message='your question here.'):
        return tkMessageBox.askyesno( title, message )
    def AskOK_Cancel(self, title='Title', message='your question here.'):
        return tkMessageBox.askokcancel( title, message )
    def AskRetryCancel(self, title='Title', message='your question here.'):
        return tkMessageBox.askretrycancel( title, message )
        
    # return "yes" for Yes, "no" for No
    def AskQuestion(self, title='Title', message='your question here.'):
        return tkMessageBox.askquestion( title, message )
    # END of standard message dialogs

    # >>>>>>insert any user code below this comment for section "standard_message_dialogs"


    # tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "standard_file_dialogs"
    # standard file dialogs... askdirectory, askopenfile, asksaveasfilename

    # return a string containing directory name
    def AskDirectory(self, title='Choose Directory', initialdir="."):
        dirname = tkFileDialog.askdirectory(parent=self.master,initialdir=initialdir,title=title)
        return dirname # <-- string
        
    # return an OPEN file type object OR None (opened using mode, 'r','rb','w','wb')
    # WARNING... opening file with mode 'w' or 'wb' will erase contents
    def AskOpenFile(self, title='Choose File', mode='rb', initialdir='.', filetypes=None):
        if filetypes==None:
            filetypes = [
                ('Text File','*.txt'),
                ('Data File','*.dat'),
                ('Output File','*.out'),
                ('Any File','*.*')]
        fileobj = tkFileDialog.askopenfile(parent=self.master,mode=mode,title=title,
            initialdir=initialdir, filetypes=filetypes)
        
        # if opened, then fileobj.name contains the name string
        return fileobj # <-- an opened file, or the value None
        
    # return a string containing file name (the calling routine will need to open the file)
    def AskSaveasFilename(self, title='Save File', filetypes=None, initialfile=''):
        if filetypes==None:
            filetypes = [
                ('Text File','*.txt'),
                ('Data File','*.dat'),
                ('Output File','*.out'),
                ('Any File','*.*')]

        fileName = tkFileDialog.asksaveasfilename(parent=self.master,filetypes=filetypes, initialfile=initialfile ,title=title)
        return fileName # <-- string
        
    # END of standard file dialogs

    # >>>>>>insert any user code below this comment for section "standard_file_dialogs"


# tk_happy generated code. DO NOT EDIT THE FOLLOWING. section "end"

def main():
    root = Tk()
    app = _Temp(root)
    root.mainloop()

if __name__ == '__main__':
    main()
