def addFitCheckBoxes(self, comps, fitpars, nofitbox): """ Add the fitting checkboxes at the top of the plk Window @param comps: A dict of model components and their 'set' parameters @param fitpars: The parameters that are currently being fitted for @param nofitbox: The parameters we should skip """ self.deleteFitCheckBoxes() self.compGrids = [] ii = 0 for comp in comps: showpars = [p for p in comps[comp] if not p in nofitbox] #Don't put anything if there are no parameters to show if len(showpars) == 0: continue #Add component label font = QtGui.QFont() font.setBold(True) ccb = QtGui.QCheckBox(comp, self) ccb.stateChanged.connect(self.changedGroupCheckBox) ccb.setFont(font) ccb.setChecked(False) self.grid.addWidget(ccb, ii, 0, 1, 1) noneChecked = True self.compGrids.append(QtGui.QGridLayout()) for pp, par in enumerate(showpars): cb = QtGui.QCheckBox(par, self) cb.stateChanged.connect(self.changedFitCheckBox) #Set checked/unchecked cb.setChecked(par in fitpars) if par in fitpars: noneChecked = False self.compGrids[ii].addWidget(cb, int(pp / self.maxcols), pp % self.maxcols, 1, 1) #Now pad the last row lastcol = len(showpars) % self.maxcols lastrow = int(len(showpars) / self.maxcols) if lastcol < self.maxcols: label = QtGui.QLabel(self) label.setText('') self.compGrids[ii].addWidget(label, lastrow, lastcol, 1, self.maxcols - lastcol) self.grid.addItem(self.compGrids[ii], ii, 1, 1, self.maxcols) if noneChecked: self.changeGroupVisibility(False, ii) ii += 1
def addFitCheckBoxes(self, setpars, fitpars, nofitbox): """ Add the fitting checkboxes at the top of the plk Window @param setpars: The parameters that are 'set' (in the model) @param fitpars: The parameters that are currently being fitted for @param nofitbox: The parameters we should skip """ # Delete the fitboxes if there were still some left if not len(self.vboxes) == 0: self.deleteFitCheckBoxes() # First add all the vbox layouts for ii in range(min(self.fitboxPerLine, len(setpars))): self.vboxes.append(QtGui.QVBoxLayout()) self.hbox.addLayout(self.vboxes[-1]) # Then add the checkbox widgets to the vboxes index = 0 for pp, par in enumerate(setpars): if not par in nofitbox: vboxind = index % self.fitboxPerLine cb = QtGui.QCheckBox(par, self) cb.stateChanged.connect(self.changedFitCheckBox) # Set checked/unchecked cb.setChecked(par in fitpars) self.vboxes[vboxind].addWidget(cb) index += 1 for vv, vbox in enumerate(self.vboxes): vbox.addStretch(1)
def export(self): """ Displays a dialog for exporting HTML generated by Qt's rich text system. Returns ------- The name of the file that was saved, or None if no file was saved. """ parent = self.control.window() dialog = QtGui.QFileDialog(parent, 'Save as...') dialog.setAcceptMode(QtGui.QFileDialog.AcceptSave) filters = [ 'HTML with PNG figures (*.html *.htm)', 'XHTML with inline SVG figures (*.xhtml *.xml)' ] dialog.setNameFilters(filters) if self.filename: dialog.selectFile(self.filename) root, ext = os.path.splitext(self.filename) if ext.lower() in ('.xml', '.xhtml'): dialog.selectNameFilter(filters[-1]) if dialog.exec_(): self.filename = dialog.selectedFiles()[0] choice = dialog.selectedNameFilter() html = py3compat.cast_unicode(self.control.document().toHtml()) # Configure the exporter. if choice.startswith('XHTML'): exporter = export_xhtml else: # If there are PNGs, decide how to export them. inline = self.inline_png if inline is None and IMG_RE.search(html): dialog = QtGui.QDialog(parent) dialog.setWindowTitle('Save as...') layout = QtGui.QVBoxLayout(dialog) msg = "Exporting HTML with PNGs" info = "Would you like inline PNGs (single large html " \ "file) or external image files?" checkbox = QtGui.QCheckBox("&Don't ask again") checkbox.setShortcut('D') ib = QtGui.QPushButton("&Inline") ib.setShortcut('I') eb = QtGui.QPushButton("&External") eb.setShortcut('E') box = QtGui.QMessageBox(QtGui.QMessageBox.Question, dialog.windowTitle(), msg) box.setInformativeText(info) box.addButton(ib, QtGui.QMessageBox.NoRole) box.addButton(eb, QtGui.QMessageBox.YesRole) layout.setSpacing(0) layout.addWidget(box) layout.addWidget(checkbox) dialog.setLayout(layout) dialog.show() reply = box.exec_() dialog.hide() inline = (reply == 0) if checkbox.checkState(): # Don't ask anymore; always use this choice. self.inline_png = inline exporter = lambda h, f, i: export_html(h, f, i, inline) # Perform the export! try: return exporter(html, self.filename, self.image_tag) except Exception as e: msg = "Error exporting HTML to %s\n" % self.filename + str(e) reply = QtGui.QMessageBox.warning(parent, 'Error', msg, QtGui.QMessageBox.Ok, QtGui.QMessageBox.Ok) return None