本文整理汇总了Python中Analyzer.Analyzer.exportToImage方法的典型用法代码示例。如果您正苦于以下问题:Python Analyzer.exportToImage方法的具体用法?Python Analyzer.exportToImage怎么用?Python Analyzer.exportToImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Analyzer.Analyzer
的用法示例。
在下文中一共展示了Analyzer.exportToImage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from Analyzer import Analyzer [as 别名]
# 或者: from Analyzer.Analyzer import exportToImage [as 别名]
#.........这里部分代码省略.........
def exportImage(self):
settings = QSettings()
filename = settings.value(MainWindow.__PREF_SAVE__)
if filename is None:
filename = os.path.dirname(__file__)
else:
filename = os.path.abspath(os.path.join(str(filename.toString()), os.path.pardir)) + "/"
filename += "%s_%s.png" % (
self.currentSolution.functionName,
"fun" if self.isFunctionSpaceSelected() else "var",
)
filename = QFileDialog.getSaveFileName(self, "Export image as", filename, ("PNG image (*.png)"))
if filename is None or filename == "":
return
settings.setValue(MainWindow.__PREF_SAVE__, QVariant(filename))
self._exportCurrentImage(filename)
self.statusBar().showMessage("Image saved!", 5000)
def isFunctionSpaceSelected(self):
return self.showSolutionsRadio.isChecked()
def _exportCurrentImage(self, filename=None):
generation = self.generationSlider.value()
self.generationLabel.setText("Run: %d" % generation)
tmp = filename is None
if tmp:
prefix = "mooi_%s_" % self.currentSolution.functionName
filename = tempfile.mkstemp(prefix=prefix, suffix=".png", text=False)[1]
resultNames = self._getSelectedResultNames()
self.analyzer.exportToImage(
self.currentSolution,
[generation - 1] * len(resultNames),
self.isFunctionSpaceSelected(),
resultNames,
str(filename),
)
if tmp:
self.plot.setPlotPixmap(filename)
try:
os.remove(filename)
except:
print >>sys.stderr, "Couldn't delete temporal file: %s" % filename
def _getSelectedResultNames(self):
resultNames = []
for i in xrange(self.analyzer.nResults):
implementationItem = self.solutionSelector.layout().itemAt(i).widget()
if implementationItem.isChecked():
resultNames.append(str(implementationItem.text()))
return resultNames
def exportAllImages(self):
settings = QSettings()
directory = settings.value(MainWindow.__PREF_SAVE_ALL__).toString()
directory = QFileDialog.getExistingDirectory(self, "Select a directory to export to", directory)
if directory is None or not os.path.exists(directory):
return
self.analyzer.exportAllImages(directory, self._getSelectedResultNames())
settings.setValue(MainWindow.__PREF_SAVEL_ALL__, QVariant(directory))
self.statusBar().showMessage("Images saved!", 5000)