def onExportScenario(self): class ChooseVersionDialog(QtGui.QDialog): """Dialog for choosing the version of GOTM to export namelists for. """ def __init__(self,parent=None): QtGui.QDialog.__init__(self,parent,QtCore.Qt.Dialog | QtCore.Qt.MSWindowsFixedSizeDialogHint | QtCore.Qt.WindowTitleHint) layout = QtGui.QVBoxLayout() # Add introductory label. self.label = QtGui.QLabel('Choose the version of GOTM to export for:',self) layout.addWidget(self.label) # Add combobox with versions. self.comboVersion = QtGui.QComboBox(self) versions = scen.getSchemaInfo().getSchemas().keys() versions.sort() for v in versions: # Only show schemas for namelist-supporting GOTM # (and not those for the GUI) if v.startswith('gotm-'): self.comboVersion.addItem(v) self.comboVersion.setCurrentIndex(self.comboVersion.count()-1) layout.addWidget(self.comboVersion) layoutButtons = QtGui.QHBoxLayout() # Add "OK" button self.bnOk = QtGui.QPushButton('&OK',self) self.bnOk.clicked.connect(self.accept) layoutButtons.addWidget(self.bnOk) # Add "Cancel" button self.bnCancel = QtGui.QPushButton('&Cancel',self) self.bnCancel.clicked.connect(self.reject) layoutButtons.addWidget(self.bnCancel) layout.addLayout(layoutButtons) self.setLayout(layout) self.setWindowTitle('Export scenario to namelists') scen = self.getProperty('scenario') dialog = ChooseVersionDialog(self) res = dialog.exec_() if res==QtGui.QDialog.Accepted: curpath = None if scen.path is not None: curpath = os.path.dirname(scen.path) path = commonqt.browseForPath(self,curpath=curpath,getdirectory=True) if path is not None: progdialog = commonqt.ProgressDialog(self,title='Exporting...',suppressstatus=True) try: progslicer = xmlstore.util.ProgressSlicer(progdialog.onProgressed,2) progslicer.nextStep('converting to desired version') exportscen = scen.convert(unicode(dialog.comboVersion.currentText()),callback=progslicer.getStepCallback()) progslicer.nextStep('writing files') exportscen.writeAsNamelists(path,addcomments=True,callback=progslicer.getStepCallback()) exportscen.release() finally: progdialog.close()
def onSaveResultAs(self): res = self.getProperty('result') path = commonqt.browseForPath(self,curpath=res.path,save=True,filter='GOTM result files (*.gotmresult);;All files (*.*)') if path is not None: dialog = commonqt.ProgressDialog(self,title='Saving...',suppressstatus=True) try: res.save(path,callback=dialog.onProgressed) finally: dialog.close() self.getSettings().addUniqueValue('Paths/RecentResults','Path',path)
def onSaveScenarioAs(self): scen = self.getProperty('scenario') path = commonqt.browseForPath(self,curpath=scen.path,save=True,filter='GOTM scenario files (*.gotmscenario);;All files (*.*)') if path is not None: dialog = commonqt.ProgressDialog(self,title='Saving...',suppressstatus=True) try: scen.saveAll(path,callback=dialog.onProgressed) finally: dialog.close() self.getSettings().addUniqueValue('Paths/RecentScenarios','Path',path)
def onExportResult(self): res = self.getProperty('result') curpath = None if res.path is not None: root,ext = os.path.splitext(res.path) curpath = root+'.nc' path = commonqt.browseForPath(self,curpath=curpath,save=True,filter='NetCDF files (*.nc);;All files (*.*)') if path is not None: QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) try: res.saveNetCDF(path) finally: QtGui.QApplication.restoreOverrideCursor()