Ejemplo n.º 1
0
    def move_node(self,
                  src_filepath,
                  childpath,
                  parent_index,
                  overwrite=False):
        """Move a `tables.Node` to a different location.

        :Parameters:

          - `src_filepath`: the full path of the source database
          - `childpath`: the full path of the node being moved
          - `parent_index`: the model index of the new parent group
          - `overwrite`: True if a node is being overwritten
        """

        try:
            QtWidgets.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
            parent_node = self.nodeFromIndex(parent_index)
            # full path of the destination database and new parent
            dst_filepath = parent_node.filepath
            parentpath = parent_node.nodepath

            #
            # Check if the nodename is already in use
            #
            (nodename,
             overwrite) = self.validateNodename(src_filepath, childpath,
                                                dst_filepath, parentpath)
            if nodename is None:
                return nodename

            # If the overwritten node (if any) exists in the tree of
            # databases view then delete it
            if overwrite:
                self.overwriteNode(parent_node, parent_index, nodename)

            # Move the node to the PyTables database
            pt_node = self.getDBDoc(src_filepath).get_node(childpath)
            db_doc = self.getDBDoc(src_filepath)
            if hasattr(pt_node, 'target'):
                editor = tlink_editor.TLinkEditor(db_doc)
            else:
                editor = tnode_editor.TNodeEditor(db_doc)
            movedname = editor.move(childpath, self.getDBDoc(dst_filepath),
                                    parentpath, nodename)
        finally:
            QtWidgets.qApp.restoreOverrideCursor()
            return movedname
Ejemplo n.º 2
0
    def pasteNode(self, index, childname, overwrite=False):
        """Paste a tables.Node.

        Paste the last copied/cut node under the currently selected group.

        :Parameters:

        - `index`: the index of the selected node (the parent group)
        - `childname`: the name of the node being pasted
        - `overwrite`: True if a node is being overwritten
        """

        try:
            QtGui.qApp.setOverrideCursor(QtCore.Qt.WaitCursor)
            parent = self.nodeFromIndex(index)

            # If the overwritten node (if any) exists in the tree of
            # databases view then delete it
            if overwrite:
                self.overwriteNode(parent, index, childname)

            # Paste the copied/cut node in the destination database
            db_doc = self.getDBDoc(parent.filepath)
            if self.ccni['target']:
                editor = tlink_editor.TLinkEditor(db_doc)
            else:
                editor = tnode_editor.TNodeEditor(db_doc)

            src_node = self.copiedNode()
            editor.paste(src_node, parent.node, childname)

            # Paste the node in the tree of databases model/view
            self.lazyAddChildren(index)
            parent.updated = True

            # Select the pasted node
            self.selectIndex(index, childname)
        finally:
            QtGui.qApp.restoreOverrideCursor()
Ejemplo n.º 3
0
 def editor(self):
     """Return an instance of `TNodeEditor`.
     """
     return tnode_editor.TNodeEditor(self.dbt_model.getDBDoc(self.filepath))