Пример #1
0
    def readDesignerMethod(self, meth, codeBody):
        """ Create a new ObjectCollection by parsing the given method body """
        from Views import ObjCollection
        import methodparse
        # Collection method
        if ObjCollection.isInitCollMeth(meth):
            ctrlName = methodparse.ctrlNameFromMeth(meth)
            try:
                res = Utils.split_seq(codeBody, '', string.strip)
                inits, body, fins = res[:3]
            except ValueError:
                raise Exception, _(
                    'Collection body %s not in init, body, fin form') % meth

            allInitialisers, unmatched = methodparse.parseMixedBody(\
             [methodparse.EventParse, methodparse.CollectionItemInitParse],body)

            creators = allInitialisers.get(methodparse.CollectionItemInitParse,
                                           [])
            collectionInits = []
            properties = []
            events = allInitialisers.get(methodparse.EventParse, [])

            methodparse.decorateParseItems(creators + events, ctrlName,
                                           self.main)
        # Normal method
        else:
            inits = []
            fins = []

            allInitialisers, unmatched = methodparse.parseMixedBody(\
              [methodparse.ConstructorParse, methodparse.EventParse,
               methodparse.CollectionInitParse, methodparse.PropertyParse],
               codeBody)

            creators = allInitialisers.get(methodparse.ConstructorParse, [])
            collectionInits = allInitialisers.get(
                methodparse.CollectionInitParse, [])
            properties = allInitialisers.get(methodparse.PropertyParse, [])
            events = allInitialisers.get(methodparse.EventParse, [])

        newObjColl = ObjCollection.ObjectCollection()
        newObjColl.setup(creators, properties, events, collectionInits, inits,
                         fins)

        if unmatched:
            wx.LogWarning(_('The following lines were not used by the Designer '\
                            'and will be lost:\n'))
            for line in unmatched:
                wx.LogWarning(line)
            wx.LogWarning(_('\nThere were unprocessed lines in the source code of '\
                            'method: %s\nIf this was unexpected, it is advised '\
                            'that you cancel this Designer session and correct '\
                            'the problem before continuing.')%meth)

        return newObjColl
Пример #2
0
    def readDesignerMethod(self, meth, codeBody):
        """ Create a new ObjectCollection by parsing the given method body """
        from Views import ObjCollection
        import methodparse
        # Collection method
        if ObjCollection.isInitCollMeth(meth):
            ctrlName = methodparse.ctrlNameFromMeth(meth)
            try:
                res = Utils.split_seq(codeBody, '', string.strip)
                inits, body, fins = res[:3]
            except ValueError:
                raise Exception, _('Collection body %s not in init, body, fin form') % meth

            allInitialisers, unmatched = methodparse.parseMixedBody(\
             [methodparse.EventParse, methodparse.CollectionItemInitParse],body)

            creators = allInitialisers.get(methodparse.CollectionItemInitParse, [])
            collectionInits = []
            properties = []
            events = allInitialisers.get(methodparse.EventParse, [])

            methodparse.decorateParseItems(creators + events, ctrlName, self.main)
        # Normal method
        else:
            inits = []
            fins = []

            allInitialisers, unmatched = methodparse.parseMixedBody(\
              [methodparse.ConstructorParse, methodparse.EventParse,
               methodparse.CollectionInitParse, methodparse.PropertyParse],
               codeBody)

            creators = allInitialisers.get(methodparse.ConstructorParse, [])
            collectionInits = allInitialisers.get(methodparse.CollectionInitParse, [])
            properties = allInitialisers.get(methodparse.PropertyParse, [])
            events = allInitialisers.get(methodparse.EventParse, [])

        newObjColl = ObjCollection.ObjectCollection()
        newObjColl.setup(creators, properties, events, collectionInits, inits, fins)

        if unmatched:
            wx.LogWarning(_('The following lines were not used by the Designer '\
                            'and will be lost:\n'))
            for line in unmatched:
                wx.LogWarning(line)
            wx.LogWarning(_('\nThere were unprocessed lines in the source code of '\
                            'method: %s\nIf this was unexpected, it is advised '\
                            'that you cancel this Designer session and correct '\
                            'the problem before continuing.')%meth)

        return newObjColl
