Exemplo n.º 1
0
 def mouseMoveEvent(self, event):
     """Mouse move event to start drag & drop"""
     if (
         event.buttons() == QtCore.Qt.LeftButton
         and self.dragStartPos
         and globalref.docRef.selection
         and (event.pos() - self.dragStartPos).manhattanLength() > QtGui.QApplication.startDragDistance()
         and globalref.options.boolData("DragTree")
     ):
         oldSelect = globalref.docRef.selection[:]
         drag = QtGui.QDrag(self)
         drag.setMimeData(self.mimeData())
         dropAction = drag.start(QtCore.Qt.MoveAction | QtCore.Qt.CopyAction)
         if dropAction == QtCore.Qt.MoveAction:
             if drag.target() == None:  # move to different session
                 if globalref.docRef.root in oldSelect:
                     return  # can't delete root
                 undoParents = filter(None, [item.parent for item in globalref.docRef.selection])
                 globalref.docRef.undoStore.addChildListUndo(undoParents)
                 globalref.docRef.selection.replace([undoParents[0]])
             elif filter(None, [node.hasDescendant(globalref.docRef.selection[0]) for node in oldSelect]):
                 return  # don't delete if drag to descendant
             for item in oldSelect:
                 item.delete()
             globalref.updateViewAll()
Exemplo n.º 2
0
 def restoreState(self, treeView):
     """Restore this state in the current file, return True if changed"""
     fileTimeStamp = os.stat(globalref.docRef.fileName).st_mtime
     if fileTimeStamp > self.timeStamp:  # file modified externally
         return False
     allNodes = globalref.docRef.root.descendantList(True)
     try:
         selectedNodes = [allNodes[i] for i in self.selectNodes]
     except IndexError:
         selectedNodes = [allNodes[0]]
     globalref.docRef.selection.replace(selectedNodes)
     globalref.docRef.selection.prevSelects = []
     for i in self.openNodes:
         try:
             node = allNodes[i]
             while not node.open and node != allNodes[0]:
                 node.open = True
                 node = node.parent
         except IndexError:
             pass
     globalref.updateViewAll()
     try:
         topNode = allNodes[self.topNode].viewData
         treeView.scrollToItem(topNode,
                               QtGui.QAbstractItemView.PositionAtTop)
     except IndexError:
         pass
     return True
Exemplo n.º 3
0
 def configCopy(self, fileRef, password=''):
     """Copy the configuration from another TreeLine file"""
     if hasattr(fileRef, 'read'):
         fileName = unicode(fileRef.name, sys.getfilesystemencoding())
     else:
         fileName = fileRef
     origDocRef = globalref.docRef
     refDoc = treedoc.TreeDoc()
     if password:
         refDoc.setPassword(fileName, password)
     try:
         refDoc.readFile(fileRef)
     except:
         globalref.docRef = origDocRef
         raise
     globalref.docRef = origDocRef
     origDocRef.undoStore.addFormatUndo(self, origDocRef.fileInfoFormat, {},
                                        {})
     for newFormat in refDoc.treeFormats.values():
         format = self.get(newFormat.name, None)
         if format:
             format.duplicateSettings(newFormat)
         else:
             self[newFormat.name] = newFormat
     self.updateAutoChoices()
     self.updateUniqueID()
     self.updateDerivedTypes()
     globalref.docRef.modified = True
     globalref.updateViewAll()
Exemplo n.º 4
0
 def mouseMoveEvent(self, event):
     """Mouse move event to start drag & drop"""
     if event.buttons() == QtCore.Qt.LeftButton and self.dragStartPos and \
             globalref.docRef.selection and \
             (event.pos() - self.dragStartPos).manhattanLength() > \
             QtGui.QApplication.startDragDistance() and \
             globalref.options.boolData('DragTree'):
         oldSelect = globalref.docRef.selection[:]
         drag = QtGui.QDrag(self)
         drag.setMimeData(self.mimeData())
         dropAction = drag.start(QtCore.Qt.MoveAction
                                 | QtCore.Qt.CopyAction)
         if dropAction == QtCore.Qt.MoveAction:
             if drag.target() == None:  # move to different session
                 if globalref.docRef.root in oldSelect:
                     return  # can't delete root
                 undoParents = filter(
                     None,
                     [item.parent for item in globalref.docRef.selection])
                 globalref.docRef.undoStore.addChildListUndo(undoParents)
                 globalref.docRef.selection.replace([undoParents[0]])
             elif filter(None, [
                     node.hasDescendant(globalref.docRef.selection[0])
                     for node in oldSelect
             ]):
                 return  # don't delete if drag to descendant
             for item in oldSelect:
                 item.delete()
             globalref.updateViewAll()
Exemplo n.º 5
0
 def configCopy(self, fileRef, password=''):
     """Copy the configuration from another TreeLine file"""
     if hasattr(fileRef, 'read'):
         fileName = unicode(fileRef.name, sys.getfilesystemencoding())
     else:
         fileName = fileRef
     origDocRef = globalref.docRef
     refDoc = treedoc.TreeDoc()
     if password:
         refDoc.setPassword(fileName, password)
     try:
         refDoc.readFile(fileRef)
     except:
         globalref.docRef = origDocRef
         raise
     globalref.docRef = origDocRef
     origDocRef.undoStore.addFormatUndo(self, origDocRef.fileInfoFormat,
                                        {}, {})
     for newFormat in refDoc.treeFormats.values():
         format = self.get(newFormat.name, None)
         if format:
             format.duplicateSettings(newFormat)
         else:
             self[newFormat.name] = newFormat
     self.updateAutoChoices()
     self.updateUniqueID()
     self.updateDerivedTypes()
     globalref.docRef.modified = True
     globalref.updateViewAll()
