"""mems.instrument.client.tk.application

Contains the top-level application code for the Tkinter client.
"""

__revision__ = "$Id: application.py,v 1.19 2002/02/19 23:20:38 akuchlin Exp $"
__version__ = "2.0a1"

import getopt, sys, string
import Tkinter, Pmw

from mems.instrument.client.tk.client import Client

def run ():
    # Set values for Pmw's About dialog box
    Pmw.aboutcopyright("Copyright 2001 "
                       "Corporation for National Research Initiatives"
                       "\nAll rights reserved" )
    Pmw.aboutcontact(
        'For information about this application contact:\n'
        'MEMS Exchange\n'
        '1895 Preston White Drive, Suite 100\n'
        'Reston, VA 20191-5434\n'
        '(703) 262-5368\n'
        'email: microscope-feedback@mems-exchange.org\n'
        'www.mems-exchange.org\n'
        )    
    Pmw.aboutversion( __version__ )
    
    device = userid = password = None
    chat = 1
    
    options, args = getopt.getopt(sys.argv[1:], 'cd:h:p:u:',
                                  ['nochat', 'help',
                                   'device=', 'user=', 'password='] )

    for (opt, param) in options:
        if opt == '-c' or opt == '--nochat': chat = 0
        elif opt == '-h' or opt == '--help':
            print """Remote Microscope %(__version__)s client:
Usage: tkclient.py [options]
Available options:
 -h, --help                    Display this help message
 -c, --nochat                  Disable displaying of the chat window
 -d dev, --device dev          Use device named dev (ex. 'MX')
 -u user, --user user          Set user name to 'user'
 -p pw, --password pw          Set password to 'pw'
""" % vars()
            sys.exit(0)
        elif opt == '-d' or opt == '--device':
            device = param.lower()
        elif opt == '-u' or opt == '--user':
            userid = param
        elif opt == '-p' or opt == '--password':
            password = param

    # Get root window
    root = Tkinter.Tk()
    root.title("Remote Microscope")
    client = Client(root, userid, password, device)
    client.pack()
    root.after(1000, client.get_authtoken, (root,) )
    root.mainloop()


        
if __name__ == '__main__':
    run()
    
