⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 project.py

📁 wxPython的基本示例程序
💻 PY
📖 第 1 页 / 共 2 页
字号:
#----------------------------------------------------------------------------# Name:         project.py# Purpose:      project model for wx.lib.pydocview## Author:       Morgan Hua## Created:      8/25/05# CVS-ID:       $Id: project.py,v 1.4 2006/04/20 06:25:57 RD Exp $# Copyright:    (c) 2005 ActiveGrid, Inc.# License:      wxWindows License#----------------------------------------------------------------------------import copyimport osimport os.pathimport activegrid.util.xmlutils as xmlutilsimport activegrid.util.aglogging as aglogging# REVIEW 07-Mar-06 stoens@activegrid.com -- Ideally move the pieces required# to generate the .dpl file out of this module so there's no dependency on wx,# instead of doing this try/catch (IDE drags in wx).try:    from IDE import ACTIVEGRID_BASE_IDEexcept:    ACTIVEGRID_BASE_IDE = False    if not ACTIVEGRID_BASE_IDE:    import activegrid.model.basedocmgr as basedocmgr    import AppInfo#----------------------------------------------------------------------------# Constants#----------------------------------------------------------------------------# Always add new versions, never edit the version number# This allows you to upgrade the file by checking the version numberPROJECT_VERSION_050730 = '10'PROJECT_VERSION_050826 = '11'#----------------------------------------------------------------------------# Classes#----------------------------------------------------------------------------class BaseProject(object):    __xmlname__ = "project"    __xmlexclude__ = ('fileName', '_projectDir', '_getDocCallback', '_cacheEnabled')    __xmlattributes__ = ("_homeDir", "version")    __xmlrename__ = { "_homeDir":"homeDir", "_appInfo":"appInfo" }    __xmlflattensequence__ = { "_files":("file",) }    __xmldefaultnamespace__ = xmlutils.AG_NS_URL    __xmlattrnamespaces__ = { "ag": ["version", "_homeDir"] }    def __init__(self):        self.__xmlnamespaces__ = { "ag" : xmlutils.AG_NS_URL }        self.version = PROJECT_VERSION_050826        self._files = []        self._projectDir = None  # default for homeDir, set on load        self._homeDir = None         # user set homeDir for use in calculating relative path        self._cacheEnabled = 0        if not ACTIVEGRID_BASE_IDE:            self._appInfo = AppInfo.AppInfo()    def initialize(self):        for file in self._files:            file._parentProj = self    def __copy__(self):        clone = Project()        clone._files = [copy.copy(file) for file in self._files]        clone._projectDir = self._projectDir        clone._homeDir = self._homeDir        if not ACTIVEGRID_BASE_IDE:            clone._appInfo = copy.copy(self._appInfo)        return clone    def GetAppInfo(self):        return self._appInfo    def AddFile(self, filePath=None, logicalFolder=None, type=None, name=None, file=None):        """ Usage: self.AddFile(filePath, logicalFolder, type, name)  # used for initial generation of object                   self.AddFile(file=xyzFile)  # normally used for redo/undo            Add newly created file object using filePath and logicalFolder or given file object        """        if file:            self._files.append(file)        else:            self._files.append(ProjectFile(self, filePath, logicalFolder, type, name, getDocCallback=self._getDocCallback))    def RemoveFile(self, file):        self._files.remove(file)    def FindFile(self, filePath):        if filePath:            for file in self._files:                if file.filePath == filePath:                    return file        return None    def _GetFilePaths(self):        return [file.filePath for file in self._files]    filePaths = property(_GetFilePaths)    def _GetProjectFiles(self):        return self._files    projectFiles = property(_GetProjectFiles)    def _GetLogicalFolders(self):        folders = []        for file in self._files:            if file.logicalFolder and file.logicalFolder not in folders:                folders.append(file.logicalFolder)        return folders    logicalFolders = property(_GetLogicalFolders)    def _GetPhysicalFolders(self):        physicalFolders = []        for file in self._files:            physicalFolder = file.physicalFolder            if physicalFolder and physicalFolder not in physicalFolders:                physicalFolders.append(physicalFolder)        return physicalFolders    physicalFolders = property(_GetPhysicalFolders)    def _GetHomeDir(self):        if self._homeDir:            return self._homeDir        else:            return self._projectDir    def _SetHomeDir(self, parentPath):        self._homeDir = parentPath    def _IsDefaultHomeDir(self):        return (self._homeDir == None)    isDefaultHomeDir = property(_IsDefaultHomeDir)    homeDir = property(_GetHomeDir, _SetHomeDir)    def GetRelativeFolders(self):        relativeFolders = []        for file in self._files:            relFolder = file.GetRelativeFolder(self.homeDir)            if relFolder and relFolder not in relativeFolders:                relativeFolders.append(relFolder)        return relativeFolders    def AbsToRelativePath(self):        for file in self._files:            file.AbsToRelativePath(self.homeDir)    def RelativeToAbsPath(self):        for file in self._files:            file.RelativeToAbsPath(self.homeDir)    def _SetCache(self, enable):        """            Only turn this on if your operation assumes files on disk won't change.            Once your operation is done, turn this back off.            Nested enables are allowed, only the last disable will disable the cache.                        This bypasses the IsDocumentModificationDateCorrect call because the modification date check is too costly, it hits the disk and takes too long.        """        if enable:            if self._cacheEnabled == 0:                # clear old cache, don't want to accidentally return stale value                for file in self._files:                    file.ClearCache()                    self._cacheEnabled += 1        else:            self._cacheEnabled -= 1                def _GetCache(self):        return (self._cacheEnabled > 0)    cacheEnabled = property(_GetCache, _SetCache)    #----------------------------------------------------------------------------    # BaseDocumentMgr methods    #----------------------------------------------------------------------------    def fullPath(self, fileName):        fileName = super(BaseProject, self).fullPath(fileName)        if os.path.isabs(fileName):            absPath = fileName        elif self.homeDir:            absPath = os.path.join(self.homeDir, fileName)        else:            absPath = os.path.abspath(fileName)        return os.path.normpath(absPath)    def documentRefFactory(self, name, fileType, filePath):        return ProjectFile(self, filePath=self.fullPath(filePath), type=fileType, name=name, getDocCallback=self._getDocCallback)    def findAllRefs(self):        return self._files    def GetXFormsDirectory(self):        forms = self.findRefsByFileType(basedocmgr.FILE_TYPE_XFORM)        filePaths = map(lambda form: form.filePath, forms)        xformdir = os.path.commonprefix(filePaths)        if not xformdir:            xformdir = self.homeDir        return xformdir    def setRefs(self, files):        self._files = files    def findRefsByFileType(self, fileType):        fileList = []        for file in self._files:            if fileType == file.type:                fileList.append(file)        return fileList    def GenerateServiceRefPath(self, wsdlFilePath):        # HACK: temporary solution to getting wsdlag path from wsdl path.        import wx        from WsdlAgEditor import WsdlAgDocument        ext = WsdlAgDocument.WSDL_AG_EXT        for template in wx.GetApp().GetDocumentManager().GetTemplates():            if template.GetDocumentType() == WsdlAgDocument:                ext = template.GetDefaultExtension()                break;        wsdlAgFilePath = os.path.splitext(wsdlFilePath)[0] + ext        return wsdlAgFilePath    def SetDocCallback(self, getDocCallback):        self._getDocCallback = getDocCallback        for file in self._files:            file._getDocCallback = getDocCallbackif ACTIVEGRID_BASE_IDE:    class Project(BaseProject):        passelse:    class Project(BaseProject, basedocmgr.BaseDocumentMgr):        passclass ProjectFile(object):    __xmlname__ = "file"    __xmlexclude__ = ('_parentProj', '_getDocCallback', '_docCallbackCacheReturnValue', '_docModelCallbackCacheReturnValue', '_doc',)    __xmlattributes__ = ["filePath", "logicalFolder", "type", "name"]    __xmldefaultnamespace__ = xmlutils.AG_NS_URL    def __init__(self, parent=None, filePath=None, logicalFolder=None, type=None, name=None, getDocCallback=None):        self._parentProj = parent        self.filePath = filePath        self.logicalFolder = logicalFolder        self.type = type        self.name = name        self._getDocCallback = getDocCallback        self._docCallbackCacheReturnValue = None        self._docModelCallbackCacheReturnValue = None        self._doc = None    def _GetDocumentModel(self):        if (self._docCallbackCacheReturnValue        and (self._parentProj.cacheEnabled or self._docCallbackCacheReturnValue.IsDocumentModificationDateCorrect())):            return self._docModelCallbackCacheReturnValue        if self._getDocCallback:            self._docCallbackCacheReturnValue, self._docModelCallbackCacheReturnValue = self._getDocCallback(self.filePath)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -