def on_arbBtn_clicked(self): dlg = QDialog(self) loadUi(dlg, 'change.ui') with SettingGroup('main') as settings: dlg.xEdit.setText(settings.value('changex', 'x')) dlg.yEdit.setText(settings.value('changey', 'y')) dlg.dyEdit.setText(settings.value('changedy', 'dy')) if dlg.exec_() != QDialog.Accepted: return settings.setValue('changex', dlg.xEdit.text()) settings.setValue('changey', dlg.yEdit.text()) settings.setValue('changedy', dlg.dyEdit.text()) xfml = dlg.xEdit.text() yfml = dlg.yEdit.text() dyfml = dlg.dyEdit.text() new_x = [] new_y = [] new_dy = [] ns = {} for dpoint in zip(self.data.x, self.data.y_raw, self.data.dy_raw): ns.update(x=dpoint[0], y=dpoint[1], dy=dpoint[2]) new_x.append(eval(xfml, ns)) new_y.append(eval(yfml, ns)) new_dy.append(eval(dyfml, ns)) self.data.x[:] = new_x self.data.y_raw[:] = new_y self.data.dy_raw[:] = new_dy self.data.y = self.data.y_raw / self.data.norm self.data.dy = self.data.dy_raw / self.data.norm self.replotRequest.emit(None) session.set_dirty()
def on_subtractBtn_clicked(self): from ufit.gui.scanitem import ScanDataItem dlg = QDialog(self) loadUi(dlg, 'subtract.ui') data2obj = dlg.setList.populate(ScanDataItem) if dlg.exec_() != QDialog.Accepted: return witems = dlg.setList.selectedItems() if not witems: return try: prec = float(dlg.precisionEdit.text()) except ValueError: QMessageBox.warning(self, 'Error', 'Please enter a valid precision.') return new_data = self.data.subtract(data2obj[witems[0].type()].data, prec, dlg.destructBox.isChecked()) if not dlg.destructBox.isChecked(): new_model = self.model.copy() from ufit.gui.scanitem import ScanDataItem session.add_item(ScanDataItem(new_data, new_model), self.item.group) else: self.replotRequest.emit(None) session.set_dirty()
def print_(self): sio = BytesIO() self.print_figure(sio, format='svg') svg = QSvgRenderer(QByteArray(sio.getvalue())) sz = svg.defaultSize() aspect = sz.width() / float(sz.height()) printer = QPrinter(QPrinter.HighResolution) printer.setOrientation(QPrinter.Landscape) dlg = QDialog(self) loadUi(dlg, 'printpreview.ui') dlg.width.setValue(self.print_width or 500) ppw = QPrintPreviewWidget(printer, dlg) dlg.layout().insertWidget(1, ppw) def render(printer): height = printer.height() * (dlg.width.value() / 1000.) width = aspect * height painter = QPainter(printer) svg.render(painter, QRectF(0, 0, width, height)) def sliderchanged(newval): ppw.updatePreview() ppw.paintRequested.connect(render) dlg.width.valueChanged.connect(sliderchanged) if dlg.exec_() != QDialog.Accepted: return self.print_width = dlg.width.value() pdlg = QPrintDialog(printer, self) if pdlg.exec_() != QDialog.Accepted: return render(printer)
def on_addCustomBtn_clicked(self): dlg = QDialog(self) loadUi(dlg, 'custommodel.ui') while 1: if dlg.exec_() != QDialog.Accepted: return modelname = str(dlg.nameBox.text()) params = str(dlg.paramBox.text()) value = str(dlg.valueEdit.toPlainText()).strip() if not ident_re.match(modelname): QMessageBox.warning( self, 'Error', 'Please enter a valid model ' 'name (must be a Python identifier using ' 'only alphabetic characters and digits).') continue if not params: QMessageBox.warning(self, 'Error', 'Please enter some parameters.') continue for param in params.split(): if not ident_re.match(param): QMessageBox.warning( self, 'Error', 'Parameter name %s is not valid (must ' 'be a Python identifier using only alphabetic ' 'characters and digits).' % param) params = None break if not params: continue break self.insert_model_code('Custom(%r, %r, %r)' % (modelname, params, value))
def on_actionMergeData_triggered(self): items = self.selected_items(ScanDataItem) if len(items) < 2: return dlg = QDialog(self) loadUi(dlg, 'rebin.ui') if dlg.exec_(): try: precision = float(dlg.precisionEdit.text()) except ValueError: return datalist = [i.data for i in items] new_data = datalist[0].merge(precision, *datalist[1:]) session.add_item(ScanDataItem(new_data), self.items[-1].group)
def on_actionReorder_triggered(self): dlg = QDialog(self) loadUi(dlg, 'reorder.ui') data2obj = dlg.itemList.populate() if not dlg.exec_(): return new_structure = [] for i in range(dlg.itemList.count()): new_index = dlg.itemList.item(i).type() obj = data2obj[new_index] if isinstance(obj, ItemGroup): new_structure.append((obj, [])) else: if not new_structure: QMessageBox.warning( self, 'ufit', 'Reordering invalid: every data item ' 'must be below a group') return new_structure[-1][1].append(obj) session.reorder_groups(new_structure) self.re_expand_tree()
def on_actionAbout_triggered(self): dlg = QDialog(self) dlg.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint) loadUi(dlg, 'about.ui') dlg.lbl.setText(dlg.lbl.text().replace('VERSION', __version__)) dlg.exec_()