Ejemplo n.º 1
0
 def __init__(self, srcPath, dstDir=None):
     if dstDir is None:
         dstDir = LIB_DIR
     srcPath = Path(srcPath)
     self._dstDir = Path(dstDir)
     
      # Init set of files
     self._dependentFiles = set()
     # Init set of files to set search path for
     self._dependingFiles = set()
     # Init set of files that were copied
     self._newFiles = set()
     
     self._dependentFilesCache = {}
     self._linkerWarnings = {}
     self.binIncludes = [os.path.normcase(n) \
             for n in self._GetDefaultBinIncludes()]
     self.binExcludes = [os.path.normcase(n) \
             for n in self._GetDefaultBinExcludes()]
     self.binPathIncludes = []
     self.binPathExcludes = [os.path.normcase(n) \
             for n in self._GetDefaultBinPathExcludes()]
     
     # If given path is a file, get and install dependencies now
     if srcPath.isdir:
         self._srcDir = srcPath
     elif srcPath.isfile:
         self._srcDir = srcPath.dirname
Ejemplo n.º 2
0
    def __init__(self, parent):
        QtGui.QWidget.__init__(self, parent)

        # Get config
        toolId = self.__class__.__name__.lower(
        ) + '2'  # This is v2 of the file browser
        if toolId not in pyzo.config.tools:
            pyzo.config.tools[toolId] = ssdf.new()
        self.config = pyzo.config.tools[toolId]

        # Ensure three main attributes in config
        for name in ['expandedDirs', 'starredDirs']:
            if name not in self.config:
                self.config[name] = []

        # Ensure path in config
        if 'path' not in self.config or not os.path.isdir(self.config.path):
            self.config.path = os.path.expanduser('~')

        # Check expandedDirs and starredDirs.
        # Make Path instances and remove invalid dirs. Also normalize case,
        # should not be necessary, but maybe the config was manually edited.
        expandedDirs, starredDirs = [], []
        for d in self.config.starredDirs:
            if 'path' in d and 'name' in d and 'addToPythonpath' in d:
                if os.path.isdir(d.path):
                    d.path = Path(d.path).normcase()
                    starredDirs.append(d)
        for p in set([str(p) for p in self.config.expandedDirs]):
            if os.path.isdir(p):
                p = Path(p).normcase()
                # Add if it is a subdir of a starred dir
                for d in starredDirs:
                    if p.startswith(d.path):
                        expandedDirs.append(p)
                        break
        self.config.expandedDirs, self.config.starredDirs = expandedDirs, starredDirs

        # Create browser(s).
        self._browsers = []
        for i in [0]:
            self._browsers.append(Browser(self, self.config))

        # Layout
        layout = QtGui.QVBoxLayout(self)
        self.setLayout(layout)
        layout.addWidget(self._browsers[0])
        layout.setSpacing(0)
        layout.setContentsMargins(4, 4, 4, 4)
Ejemplo n.º 3
0
 def __init__(self, parent):
     QtGui.QWidget.__init__(self, parent)
     
     # Get config
     toolId =  self.__class__.__name__.lower() + '2'  # This is v2 of the file browser
     if toolId not in pyzo.config.tools:
         pyzo.config.tools[toolId] = ssdf.new()
     self.config = pyzo.config.tools[toolId]
     
     # Ensure three main attributes in config
     for name in ['expandedDirs', 'starredDirs']:
         if name not in self.config:
             self.config[name] = []
     
     # Ensure path in config
     if 'path' not in self.config or not os.path.isdir(self.config.path):
         self.config.path = os.path.expanduser('~')
     
     # Check expandedDirs and starredDirs. 
     # Make Path instances and remove invalid dirs. Also normalize case, 
     # should not be necessary, but maybe the config was manually edited.
     expandedDirs, starredDirs = [], []
     for d in self.config.starredDirs:
         if 'path' in d and 'name' in d and 'addToPythonpath' in d:
             if os.path.isdir(d.path):
                 d.path = Path(d.path).normcase()
                 starredDirs.append(d)
     for p in set([str(p) for p in self.config.expandedDirs]):
         if os.path.isdir(p):
             p = Path(p).normcase()
             # Add if it is a subdir of a starred dir
             for d in starredDirs:
                 if p.startswith(d.path):
                     expandedDirs.append(p)
                     break
     self.config.expandedDirs, self.config.starredDirs = expandedDirs, starredDirs
     
     # Create browser(s).
     self._browsers = []
     for i in [0]:
         self._browsers.append( Browser(self, self.config) )
     
     # Layout
     layout = QtGui.QVBoxLayout(self)
     self.setLayout(layout)
     layout.addWidget(self._browsers[0])
     layout.setSpacing(0)
     layout.setContentsMargins(4,4,4,4)
