#!/usr/bin/env python2.4

#FramePanel:modScoping
"""
  This module has the user interface for the notebook tab named 'Scoping.'
"""

import wx
import string

class ListPanel(wx.Panel):
  def __init__(self, prnt, Data):
    wx.Panel.__init__(self, prnt, wx.ID_ANY)

    Name = wx.StaticBox(self, wx.ID_ANY, Data['title'], size=wx.Size(185,550))
    Box = wx.StaticBoxSizer(Name, wx.VERTICAL)

    vbox1 = wx.BoxSizer(wx.VERTICAL)

    self.lc = wx.ListCtrl(self, wx.ID_ANY, size=wx.Size(175,200), style=wx.LC_REPORT)
    self.lc.InsertColumn(0, 'Component')
    self.lc.SetColumnWidth(0, 175)
    self.tc1 = wx.TextCtrl(self, wx.ID_ANY)
    self.AddBut = wx.Button(self, wx.ID_ADD, '&Add')
    self.AddBut.Bind(wx.EVT_BUTTON, self.OnAdd)
    self.ClrBut = wx.Button(self, wx.ID_CLEAR, '&Clear')
    self.ClrBut.Bind(wx.EVT_BUTTON, self.OnClear)
    self.OkBut = wx.Button(self, wx.ID_OK, '&OK')
    self.OkBut.Bind(wx.EVT_BUTTON, self.OnOK)

    vbox1.Add(self.lc, 1, wx.EXPAND|wx.ALIGN_CENTER|wx.ALL, 5)
    vbox1.Add(self.tc1, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    vbox1.Add(self.AddBut, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    vbox1.Add(self.ClrBut, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    vbox1.Add(self.OkBut, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    Box.Add(vbox1,1,wx.EXPAND)

    self.SetAutoLayout(True)
    self.SetSizer(Box)
    Box.Fit(self)
    Box.SetSizeHints(self)
    self.Layout()

    self.Data = []

  def OnAdd(self,event):
    if not self.tc1.GetValue():
      return
    num_items = self.lc.GetItemCount()
    self.lc.InsertStringItem(num_items, self.tc1.GetValue())
    self.tc1.Clear()

  def OnOK(self, event):
    num_items = self.lc.GetItemCount()
    fh = open(name + '.in', 'a')
    for index in range(num_items):
      text = self.lc.GetItemText(index)
      fh.write(text)
      fh.write('\n')
    fh.close
                                  
  def OnClear(self, event):
    self.tc1.Clear()


class modScoping(wx.Panel):
  def __init__(self, prnt, ID):
    wx.Panel.__init__(self, prnt, wx.ID_ANY)

    topSizer = wx.BoxSizer(wx.VERTICAL)
    sidewaysBox = wx.BoxSizer(wx.HORIZONTAL)

    Data = {'title': "Natural:"}
    naturalPanel = ListPanel(self, Data)
    Data = {'title': "Economic:"}
    economicPanel = ListPanel(self, Data)
    Data = {'title': "Societal:"}
    socialPanel = ListPanel(self, Data)

    dividerLeft = wx.StaticLine(self, wx.ID_ANY, style=wx.LI_VERTICAL)
    dividerRight = wx.StaticLine(self, wx.ID_ANY, style=wx.LI_VERTICAL)
    sidewaysBox.Add(naturalPanel, 1, wx.EXPAND|wx.CENTER|wx.ALL, 5)
    sidewaysBox.Add(dividerLeft, 0, wx.EXPAND)
    sidewaysBox.Add(economicPanel, 1, wx.EXPAND|wx.CENTER|wx.ALL, 5)
    sidewaysBox.Add(dividerRight, 0, wx.EXPAND)
    sidewaysBox.Add(socialPanel, 1, wx.EXPAND|wx.CENTER|wx.ALL, 5)

    topSizer.Add(sidewaysBox, 1, wx.EXPAND|wx.ALL, 5)

    self.SetAutoLayout(True)
    self.SetSizer(topSizer)
    topSizer.Fit(self)
    topSizer.SetSizeHints(self)
    self.Layout()


class MyApp(wx.App):
  def OnInit(self):
    frame = wx.Frame(None, wx.ID_ANY)
    Panel = modScoping(frame, wx.ID_ANY)
    frame.Fit()
    frame.Layout()
    frame.Show(True)
    return True

app = MyApp(0)
app.MainLoop()
