Changeset 1499


Ignore:
Timestamp:
Sep 17, 2014 2:58:30 PM (7 years ago)
Author:
vondreele
Message:

Drag/drop of tree items now works; one odd bit if trying to drag to bottom of tree. Sometimes fails, but not catastrophic.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASII.py

    r1498 r1499  
    18661866        self.PatternTree.Bind(wx.EVT_TREE_KEY_DOWN,
    18671867            self.OnPatternTreeKeyDown, id=wxID_PATTERNTREE)
    1868 #Can't get drag/drop of tree items to work except in simple cases (e.g. Controls)
    1869 #        self.PatternTree.Bind(wx.EVT_TREE_BEGIN_RDRAG,
    1870 #            self.OnPatternTreeBeginRDrag, id=wxID_PATTERNTREE)       
    1871 #        self.PatternTree.Bind(wx.EVT_TREE_END_DRAG,
    1872 #            self.OnPatternTreeEndDrag, id=wxID_PATTERNTREE)       
     1868        self.PatternTree.Bind(wx.EVT_TREE_BEGIN_RDRAG,
     1869            self.OnPatternTreeBeginRDrag, id=wxID_PATTERNTREE)       
     1870        self.PatternTree.Bind(wx.EVT_TREE_END_DRAG,
     1871            self.OnPatternTreeEndDrag, id=wxID_PATTERNTREE)       
    18731872        self.root = self.PatternTree.AddRoot('Loaded Data: ')
    1874        
    18751873        plotFrame = wx.Frame(None,-1,'GSASII Plots',size=wx.Size(700,600), \
    18761874            style=wx.DEFAULT_FRAME_STYLE ^ wx.CLOSE_BOX)
     
    19981996        event.Allow()
    19991997        self.BeginDragId = event.GetItem()
    2000         print 'start',self.PatternTree.GetItemText(self.BeginDragId)
    20011998        self.ParentId = self.PatternTree.GetItemParent(self.BeginDragId)
    2002         self.DragData = self.PatternTree.GetItemPyData(self.BeginDragId)
     1999        DragText = self.PatternTree.GetItemText(self.BeginDragId)
     2000        self.DragData = [[DragText,self.PatternTree.GetItemPyData(self.BeginDragId)],]
     2001        item, cookie = self.PatternTree.GetFirstChild(self.BeginDragId)
     2002        while item:     #G2 data tree has no sub children under a child of a tree item
     2003            name = self.PatternTree.GetItemText(item)
     2004            self.DragData.append([name,self.PatternTree.GetItemPyData(item)])
     2005            item, cookie = self.PatternTree.GetNextChild(self.BeginDragId, cookie)                           
    20032006       
    20042007    def OnPatternTreeEndDrag(self,event):
     
    20092012            print 'drag not allowed - wrong parent'
    20102013        else:
    2011             Name = self.PatternTree.GetItemText(self.BeginDragId)
    2012             self.PatternTree.InsertItem(self.ParentId,self.EndDragId,Name,data=None)
    2013             Id = G2gd.GetPatternTreeItemId(self, self.ParentId,Name)
    2014             self.PatternTree.SetItemPyData(Id,self.DragData)
     2014            Name,Item = self.DragData[0]
     2015            NewId = self.PatternTree.InsertItem(self.ParentId,self.EndDragId,Name,data=None)
     2016            self.PatternTree.SetItemPyData(NewId,Item)
     2017            for name,item in self.DragData[1:]:     #loop over children
     2018                Id = self.PatternTree.AppendItem(parent=NewId,text=name)
     2019                self.PatternTree.SetItemPyData(Id,item)
    20152020            self.PatternTree.Delete(self.BeginDragId)
    2016         print 'end',self.PatternTree.GetItemText(self.EndDragId)
     2021            G2gd.MovePatternTreeToGrid(self,NewId)
    20172022       
    20182023    def OnPatternTreeKeyDown(self,event):
Note: See TracChangeset for help on using the changeset viewer.