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

📄 uicommon.py

📁 Wxpython Implemented on Windows CE, Source code
💻 PY
📖 第 1 页 / 共 2 页
字号:
                    paths.remove(path)
            if paths:
                projectDocument.GetCommandProcessor().Submit(ProjectEditor.ProjectAddFilesCommand(projectDocument, paths, folderPath=folderPath, types=types, names=names))
                if save:
                    projectDocument.OnSaveDocument(projectDocument.GetFilename())

def AddFilesToProject(projectDocument, paths, types=None, names=None, save=False):
    if projectDocument:
        files = projectDocument.GetFiles()
        for path in paths:
            if path in files:
                paths.remove(path)
        if paths:
            projectDocument.GetCommandProcessor().Submit(ProjectEditor.ProjectAddFilesCommand(projectDocument, paths, types=types, names=names))
            if save:
                projectDocument.OnSaveDocument(projectDocument.GetFilename())


def MakeNameEndInExtension(name, extension):
    if not name:
        return name
    root, ext = os.path.splitext(name)
    if ext == extension:
        return name
    else:
        return name + extension
 

def GetPythonExecPath():
    pythonExecPath = wx.ConfigBase_Get().Read("ActiveGridPythonLocation")
    if not pythonExecPath:
        pythonExecPath = sysutils.pythonExecPath
    return pythonExecPath
    

def GetPHPExecPath():
    PHPExecPath = wx.ConfigBase_Get().Read("ActiveGridPHPLocation")
    return PHPExecPath


def GetPHPINIPath():
    PHPINIPath = wx.ConfigBase_Get().Read("ActiveGridPHPINILocation")
    return PHPINIPath


def _DoRemoveRecursive(path, skipFile=None, skipped=False):
    if path == skipFile:
        skipped = True
    elif os.path.isdir(path):
        for file in os.listdir(path):
            file_or_dir = os.path.join(path,file)
            if skipFile == file_or_dir:
                skipped = True
            elif os.path.isdir(file_or_dir) and not os.path.islink(file_or_dir):
                if _DoRemoveRecursive(file_or_dir, skipFile): # it's a directory recursive call to function again
                    skipped = True
            else:
                os.remove(file_or_dir) # it's a file, delete it
        if not skipped:
            os.rmdir(path) # delete the directory here
    else:
        os.remove(path)
        
    return skipped


def RemoveRecursive(path, skipFile=None):
    _DoRemoveRecursive(path, skipFile)    


def CaseInsensitiveCompare(s1, s2):
    """ Method used by sort() to sort values in case insensitive order """
    return strutils.caseInsensitiveCompare(s1, s2)


def GetAnnotation(model, elementName):
    """ Get an object's annotation used for tooltips """
    if hasattr(model, "_complexType"):
        ct = model._complexType
    elif hasattr(model, "__xsdcomplextype__"):
        ct = model.__xsdcomplextype__
    else:
        ct = None
            
    if ct:
        el = ct.findElement(elementName)
        if el and el.annotation:
            return el.annotation
            
    return ""


def GetDisplayName(doc, name):
    if name:
        appDocMgr = doc.GetAppDocMgr()
        if appDocMgr:
            name = appDocMgr.toDisplayTypeName(name)
        else:
            namespace, name = xmlutils.splitType(name)
            if namespace and hasattr(doc.GetModel(), "getXmlNamespaces"):
                for xmlkey, xmlval in doc.GetModel().getXmlNamespaces().iteritems():
                    if xmlval == namespace:
                        name = "%s:%s" % (xmlkey, name)
                        break                    
    
        if name:
            import activegrid.model.schema as schemalib
            baseTypeName = schemalib.mapXsdType(name)
            if baseTypeName:
                name = baseTypeName

    return name


def GetInternalName(doc, name):
    if name:
        appDocMgr = doc.GetAppDocMgr()
        if appDocMgr:
            name = appDocMgr.toInternalTypeName(name)
        else:
            namespace, name = xmlutils.splitType(name)
            if namespace and hasattr(doc.GetModel(), "getXmlNamespaces"):
                for xmlkey, xmlval in doc.GetModel().getXmlNamespaces().iteritems():
                    if xmlkey == namespace:
                        name = "%s:%s" % (xmlval, name)
                        break  
                                          
        import activegrid.model.schema as schemalib
        name = schemalib.mapAGType(name)

    return name


