Changeset 2913


Ignore:
Timestamp:
Jul 6, 2017 3:09:41 PM (4 years ago)
Author:
toby
Message:

implement restraint tab selection menu; fix restraint scroll bar problem (remove/comment all DestroyChildren?); consolidate menu generation

Location:
branch/2frame
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branch/2frame/GSASIIconstrGUI.py

    r2911 r2913  
    10611061        notebook tab. Called in :func:`OnPageChanged`
    10621062        '''
    1063 #        if panel.GetSizer(): panel.GetSizer().Clear(True) # N.B. don't use panel.DestroyChildren()
    1064         # because it deletes scrollbars on Mac
     1063        if panel.GetSizer(): panel.GetSizer().Clear(True)
    10651064        Siz = wx.BoxSizer(wx.VERTICAL)
    10661065        Siz.Add((5,5),0)
     
    17761775                refChoice[rbId][i].sort()     
    17771776           
    1778         #VectorRB.DestroyChildren() # bad, deletes scrollbars on Mac!
    1779         if VectorRB.GetSizer():
    1780             VectorRB.GetSizer().Clear(True)
     1777        if VectorRB.GetSizer(): VectorRB.GetSizer().Clear(True)
    17811778        VectorRBDisplay = wx.Panel(VectorRB)
    17821779        VectorRBSizer = wx.BoxSizer(wx.VERTICAL)
     
    20542051                refChoice[rbId][i].sort()     
    20552052           
     2053        if ResidueRB.GetSizer(): ResidueRB.GetSizer().Clear(True)
    20562054        ResidueRBDisplay = wx.Panel(ResidueRB)
    20572055        ResidueRBSizer = wx.BoxSizer(wx.VERTICAL)
  • branch/2frame/GSASIIctrlGUI.py

    r2911 r2913  
    18311831        wx.Dialog.__init__(self,parent,-1,title,
    18321832            pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE)
    1833         self.panel = wx.Panel(self)         #just a dummy - gets destroyed in Draw!
     1833        self.panel = None
    18341834        self.colnames = colnames
    18351835        self.rownames = rownames
     
    18461846            self.newflags[name][ia] = Obj.GetValue()
    18471847           
    1848         self.panel.DestroyChildren()
    1849         self.panel.Destroy()
     1848        if self.panel:
     1849            self.panel.DestroyChildren()  #safe: wx.Panel
     1850            self.panel.Destroy()
    18501851        self.panel = wx.Panel(self)
    18511852        mainSizer = wx.BoxSizer(wx.VERTICAL)
     
    19081909        wx.Dialog.__init__(self,parent,-1,title,
    19091910            pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE)
    1910         self.panel = wx.Panel(self)         #just a dummy - gets destroyed in Draw!
     1911        self.panel = None
    19111912        self.prompt = prompt
    19121913        self.choices = choices
     
    19231924            self.Draw()
    19241925           
    1925         self.panel.DestroyChildren()
    1926         self.panel.Destroy()
     1926        if self.panel:
     1927            self.panel.DestroyChildren()  #safe: wx.Panel
     1928            self.panel.Destroy()
    19271929        self.panel = wx.Panel(self)
    19281930        mainSizer = wx.BoxSizer(wx.VERTICAL)
     
    19741976        wx.Dialog.__init__(self,parent,-1,title,
    19751977            pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE)
    1976         self.panel = wx.Panel(self)         #just a dummy - gets destroyed in Draw!
     1978        self.panel = None
    19771979        self.limits = limits
    19781980        self.value = value
     
    19941996            valItem.SetValue(self.format%(self.value))
    19951997           
    1996         self.panel.Destroy()
     1998        if self.panel: self.panel.Destroy()
    19971999        self.panel = wx.Panel(self)
    19982000        mainSizer = wx.BoxSizer(wx.VERTICAL)
     
    20352037        wx.Dialog.__init__(self,parent,-1,title,
    20362038            pos=wx.DefaultPosition,style=wx.DEFAULT_DIALOG_STYLE)
    2037         self.panel = wx.Panel(self)         #just a dummy - gets destroyed in Draw!
     2039        self.panel = None
    20382040        self.limits = limits
    20392041        self.values = values
     
    20582060           
    20592061        Indx = {}
    2060         self.panel.Destroy()
     2062        if self.panel: self.panel.Destroy()
    20612063        self.panel = wx.Panel(self)
    20622064        mainSizer = wx.BoxSizer(wx.VERTICAL)
     
    28072809        self.Reset = Reset
    28082810        self.Angle = Angle
    2809         self.panel = wx.Panel(self)         #just a dummy - gets destroyed in Draw!
     2811        self.panel = None
    28102812        self._default(data,self.default)
    28112813        self.Draw(self.data)
     
    28292831        by :meth:`__init__`.
    28302832        '''
    2831         self.panel.Destroy()
     2833        if self.panel: self.panel.Destroy()
    28322834        self.panel = wx.Panel(self)
    28332835        mainSizer = wx.BoxSizer(wx.VERTICAL)
     
    29022904        wx.Dialog.__init__(self,parent,wx.ID_ANY,title,size=size,
    29032905                           style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
    2904         self.panel = wxscroll.ScrolledPanel(self)         #just a dummy - gets destroyed in DrawPanel!
     2906        self.panel = wxscroll.ScrolledPanel(self)
    29052907        self.parmChoice = 'Phase'
    29062908        self.parmDict = parmDict
     
    29652967            wx.CallLater(100,self.DrawPanel)
    29662968
    2967         if self.panel:
    2968             #self.panel.DestroyChildren() # Bad on Mac: deletes scroll bars
    2969             sizer = self.panel.GetSizer()
    2970             if sizer: sizer.DeleteWindows()
    2971 
    2972         mainSizer = wx.BoxSizer(wx.VERTICAL)
     2969        if self.panel.GetSizer(): self.panel.GetSizer().Clear(True)
     2970        mainSizer = self.panel.GetSizer()
    29732971        num = len(self.varyList)
    29742972        mainSizer.Add(wx.StaticText(self.panel,label=' Number of refined variables: '+str(num)),0)
  • branch/2frame/GSASIIdataGUI.py

    r2911 r2913  
    29182918        self.ExportCIF = []
    29192919        #
    2920         self.GSASIIMenu = wx.MenuBar()
    2921         # create a list of all menus (appended in PrefillDataMenu)
    2922         self.dataMenuBars = [self.GSASIIMenu]
    2923         self.MacroStatusList = []
    2924         self.FillMainMenu(self.GSASIIMenu)
    2925         self.SetMenuBar(self.GSASIIMenu)
     2920        # Main menu now done in DataWindow._initMenus for consistency
     2921        #self.GSASIIMenu = wx.MenuBar()
     2922        #self.dataMenuBars = [self.GSASIIMenu] # list of all menus (added to in PrefillDataMenu)
     2923        #self.FillMainMenu(self.GSASIIMenu)
     2924        #self.SetMenuBar(self.GSASIIMenu)
     2925        self.MacroStatusList = []  # logging
    29262926        self.Status = self.CreateStatusBar()
    29272927        # Bob: note different ways to display the SplitterWindow. I like the 3d effect on the Mac
     
    29652965        self.root = self.GPXtree.root       
    29662966
    2967         # debug code to fill initial window and check scroll bar works
    2968         #def FillWindow(panel,size=1.):
    2969         #    sizer = panel.GetSizer()
    2970         #    sizer.Add(wx.StaticText(panel, wx.ID_ANY, "Panel Two: long line "+int(size*40)*'*', (5,5)))
    2971         #    for i in range(int(size*15)): sizer.Add(wx.StaticText(panel, wx.ID_ANY, "Line "+str(2+i), (5,5)))
    2972         #    panel.Layout()
    2973         #    panel.SendSizeEvent()
    2974         #FillWindow(self.dataWindow)
    2975        
    29762967        self.dataWindow.SetupScrolling()
    29772968       
     
    47424733    where the functions to be called are defined.
    47434734    '''
     4735    # TODO: debug code ######################################################################
    47444736    def Bind(self,eventtype,handler,*args,**kwargs):  # PATCH: debug code: catch when a menu is bind'ed to
    4745         # the dataWindow this should not be done in the 2 frame version. Remove this routine eventually.
     4737        # the dataWindow as this should not be done in the 2 frame version.
    47464738        if eventtype == wx.wx.EVT_MENU:
    47474739            print 'wx.EVT_MENU Bind to dataWindow'
     
    47504742        else:
    47514743            wxscroll.ScrolledPanel.Bind(self,eventtype,handler,*args,**kwargs)
    4752 #    def Bind(self,eventtype,handler,*args,**kwargs):
    4753 #        '''Override the Bind() function: on the Mac the binding is to
    4754 #        the main window, so that menus operate with any window on top.
    4755 #        For other platforms, either wrap calls that will be logged
    4756 #        or call the default wx.Frame Bind() to bind to the menu item directly.
    4757 #
    4758 #        Note that bindings can be made to objects by Id or by direct reference to the
    4759 #        object. As a convention, when bindings are to objects, they are not logged
    4760 #        but when bindings are by Id, they are logged.
    4761 #        '''
    4762 #        if sys.platform == "darwin": # mac
    4763 #            self.Bind(eventtype,handler,*args,**kwargs)
    4764 #            return
    4765 #        if eventtype == wx.EVT_MENU and 'id' in kwargs:
    4766 ##            menulabels = log.SaveMenuCommand(kwargs['id'],self,handler)
    4767 ##            if menulabels:
    4768 ##                #print 'intercepting bind for',handler,menulabels,kwargs['id']
    4769 ##                wx.Window.Bind(self,eventtype,self.MenuBinding,*args,**kwargs)
    4770 ##                return
    4771 #            self.Bind(self,eventtype,handler,*args,**kwargs)
    4772 
    47734744    def DestroyChildren(self):
    4774         print 'Fix this: DestroyChildren called'
     4745        print 'Fix this: dataWindow.DestroyChildren called'
    47754746        G2obj.HowDidIgetHere()
    4776        
     4747    def SetTitle(self,*args):
     4748        print('Warning: attempt to label dataWindow')
     4749        G2obj.HowDidIgetHere(True)
     4750        self.G2frame.SetTitle(*args)
     4751    def SetLabel(self,*args):
     4752        print('Warning: attempt to label dataWindow')
     4753        G2obj.HowDidIgetHere(True)
     4754        self.G2frame.SetTitle(*args)
     4755    # end TODO: remove this later ############################################################
     4756
     4757    def __init__(self,parent):
     4758        wxscroll.ScrolledPanel.__init__(self,parent,wx.ID_ANY,size=parent.GetSize())
     4759        self.parent = parent
     4760        self._initMenus()
     4761        self.currentGrids = []
     4762        self.helpKey = ''  # defines help entry for current item selected in data tree
     4763       
     4764    def ClearData(self):
     4765        '''Initializes the contents of the dataWindow panel
     4766        '''
     4767        #self.SetBackgroundColour(wx.WHITE)
     4768        self.SetBackgroundColour(VERY_LIGHT_GREY)  # BHT: I prefer a gray background. Makes TextCtrls stand out, but
     4769        # a bit lighter than the splitter bar
     4770        Sizer = self.GetSizer()
     4771        if Sizer:
     4772            Sizer.Clear(True)
     4773        else:
     4774            print 'No sizer in dataWindow'
     4775            if GSASIIpath.GetConfigValue('debug'): raise Exception
     4776       
     4777    def SetDataSize(self):
     4778        '''Sizes the contents of the dataWindow panel
     4779        '''
     4780        Sizer = self.GetSizer()
     4781        if GSASIIpath.GetConfigValue('debug') and not Sizer:
     4782            print 'No sizer in dataWindow'
     4783            raise Exception
     4784        self.Layout()
     4785        self.SendSizeEvent()
     4786
    47774787    def PrefillDataMenu(self,menu,empty=False):
    47784788        '''Create the "standard" part of data frame menus & add the dataWindow menu headings
     
    47964806        menu.Append(menu=HelpMenu,title='&Help')
    47974807
    4798     def _initMenus_(self):
     4808    def _initMenus(self):
    47994809        'define all GSAS-II data window menus'
    4800 
    4801         # for use where no menu or data frame help is provided
    4802         self.BlankMenu = wx.MenuBar()
    4803        
     4810       
     4811        # Main menu
     4812        G2frame = self.GetTopLevelParent()
     4813        G2frame.GSASIIMenu = wx.MenuBar()
     4814        G2frame.dataMenuBars = [G2frame.GSASIIMenu] # list of all menus (added to in PrefillDataMenu)
     4815        G2frame.FillMainMenu(G2frame.GSASIIMenu)
     4816        G2frame.SetMenuBar(G2frame.GSASIIMenu)
     4817
    48044818        # Controls
    48054819        self.ControlsMenu = wx.MenuBar()
     
    51005114        self.InstEdit.Append(id=wxID_INST1VAL, kind=wx.ITEM_NORMAL,text='Set one value',
    51015115            help='Set one instrument parameter value across multiple histograms')
    5102 
    51035116        self.PostfillDataMenu()
    51045117       
     
    57325745    # end of GSAS-II menu definitions
    57335746   
    5734     def __init__(self,parent):
    5735         wxscroll.ScrolledPanel.__init__(self,parent,wx.ID_ANY,size=parent.GetSize())
    5736         self.parent = parent
    5737         self._initMenus_()
    5738         self.currentGrids = []
    5739         self.helpKey = ''  # defines help entry for current item selected in data tree
    5740        
    5741     def ClearData(self):
    5742         '''Initializes the contents of the dataWindow panel
    5743         '''
    5744         #self.SetBackgroundColour(wx.WHITE)  # BHT: I prefer a gray background. Makes TextCtrls stand out
    5745         self.SetBackgroundColour(VERY_LIGHT_GREY)  # BHT: I prefer a gray background. Makes TextCtrls stand out, but
    5746         # a bit lighter than the splitter bar
    5747 
    5748         Sizer = self.GetSizer()
    5749         if Sizer:
    5750             Sizer.Clear(True)
    5751         else:
    5752             print 'No sizer in dataWindow'
    5753             if GSASIIpath.GetConfigValue('debug'): raise Exception
    5754        
    5755     def SetDataSize(self):
    5756         '''Sizes the contents of the dataWindow panel
    5757         '''
    5758         Sizer = self.GetSizer()
    5759         if GSASIIpath.GetConfigValue('debug') and not Sizer:
    5760             print 'No sizer in dataWindow'
    5761             raise Exception
    5762         self.Layout()
    5763         self.SendSizeEvent()
    5764 
    5765     # TODO: remove this later
    5766     def SetTitle(self,*args):
    5767         print('Warning: attempt to label dataWindow')
    5768         G2obj.HowDidIgetHere()
    5769         self.G2frame.SetTitle(*args)
    5770     def SetTitle(self,*args):
    5771         print('Warning: attempt to label dataWindow')
    5772         G2obj.HowDidIgetHere()
    5773         self.G2frame.SetTitle(*args)
    5774 
    57755747       
    57765748#TODO - remove         
     
    77427714        if G2frame.dataDisplay:
    77437715            oldPage = G2frame.dataDisplay.GetSelection()
    7744     #G2frame.SetLabel(G2frame.GetLabel().split('||')[0]+' || '+'')
    77457716    G2frame.SetLabel('')
    77467717       
  • branch/2frame/GSASIIphsGUI.py

    r2912 r2913  
    12441244        """       
    12451245        # UpdateGeneral execution starts here
    1246         #General.DestroyChildren() # bad, deletes scrollbars on Mac!
    1247         if General.GetSizer():
    1248             General.GetSizer().Clear(True)
     1246        if General.GetSizer(): General.GetSizer().Clear(True)
    12491247        phaseTypes = ['nuclear','magnetic','macromolecular','faulted']
    12501248        SetupGeneral()
     
    63456343       
    63466344        # UpdateTexture executable starts here
    6347         #Texture.DestroyChildren() # bad, deletes scrollbars on Mac!
    6348         if Texture.GetSizer():
    6349             Texture.GetSizer().Clear(True)
     6345        if Texture.GetSizer(): Texture.GetSizer().Clear(True)
    63506346        G2frame.GetStatusBar().SetStatusText('')
    63516347        generalData = data['General']       
     
    70977093        # FillRigidBodyGrid executable code starts here
    70987094        if refresh:
    7099             #RigidBodies.DestroyChildren() # bad, deletes scrollbars on Mac!
    7100             if RigidBodies.GetSizer():
    7101                 RigidBodies.GetSizer().Clear(True)
     7095            if RigidBodies.GetSizer(): RigidBodies.GetSizer().Clear(True)
    71027096        general = data['General']
    71037097        cx,ct,cs,cia = general['AtomPtrs']
     
    73737367                G2plt.PlotStructure(G2frame,data)
    73747368                   
    7375             #RigidBodies.DestroyChildren() # bad, deletes scrollbars on Mac!
    7376             if RigidBodies.GetSizer():
    7377                 RigidBodies.GetSizer().Clear(True)
     7369            if RigidBodies.GetSizer(): RigidBodies.GetSizer().Clear(True)
    73787370            mainSizer = wx.BoxSizer(wx.VERTICAL)
    73797371            mainSizer.Add((5,5),0)
     
    79937985       
    79947986        # UpdateMCSA executable code starts here
    7995         #G2frame.MCSA.DestroyChildren() # bad, deletes scrollbars on Mac!
    7996         if G2frame.MCSA.GetSizer():
    7997             G2frame.MCSA.GetSizer().Clear(True)
     7987        if G2frame.MCSA.GetSizer(): G2frame.MCSA.GetSizer().Clear(True)
    79987988        if not data['Drawing']:                 #if new drawing - no drawing data!
    79997989            SetupDrawingData()
     
    91719161    G2frame.phaseDisplay.gridList = [] # list of all grids in notebook
    91729162    Pages = []   
    9173     G2frame.phaseDisplay.gridList = []
    91749163    General = wx.ScrolledWindow(G2frame.phaseDisplay)
    91759164    G2frame.phaseDisplay.AddPage(General,'General')
  • branch/2frame/GSASIIplot.py

    r2911 r2913  
    320320        self.plotList = []
    321321        self.panelList = []
    322         self.status.DestroyChildren()
     322        self.status.DestroyChildren() #get rid of special stuff on status bar
    323323       
    324324    def Rename(self,oldName,newName):
     
    18621862                                           (G2frame,newPlot,plotType),kwargs)
    18631863    # now start plotting
    1864     G2frame.G2plotNB.status.DestroyChildren()
     1864    G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar
    18651865    Page.tickDict = {}
    18661866    DifLine = ['']
     
    23572357            if ref[6+im] > 0.:
    23582358                DS.append((ref[5+im]-ref[7+im])/ref[6+im])
    2359     G2frame.G2plotNB.status.DestroyChildren()
     2359    G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar
    23602360    DS.sort()
    23612361    EDS = np.zeros_like(DS)
     
    25792579        Page.Offset = [0,0]
    25802580   
    2581     G2frame.G2plotNB.status.DestroyChildren()
     2581    G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar
    25822582    if Peaks == None:
    25832583        if G2frame.Contour:
     
    27992799   
    28002800    Page.Choice = None
    2801     G2frame.G2plotNB.status.DestroyChildren()
     2801    G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar
    28022802    Plot.set_title(Title)
    28032803    Plot.set_xlabel(r'd-spacing',fontsize=14)
     
    30473047    Page.keyPress = OnKeyPress
    30483048    Page.SetFocus()
    3049     G2frame.G2plotNB.status.DestroyChildren()
     3049    G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar
    30503050    Nxy = Z.shape
    30513051    Zmax = np.max(Z)
     
    31053105   
    31063106    Page.Choice = None
    3107     G2frame.G2plotNB.status.DestroyChildren()
     3107    G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar
    31083108    Plot.set_title('Strain')
    31093109    Plot.set_ylabel(r'd-spacing',fontsize=14)
     
    38703870        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
    38713871        Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress)
    3872     G2frame.G2plotNB.status.DestroyChildren()
     3872    G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar
    38733873    General = data['General']
    38743874    cx,ct,cs,cia = General['AtomPtrs']
     
    39563956    title = G2obj.StripUnicode(' for\n'+Data['title'],'') # matplotlib 1.x does not like unicode
    39573957    newAtomDict = Data.get('newAtomDict',{})
    3958     G2frame.G2plotNB.status.DestroyChildren()
     3958    G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar
    39593959
    39603960    def OnPlotKeyPress(event):
     
    50795079    Page.Choice = None
    50805080    Title = G2frame.GPXtree.GetItemText(G2frame.Image)[4:]
    5081     G2frame.G2plotNB.status.DestroyChildren()
     5081    G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar
    50825082    if G2frame.logPlot:
    50835083        Title = 'log('+Title+')'
  • branch/2frame/GSASIIpwdGUI.py

    r2912 r2913  
    13441344            mainSizer.Add(ExclSizer())
    13451345       
    1346     #if G2frame.dataWindow:
    1347     #    G2frame.dataWindow.DestroyChildren()
    13481346    G2frame.ifGetExclude = False
    13491347    G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.LimitMenu)
  • branch/2frame/GSASIIrestrGUI.py

    r2912 r2913  
    3232
    3333VERY_LIGHT_GREY = wx.Colour(235,235,235)
     34TabSelectionIdDict = {}
    3435
    3536################################################################################
     
    5455    data tree
    5556    '''
    56     if not Phases:
    57         print 'There are no phases to form restraints'
    58         return
    59     if not len(Phases):
    60         print 'There are no phases to form restraints'
    61         return
    62     phasedata = Phases[phaseName]
    63     if phaseName not in data:
    64         data[phaseName] = {}
    65     restrData = data[phaseName]
    66     if 'Bond' not in restrData:
    67         restrData['Bond'] = {'wtFactor':1.0,'Range':1.1,'Bonds':[],'Use':True}
    68     if 'Angle' not in restrData:
    69         restrData['Angle'] = {'wtFactor':1.0,'Range':0.85,'Angles':[],'Use':True}
    70     if 'Plane' not in restrData:
    71         restrData['Plane'] = {'wtFactor':1.0,'Planes':[],'Use':True}
    72     if 'Chiral' not in restrData:
    73         restrData['Chiral'] = {'wtFactor':1.0,'Volumes':[],'Use':True}
    74     if 'Torsion' not in restrData:
    75         restrData['Torsion'] = {'wtFactor':1.0,'Coeff':{},'Torsions':[],'Use':True}
    76     if 'Rama' not in restrData:
    77         restrData['Rama'] = {'wtFactor':1.0,'Coeff':{},'Ramas':[],'Use':True}
    78     if 'Texture' not in restrData:
    79         restrData['Texture'] = {'wtFactor':1.0,'HKLs':[],'Use':True}
    80     if 'ChemComp' not in restrData:
    81         restrData['ChemComp'] = {'wtFactor':1.0,'Sites':[],'Use':True}
    82     General = phasedata['General']
    83     Cell = General['Cell'][1:7]          #skip flag & volume   
    84     Amat,Bmat = G2lat.cell2AB(Cell)
    85     SGData = General['SGData']
    86     cx,ct,cs,cia = General['AtomPtrs']
    87     Atoms = phasedata['Atoms']
    88     AtLookUp = G2mth.FillAtomLookUp(Atoms,cia+8)
    89     if 'macro' in General['Type']:
    90         Names = [atom[0]+':'+atom[1]+atom[2]+' '+atom[3] for atom in Atoms]
    91         Ids = []
    92         Coords = []
    93         Types = []
    94     else:   
    95         Names = ['all '+ name for name in General['AtomTypes']]
    96         iBeg = len(Names)
    97         Types = [name for name in General['AtomTypes']]
    98         Coords = [ [] for type in Types]
    99         Ids = [ 0 for type in Types]
    100         Names += [atom[ct-1] for atom in Atoms]
    101     Types += [atom[ct] for atom in Atoms]
    102     Coords += [atom[cx:cx+3] for atom in Atoms]
    103     Ids += [atom[cia+8] for atom in Atoms]
    104     rama = G2data.ramachandranDist['All']
    105     ramaName = 'All'
    10657   
    10758    def OnSelectPhase(event):
     
    858809            UpdateBondRestr(bondRestData)               
    859810           
    860         BondRestr.DestroyChildren()
    861 #        if BondRestr.GetSizer():
    862 #            BondRestr.GetSizer().Clear(True)
     811        if BondRestr.GetSizer(): BondRestr.GetSizer().Clear(True)
    863812        mainSizer = wx.BoxSizer(wx.VERTICAL)
    864813        mainSizer.Add((5,5),0)
     
    994943            UpdateAngleRestr(angleRestData)               
    995944           
    996         AngleRestr.DestroyChildren()
    997 #        if AngleRestr.GetSizer():
    998 #            AngleRestr.GetSizer().Clear(True)
     945        if AngleRestr.GetSizer():
     946            AngleRestr.GetSizer().Clear(True)
    999947        mainSizer = wx.BoxSizer(wx.VERTICAL)
    1000948        mainSizer.Add((5,5),0)
     
    11161064            UpdatePlaneRestr(planeRestData)               
    11171065           
    1118         PlaneRestr.DestroyChildren()
    1119 #        if PlaneRestr.GetSizer():
    1120 #            PlaneRestr.GetSizer().Clear(True)
     1066        if PlaneRestr.GetSizer():
     1067            PlaneRestr.GetSizer().Clear(True)
    11211068        mainSizer = wx.BoxSizer(wx.VERTICAL)
    11221069        mainSizer.Add((5,5),0)
     
    12521199            UpdateChiralRestr(chiralRestData)               
    12531200                                           
    1254         ChiralRestr.DestroyChildren()
    1255 #        if ChiralRestr.GetSizer():
    1256 #            ChiralRestr.GetSizer().Clear(True)
     1201        if ChiralRestr.GetSizer(): ChiralRestr.GetSizer().Clear(True)
    12571202        mainSizer = wx.BoxSizer(wx.VERTICAL)
    12581203        mainSizer.Add((5,5),0)
     
    13691314            wx.CallAfter(UpdateTorsionRestr,torsionRestData)               
    13701315                                           
    1371         TorsionRestr.DestroyChildren()
    1372 #        if TorsionRestr.GetSizer():
    1373 #            TorsionRestr.GetSizer().Clear(True)
     1316        if TorsionRestr.GetSizer(): TorsionRestr.GetSizer().Clear(True)
    13741317        mainSizer = wx.BoxSizer(wx.VERTICAL)
    13751318        mainSizer.Add((5,5),0)
     
    14901433            UpdateRamaRestr(ramaRestData)               
    14911434                                           
    1492         RamaRestr.DestroyChildren()
    1493 #        if RamaRestr.GetSizer():
    1494 #            RamaRestr.GetSizer().Clear(True)
     1435        if RamaRestr.GetSizer(): RamaRestr.GetSizer().Clear(True)
    14951436        mainSizer = wx.BoxSizer(wx.VERTICAL)
    14961437        mainSizer.Add((5,5),0)
     
    16291570            UpdateChemcompRestr(chemcompRestData)               
    16301571
    1631         ChemCompRestr.DestroyChildren()
    1632 #        if ChemCompRestr.GetSizer():
    1633 #            ChemCompRestr.GetSizer().Clear(True)
     1572        if ChemCompRestr.GetSizer(): ChemCompRestr.GetSizer().Clear(True)
    16341573        mainSizer = wx.BoxSizer(wx.VERTICAL)
    16351574        mainSizer.Add((5,5),0)
     
    17391678            wx.CallAfter(UpdateTextureRestr,textureRestData)               
    17401679
    1741         TextureRestr.DestroyChildren()
     1680        if TextureRestr.GetSizer(): TextureRestr.GetSizer().Clear(True)
    17421681        mainSizer = wx.BoxSizer(wx.VERTICAL)
    17431682        mainSizer.Add((5,5),0)
     
    17831722           
    17841723    def OnPageChanged(event):
    1785         #print 'OnPageChanged'
    17861724        page = event.GetSelection()
    17871725        #G2frame.restrBook.SetSize(G2frame.dataWindow.GetClientSize())    #TODO -almost right
     
    18551793#        except ValueError:
    18561794#            print('Unexpected event in RaisePage')
    1857 #       
    1858     G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.RestraintMenu)
    1859     #G2frame.SetLabel(G2frame.GetLabel().split('||')[0]+' || '+'restraints for '+phaseName)
    1860     G2frame.SetTitle('restraints for '+phaseName)
    1861     #G2frame.restrBook = G2G.GSNoteBook(parent=G2frame.dataWindow,size=G2frame.dataWindow.GetClientSize())
    1862     G2frame.restrBook = G2G.GSNoteBook(parent=G2frame.dataWindow)
    1863     G2frame.dataWindow.GetSizer().Add(G2frame.restrBook,1,wx.ALL|wx.EXPAND,1)
    1864    
     1795#
     1796    def OnSelectPage(event):
     1797        'Called when an item is selected from the Select page menu'
     1798        # lookup the menu item that called us and get its text
     1799        tabname = TabSelectionIdDict.get(event.GetId())
     1800        if not tabname:
     1801            print 'Warning: menu item not in dict! id=',event.GetId()
     1802            return
     1803        # find the matching tab
     1804        for PageNum in range(G2frame.restrBook.GetPageCount()):
     1805            if tabname == G2frame.restrBook.GetPageText(PageNum):
     1806                G2frame.restrBook.SetSelection(PageNum)
     1807                return
     1808        else:
     1809            print "Warning: tab "+tabname+" was not found"
     1810
     1811    # UpdateRestraints execution starts here
     1812    if not Phases:
     1813        print 'There are no phases to form restraints'
     1814        return
     1815    if not len(Phases):
     1816        print 'There are no phases to form restraints'
     1817        return
     1818    phasedata = Phases[phaseName]
     1819    if phaseName not in data:
     1820        data[phaseName] = {}
     1821    restrData = data[phaseName]
     1822    if 'Bond' not in restrData:
     1823        restrData['Bond'] = {'wtFactor':1.0,'Range':1.1,'Bonds':[],'Use':True}
     1824    if 'Angle' not in restrData:
     1825        restrData['Angle'] = {'wtFactor':1.0,'Range':0.85,'Angles':[],'Use':True}
     1826    if 'Plane' not in restrData:
     1827        restrData['Plane'] = {'wtFactor':1.0,'Planes':[],'Use':True}
     1828    if 'Chiral' not in restrData:
     1829        restrData['Chiral'] = {'wtFactor':1.0,'Volumes':[],'Use':True}
     1830    if 'Torsion' not in restrData:
     1831        restrData['Torsion'] = {'wtFactor':1.0,'Coeff':{},'Torsions':[],'Use':True}
     1832    if 'Rama' not in restrData:
     1833        restrData['Rama'] = {'wtFactor':1.0,'Coeff':{},'Ramas':[],'Use':True}
     1834    if 'Texture' not in restrData:
     1835        restrData['Texture'] = {'wtFactor':1.0,'HKLs':[],'Use':True}
     1836    if 'ChemComp' not in restrData:
     1837        restrData['ChemComp'] = {'wtFactor':1.0,'Sites':[],'Use':True}
     1838    General = phasedata['General']
     1839    Cell = General['Cell'][1:7]          #skip flag & volume   
     1840    Amat,Bmat = G2lat.cell2AB(Cell)
     1841    SGData = General['SGData']
     1842    cx,ct,cs,cia = General['AtomPtrs']
     1843    Atoms = phasedata['Atoms']
     1844    AtLookUp = G2mth.FillAtomLookUp(Atoms,cia+8)
     1845    if 'macro' in General['Type']:
     1846        Names = [atom[0]+':'+atom[1]+atom[2]+' '+atom[3] for atom in Atoms]
     1847        Ids = []
     1848        Coords = []
     1849        Types = []
     1850    else:   
     1851        Names = ['all '+ name for name in General['AtomTypes']]
     1852        iBeg = len(Names)
     1853        Types = [name for name in General['AtomTypes']]
     1854        Coords = [ [] for type in Types]
     1855        Ids = [ 0 for type in Types]
     1856        Names += [atom[ct-1] for atom in Atoms]
     1857    Types += [atom[ct] for atom in Atoms]
     1858    Coords += [atom[cx:cx+3] for atom in Atoms]
     1859    Ids += [atom[cia+8] for atom in Atoms]
     1860    rama = G2data.ramachandranDist['All']
     1861    ramaName = 'All'
     1862    G2gd.SetDataMenuBar(G2frame,G2frame.dataWindow.RestraintMenu)   
    18651863    G2frame.dataWindow.RestraintEdit.Enable(G2gd.wxID_RESTSELPHASE,False)
    18661864    if len(Phases) > 1:
     
    18731871        G2frame.Bind(wx.EVT_MENU, OnPlotAARestraint, id=G2gd.wxID_AARESTRAINTPLOT)
    18741872   
     1873    # GUI defined here
     1874    G2frame.SetTitle('restraints for '+phaseName)
     1875    #G2frame.restrBook = G2G.GSNoteBook(parent=G2frame.dataWindow,size=G2frame.dataWindow.GetClientSize())
     1876    G2frame.restrBook = G2G.GSNoteBook(parent=G2frame.dataWindow)
     1877    G2frame.dataWindow.GetSizer().Add(G2frame.restrBook,1,wx.ALL|wx.EXPAND,1)
    18751878    # clear menu and menu pointers
     1879    Pages = []   
    18761880
    18771881    txt = 'Bond'
    18781882    BondRestr = wx.ScrolledWindow(G2frame.restrBook)
    18791883    G2frame.restrBook.AddPage(BondRestr,txt)
     1884    Pages.append(txt)
    18801885
    18811886    txt = 'Angle'
    18821887    AngleRestr = wx.ScrolledWindow(G2frame.restrBook)
    18831888    G2frame.restrBook.AddPage(AngleRestr,txt)
     1889    Pages.append(txt)
    18841890   
    18851891    txt = 'Plane'
    18861892    PlaneRestr = wx.ScrolledWindow(G2frame.restrBook)
    18871893    G2frame.restrBook.AddPage(PlaneRestr,txt)
     1894    Pages.append(txt)
    18881895
    18891896    txt = 'Chiral'
    18901897    ChiralRestr = wx.ScrolledWindow(G2frame.restrBook)
    18911898    G2frame.restrBook.AddPage(ChiralRestr,txt)
     1899    Pages.append(txt)
    18921900
    18931901    if 'macro' in General['Type']:
     
    18951903        TorsionRestr = wx.ScrolledWindow(G2frame.restrBook)
    18961904        G2frame.restrBook.AddPage(TorsionRestr,txt)
     1905        Pages.append(txt)
    18971906
    18981907        txt = 'Ramachandran'
    18991908        RamaRestr = wx.ScrolledWindow(G2frame.restrBook)
    19001909        G2frame.restrBook.AddPage(RamaRestr,txt)
     1910        Pages.append(txt)
    19011911
    19021912    txt = 'Chem. comp.'
    19031913    ChemCompRestr = wx.ScrolledWindow(G2frame.restrBook)
    19041914    G2frame.restrBook.AddPage(ChemCompRestr,txt)
     1915    Pages.append(txt)
    19051916   
    19061917    if General['SH Texture']['Order']:
     
    19081919        TextureRestr = wx.ScrolledWindow(G2frame.restrBook)
    19091920        G2frame.restrBook.AddPage(TextureRestr,txt)
    1910    
     1921        Pages.append(txt)
     1922
    19111923    UpdateBondRestr(restrData['Bond'])
    19121924
    19131925    G2frame.restrBook.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CHANGED, OnPageChanged)
     1926
     1927    # fill page selection menu
     1928    menu = G2frame.dataWindow.RestraintTab
     1929    for page in Pages:
     1930        if menu.FindItem(page) >= 0: continue # is tab already in menu?
     1931        Id = wx.NewId()
     1932        TabSelectionIdDict[Id] = page
     1933        menu.Append(id=Id,kind=wx.ITEM_NORMAL,text=page)
     1934        G2frame.Bind(wx.EVT_MENU, OnSelectPage, id=Id)
Note: See TracChangeset for help on using the changeset viewer.