Ejemplo n.º 4
0
 def onProjectSelect(self, index):
     path = self._combo.itemData(index)
     if path:
         # Go to dir
         self.dirChanged.emit(Path(path))
     else:
         # Dummy item, reset
         self.setPath(self._path)
Ejemplo n.º 5
0
Archivo: tree.py Proyecto: operade/pyzo
 def setPathUp(self):
     """ Go one directory up.
     """
     newPath = self.path().dirname
     
     if newPath == self.path():
         self.setPath(Path(MOUNTS))
     else:
         self.setPath(newPath)
Ejemplo n.º 6
0
Archivo: tree.py Proyecto: operade/pyzo
def createMounts(browser, tree):
    """ Create items for all known mount points (i.e. drives on Windows).
    """
    fsProxy = browser._fsProxy
    
    mountPoints = getMounts()
    mountPoints.sort(key=lambda x: x.lower())
    for entry in mountPoints:
        entry = Path(entry)
        item = DriveItem(tree, fsProxy.dir(entry))
Ejemplo n.º 7
0
    def __init__(self, parent, config, path=None):
        QtGui.QWidget.__init__(self, parent)

        # Store config
        self.config = config

        # Create star button
        self._projects = Projects(self)

        # Create path input/display lineEdit
        self._pathEdit = PathInput(self)

        # Create file system proxy
        self._fsProxy = proxies.NativeFSProxy()
        self.destroyed.connect(self._fsProxy.stop)

        # Create tree widget
        self._tree = Tree(self)
        self._tree.setPath(Path(self.config.path))

        # Create name filter
        self._nameFilter = NameFilter(self)
        #self._nameFilter.lineEdit().setToolTip('File filter pattern')
        self._nameFilter.setToolTip(translate('filebrowser',
                                              'Filename filter'))
        self._nameFilter.setPlaceholderText(self._nameFilter.toolTip())

        # Create search filter
        self._searchFilter = SearchFilter(self)
        self._searchFilter.setToolTip(
            translate('filebrowser', 'Search in files'))
        self._searchFilter.setPlaceholderText(self._searchFilter.toolTip())

        # Signals to sync path.
        # Widgets that can change the path transmit signal to _tree
        self._pathEdit.dirUp.connect(self._tree.setFocus)
        self._pathEdit.dirUp.connect(self._tree.setPathUp)
        self._pathEdit.dirChanged.connect(self._tree.setPath)
        self._projects.dirChanged.connect(self._tree.setPath)
        #
        self._nameFilter.filterChanged.connect(
            self._tree.onChanged)  # == update
        self._searchFilter.filterChanged.connect(self._tree.onChanged)
        # The tree transmits signals to widgets that need to know the path
        self._tree.dirChanged.connect(self._pathEdit.setPath)
        self._tree.dirChanged.connect(self._projects.setPath)

        self._layout()

        # Set and sync path ...
        if path is not None:
            self._tree.SetPath(path)
        self._tree.dirChanged.emit(self._tree.path())
Ejemplo n.º 8
0
Archivo: tree.py Proyecto: guanzd88/iep
 def setFileIcon(self):
     # Create dummy file in iep user dir
     dummy_filename = Path(iep.appDataDir) / 'dummyFiles' / 'dummy' + self.path().ext
     # Create file?
     if not dummy_filename.isfile:
         if not dummy_filename.dirname.isdir:
             os.makedirs(dummy_filename.dirname)
         f = open(dummy_filename, 'wb')
         f.close()
     # Use that file
     icon = iconprovider.icon(QtCore.QFileInfo(dummy_filename))
     icon = addIconOverlays(icon)
     self.setIcon(0, icon)