#----------------------------------------------------------------------------
# Methods for finding application level info
#----------------------------------------------------------------------------

def GetProjectForDoc(doc):
    """ Given a document find which project it belongs to.
        Tries to intelligently resolve conflicts if it is in more than one open project.
    """
    projectService = wx.GetApp().GetService(ProjectEditor.ProjectService)

    projectDoc = projectService.FindProjectFromMapping(doc)
    if projectDoc:
        return projectDoc

    projectDoc = projectService.GetCurrentProject()
    if not projectDoc:
        return None
    if projectDoc.IsFileInProject(doc.GetFilename()):
        return projectDoc

    projects = []
    openDocs = wx.GetApp().GetDocumentManager().GetDocuments()
    for openDoc in openDocs:
        if openDoc == projectDoc:
            continue
        if(isinstance(openDoc, ProjectEditor.ProjectDocument)):
            if openDoc.IsFileInProject(doc.GetFilename()):
                projects.append(openDoc)
                
    if projects:
        if len(projects) == 1:
            return projects[0]
        else:
            choices = [os.path.basename(project.GetFilename()) for project in projects]
            dlg = wx.SingleChoiceDialog(wx.GetApp().GetTopWindow(), _("'%s' found in more than one project.\nWhich project should be used for this operation?") % os.path.basename(doc.GetFilename()), _("Select Project"), choices, wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER|wx.OK|wx.CENTRE)
            dlg.CenterOnParent()
            projectDoc = None
            if dlg.ShowModal() == wx.ID_OK:
                i = dlg.GetSelection()
                projectDoc = projects[i]
            dlg.Destroy()
            return projectDoc

    return None


def GetAppInfoForDoc(doc):
    """ Get the AppInfo for a given document """
    projectDoc = GetProjectForDoc(doc)
    if projectDoc:
        return projectDoc.GetAppInfo()
    return None


def GetAppDocMgrForDoc(doc):
    """ Get the AppDocMgr for a given document """
    projectDoc = GetProjectForDoc(doc)
    if projectDoc:
        return projectDoc.GetModel()
    return None


def GetAppInfoLanguage(doc=None):
    from activegrid.server.projectmodel import LANGUAGE_DEFAULT
    
    if doc:
        language = doc.GetAppInfo().language
    else:
        language = None
        
    if not language:
        config = wx.ConfigBase_Get()
        language = config.Read(ProjectEditor.APP_LAST_LANGUAGE, LANGUAGE_DEFAULT)
        
        if doc:
            doc.GetAppInfo().language = language  # once it is selected, it must be set.
        
    return language

def AddWsdlAgToProjectFromWsdlRegistration(wsdlRegistration):
    """Add wsdl ag for registry entry."""

    wsdlPath = wsdlRegistration.path
    rootPath = None
    serviceRefName = wsdlRegistration.name
    
    agwsDoc = _InitWsdlAg(wsdlPath, rootPath, serviceRefName)

    if (agwsDoc == None):
        return

    serviceRef = agwsDoc.GetModel()    
    
    serviceRef.serviceType = wsdlRegistration.type

    import activegrid.server.deployment as deployment

    if (serviceRef.serviceType == deployment.SERVICE_LOCAL):
        serviceRef.localService = deployment.LocalService(
            wsdlRegistration.codeFile)
        
    elif (serviceRef.serviceType == deployment.SERVICE_DATABASE):
        serviceRef.databaseService = deployment.DatabaseService(
            wsdlRegistration.datasourceName)
        
    elif (serviceRef.serviceType == deployment.SERVICE_SOAP):
        pass
    
    elif (serviceRef.serviceType == deployment.SERVICE_RSS):
        serviceRef.rssService = deployment.RssService(wsdlRegistration.feedUrl)
        
    elif (serviceRef.serviceType == deployment.SERVICE_REST):
        serviceRef.restService = deployment.RestService(
            wsdlRegistration.baseUrl)
    else:
        raise AssertionError("Unknown service type")

    _AddToProject(agwsDoc, addWsdl=True)
    