Пример #3
0
    def pasteCtrls(self, destCtrlName, input):
        # Split up into methods
        methList = []
        for line in input:
            splitLine = line.split()
            if len(splitLine) >= 2 and splitLine[0] == 'def':
                meth = splitLine[1][:splitLine[1].find('(')]
                currMeth = [meth]
                methList.append(currMeth)
            else:
                try:
                    currMeth.append(line)
                except NameError:
                    print 'PASTE ERROR', input
        if not methList:
            raise Exception, _('Nothing to paste')

        collObjColls = []
        pastedCtrls = []
        collMethod = ''
        # find main method
        idx = -1
        for meth in methList[:]:
            idx = idx + 1
            if meth[0] == self.collectionMethod:
                collMethod = meth[0]
                methBody = meth[1:]
            else:
                # XXX not good :(
                ctrlName = methodparse.ctrlNameFromMeth(meth[0])
                newObjColl = self.model.readDesignerMethod(meth[0], meth[1:])
                methodparse.decorateParseItems(
                      newObjColl.creators + newObjColl.events,
                      ctrlName, self.model.main)

                for plp in newObjColl.creators + newObjColl.events + \
                      newObjColl.properties + newObjColl.collections:
                    plp.prependFrameWinId(self.model.main)

                collObjColls.append( (meth[0], ctrlName, newObjColl) )

        if not collMethod:
            raise DesignerError, _('Method %s not found') % self.collectionMethod

        # Parse input source
        objCol = self.model.readDesignerMethod(collMethod, methBody)

        if not len(objCol.creators):
            return []

        # Fixup window ids
        for plp in objCol.creators + objCol.events + objCol.properties + \
              objCol.collections:
            plp.prependFrameWinId(self.model.main)

        # Rename possible name clashes
        objCol.indexOnCtrlName()
        pasteNameClasses = objCol.getCtrlNames()
        
        for name, cls in pasteNameClasses:
            if objCol.eventsByName.has_key(name):
                methodparse.decorateParseItems(objCol.eventsByName[name], name, 
                      self.model.main)
        
        newNames = []
        oldNames = []
        # Preserve order, but determine all new names before creating objs
        for name, clss in pasteNameClasses:
            if name in self.objectOrder:
                newName = self.newObjName(clss, newNames)
                newNames.append(newName)
                oldNames.append(name)
            else:
                newNames.append(name)
                oldNames.append(name)

        for oldName, newName in map(None, oldNames, newNames):
            if newName != oldName:
                objCol.renameCtrl(oldName, newName)
                pastedCtrls.append(newName)
                for idx in range(len(collObjColls)):
                    meth, collCtrlName, collObjColl = collObjColls[idx]
                    collObjColl.renameCtrl(oldName, newName)
                    if collCtrlName == oldName:
                        itms = meth.split('_')
                        itms[3:-1] = [newName]
                        collObjColls[idx] = ('_'.join(itms), newName, collObjColl)
            else:
                pastedCtrls.append(oldName)

        # Update model's object collections' collections
        for meth, collCtrlName, collObjColl in collObjColls:
            self.model.objectCollections[meth] = collObjColl

        # Get previous parent, 1st item in the group's parent will always be
        # the root parent
        # Only reparent visual controls
        if objCol.creators[0].params.has_key('parent'):
            copySource = objCol.creators[0].params['parent']
            objCol.reparent(copySource, Utils.srcRefFromCtrlName(destCtrlName))

        # create controls
        deps = {}
        depLnks = {}
        self.inspector.vetoSelect = True
        try:
            self.initObjectsAndCompanions(objCol.creators, objCol, deps, depLnks)
        finally:
            self.inspector.vetoSelect = False

        # merge pasted controls with current controls
        self.model.objectCollections[collMethod].merge(objCol)

        return pastedCtrls