def openFile(self, filenameOrBuffer): start = time.time() tree = etree.parse(filenameOrBuffer) try: if self.profileLoading: import cProfile p = cProfile.Profile() p.enable() self.document = document.SVGDocument(tree.getroot()) if self.profileLoading: import pstats p.disable() results = pstats.Stats(p) self.profileResults.SetResults(results) else: self.profileResults.SetResults(None) self.render.document = self.document except: #pdb.set_trace() import traceback self.render.document = None traceback.print_exc() amount = time.time() - start self.tree.updateTree(tree) self.SetStatusText("Loaded in %2f seconds" % amount, self.LOAD_TIME) self.SetStatusText(filenameOrBuffer) self.currentFile = filenameOrBuffer self.Refresh()
def _current_file_changed(self, new): # Reset the warnings filters. While it's good to only get 1 warning per # file, we want to get the same warning again if a new file issues it. warnings.resetwarnings() self.profile_this.start('Parsing') self.current_xml = ET.parse(self.abs_current_file).getroot() self.current_xml_view = xml_to_tree(self.current_xml) resources = document.ResourceGetter.fromfilename(self.abs_current_file) self.profile_this.stop() try: self.profile_this.start('Creating WX document') self.document = document.SVGDocument(self.current_xml, resources=resources, renderer=WxRenderer) except: logger.exception('Error parsing document %s', new) self.document = None self.profile_this.stop() try: self.profile_this.start('Creating Kiva document') self.kiva_component.document = document.SVGDocument( self.current_xml, resources=resources, renderer=KivaRenderer) except Exception as e: logger.exception('Error parsing document %s', new) self.kiva_component.document self.profile_this.stop() png_file = self.svg_png.get(new, None) if png_file is None: png_file = self.default_png else: png_file = self.locate_file(png_file, 'png') self.display_test_description() self.display_reference_png(png_file)
def setUp(self): self.document = document.SVGDocument(minimalSVG.getroot(), renderer=KivaRenderer()) self.stateStack = [{}]