def AddWsdlAgToProject(wsdlPath, rootPath=fileutils.AG_SYSTEM_STATIC_VAR_REF,
                       serviceRefName=None, className=None, serviceType=None,
                       dataSourceName=None):
    """
       wsdlPath: path to wsdl from rootPath. If wsdlPath is absolute, rootPath
       is ignored. rootPath is also ignored when rootPath is set to None. 
       rootPath: defaults to ${AG_SYSTEM_STATIC}.
       serviceRefName: If None, it will be set to the wsdl file name without
       the .wsdl file extension.
       className: if not None, will be used for the the wsdlag's ClassName.
       serviceType: defaults to local.
       dataSourceName: if serviceType is deployment.DATABASE, the ds must be
       provided.
    """
    import WsdlAgEditor
    import XFormWizard
    import activegrid.model.basedocmgr as basedocmgr
    import activegrid.server.deployment as deployment

    if (serviceType == None):
        serviceType = deployment.SERVICE_LOCAL


    agwsDoc = _InitWsdlAg(wsdlPath, rootPath, serviceRefName)

    if (agwsDoc == None):
        return

    serviceRef = agwsDoc.GetModel()    
    
    serviceRef.serviceType = serviceType

    if (serviceType == deployment.SERVICE_DATABASE and dataSourceName != None):
        serviceRef.databaseService = deployment.DatabaseService(dataSourceName)
    else:
        serviceRef.localService = deployment.LocalService(className=className)

    _AddToProject(agwsDoc)
        

def _AddToProject(agwsDoc, addWsdl=False):
    import activegrid.model.basedocmgr as basedocmgr    
    projectDoc = GetCurrentProject()
    agwsDoc.OnSaveDocument(agwsDoc.GetFilename())

    files = [agwsDoc.fileName]
    types = [basedocmgr.FILE_TYPE_SERVICE]
    names = [agwsDoc.GetModel().name]
    if (addWsdl):
        m = agwsDoc.GetModel()        
        wsdlName = os.path.splitext(os.path.basename(m.filePath))[0]
        appDocMgr = projectDoc.GetAppDocMgr()
        if (appDocMgr.findService(wsdlName) == None):
            m = agwsDoc.GetModel()            
            files.append(m.filePath)
            types.append(None)
            names.append(wsdlName)
    
    ProjectEditor.ProjectAddFilesCommand(projectDoc, files, types=types,
                                         names=names).Do()
    

def _InitWsdlAg(wsdlPath, rootPath=fileutils.AG_SYSTEM_STATIC_VAR_REF,
                serviceRefName=None):

    projectDoc = GetCurrentProject()
    appDocMgr = projectDoc.GetAppDocMgr()

    if (serviceRefName == None):
        serviceRefName = os.path.splitext(os.path.basename(wsdlPath))[0]
    
    if (appDocMgr.findServiceRef(serviceRefName) != None):
        return None

    import WsdlAgEditor
    import XFormWizard
    import activegrid.server.deployment as deployment

    template = XFormWizard.GetTemplate(WsdlAgEditor.WsdlAgDocument)
    ext = template.GetDefaultExtension()
    fullPath = os.path.join(appDocMgr.homeDir, serviceRefName + ext)

    agwsDoc = template.CreateDocument(
        fullPath, flags=(wx.lib.docview.DOC_NO_VIEW|wx.lib.docview.DOC_NEW|
                         wx.lib.docview.DOC_OPEN_ONCE))
    
    serviceRef = agwsDoc.GetModel()
    serviceRef.name = serviceRefName

    if (rootPath == None or os.path.isabs(wsdlPath)):
        serviceRef.filePath = wsdlPath
    else:
        # make sure to use forward slashes for the path to the .wsdl
        wsdlPath = wsdlPath.replace("\\", "/")
        
        if not wsdlPath.startswith("/"):
            wsdlPath = "/%s" % wsdlPath
        serviceRef.filePath = "%s%s" % (rootPath, wsdlPath)

    agwsDoc.fileName = fullPath        

    return agwsDoc


def GetSchemaName(schema):
    return os.path.basename(schema.fileName)


class AGChoice(wx.Choice):
    """Extension to wx.Choice that fixes linux bug where first item of choices
    passed into ctor would be visible, but not selected."""
    def __init__(self, parent, id, choices=[]):
        super(AGChoice, self).__init__(parent=parent, id=id)
        self.AppendItems(choices)

⌨️ 快捷键说明

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