#!/usr/bin/env python2.3

import sys
import getopt
import gtk
import spellcast_gui
import Player
from hflib import protocol


# Debugging flag
df = False

def usage(exitcode=1):
    s = "%s [-H] [-h hostname] [-p portnumber] [myname]" % sys.argv[0]
    if exitcode==0:
        print "Start the spellcast gui with "+s
    else:
        print >>sys.stderr, "Usage: "+s
    sys.exit(exitcode)

try:
    options, args = getopt.getopt(sys.argv[1:], "dh:p:H")
except getopt.GetoptError, goe:
    print >>sys.stderr, goe.msg
    usage()

for option in options:
    if option[0] == '-h':
        spellcast_gui.serverHost = option[1]
    elif option[0] == '-p':
        try:
            portNum = int(option[1])
        except ValueError, ve:
            print >>sys.stderr, ve[0]
            usage()
        spellcast_gui.serverPort = option[1]
    elif option[0] == '-d':
        df = True
    elif option[0] == '-H':
        usage(0)
    else:
        print >>sys.stderr, "Unknown option %s" % option[0]
        usage()
if len(args) > 1:
    usage()
if len(args)==1:
    spellcast_gui.myPlayerName = args[0]

try:
    spellcast_gui.df = df
    Player.df = df
    protocol.df = df
    spellcast_gui.setupGui()
    gtk.main()
except KeyboardInterrupt:
    # Get rid of the gumph that comes out when we press ^C.
    sys.exit(1)



# Local variables: ***
# mode:python ***
# py-indent-offset:4 ***
# fill-column:80 ***
# End: ***
### arch-tag: eaa5e9d8-23e1-4202-999e-c56154e3e354
