#!/usr/bin/env python
import wx
from wx.gizmos import EditableListBox

class LeafEditDialog(wx.Dialog):
    def SetControl(self, editControl):
        sizer = wx.BoxSizer(wx.VERTICAL)
        
        sizer.Add(editControl, 1, wx.EXPAND)
        sizer.AddSpacer(10)
        sizer.Add(self.optionsBox, 0, wx.CENTER)
        sizer.AddSpacer(10)
        sizer.Add(self.buttonSizer, 0, wx.CENTER)
        sizer.AddSpacer(10)
        
        self.SetSizerAndFit(sizer)
        
    
    def __init__(self, parent=None, title=''):
        """
        This dialog is used to do advanced editing of a leaf.
        The control is passed in later with SetControl, since the dialog
        needs to exist first, to be the parent of the widget
        """
        wx.Dialog.__init__(self, parent, -1, title="Editing '%s'"%title)

        #FILTERS
        applyTxt = wx.StaticText(self, -1, "Apply change to:")
        filterTxt = wx.StaticText(self, -1, "Filter matches by:")
        radio1 = wx.RadioButton( self, -1, "Global (All Features)", style = wx.RB_GROUP )
        radio2 = wx.RadioButton( self, -1, "Tagged Features" )
        radio3 = wx.RadioButton( self, -1, "Current Feature")
        radio4 = wx.RadioButton( self, -1, "This Attribute Only" )
        radio4.SetValue(True)
        
        matchFeat = wx.CheckBox(self, -1, "Feature")
        matchTar = wx.CheckBox(self, -1, "Target")
        matchPoint = wx.CheckBox(self, -1, "Point #")
            
        optionsBox = wx.BoxSizer(wx.HORIZONTAL)
            
        rbox = wx.BoxSizer(wx.VERTICAL)
        rbox.Add(applyTxt)
        rbox.Add(radio1, 0, wx.ALIGN_LEFT|wx.LEFT|wx.TOP, 5)
        rbox.Add(radio2, 0, wx.ALIGN_LEFT|wx.LEFT|wx.TOP, 5)
        rbox.Add(radio3, 0, wx.ALIGN_LEFT|wx.LEFT|wx.TOP, 5)
        rbox.Add(radio4, 0, wx.ALIGN_LEFT|wx.LEFT|wx.TOP, 5)
        
        cbox = wx.BoxSizer(wx.VERTICAL)
        cbox.Add(filterTxt)
        cbox.Add(matchFeat, 0, wx.ALIGN_LEFT|wx.LEFT|wx.TOP, 5)
        cbox.Add(matchTar, 0, wx.ALIGN_LEFT|wx.LEFT|wx.TOP, 5)
        cbox.Add(matchPoint, 0, wx.ALIGN_LEFT|wx.LEFT|wx.TOP, 5)

        optionsBox.AddSpacer(10)
        optionsBox.Add(rbox, 1, wx.LEFT)
        optionsBox.AddSpacer(20)
        optionsBox.Add(cbox, 1, wx.LEFT)
        optionsBox.AddSpacer(10)
        
        #OKAY/CANCEL BUTTONS
        okayButton = wx.Button(self, wx.ID_OK, "OK")
        okayButton.SetDefault()
        cancelButton = wx.Button(self, wx.ID_CANCEL, "CANCEL")
        
        buttonSizer = wx.BoxSizer(wx.HORIZONTAL)
        buttonSizer.Add(okayButton, 0, wx.ALIGN_CENTER)
        buttonSizer.AddSpacer(20) #they don't need to be kissing
        buttonSizer.Add(cancelButton, 0, wx.ALIGN_CENTER)
        
        self.buttonSizer, self.optionsBox = buttonSizer, optionsBox
        self.radio1, self.radio2, self.radio3 = radio1, radio2, radio3
        self.matchFeat, self.matchTar, self.matchPoint = matchFeat, matchTar, matchPoint
        

class MyApp(wx.App):
    def OnInit(self):
        dlg4 = LeafEditDialog(title='Choice')
        dlg4.SetControl( wx.Choice(dlg4, -1, choices=['hey','hi','hello']) )
        dlg4.ShowModal()
        
        dlg3 = LeafEditDialog(title='ELBox')
        dlg3.SetControl( EditableListBox(dlg3, -1, 'Editable List Box') )
        dlg3.ShowModal()
        
        dlg2 = LeafEditDialog(title='TextCtrl')
        dlg2.SetControl( wx.TextCtrl(dlg2, -1) )
        dlg2.ShowModal()

        dlg = LeafEditDialog(title='CheckBox')
        dlg.SetControl( wx.CheckBox(dlg, -1) )
        dlg.ShowModal()
        
        return False

MyApp(0).MainLoop()
