def __init__(self, parent, mapsystem, title):
        _SubPanel.__init__(self, parent, mapsystem, title)

        #### Loading XRC file and Setting the panel
        xmlresource=wx.xrc.XmlResource("OnSight/data/xrc/msetpanel.xrc")
        self.panel=xmlresource.LoadPanel(self,"msetpanel")

        sizer=wx.BoxSizer()
        sizer.Add(self.panel,proportion=1,flag= wx.ALL | wx.EXPAND)
        self.SetSizer(sizer)
        
        ### Setting default values
        self.map = self.mapsystem.map
        self.Psetting = self.map.Psetting
        self.iteration = wx.xrc.XRCCTRL(self.panel,'SpinCtrlIteration').GetValue()
        self.initial_p = float(wx.xrc.XRCCTRL(self.panel,'TextCtrlInitial_p').GetValue())
        self.branchsearch = maps.CompPathIntegration.BranchSearch(self.map, self.initial_p, self.iteration)            
        wx.xrc.XRCCTRL(self.panel,'StaticTextPreference').SetLabel('Preference: iteration=%d, p_0 = %.2f' % (self.iteration,self.initial_p))

        self.mapdata = [] 
        self.checkedbranchonly = False
        self.checkedlsetonly = True
        self.checkedlsetdraw = False
        self.checkedactiondraw = False
        self.load_branch_num = 0
        ### Creating PlotPanel,
        # move plot panel to under other plot panel after last modified 
        self.msetplot = parent.GetParent().MakePlotPanel('set M')
        self.msetplot.OnPress=self.OnPress         

        ### Event methods

        def OnApply(event):
            self.Initialization()
            self.GetMset()
            self.DrawMset()      
        def OnSpinCtrlIteration(event):
            self.iteration = wx.xrc.XRCCTRL(self.panel,'SpinCtrlIteration').GetValue()
        def OnTextCtrlInitial_p(event):
            self.initial_p = float(wx.xrc.XRCCTRL(self.panel,'TextCtrlInitial_p').GetValue())
        def OnDrawMset(event):
            self.msetplot.clear()
            self.GetMset()
            self.DrawBranch(isDrawMset=not self.checkedbranchonly)
        def OnCheckBoxBranchOnly(event):
            self.checkedbranchonly = event.IsChecked()
            self.msetplot.clear()
            self.DrawBranch(isDrawMset=not event.IsChecked())
        def OnDrawLset(event):
            try: self.lsetplot
            except AttributeError: self.lsetplot = parent.GetParent().MakePlotPanel('set L')
            self.lsetplot.clear()
            self.GetLset()
            self.DrawLset(isDrawMap=not self.checkedlsetonly)
        def OnCheckBoxLsetOnly(event):
            self.checkedlsetonly = event.IsChecked()
            self.lsetplot.clear()
            self.DrawLset(isDrawMap=not event.IsChecked())
        def OnCheckBoxQmapDraw(event):
            # todo draw wave function
            pass
        def OnQmapSet(event):
            self.get_qmap_range()
        def OnCheckListBranch(event):
            index = event.GetSelection()
            if self.checklistbranch1.IsChecked(index):
                self.checkedindex1.append(index)
            else:
                self.checkedindex1.remove(index)
            self.checkedindex1.sort()
        def OnDeleteBranch(event):
            if 0 in self.checkedindex1: raise TypeError, "Branch0 can't delete"
            if len(self.checkedindex1) != 0:
                self.DeleteCheckedBranches()
        def OnCheckBoxLsetDraw(event):
            self.checkedlsetdraw = event.IsChecked()
        def OnCheckBoxActionDraw(event):
            self.checkedactiondraw = event.IsChecked()
        # branch data
        def OnSearch(event):
            if len(self.checklistindex1) == 0: raise ValueError, 'Branch was not searched'
            dlg = wx.MessageDialog(self, 'Branch Search tasks a long time.\nSo, Each Branch data are saved in your home directory.\nAre you OK?',
                                   'Warning',
                                   wx.OK | wx.CANCEL | wx.ICON_WARNING)
            result = dlg.ShowModal()
            dlg.Destroy()
            if result == wx.ID_OK:
                self.SearchBranch()
                self.SaveBranch()
            print 'End Searching'
            #path = os.environ['HOME'] + '/.onsight/%s/Mset/project' % (self.mapsystem.MapName)
            #self.loadBranch(path)
        def OnLoad(event):
            if len(self.checklistindex2) != 0: self.InitializationCheckList2()
            import os
            home = os.environ['HOME']
            projpath = home + '/.onsight/%s/Mset/project' % (self.mapsystem.MapName)
            dlg = wx.FileDialog(self, message='Choose a .mset file',
                                    defaultDir=projpath, defaultFile="",
                                    wildcard='.mset',
                                    style=wx.OPEN | wx.MULTIPLE | wx.CHANGE_DIR)
            if dlg.ShowModal() == wx.ID_OK:
                path=str(dlg.GetPaths()[0])
                file = open('%s' % path, 'r')
                proj = []
                for line in file:
                    proj.append(line)
                file.close()
                self.LoadBranch(proj)
            dlg.Destroy()
            wx.xrc.XRCCTRL(self.panel, 'ButtonPruning').Enable(True)
        def OnCheckList2Branch(event):
            index = event.GetSelection()
            if self.checklistbranch2.IsChecked(index):
                self.checkedindex2.append(index)
            else:
                self.checkedindex2.remove(index)
            self.checkedindex2.sort()

        def OnDrawAction(event):
            try: self.actionplot
            except AttributeError: self.actionplot = parent.GetParent().MakePlotPanel('Im Action vs Re p_n') 
            self.GetAction()
            self.DrawAction()
        def OnDrawAll(event):
            self.DrawBranch(isDrawMset=not self.checkedbranchonly,marker='--', isDrawCutBranch=True)

            if self.checkedlsetdraw:
                try: self.lsetplot
                except AttributeError: self.lsetplot = parent.GetParent().MakePlotPanel('set L')
                self.GetLset()
                self.DrawLset(isDrawMap=not self.checkedlsetonly,marker=',',isDrawCutBranch=True)
            if self.checkedactiondraw:
                try: self.actionplot
                except AttributeError: self.actionplot = parent.GetParent().MakePlotPanel('Im Action vs Re p_n')
                self.GetLset()
                self.GetAction() 
                self.DrawAction(marker=':', isDrawCutBranch=True)

        def OnBranchPruning(event):
            if len(self.checklistindex1) == 0: raise ValueError
            if len(self.branchsearch.cut_branches_data) != 0: self.branchsearch.cut_branches_data =[] 
            index = range(len(self.checklistindex1))
            count = 0
            for i in index:
                if i in self.checkedindex1:
                    isChain=True
                else:
                    isChain=False
                branch = self.branchsearch.branch_data[i]
                self.branchsearch.get_pruning_branch(branch,cut_pmin=-7.0, cut_pmax=7.0, isChain=isChain)
            self.DrawBranch(isDrawMset=False,marker='--', isDrawCutBranch='ALL')
            self.InitializationCheckList2()
            self.UpdataCheckList2()
            wx.xrc.XRCCTRL(self.panel, 'ButtonDrawAll').Enable(True)
            # todo reset checkedindex1
        def OnDrawCheckedContribution(event):
            try: self.wavepanel
            except AttributeError: self.wavepanel=parent.GetParent().MakePlotPanel('Momentam Rep. of Wave Function')
            self.DrawCheckedWaveFunction()
        def OnDrawSemiclassicalWave(event):
            try: self.wavepanel
            except AttributeError: self.wavepanel=parent.GetParent().MakePlotPanel('Momentam Rep. of Wave Function')
            self.GetSemiclassicalWaveFunction()
        
        def OnSliderPruning(event):
            index_min = int(wx.xrc.XRCCTRL(self.panel, 'SliderBranchPruning_min').GetValue())
            index_max = int(wx.xrc.XRCCTRL(self.panel, 'SliderBranchPruning_max').GetValue())
            if index_max > index_min:
                self.branchsearch.hand_branch_pruning(index_min ,index_max, self.slider_pruning_index)
            else:
                self.branchsearch.hand_branch_pruning(index_max, index_min, self.slider_pruning_index)
            self.DrawBranch(isDrawMset=not self.checkedbranchonly, isDrawCutBranch='ALL')
        def OnBranchChoice(event):
            self.slider_pruning_index = self.checklistlabel2.index(str(event.GetString()))
            branch = self.branchsearch.branch_data[self.slider_pruning_index]
            cut_index = self.branchsearch.cut_index[self.slider_pruning_index]
            wx.xrc.XRCCTRL(self.panel,'SliderBranchPruning_min').SetMax(int( len(branch[0]) -1 ))
            wx.xrc.XRCCTRL(self.panel,'SliderBranchPruning_max').SetMax(int( len(branch[0]) - 1 ))
            wx.xrc.XRCCTRL(self.panel,'SliderBranchPruning_min').SetValue(cut_index.min())
            wx.xrc.XRCCTRL(self.panel,'SliderBranchPruning_max').SetValue(cut_index.max())
            self.DrawBranch(isDrawMset=not self.checkedbranchonly, isDrawCutBranch='ALL')

 
        
        if wx.Platform != '__WXMAC__':
            self.Bind(wx.EVT_SPINCTRL,OnSpinCtrlIteration, wx.xrc.XRCCTRL(self.panel, 'SpinCtrlIteration'))
        else:
            self.Bind(wx.EVT_TEXT, OnSpinCtrlIteration, wx.xrc.XRCCTRL(self.panel, 'SpinCtrlIteration'))
        self.Bind(wx.EVT_TEXT_ENTER, OnTextCtrlInitial_p,  wx.xrc.XRCCTRL(self.panel, 'TextCtrlInitial_p'))
        self.Bind(wx.EVT_BUTTON, OnApply, wx.xrc.XRCCTRL(self.panel, 'ButtonApply')) 
        self.Bind(wx.EVT_BUTTON, OnDrawMset, wx.xrc.XRCCTRL(self.panel,'ButtonDrawMset'))
        self.Bind(wx.EVT_CHECKBOX, OnCheckBoxBranchOnly, wx.xrc.XRCCTRL(self.panel, 'CheckBoxBranchOnly'))
        self.Bind(wx.EVT_BUTTON, OnDrawLset, wx.xrc.XRCCTRL(self.panel,'ButtonDrawLset'))
        self.Bind(wx.EVT_CHECKBOX, OnCheckBoxLsetOnly,   wx.xrc.XRCCTRL(self.panel, 'CheckBoxLsetOnly'))
        ###
        self.checklistindex1 = []
        self.checkedindex1 = []
        self.checklistlabel1 = []
        self.checklistbranch1 = wx.xrc.XRCCTRL(self.panel, 'CheckListBranch1')
        self.Bind(wx.EVT_CHECKLISTBOX, OnCheckListBranch, self.checklistbranch1)
        self.Bind(wx.EVT_BUTTON, OnDeleteBranch, wx.xrc.XRCCTRL(self.panel, 'ButtonDeleteBranch'))
        self.Bind(wx.EVT_BUTTON, OnDrawAll, wx.xrc.XRCCTRL(self.panel, 'ButtonDrawAll'))
        wx.xrc.XRCCTRL(self.panel, 'ButtonDrawAll').Enable(False)
        self.Bind(wx.EVT_BUTTON, OnSearch, wx.xrc.XRCCTRL(self.panel, 'ButtonSearch'))
        self.Bind(wx.EVT_BUTTON, OnLoad , wx.xrc.XRCCTRL(self.panel, 'ButtonLoad'))
        ###
        #
        self.Bind(wx.EVT_BUTTON, OnDrawAction, wx.xrc.XRCCTRL(self.panel, 'ButtonDrawAction'))
        
        self.Bind(wx.EVT_CHECKBOX, OnCheckBoxQmapDraw, wx.xrc.XRCCTRL(self.panel, 'CheckBoxQmapDraw'))
        self.Bind(wx.EVT_BUTTON, OnQmapSet, wx.xrc.XRCCTRL(self.panel, 'ButtonQmapSet'))
        ### Branch Pruning
        self.checkedindex2 = []
        self.checklistindex2 = []
        self.checklistlabel2 = []
        self.checklistbranch2 = wx.xrc.XRCCTRL(self.panel, 'CheckListBranch2')
        self.Bind(wx.EVT_CHECKLISTBOX, OnCheckList2Branch, self.checklistbranch2)
        self.Bind(wx.EVT_BUTTON, OnBranchPruning, wx.xrc.XRCCTRL(self.panel, 'ButtonPruning'))
        wx.xrc.XRCCTRL(self.panel, 'ButtonPruning').Enable(False)
        
        ###
        self.Bind(wx.EVT_CHECKBOX, OnCheckBoxLsetDraw, wx.xrc.XRCCTRL(self.panel, 'CheckBoxLsetDraw'))
        self.Bind(wx.EVT_CHECKBOX, OnCheckBoxActionDraw, wx.xrc.XRCCTRL(self.panel, 'CheckBoxActionDraw'))
        self.Bind(wx.EVT_BUTTON, OnDrawCheckedContribution, wx.xrc.XRCCTRL(self.panel,'ButtonDrawCheckedContribution'))
        self.Bind(wx.EVT_BUTTON, OnDrawSemiclassicalWave, wx.xrc.XRCCTRL(self.panel, 'ButtonDrawSemiclassicalWave'))
        
        #
        self.Bind(wx.EVT_CHOICE, OnBranchChoice, wx.xrc.XRCCTRL(self.panel, 'ChoiceBranch'))
        self.Bind(wx.EVT_SLIDER, OnSliderPruning, wx.xrc.XRCCTRL(self.panel, 'SliderBranchPruning_min'))
        self.Bind(wx.EVT_SLIDER, OnSliderPruning, wx.xrc.XRCCTRL(self.panel, 'SliderBranchPruning_max'))
        self.branch_or_chain = 0
        self.GetMset()
        self.DrawMset()
    def __init__(self, parent, mapsystem, title):
        _SubPanel.__init__(self, parent, mapsystem, title)

        xmlresource=wx.xrc.XmlResource("OnSight/data/xrc/qmapeigenpanel.xrc")
        self.panel=xmlresource.LoadPanel(self,"qmapeigenpanel")

        sizer=wx.BoxSizer()
        sizer.Add(self.panel,proportion=1,flag= wx.ALL | wx.EXPAND)
        self.SetSizer(sizer)
        
        self.map = self.mapsystem.map
        self.qmap = maps.QuantumMap.QMap(self.map)
        
        self.cmap_data = []


        ### 
        self.state_num = 0
        exp_part = int(wx.xrc.XRCCTRL(self.panel, 'TextCtrlexp_part').GetValue())
        self.vmin = 10**(-exp_part)
        self.draw = self.DrawHsm
        self.rep = 'hsm'
        self.logplot = False
        
        ###
        self.Initialization()
        
        
        def OnButtonGet(event):
            range=self.get_range()
            self.N = range[4]
            self.qmap.setRange(range[0], range[1], range[2], range[3], range[4])
            self.qmap.getEigen()
            self.qmap.get_pvecs()
            try: self.evalplot.clear()
            except :pass
            self.rep = 'hsm'
            self.DrawHsm(0, self.rep)
            wx.xrc.XRCCTRL(self.panel, 'RadioBoxRep').SetSelection(0)
            wx.xrc.XRCCTRL(self.panel, 'SpinCtrlState').Enable(True)
            wx.xrc.XRCCTRL(self.panel, 'SpinCtrlState').SetRange(0,self.N-1)
            wx.xrc.XRCCTRL(self.panel, 'SpinCtrlState').SetValue(0)
            wx.xrc.XRCCTRL(self.panel, 'ButtonDraw').Enable(True)
            wx.xrc.XRCCTRL(self.panel, 'ButtonNext').Enable(True)
            wx.xrc.XRCCTRL(self.panel, 'ButtonEigenValueDraw').Enable(True)
            
        def OnSpinState(event):
            self.state_num = wx.xrc.XRCCTRL(self.panel, 'SpinCtrlState').GetValue()
            if self.state_num == self.N - 1:
                wx.xrc.XRCCTRL(self.panel,'ButtonNext').Enable(False)
            elif self.state_num == 0:
                wx.xrc.XRCCTRL(self.panel,'ButtonPrev').Enable(False)
            else:
                wx.xrc.XRCCTRL(self.panel,'ButtonPrev').Enable(True)
                wx.xrc.XRCCTRL(self.panel,'ButtonNext').Enable(True)

        def OnRadioBoxRep(event):
            radio = event.GetSelection()
            if radio == 0:
                self.rep = 'hsm'
                self.draw = self.DrawHsm
            elif radio == 1:
                self.rep = 'p'
                self.draw = self.Draw
            else:
                self.rep = 'q'
                self.draw = self.Draw

        def OnButtonDraw(event):
            self.plotpanel.clear()
            self.draw(self.state_num, self.rep)
            
        def OnButtonNext(event):
            self.state_num += 1
            wx.xrc.XRCCTRL(self.panel,'SpinCtrlState').SetValue(self.state_num)
            if self.state_num == self.N:
                wx.xrc.XRCCTRL(self.panel,'ButtonNext').Enable(False)
            else:
                wx.xrc.XRCCTRL(self.panel,'ButtonPrev').Enable(True)
                wx.xrc.XRCCTRL(self.panel,'ButtonNext').Enable(True)
            self.draw(self.state_num, self.rep)

        def OnButtonPrev(event):
            self.state_num -= 1
            wx.xrc.XRCCTRL(self.panel,'SpinCtrlState').SetValue(self.state_num)
            if self.state_num == 0:
                wx.xrc.XRCCTRL(self.panel,'ButtonPrev').Enable(False)
            else:
                wx.xrc.XRCCTRL(self.panel,'ButtonPrev').Enable(True)
                wx.xrc.XRCCTRL(self.panel,'ButtonNext').Enable(True)
            self.draw(self.state_num, self.rep)

        def OnCheckBoxLog(event):
            self.logplot = event.IsChecked()

        def OnTextLogMin(event):
            exp_part = wx.xrc.XRCCTRL(self.panel, 'TextCtrlLogMin').GetValue()
            if exp_part != '':
                self.vmin = 10**(-int(exp_part))
                
        def OnButtonEvalsDraw(event):
            try: self.evalplot.clear()
            except: self.evalplot=parent.GetParent().MakePlotPanel('eigen values')
            self.DrawEigenValues()
        
        def OnButtonClear(event):
            self.cmap_data = []
            self.plotpanel.clear()
            try :self.draw(self.state_num, self.rep)
            except: pass
                        
        self.Bind(wx.EVT_BUTTON, OnButtonGet, wx.xrc.XRCCTRL(self.panel, 'ButtonGet'))
        if wx.Platform != '__WXMAC__':
            self.Bind(wx.EVT_SPINCTRL,OnSpinState, wx.xrc.XRCCTRL(self.panel, 'SpinCtrlState'))
        else:
            self.Bind(wx.EVT_TEXT, OnSpinState, wx.xrc.XRCCTRL(self.panel, 'SpinCtrlState'))
        self.Bind(wx.EVT_RADIOBOX, OnRadioBoxRep, wx.xrc.XRCCTRL(self.panel, 'RadioBoxRep'))
        self.Bind(wx.EVT_BUTTON, OnButtonDraw, wx.xrc.XRCCTRL(self.panel, 'ButtonDraw'))
        self.Bind(wx.EVT_BUTTON, OnButtonNext, wx.xrc.XRCCTRL(self.panel, 'ButtonNext'))
        self.Bind(wx.EVT_BUTTON, OnButtonPrev, wx.xrc.XRCCTRL(self.panel, 'ButtonPrev'))
        self.Bind(wx.EVT_CHECKBOX, OnCheckBoxLog, wx.xrc.XRCCTRL(self.panel, 'CheckBoxLog'))
        self.Bind(wx.EVT_TEXT, OnTextLogMin, wx.xrc.XRCCTRL(self.panel, 'TextCtrlexp_part'))
        self.Bind(wx.EVT_BUTTON, OnButtonEvalsDraw, wx.xrc.XRCCTRL(self.panel, 'ButtonEigenValueDraw'))
        self.Bind(wx.EVT_BUTTON, OnButtonClear, wx.xrc.XRCCTRL(self.panel, 'ButtonClear'))
        
        self.plotpanel=parent.GetParent().MakePlotPanel(self.title)
        self.plotpanel.OnPress = self.OnPress
        self.plotpanel.plot()
        self.set_lim()
        self.plotpanel.draw()
    def __init__(self, parent, mapsystem, title):
        _SubPanel.__init__(self, parent, mapsystem, title)

        xmlresource=wx.xrc.XmlResource("OnSight/data/xrc/qmapevolvepanel.xrc")
        self.panel=xmlresource.LoadPanel(self,"qmapevolvepanel")

        sizer=wx.BoxSizer()
        sizer.Add(self.panel,proportion=1,flag= wx.ALL | wx.EXPAND)
        self.SetSizer(sizer)
        
        self.map = self.mapsystem.map
        self.qmap = maps.QuantumMap.QMap(self.map)
        
        self.Initialization()
        
        self.state = 'p'
        self.range = self.get_range()
        self.vrange = self.get_vrange()
        self.ini_c = self.get_initial()
        self.rb_initial = 0
        self.iteration = wx.xrc.XRCCTRL(self.panel,'SpinCtrlIteration').GetValue()
        self.step = wx.xrc.XRCCTRL(self.panel, 'SpinCtrlDrawStep').GetValue()
        self.logplot = False
        self.cmap_data = []
        exp_part = int(wx.xrc.XRCCTRL(self.panel, 'TextCtrlLogMin').GetValue())
        self.vmin = 10**(-exp_part)
        self.draw = self.DrawHsm
        self.rep = 'hsm'
        

        def OnClear(event):
            self.cmap_data = []
            self.plotpanel.clear()
            try: self.draw(self.step, self.rep)
            except :pass

        def OnRadioBoxInitial(event):
            radio = event.GetSelection()
            if radio == 0 or radio == 3:
                if radio == 0: self.state = 'p'
                else: self.state = 'qlt'
                wx.xrc.XRCCTRL(self.panel, 'TextCtrlq_c').Enable(False)
                wx.xrc.XRCCTRL(self.panel, 'TextCtrlp_c').Enable(True)
            elif radio == 1:
                self.state = 'q'
                wx.xrc.XRCCTRL(self.panel, 'TextCtrlq_c').Enable(True)
                wx.xrc.XRCCTRL(self.panel, 'TextCtrlp_c').Enable(False)
            else:
                self.state = 'cs'
                wx.xrc.XRCCTRL(self.panel, 'TextCtrlq_c').Enable(True)
                wx.xrc.XRCCTRL(self.panel, 'TextCtrlp_c').Enable(True)

        def OnSetInitialState(event):
            self.plotpanel.clear()
            self.range = self.get_range()
            self.ini_c = self.get_initial()
            self.qmap.setRange(self.range[0], self.range[1], self.range[2],self.range[3], self.range[4])
            
            if self.state in ('p','plt'):
                if self.ini_c[1] < self.range[2] or self.ini_c[1] > self.range[3]:
                    raise ValueError
                self.qmap.setState(self.state,self.ini_c[1])
            elif self.state in ('q'):
                if self.ini_c[0] < self.range[0] or self.ini_c[0] > self.range[1]:
                    raise ValueError
                self.qmap.setState(self.state, self.ini_c[0])
            else:
                if self.ini_c[1] < self.range[2] or self.ini_c[1] > self.range[3] or\
                     self.ini_c[0] < self.range[0] or self.ini_c[0] > self.range[1]:
                    raise ValueError
                self.qmap.setState(self.state, self.ini_c[0],self.ini_c[1])
            self.DrawHsm(0, 'hsm')
            wx.xrc.XRCCTRL(self.panel, 'ButtonIter').Enable(True)
            wx.xrc.XRCCTRL(self.panel, 'ButtonDraw').Enable(False)
            wx.xrc.XRCCTRL(self.panel, 'ButtonNext').Enable(False)
            wx.xrc.XRCCTRL(self.panel, 'ButtonPrev').Enable(False)

        def OnSpinIteration(event):
            self.iteration = wx.xrc.XRCCTRL(self.panel,'SpinCtrlIteration').GetValue()

        def OnButtonIteration(event):
            wx.xrc.XRCCTRL(self.panel, 'ButtonDraw').Enable(True)
            wx.xrc.XRCCTRL(self.panel, 'ButtonNext').Enable(True)
            self.step = 0
            wx.xrc.XRCCTRL(self.panel, 'SpinCtrlDrawStep').SetValue(self.step)
            self.qmap.evolve(self.iteration)
            self.qmap.get_pvecs()

        def OnRadioBoxRep(event):
            radio = event.GetSelection()
            if radio == 0:
                self.rep = 'hsm'
                self.draw = self.DrawHsm
            elif radio == 1:
                self.rep = 'p'
                self.draw = self.Draw
            else:
                self.rep = 'q'
                self.draw = self.Draw

        def OnSpinDrawStep(event):
            self.step = wx.xrc.XRCCTRL(self.panel, 'SpinCtrlDrawStep').GetValue()
            if self.step == self.iteration:
                wx.xrc.XRCCTRL(self.panel,'ButtonNext').Enable(False)
            elif self.step == 0:
                wx.xrc.XRCCTRL(self.panel,'ButtonPrev').Enable(False)
            else:
                wx.xrc.XRCCTRL(self.panel,'ButtonPrev').Enable(True)
                wx.xrc.XRCCTRL(self.panel,'ButtonNext').Enable(True)
            wx.xrc.XRCCTRL(self.panel,'SpinCtrlDrawStep').SetRange(0,self.iteration)

        def OnButtonDraw(event):
            self.plotpanel.clear()
            self.draw(self.step, self.rep)

        def OnButtonNext(event):
            self.step += 1
            wx.xrc.XRCCTRL(self.panel,'SpinCtrlDrawStep').SetValue(self.step)
            if self.step == self.iteration:
                wx.xrc.XRCCTRL(self.panel,'ButtonNext').Enable(False)
            else:
                wx.xrc.XRCCTRL(self.panel,'ButtonPrev').Enable(True)
                wx.xrc.XRCCTRL(self.panel,'ButtonNext').Enable(True)
            self.draw(self.step, self.rep)

        def OnButtonPrev(event):
            self.step -= 1
            wx.xrc.XRCCTRL(self.panel,'SpinCtrlDrawStep').SetValue(self.step)
            if self.step == 0:
                wx.xrc.XRCCTRL(self.panel,'ButtonPrev').Enable(False)
            else:
                wx.xrc.XRCCTRL(self.panel,'ButtonPrev').Enable(True)
                wx.xrc.XRCCTRL(self.panel,'ButtonNext').Enable(True)

            self.draw(self.step, self.rep)

        def OnCheckBoxLog(event):
            self.logplot = event.IsChecked()
 
        def OnTextLogMin(event):
            exp_part = wx.xrc.XRCCTRL(self.panel, 'TextCtrlLogMin').GetValue()
            if exp_part != '':
                self.vmin = 10**(-int(exp_part))




        self.Bind(wx.EVT_BUTTON, OnClear, wx.xrc.XRCCTRL(self.panel, 'ButtonClear'))
        self.Bind(wx.EVT_RADIOBOX, OnRadioBoxInitial, wx.xrc.XRCCTRL(self.panel,'RadioBoxIniState'))
        self.Bind(wx.EVT_BUTTON, OnSetInitialState, wx.xrc.XRCCTRL(self.panel, 'ButtonSet'))  
        if wx.Platform != '__WXMAC__':
            self.Bind(wx.EVT_SPINCTRL,OnSpinIteration, wx.xrc.XRCCTRL(self.panel, 'SpinCtrlIteration'))
        else:
            self.Bind(wx.EVT_TEXT, OnSpinIteration, wx.xrc.XRCCTRL(self.panel, 'SpinCtrlIteration'))
        self.Bind(wx.EVT_BUTTON, OnButtonIteration, wx.xrc.XRCCTRL(self.panel, 'ButtonIter'))
        self.Bind(wx.EVT_RADIOBOX, OnRadioBoxRep, wx.xrc.XRCCTRL(self.panel, 'RadioBoxRep'))
        if wx.Platform != '__WXMAC__':
            self.Bind(wx.EVT_SPINCTRL,OnSpinDrawStep, wx.xrc.XRCCTRL(self.panel, 'SpinCtrlDrawStep'))
        else:
            self.Bind(wx.EVT_TEXT, OnSpinDrawStep, wx.xrc.XRCCTRL(self.panel, 'SpinCtrlDrawStep'))
        self.Bind(wx.EVT_BUTTON, OnButtonDraw, wx.xrc.XRCCTRL(self.panel, 'ButtonDraw'))
        self.Bind(wx.EVT_BUTTON, OnButtonNext, wx.xrc.XRCCTRL(self.panel, 'ButtonNext'))
        self.Bind(wx.EVT_BUTTON, OnButtonPrev, wx.xrc.XRCCTRL(self.panel, 'ButtonPrev'))
        self.Bind(wx.EVT_CHECKBOX, OnCheckBoxLog, wx.xrc.XRCCTRL(self.panel, 'CheckBoxLog'))
        self.Bind(wx.EVT_TEXT, OnTextLogMin, wx.xrc.XRCCTRL(self.panel, 'TextCtrlLogMin'))
        ## make plotpanel
        self.plotpanel=parent.GetParent().MakePlotPanel(self.title)
        self.plotpanel.OnPress = self.OnPress
        self.plotpanel.plot()
        self.set_lim()
        self.plotpanel.draw()
	def __init__(self,parent,mapsystem,title):
		_SubPanel.__init__(self,parent,mapsystem,title)
		
		#### Loading XRC file and Setting the panel
		xmlresource=wx.xrc.XmlResource("OnSight/data/xrc/recurrencetimepanel.xrc")
		self.panel=xmlresource.LoadPanel(self,"recurrencetimepanel")
		
		sizer=wx.BoxSizer()
		sizer.Add(self.panel,proportion=1,flag= wx.ALL | wx.EXPAND)
		self.SetSizer(sizer)
		
		#### Creating TextCtrls and StaticTexts 
		axislabel=Utils.getAxisLabel(self.mapsystem)
		
		proportion_st=0
		proportion_tc=1
		style_tc=wx.TE_RIGHT
		flag_st=flag_tc=wx.ALL | wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL
		
		input=[[axislabel[d]+': ', 'min ', 0.0, 'max ', 1.0] for d in range(self.mapsystem.dim)]
		
		sizer1=wx.xrc.XRCCTRL(self.panel,'StaticLine1').GetContainingSizer()
		self.TCListRect=Utils._putTextCtrlFlexGrid(self.panel,sizer1.GetChildren()[2].GetSizer(),input,
			proportion_st=proportion_st,flag_st=flag_st,style_tc=style_tc,proportion_tc=proportion_tc,flag_tc=flag_tc)
		
		input=[[axislabel[d]+': ', 'center ', 0.0] for d in range(self.mapsystem.dim)]
		input.append(['','edge ',1.0])
		
		self.TCListBox=Utils._putTextCtrlFlexGrid(self.panel,sizer1.GetChildren()[3].GetSizer(),input,
			proportion_st=proportion_st,flag_st=flag_st,style_tc=style_tc,proportion_tc=proportion_tc,flag_tc=flag_tc)
		
		input=[[axislabel[d]+': ', 'center ', 0.0] for d in range(self.mapsystem.dim)]
		input.append(['','radius ',1.0])
		
		self.TCListCircle=Utils._putTextCtrlFlexGrid(self.panel,sizer1.GetChildren()[4].GetSizer(),input,
			proportion_st=proportion_st,flag_st=flag_st,style_tc=style_tc,proportion_tc=proportion_tc,flag_tc=flag_tc)
		
		for i in range(3): sizer1.Show(i+2,i==0)
		
		#### Event Handling
		def OnSpinCtrlSample(event):
			self.sample=event.GetInt()
		def OnSpinCtrlIteration(event):
			self.iteration=event.GetInt()
		def OnRadioBoxType(event):
			self.type=event.GetSelection()
			sizer1=wx.xrc.XRCCTRL(self.panel,'StaticLine1').GetContainingSizer()
			for i in range(3):
				sizer1.Show(i+2, i==self.type)
			self.panel.Layout()
		def OnButtonDraw(event):
			self.SetRegion()
			self.recurrencetime.calc(self.sample,self.iteration)
			wx.xrc.XRCCTRL(self.panel,'TextCtrlAverage').SetValue(str(self.recurrencetime.average))
			self.distplotpanel.plot(self.recurrencetime.axis,self.recurrencetime.dist,'-')
			self.cumplotpanel.plot(self.recurrencetime.axis,self.recurrencetime.cum,'-')
		def OnButtonSet(event):
			dlg=Utils.RegionDialog(self,self.type,style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.CENTER)
			
			pages=self.GetParent().GetPages()
			if pages.has_key('Poincare Plot'):
				for (args,kwargs) in pages['Poincare Plot'].plotpanel.data:
					dlg.axes.plot(*args,**kwargs)
			
			if dlg.ShowModal() == wx.ID_OK:
				values=dlg.GetValues()
				if self.type == 0:
					self.TCListRect[0][0].SetValue(str(values[0]))
					self.TCListRect[0][1].SetValue(str(values[1]))
					self.TCListRect[1][0].SetValue(str(values[2]))
					self.TCListRect[1][1].SetValue(str(values[3]))
					
				if self.type == 1:
					self.TCListBox[0][0].SetValue(str(values[0]))
					self.TCListBox[1][0].SetValue(str(values[1]))
					self.TCListBox[2][0].SetValue(str(values[2]))
					
				if self.type == 2:
					self.TCListCircle[0][0].SetValue(str(values[0]))
					self.TCListCircle[1][0].SetValue(str(values[1]))
					self.TCListCircle[2][0].SetValue(str(values[2]))
			
			dlg.Destroy()
		
		self.Bind(wx.EVT_SPINCTRL, OnSpinCtrlSample, wx.xrc.XRCCTRL(self.panel,'SpinCtrlSample'))
		self.Bind(wx.EVT_SPINCTRL, OnSpinCtrlIteration, wx.xrc.XRCCTRL(self.panel,'SpinCtrlIteration'))
		self.Bind(wx.EVT_RADIOBOX, OnRadioBoxType, wx.xrc.XRCCTRL(self.panel,'RadioBoxType'))
		self.Bind(wx.EVT_BUTTON, OnButtonDraw, wx.xrc.XRCCTRL(self.panel,'ButtonDraw'))
		self.Bind(wx.EVT_BUTTON, OnButtonSet, wx.xrc.XRCCTRL(self.panel,'ButtonSet'))
		
		#### Creating PlotPanel and RecurrenceTime, Setting default values
		self.distplotpanel=parent.GetParent().MakePlotPanel(self.title+' Distrbution')
		self.cumplotpanel=parent.GetParent().MakePlotPanel(self.title+' Cumulative Distrbution')
		
		self.recurrencetime=maps.TimeStatistics.RecurrenceTime(self.mapsystem)
		
		self.sample=wx.xrc.XRCCTRL(self.panel,'SpinCtrlSample').GetValue()
		self.iteration=wx.xrc.XRCCTRL(self.panel,'SpinCtrlIteration').GetValue()
		self.type=wx.xrc.XRCCTRL(self.panel,'RadioBoxType').GetSelection()
		
		self.SetRegion()
	def __init__(self,parent,mapsystem,title):
		_SubPanel.__init__(self,parent,mapsystem,title)
		#### Loading XRC file and Setting the panel
		xmlresource=wx.xrc.XmlResource("OnSight/data/xrc/poincareplotpanel.xrc")
		self.panel=xmlresource.LoadPanel(self,"poincareplotpanel")
		
		sizer=wx.BoxSizer()
		sizer.Add(self.panel,proportion=1,flag= wx.ALL | wx.EXPAND)
		self.SetSizer(sizer)
		
		#### Creating TextCtrls and StaticTexts 
		axislabel=Utils.getAxisLabel(self.mapsystem)
		
		proportion_st=0
		proportion_tc=1
		style_tc=wx.TE_RIGHT
		flag_st=flag_tc=wx.ALL | wx.ALIGN_LEFT | wx.ALIGN_CENTER_VERTICAL
		
		input=[[axislabel[d]+': ', 'min ', 0.0, 'max ', 1.0] for d in range(self.mapsystem.dim)]
		
		sizer1=wx.xrc.XRCCTRL(self.panel,'StaticLine1').GetContainingSizer()
		self.TCListRect=Utils._putTextCtrlFlexGrid(self.panel,sizer1.GetChildren()[2].GetSizer(),input,
			proportion_st=proportion_st,flag_st=flag_st,style_tc=style_tc,proportion_tc=proportion_tc,flag_tc=flag_tc)
		
		input=[[axislabel[d]+': ', 'center ', 0.0] for d in range(self.mapsystem.dim)]
		input.append(['','edge ',1.0])
		
		self.TCListBox=Utils._putTextCtrlFlexGrid(self.panel,sizer1.GetChildren()[3].GetSizer(),input,
			proportion_st=proportion_st,flag_st=flag_st,style_tc=style_tc,proportion_tc=proportion_tc,flag_tc=flag_tc)
		
		input=[[axislabel[d]+': ', 'center ', 0.0] for d in range(self.mapsystem.dim)]
		input.append(['','radius ',1.0])
		
		self.TCListCircle=Utils._putTextCtrlFlexGrid(self.panel,sizer1.GetChildren()[4].GetSizer(),input,
			proportion_st=proportion_st,flag_st=flag_st,style_tc=style_tc,proportion_tc=proportion_tc,flag_tc=flag_tc)
		
		for i in range(3): sizer1.Show(i+2,i==0)
		
		#### Event Handling
		def OnSpinCtrlSample(event):
			self.sample=event.GetInt()
		def OnSpinCtrlIteration(event):
			self.iteration=event.GetInt()
		def OnRadioBoxType(event):
			self.type=event.GetSelection()
			sizer1=wx.xrc.XRCCTRL(self.panel,'StaticLine1').GetContainingSizer()
			for i in range(3):
				sizer1.Show(i+2, i==self.type)
			self.panel.Layout()
		def OnRadioBoxRandom(event):
			self.random=(event.GetSelection()==0)
		def OnCheckBoxTrajectory(event):
			self.trajectory=event.IsChecked()
			wx.xrc.XRCCTRL(self.panel,'ButtonPrev').Enable(enable=1-self.trajectory)
			wx.xrc.XRCCTRL(self.panel,'ButtonNext').Enable(enable=1-self.trajectory)
		def OnButtonDraw(event):
			self.SetInitialPoints()
			self.mapsystem.evolves(self.iteration)
			self.Draw()
		def OnButtonPrev(event):
			if self.iteration<=0: return
			self.iteration= self.iteration-1
			wx.xrc.XRCCTRL(self.panel,'SpinCtrlIteration').SetValue(self.iteration)
			OnButtonDraw(event)
		def OnButtonNext(event):
			self.iteration= self.iteration+1
			wx.xrc.XRCCTRL(self.panel,'SpinCtrlIteration').SetValue(self.iteration)
			OnButtonDraw(event)
		def OnButtonSet(event):
			dlg=Utils.RegionDialog(self,self.type,style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER| wx.CENTER)

			for (args,kwargs) in self.plotpanel.data:
				dlg.axes.plot(*args,**kwargs)
			
			if dlg.ShowModal() == wx.ID_OK:
				values=dlg.GetValues()
				if self.type == 0:
					self.TCListRect[0][0].SetValue(str(values[0]))
					self.TCListRect[0][1].SetValue(str(values[1]))
					self.TCListRect[1][0].SetValue(str(values[2]))
					self.TCListRect[1][1].SetValue(str(values[3]))
					
				if self.type == 1:
					self.TCListBox[0][0].SetValue(str(values[0]))
					self.TCListBox[1][0].SetValue(str(values[1]))
					self.TCListBox[2][0].SetValue(str(values[2]))
					
				if self.type == 2:
					self.TCListCircle[0][0].SetValue(str(values[0]))
					self.TCListCircle[1][0].SetValue(str(values[1]))
					self.TCListCircle[2][0].SetValue(str(values[2]))
			
			dlg.Destroy()

		self.Bind(wx.EVT_SPINCTRL, OnSpinCtrlSample, wx.xrc.XRCCTRL(self.panel,'SpinCtrlSample'))
		self.Bind(wx.EVT_SPINCTRL, OnSpinCtrlIteration, wx.xrc.XRCCTRL(self.panel,'SpinCtrlIteration'))
		self.Bind(wx.EVT_RADIOBOX, OnRadioBoxType, wx.xrc.XRCCTRL(self.panel,'RadioBoxType'))
		self.Bind(wx.EVT_RADIOBOX, OnRadioBoxRandom, wx.xrc.XRCCTRL(self.panel,'RadioBoxRandom'))
		self.Bind(wx.EVT_CHECKBOX, OnCheckBoxTrajectory, wx.xrc.XRCCTRL(self.panel,'CheckBoxTrajectory'))
		self.Bind(wx.EVT_BUTTON, OnButtonSet, wx.xrc.XRCCTRL(self.panel,'ButtonSet'))
		self.Bind(wx.EVT_BUTTON, OnButtonPrev, wx.xrc.XRCCTRL(self.panel,'ButtonPrev'))
		self.Bind(wx.EVT_BUTTON, OnButtonNext, wx.xrc.XRCCTRL(self.panel,'ButtonNext'))
		self.Bind(wx.EVT_BUTTON, OnButtonDraw, wx.xrc.XRCCTRL(self.panel,'ButtonDraw'))
		
		#### Creating PlotPanel, Setting default values
		self.plotpanel=parent.GetParent().MakePlotPanel(self.title)
		
		self.plotpanel.OnPress=self.OnPress
		
		self.sample=wx.xrc.XRCCTRL(self.panel,'SpinCtrlSample').GetValue()
		self.iteration=wx.xrc.XRCCTRL(self.panel,'SpinCtrlIteration').GetValue()
		self.type=wx.xrc.XRCCTRL(self.panel,'RadioBoxType').GetSelection()
		self.random=(wx.xrc.XRCCTRL(self.panel,'RadioBoxRandom').GetSelection()==0)
		self.trajectory=wx.xrc.XRCCTRL(self.panel,'CheckBoxTrajectory').IsChecked()
		
		self.SetInitialPoints()
		self.mapsystem.evolves(self.iteration)
		self.Draw()