Exemplo n.º 6
0
 def restoreState(self, treeView):
     """Restore this state in the current file, return True if changed"""
     fileTimeStamp = os.stat(globalref.docRef.fileName).st_mtime
     if fileTimeStamp > self.timeStamp:  # file modified externally
         return False
     allNodes = globalref.docRef.root.descendantList(True)
     try:
         selectedNodes = [allNodes[i] for i in self.selectNodes]
     except IndexError:
         selectedNodes = [allNodes[0]]
     globalref.docRef.selection.replace(selectedNodes)
     globalref.docRef.selection.prevSelects = []
     for i in self.openNodes:
         try:
             node = allNodes[i]
             while not node.open and node != allNodes[0]:
                 node.open = True
                 node = node.parent
         except IndexError:
             pass
     globalref.updateViewAll()
     try:
         topNode = allNodes[self.topNode].viewData
         treeView.scrollToItem(topNode,
                               QtGui.QAbstractItemView.PositionAtTop)
     except IndexError:
         pass
     return True
Exemplo n.º 7
0
 def undo(self, redoRef=None):
     """Restore saved state for next undo item,
        add undo item to redoRef, update selection and views"""
     if self.undoList:
         self.tmpRedoRef = redoRef
         obj = self.undoList.pop()
         obj.undo(redoRef)
         globalref.docRef.modified = obj.docModified
         globalref.docRef.selection = obj.selection
         globalref.docRef.selection.selectEmptyCurrent()
         globalref.updateViewAll()
Exemplo n.º 8
0
 def undo(self, redoRef=None):
     """Restore saved state for next undo item,
        add undo item to redoRef, update selection and views"""
     if self.undoList:
         self.tmpRedoRef = redoRef
         obj = self.undoList.pop()
         obj.undo(redoRef)
         globalref.docRef.modified = obj.docModified
         globalref.docRef.selection = obj.selection
         globalref.docRef.selection.selectEmptyCurrent()
         globalref.updateViewAll()
Exemplo n.º 9
0
 def dropMimeData(self, parent, mimeData, isCopy=False):
     """Decode dropped data"""
     mainWin = self.parent().parent().parent().parent()
     oldMainWin = globalref.mainWin
     if globalref.treeControl.duplicateWindows():
         oldMainWin.saveMultiWinTree()
     globalref.updateRefs(mainWin)
     text = unicode(mimeData.data('text/xml'), 'utf-8')
     root, newFormats = globalref.docRef.readXmlStringAndFormat(text)
     if not root:
         globalref.updateRefs(oldMainWin)
         return False
     if root.formatName == treedoc.TreeDoc.copyFormat.name:
         itemList = root.childList
     else:
         itemList = [root]
     undoParents = [parent] + filter(
         None, [item.parent for item in globalref.docRef.selection])
     if newFormats:
         globalref.docRef.undoStore.addBranchUndo(undoParents)
         for format in newFormats:
             globalref.docRef.treeFormats.addIfMissing(format)
         globalref.docRef.treeFormats.updateDerivedTypes()
         globalref.docRef.treeFormats.updateUniqueID()
         if treemainwin.TreeMainWin.configDlg:
             treemainwin.TreeMainWin.configDlg.resetParam()
     else:
         globalref.docRef.undoStore.addChildListUndo(undoParents)
     for node in itemList:
         parent.addTree(node)
         if isCopy:
             node.setDescendantUniqueID(True)
     parent.open = True
     globalref.docRef.selection.replace(itemList)
     if newFormats:
         globalref.docRef.treeFormats.updateAutoChoices()
     globalref.updateViewAll()
     globalref.updateRefs(oldMainWin)
     if globalref.treeControl.duplicateWindows():
         oldMainWin.updateMultiWinTree()
     return True
Exemplo n.º 10
0
 def dropMimeData(self, parent, mimeData, isCopy=False):
     """Decode dropped data"""
     mainWin = self.parent().parent().parent().parent()
     oldMainWin = globalref.mainWin
     if globalref.treeControl.duplicateWindows():
         oldMainWin.saveMultiWinTree()
     globalref.updateRefs(mainWin)
     text = unicode(mimeData.data("text/xml"), "utf-8")
     root, newFormats = globalref.docRef.readXmlStringAndFormat(text)
     if not root:
         globalref.updateRefs(oldMainWin)
         return False
     if root.formatName == treedoc.TreeDoc.copyFormat.name:
         itemList = root.childList
     else:
         itemList = [root]
     undoParents = [parent] + filter(None, [item.parent for item in globalref.docRef.selection])
     if newFormats:
         globalref.docRef.undoStore.addBranchUndo(undoParents)
         for format in newFormats:
             globalref.docRef.treeFormats.addIfMissing(format)
         globalref.docRef.treeFormats.updateDerivedTypes()
         globalref.docRef.treeFormats.updateUniqueID()
         if treemainwin.TreeMainWin.configDlg:
             treemainwin.TreeMainWin.configDlg.resetParam()
     else:
         globalref.docRef.undoStore.addChildListUndo(undoParents)
     for node in itemList:
         parent.addTree(node)
         if isCopy:
             node.setDescendantUniqueID(True)
     parent.open = True
     globalref.docRef.selection.replace(itemList)
     if newFormats:
         globalref.docRef.treeFormats.updateAutoChoices()
     globalref.updateViewAll()
     globalref.updateRefs(oldMainWin)
     if globalref.treeControl.duplicateWindows():
         oldMainWin.updateMultiWinTree()
     return True
Exemplo n.º 11
0
 def updateViews(self):
     """Refresh the tree view and the current right-side views to reflect
        current data"""
     globalref.updateViewAll()
Exemplo n.º 12
0
 def updateViews(self):
     """Refresh the tree view and the current right-side views to reflect
        current data"""
     globalref.updateViewAll()