# expfltGUI1.py
# Written by Todd Wareham for CS 2500
"""
Given a string-representation of an exponential number obtained from a GUI,
 compute and print the floating-point value of this exponential number.

Note that we assume that this esxponential number is in the range of 
 floating-point values.
"""

import sys 
import re
from Tkinter import *


def expNumVal(expNumStr):
    mantissa = r"([+\-]?\d\.\d+)"
    exponent = r"([+\-]\d+)"
    r = re.compile(mantissa + "[eE]" + exponent)
    m = r.match(expNumStr)
    return float(m.group(1)) * pow(10, int(m.group(2)))


def runGUI(title):
## Create and execute GUI with specified title

## Root window setup / Global GUI data-variables

    root = Tk()
    env = StringVar()

    def makeGUI(title):
##  Set up appearance and behavior of GUI with specified title

## Configure root window

        root.title(title)

## GUI widgets

        Button(root, text="Process\nNumber", command=root.quit).pack(expand=YES, fill=BOTH, side=BOTTOM)

	env.set("--")
	Label(root, text="Exponential Number: ").pack(expand=YES, fill=BOTH, side=LEFT)
	Entry(root, textvariable=env).pack(expand=YES, fill=X, side=RIGHT)


## Body of method runGUI: create GUI, execute GUI, and return GUI variable
##  values on GUI termination.

    makeGUI(title)
    root.mainloop()
    return env.get()



if __name__ == "__main__":

    expNumStr = runGUI(sys.argv[0])

    print "The floating-point value of ", expNumStr, " is ", \
          expNumVal(expNumStr)