Ejemplo n.º 9
0
 def checkValid(self):
     # todo: This kind of violates the abstraction of the file system
     # ok for now, but we should find a different approach someday
     # Check
     text = self.text()
     dir = Path(text)
     isvalid = text and dir.isdir and os.path.isabs(dir)
     # Apply styling
     ss = self.styleSheet().replace('font-style:italic; ', '')
     if not isvalid:
         ss = ss.replace('QLineEdit {', 'QLineEdit {font-style:italic; ')
     self.setStyleSheet(ss)
     # Return
     return isvalid
Ejemplo n.º 10
0
Archivo: tree.py Proyecto: operade/pyzo
 def setFileIcon(self):
     # Create dummy file in pyzo user dir
     dummy_filename = Path(pyzo.appDataDir) / 'dummyFiles' / 'dummy' + self.path().ext
     # Create file?
     if not dummy_filename.isfile:
         if not dummy_filename.dirname.isdir:
             os.makedirs(dummy_filename.dirname)
         f = open(dummy_filename, 'wb')
         f.close()
     # Use that file
     if sys.platform.startswith('linux') and \
                                 not QtCore.__file__.startswith('/usr/'):
         icon = iconprovider.icon(iconprovider.File)
     else:
         icon = iconprovider.icon(QtCore.QFileInfo(dummy_filename))        
     icon = addIconOverlays(icon)
     self.setIcon(0, icon)
Ejemplo n.º 11
0
Archivo: tree.py Proyecto: operade/pyzo
def createItemsFun(browser, parent):
    """ Create the tree widget items for a Tree or DirItem.
    """
    
    # Get file system proxy and dir proxy for which we shall create items
    fsProxy = browser._fsProxy
    dirProxy = parent._proxy
    
    # Get meta information from browser
    nameFilter = browser.nameFilter()
    searchFilter = browser.searchFilter()
    searchFilter = searchFilter if searchFilter['pattern'] else None
    expandedDirs = browser.expandedDirs
    starredDirs = browser.starredDirs
    
    
    # Filter the contents of this folder
    try:
        dirs = []
        for entry in dirProxy.dirs():
            entry = Path(entry)
            if entry.basename.startswith('.'):
                continue # Skip hidden files
            if hasHiddenAttribute(entry):
                continue # Skip hidden files on Windows
            if entry.basename == '__pycache__':
                continue
            dirs.append(entry)
        
        files = []
        for entry in dirProxy.files():
            entry = Path(entry)
            if entry.basename.startswith('.'):
                continue # Skip hidden files
            if hasHiddenAttribute(entry):
                continue # Skip hidden files on Windows
            if not _filterFileByName(entry.basename, nameFilter):
                continue
            files.append(entry)
    
    except (OSError, IOError) as err:
        ErrorItem(parent, str(err))
        return 
    
    # Sort dirs (case insensitive)
    dirs.sort(key=lambda x: x.lower())
    
    # Sort files 
    # (first by name, then by type, so finally they are by type, then name)
    files.sort(key=lambda x: x.lower())
    files.sort(key=lambda x: x.ext.lower())
        
    
    if not searchFilter:
        
        # Create dirs 
        for path in dirs:
            starred = path.normcase() in starredDirs
            item = DirItem(parent, fsProxy.dir(path), starred)
            # Set hidden, we can safely expand programmatically when hidden
            item.setHidden(True)
            # Set expanded and visibility
            if path.normcase() in expandedDirs:
                item.setExpanded(True)
            item.setHidden(False)
        
        # Create files        
        for path in files:
            item = FileItem(parent, fsProxy.file(path))
    
    else:
        
        # If searching, inject everything in the tree
        # And every item is hidden at first
        parent = browser._tree
        if parent.topLevelItemCount():
            searchInfoItem = parent.topLevelItem(0)
        else:
            searchInfoItem = SearchInfoItem(parent)
        
        # Increase number of found files
        searchInfoItem.increaseTotal(len(files))
        
        # Create temporary file items
        for path in files:
            item = TemporaryFileItem(parent, fsProxy.file(path))
            item.search(searchFilter)
        
        # Create temporary dir items
        if searchFilter['subDirs']:
            for path in dirs:
                item = TemporaryDirItem(parent, fsProxy.dir(path))
    
    
    # Return number of files added
    return len(dirs) + len(files)
Ejemplo n.º 12
0
 def onTextEdited(self, dummy=None):
     text = self.text()
     if self.checkValid():            
         self.dirChanged.emit(Path(text))