#!/usr/bin/env python

try:
  import gtk, gtk.glade
  import gobject
except:
  print "You do not have python gtk bindings, or you're missing glade libs"
  print "To use Lephisto's resedit you must install them"
  print "http://pygtk.org/"
  raise SystemExit

import space, faction, fleet, commodity

path = "../../dat/"

# Load the factions
factions = faction.Factions()
factions.loadFactions(path+"faction.xml")

# Load the fleets.
fleets = fleet.Fleets()
fleets.loadFleets(path+"fleet.xml")

# Load the commodities.
commodities = commodity.Commodities()
commodities.loadCommodities(path+"commodity.xml")

# Load the universe.
universe = space.Space(factions.data(), fleets.data(), commodities.data())
universe.loadSystems(path+"ssys.xml")
universe.loadPlanets(path+"planet.xml")

# Load the editor interface.
# Functions.
def winSystem(widget=None, event=None):
  if wtree.get_widget("butEditSystem").get_active():
    universe.windowSystem()
  else:
    universe.windowSystemClose()

def winPlanet(widget=None, event=None):
  if wtree.get_widget("butEditPlanet").get_active():
    universe.windowPlanet()
  else:
    universe.windowPlanetClose()

wtree = gtk.glade.XML("resedit.glade", "winResedit")
hooks = {
  "winResedit":["destroy", gtk.main_quit],
  "butEditSystem":["toggled", winSystem],
  "butEditPlanet":["toggled", winPlanet]
}

for key, val in hooks.items():
  wtree.get_widget(key).connect(val[0], val[1])
wtree.get_widget("winResedit").show_all()

gtk.main()