#!/usr/bin/env/ python

# rich.ScopingPage.py -- a stand-alone testing application

import wx

class DiaScope(wx.Dialog):
  def __init__(self, parent, id, title):
    wx.Dialog.__init__(self, parent, id, title, style=wx.DEFAULT_DIALOG_STYLE)

    vbox1 = wx.BoxSizer(wx.VERTICAL)
    pnl1 = wx.Panel(self, wx.ID_ANY, style=wx.RAISED_BORDER)
    
    self.lc = wx.ListCtrl(self, wx.ID_ANY, size=wx.Size(175,200), style=wx.LC_REPORT|
                          wx.LC_EDIT_LABELS|wx.LC_SINGLE_SEL|wx.RAISED_BORDER)
    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, 0, wx.ALL, 3)
    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)

    self.SetSizerAndFit(vbox1)

    self.Data = None
                                                
  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):
    Component = self.tc1.GetValue()
    self.Data = (Component)
    # check here if the data is valid.
    event.Skip() # this will let the event continue and be handles by the usual OK event.
                                                        
  def OnClear(self, event):
    self.tc1.Clear()
                                


class modScoping(wx.Panel):
  """ Scoping is used with the FuzzyEI-Assessor model, forest sustainability
  model, and other models where public values and beliefs need to be incorporated.

  There are three categories of components: Natural world, Economic, and Social. Up
  to 8 components can be listed for each category. When done, the names are used to
  produce LaTeX forms for the OMR reader. The input data are placed in a symmetrical
  matrix and the principal eigenvector calculated. The results -- a vector of
  relative importance weights -- is displayed.
  """
  
  def __init__(self, prnt, ID):
    wx.Panel.__init__(self, prnt, wx.ID_ANY)

    self.SetClientSize(wx.Size(800, 600))

    topSizer = wx.BoxSizer(wx.VERTICAL)     
    sidewaysBox = wx.BoxSizer(wx.HORIZONTAL)

    natData = {'title': " Natural World: "}
    ecoData = {'title': " Economic World: "}
    socData = {'title': " Social World: "}
    # Left column: Natural environment
    
    naturalName = wx.StaticBox(self, wx.ID_ANY, natData['title'])
    naturalBox = wx.StaticBoxSizer(naturalName, wx.VERTICAL)
    naturalPnl = wx.DiaScope(self, wx.ID_ANY, naturalName)

    # Middle column: Economic environment
    
    economicName = wx.StaticBox(self, wx.ID_ANY, ecoData['title'])
    economicBox = wx.StaticBoxSizer(economicName, wx.VERTICAL)
    economicPnl = wx.DiaScope(self, wx.ID_ANY, economicName)

    # Right column: Social environment
    
    socialName = wx.StaticBox(self, wx.ID_ANY, socData['title'])
    socialBox = wx.StaticBoxSizer(socialName, wx.VERTICAL)
    socialPnl = wx.DiaScope(self, wx.ID_ANY, socialName)

    dividerLeft = wx.StaticLine(self, wx.ID_ANY, size=wx.Size(-1, 485), style=wx.LI_VERTICAL)
    dividerRight = wx.StaticLine(self, wx.ID_ANY, size=wx.Size(-1, 485), style=wx.LI_VERTICAL)

    sidewaysBox.Add(naturalBox, 1, wx.EXPAND|wx.CENTER|wx.ALL, 5)
    sidewaysBox.Add(dividerLeft, 0, wx.EXPAND)
    sidewaysBox.Add(economicBox, 1, wx.EXPAND|wx.CENTER|wx.ALL, 5)
    sidewaysBox.Add(dividerRight, 0, wx.EXPAND)
    sidewaysBox.Add(socialBox, 1, wx.EXPAND|wx.CENTER|wx.ALL, 5)
    
    topSizer.Add(sidewaysBox, 1, wx.EXPAND|wx.ALL, 5)
    
    self.SetSizerAndFit(topSizer)
    
  " Event Handlers Follow "
  
  def message(self, event):
    """ This message dialog box is called to show the user that the selected
    function has not yet been implemented. It tells the user that something
    has happened."""
    notYet = wx.MessageDialog(self, 'This function is not yet implemented. Please come back soon.',
      "Uh-oh!", wx.OK|wx.ICON_EXCLAMATION)
    notYet.ShowModal()
    notYet.Destroy()

class MyApp(wx.App):
  def OnInit(self):
    dia = modScoping(None, wx.ID_ANY)
    dia.ShowModal()
    dia.Destroy()
    return True
                        
app = MyApp(0)
app.MainLoop()
