當前位置: 首頁>>代碼示例>>Python>>正文


Python Log.subLayer方法代碼示例

本文整理匯總了Python中log.Log.Log.subLayer方法的典型用法代碼示例。如果您正苦於以下問題:Python Log.subLayer方法的具體用法?Python Log.subLayer怎麽用?Python Log.subLayer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在log.Log.Log的用法示例。


在下文中一共展示了Log.subLayer方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: createBufferForSvgFile

# 需要導入模塊: from log.Log import Log [as 別名]
# 或者: from log.Log.Log import subLayer [as 別名]

#.........這裏部分代碼省略.........

        # show all layers
        for layer in layers:
            SvgManipulations.removeStyleAttribute(layer, "display:none")
            SvgManipulations.removeStyleAttribute(layer, "display:inline")
            
#         tree.write(svgPath+"-debug.svg", encoding="UTF-8", xml_declaration=True)

        # create slides
        self.log.write("Creating slides...")
        for layerIndex, layer in enumerate(layers):
            # only loop over slides
            if SvgManipulations.isBackground(layer):
                continue
            
#             print "."

            # xmlNamespacesnew svg tree, because we will delete stuff!
            newSvgTree = etree.ElementTree(root.copy())
            newSvgRoot = newSvgTree.getroot()
            newLayers = SvgManipulations.extractAllLayers(newSvgRoot)
            
            # scan for references
            defsCollector = SvgManipulations.DefsCollector(newSvgRoot)
            for newLayerIndex, newLayer in enumerate(newLayers):
                if (newLayerIndex==layerIndex) or SvgManipulations.isBackground(newLayer):
                    defsCollector.addRecursively(newLayer)

            # delete unused RasterImagedefs
            newDefsList = root.findall("svg:defs", NSS)
            for defsElement in newDefsList:
                newSvgRoot.remove(defsElement)
                                    
            # delete unused layers
            for newLayerIndex, newLayer in enumerate(newLayers):
                if (newLayerIndex!=layerIndex) and not SvgManipulations.isBackground(newLayer):
                    newSvgRoot.remove(newLayer)
            
            # add my defs
            newSvgRoot.insert(0, defsCollector.defs)

#             # convert tree into plain svg
#             hash, dummy = self.plainSvgFiles.hashAndOutput(svgTree.tostring(svgTree.getroot(), encoding="utf8"))
            
            # new slide into presentation structure
            slide = SvgSlide.createFromSvgRootElement(self.log.subLayer(), self.slideBuffer, self.pagecolor, newSvgRoot)
            self.slides.append(slide)
        self.log.write("Done.")
        return True
    
    def loadFromXmlFile(self, path):
        self.reset()
        print "Loading buffered presentation data..."
        presentationTree = etree.parse(path)
        presentation = presentationTree.getroot()
        self.width = float(presentation.get("width"))
        self.height = float(presentation.get("height"))
        self.pagecolor = presentation.get("pagecolor", "#ffffff")
        for e in presentation:
            slide = SvgSlide.createFromPresentationXmlElement(self.slideBuffer, self.pagecolor, e)
            self.slides.append(slide)
        print "Done."
        
    def saveToXmlFile(self, path):
        # create xml digest
        presentation = etree.Element("presentation")
        presentation.set("width", str(self.width))
        presentation.set("height", str(self.height))
        presentation.set("pagecolor", self.pagecolor)
        for slide in self.slides:
            presentation.append(slide.createPresentationXmlElement())
        presentationTree = etree.ElementTree(presentation)
        presentationTree.write(path, encoding="UTF-8", xml_declaration=True)

    def slide(self, index):
        return self.slides[index]
    
    def numberOfSlides(self):
        return len(self.slides)

    def moviePath(self):
        return self.baseFolderPath
    
    def exportAsPdf(self, pdfPath=None):
        if pdfPath is None:
            basePath, extension = os.path.splitext(self.svgPath)
            pdfPath = basePath + ".pdf"
            
        self.log.write("Exporting presentation as %s..."%pdfPath)
        subLog = self.log.subLayer()
        
        slidePdfPaths = []
        for slide in self.slides:
            slidePdfPaths.append(slide.providePdfFile(subLog))
            
        subLog.write("Concatenating...")
        subprocess.check_output(["pdftk"] + slidePdfPaths + ["cat", "output", pdfPath])
        
        self.log.write("Done.")        
        return pdfPath
開發者ID:mmpi,項目名稱:SvgPresenter,代碼行數:104,代碼來源:SvgPresentation.py


注:本文中的log.Log.Log.subLayer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。