# IMPORTE TKINTER
from Tkinter import *
import tkMessageBox
import tkFileDialog

# IMPORTE AVIFPS
import aviFps

# OS.PATH
import os.path

# INTERFACE
class AviFpsGui:

  def __init__(self, root):
    # contenu principal
    frame = Frame(root)
    frame.pack(side=TOP, padx=4, pady=4)

    # boutons
    self.btnOpen = Button(frame, text="Open AVI", command=self.computeFramerate)
    self.btnOpen.pack(side=LEFT, padx=2)
    self.btnQuit = Button(frame, text="Exit", command=frame.quit)
    self.btnQuit.pack(side=LEFT, padx=2)

    # contient la barre de statut
    statusFrame = Frame(root)
    statusFrame.pack(side=BOTTOM, fill=X)

    # barre de status
    self.status = Label(statusFrame, text="AVI Fps", bd=1, relief=SUNKEN, anchor=W)
    self.status.pack(side=BOTTOM, fill=X)

  def computeFramerate(self):
    # ouverture fichier
    file = tkFileDialog.askopenfilename(title="Choose an AVI file...", \
                                        defaultextension=".avi", \
                                        filetypes=[("AVI Files", ".avi")])
    fps = aviFps.getAVIFrameRate(file)
    file = os.path.basename(file)
    tkMessageBox.showinfo("AVI frame rate", """The framerate of "%s" is %s fps""" % (file, fps))

##########################
# MAIN
##########################

if __name__ == '__main__':
  root = Tk()
  root.title("AVI Fps")
  gui = AviFpsGui(root)
  root.mainloop()
