def save_plot(self, proxy, plot_id, page=0, name=False, text=False): if not name: name = plot_id if not text: text = cStringIO.StringIO() self.saveToFile(text) text = text.getvalue() ci = document.CommandInterface(self) tmp = os.path.join(params.pathTmp, 'export.jpg') if os.path.exists(tmp): os.remove(tmp) # Touch the file open(tmp, 'w').close() mx = len(self.basewidget.children) - 1 if page > mx: page = mx ci.Export(tmp, page=page) render = open(tmp, 'rb').read() if not len(render): logging.debug('Failed rendering') render = False r = proxy.save_plot(text, plot_id=plot_id, title=name, render=render, render_format='jpg') os.remove(tmp) return r, text
def renderVszTest(invsz, outfile, test_saves=False, test_unlink=False): """Render vsz document to create outfile.""" doc = document.Document() mode = 'hdf5' if os.path.splitext(invsz)[1] == '.vszh5' else 'vsz' doc.load(invsz, mode=mode) if test_unlink: for d in doc.data: doc.data[d].linked = None if test_saves and h5py is not None: tempfilename = 'self-test-temporary.vszh5' doc.save(tempfilename, mode='hdf5') doc = document.Document() doc.load(tempfilename, mode='hdf5') os.unlink(tempfilename) if test_saves: tempfilename = 'self-test-temporary.vsz' doc.save(tempfilename, mode='vsz') doc = document.Document() doc.load(tempfilename, mode='vsz') os.unlink(tempfilename) ifc = document.CommandInterface(doc) ifc.Export(outfile)
def add_versions_to_file(self): command_interface = document.CommandInterface(self.doc) command_interface.AddCustom( u"constant", u"canon_version", canon_version.__version__.replace(".", "-")) command_interface.AddCustom( u"constant", u"client_version", client_version.__version__.replace(".", "-")) command_interface.AddCustom(u"constant", u"vsz_file_format_version", client_version.__vsz_file_format_version__)
def process_image_dropEvent(plot_window, drop_event): pix = drop_event.mimeData().data("image/png") p = plot_window.getPageNumber() page = plot_window.document.basewidget.children[p] graph = searchFirstOccurrence(page, 'graph') cmd = document.CommandInterface(plot_window.document) name = unicode(drop_event.mimeData().data("text/plain")) name = name.replace(':/', ':').replace('/', '_') cmd.To(graph.path) cmd.Add('imagefile', name=name, autoadd=False) cmd.To(name) cmd.Set('filename', '{embedded}') cmd.Set('embeddedImageData', unicode(b64encode(pix)))
def renderTest(invsz, outfile): """Render vsz document to create outfile.""" d = document.Document() ifc = document.CommandInterface(d) # this lot looks a bit of a mess cmds = d.eval_context for cmd in document.CommandInterface.safe_commands: cmds[cmd] = getattr(ifc, cmd) for cmd in document.CommandInterface.unsafe_commands: cmds[cmd] = getattr(ifc, cmd) exec "from numpy import *" in cmds ifc.AddImportPath(os.path.dirname(invsz)) exec open(invsz) in cmds ifc.Export(outfile)
def set_doc(self, doc): self.previous_selection = False self.doc = doc self.cmd = document.CommandInterface(self.doc) self.setWindowTitle(_('Opened Misura Tests')) self.mod = self.doc.model self.mod.ncols = self.ncols self.setModel(self.mod) self.expandAll() self.selection = QtGui.QItemSelectionModel(self.model()) self.set_status() self.doc.signalModified.connect(self.refresh_model) self.doc.sigConfProxyModified.connect(self.update_view) self.mod.sigPageChanged.connect(self.ensure_sync_of_view_and_model) if self.ncols > 1: self.setColumnWidth(0, 400) if hasattr(self.mainwindow.plot, 'set_navigator'): self.mainwindow.plot.set_navigator(self)
def test(self): """Double import a file and subtract the same datasets.""" nativem4 = os.path.join(iut.data_dir, 'test_video.h5') # Simulate an import imp = filedata.OperationMisuraImport( filedata.ImportParamsMisura(filename=nativem4)) misuraDocument = filedata.MisuraDocument() self.cmd = document.CommandInterface(misuraDocument) plugin.makeDefaultDoc(self.cmd) imp.do(misuraDocument) # Import again imp.do(misuraDocument) misuraDocument.model.refresh() tree = misuraDocument.model.tree entry = tree.traverse('0:hsm/sample0') self.assertTrue(entry != False) self.do(misuraDocument, entry)
def set_doc(self, doc=False): self.treeedit.close() self.lay.removeWidget(self.plot) self.plot.hide() self.plot.close() del self.plot # Adding Veusz objects if not doc: doc = filedata.MisuraDocument() self.document = doc self.cmd = document.CommandInterface(self.document) self.ci = document.CommandInterpreter(self.document) self.plot = VeuszPlotWindow(self.document, self) self.lay.addWidget(self.plot) self.enable_shortcuts() # Faking mainwindow self.treeedit = treeeditwindow.TreeEditDock(doc, self) self.treeedit.hide() self.vinit = 0 # Loading Stylesheet if os.path.exists('/opt/misura/misura/client/art/plot.vst'): self.ci.run("Load('/opt/misura/misura/client/art/plot.vst')") plugin.makeDefaultDoc(self.cmd) # Override the zoompage action in order to fit the plot into widget # dimension. zp = self.plot.vzactions['view.zoompage'] self.plot.disconnect(zp, QtCore.SIGNAL('triggered()'), self.plot.slotViewZoomPage) self.plot.connect(zp, QtCore.SIGNAL('triggered()'), self.fitSize) self.delayed = QtCore.QTimer() self.zoompageAct = zp self.plot.sigWidgetClicked.connect(self.treeedit.selectWidget) self.treeedit.widgetsSelected.connect(self.plot.selectedWidgets) self.treeedit.sigPageChanged.connect(self.plot.setPageNumber) self.document.model.sigPageChanged.connect(self.sync_page)
def test(self): # Simulate an import imp = filedata.OperationMisuraImport( filedata.ImportParamsMisura(filename=nativem4)) doc = filedata.MisuraDocument() self.cmd = document.CommandInterface(doc) plugin.makeDefaultDoc(self.cmd) imp.do(doc) fields = { 'd': 'summary/vertical/sample0/d', 'T': 'summary/kiln/T', 'std': 'NIST SRM738', 'start': 50, 'end': 50, 'label': 1, 'add': 1, 'currentwidget': '/' } p = plugin.CalibrationFactorPlugin() p.apply(self.cmd, fields) self.assertIn(fields['d'] + '_NIST_SRM738', doc.data) doc.model.refresh(force=True)