Changeset 2641 for trunk/GSASII.py


Ignore:
Timestamp:
Jan 17, 2017 10:32:09 PM (5 years ago)
Author:
toby
Message:

move and expand selected tree items

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r2637 r2641  
    160160            kind=wx.ITEM_NORMAL,text='&New project')
    161161        self.Bind(wx.EVT_MENU, self.OnFileClose, id=item.GetId())
    162         item = parent.Append(              #not a good idea - reads all images as each is expanded!
     162        item = parent.Append(
    163163            help='Expand all items in GSAS-II data tree',id=wx.ID_ANY,
    164164            kind=wx.ITEM_NORMAL,text='Expand all')
     
    217217            text='Delete data')
    218218        self.Bind(wx.EVT_MENU, self.OnDataDelete, id=item.GetId())
    219                
     219        expandmenu = wx.Menu()
     220        item = parent.AppendMenu(
     221            wx.ID_ANY, 'Expand tree items', expandmenu,
     222            help='Expand items of type in GSAS-II data tree')
     223        for s in 'all','IMG','PWDR','PDF','HKLF','SASD':
     224            if s == 'all':
     225                help = 'Expand all items in GSAS-II data tree'
     226            else:
     227                help = 'Expand '+s+' type items in GSAS-II data tree'
     228            item = expandmenu.Append(wx.ID_ANY,kind=wx.ITEM_NORMAL,text=s,help=help)
     229            self.Bind(wx.EVT_MENU,self.ExpandAll,id=item.GetId())
     230        movemenu = wx.Menu()
     231        item = parent.AppendMenu(
     232            wx.ID_ANY, 'Move tree items', movemenu,
     233            help='Move items of type items to end of GSAS-II data tree')
     234        for s in 'IMG','PWDR','PDF','HKLF','SASD','Phase':
     235            help = 'Move '+s+' type items to end of GSAS-II data tree'
     236            item = movemenu.Append(wx.ID_ANY,kind=wx.ITEM_NORMAL,text=s,help=help)
     237            self.Bind(wx.EVT_MENU,self.MoveTreeItems,id=item.GetId())
     238
    220239    def _Add_CalculateMenuItems(self,parent):
    221240        item = parent.Append(help='Make new PDFs from selected powder patterns',
     
    24232442        self.EnablePlot = True
    24242443        self.hist = ''              # selected histogram in Phase/Data tab
    2425         self.dirname = os.path.expanduser('~')       #start in the users home directory by default; may be meaningless
     2444        self.dirname = os.path.abspath(os.path.expanduser('~'))       #start in the users home directory by default; may be meaningless
    24262445        self.TutorialImportDir = None  # location to read tutorial files, set when a tutorial is viewed
    24272446        self.LastImportDir = None # last-used directory where an import was done
     
    24352454        if len(arg) > 1 and arg[1]:
    24362455            self.GSASprojectfile = os.path.splitext(arg[1])[0]+'.gpx'
    2437             self.dirname = os.path.dirname(arg[1])
     2456            self.dirname = os.path.abspath(os.path.dirname(arg[1]))
    24382457            if self.dirname: os.chdir(self.dirname)
    24392458            try:
     
    33283347           
    33293348    def ExpandAll(self,event):
     3349        '''Expand all tree items or those of a single type
     3350        '''
     3351        txt = self.GetMenuBar().GetLabel(event.Id)
     3352        if txt == 'all':
     3353            self.ExpandingAll = True
     3354            try:
     3355                self.PatternTree.ExpandAll()
     3356            finally:
     3357                self.ExpandingAll = False
     3358        else:
     3359            self.ExpandingAll = True
     3360            try:
     3361                item, cookie = self.PatternTree.GetFirstChild(self.root)
     3362                while item:
     3363                    name = self.PatternTree.GetItemText(item)
     3364                    if name.startswith(txt+' '): self.PatternTree.Expand(item)
     3365                    item, cookie = self.PatternTree.GetNextChild(self.root, cookie)
     3366            finally:
     3367                self.ExpandingAll = False
     3368
     3369    def MoveTreeItems(self,event):
     3370        '''Move tree items of a single type to the end of the tree
     3371        '''
     3372        txt = self.GetMenuBar().GetLabel(event.Id)
     3373        # make a list of items to copy
     3374        copyList = []
     3375        item, cookie = self.PatternTree.GetFirstChild(self.root)
     3376        while item:
     3377            if self.PatternTree.GetItemText(item).startswith(txt+' '):
     3378                copyList.append(item)
     3379            item, cookie = self.PatternTree.GetNextChild(self.root, cookie)
     3380       
    33303381        self.ExpandingAll = True
    33313382        try:
    3332             self.PatternTree.ExpandAll()
     3383            for item in copyList:
     3384                name = self.PatternTree.GetItemText(item)
     3385                newId = self.PatternTree.AppendItem(self.root,name)
     3386                self.PatternTree.SetItemPyData(newId,self.PatternTree.GetItemPyData(item))
     3387                chld, chldcookie = self.PatternTree.GetFirstChild(item)
     3388                while chld:
     3389                    chname = self.PatternTree.GetItemText(chld)
     3390                    newCh = self.PatternTree.AppendItem(newId,chname)
     3391                    self.PatternTree.SetItemPyData(newCh,self.PatternTree.GetItemPyData(chld))
     3392                    chld, chldcookie = self.PatternTree.GetNextChild(item, chldcookie)
     3393                self.PatternTree.Delete(item)
    33333394        finally:
    33343395            self.ExpandingAll = False
    3335 
     3396        G2gd.SelectDataTreeItem(self,self.root)
     3397           
    33363398    def ExitMain(self, event):
    33373399        '''Called if the main window is closed'''
Note: See TracChangeset for help on using the changeset viewer.