class QUserFunctionDialog(QtGui.QDialog): """ QUserFunctionDialog provides an interface for user to edit a python function """ def __init__(self, function, parent=None): """ QUserFunctionDialog(function: str, parent: QWidget) -> QUserFunctionDialog Set up a python source editor """ QtGui.QDialog.__init__(self, parent) vLayout = QtGui.QVBoxLayout() vLayout.setMargin(0) vLayout.setSpacing(0) self.setLayout(vLayout) self.setWindowTitle('User-defined Function') label = QtGui.QLabel("Please define your function below. This " "'value(i)' function will be iteratively called " "for <step count> numbers. For each step, " "it should return a value of parameter type.") label.setMargin(5) label.setWordWrap(True) vLayout.addWidget(label) self.editor = PythonEditor(self) self.editor.setPlainText(function) vLayout.addWidget(self.editor) hLayout = QtGui.QHBoxLayout() vLayout.addLayout(hLayout) okButton = QtGui.QPushButton('&OK') okButton.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Maximum) self.connect(okButton, QtCore.SIGNAL('clicked()'), self.accept) hLayout.addWidget(okButton) cancelButton = QtGui.QPushButton('&Cancel') cancelButton.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Maximum) self.connect(cancelButton, QtCore.SIGNAL('clicked()'), self.reject) hLayout.addWidget(cancelButton) def sizeHint(self): """ sizeHint() -> QSize Return the recommended size for the widget """ return QtCore.QSize(512, 512)
def showSource(self, source, sheetName=None, row=-1, col=-1, rowSpan=1, colSpan=1): if source is not None: editor = PythonEditor(self) editor.setPlainText(source) name = sheetName + ' @ %s%s' % (chr(ord('A') + col), row+1) if rowSpan > 1 or colSpan > 1: name += ' to %s%s' % (chr(ord('A') + col + colSpan-1), row + rowSpan) self.tabWidget.addTab(editor, name) self.tabWidget.setCurrentWidget(editor) if editor.__class__.__name__ != '_PythonEditor': editor.document().setModified(False) else: editor.setModified(False) editor.setFocus()
def showSource(self, source, sheetName=None, row=-1, col=-1, rowSpan=1, colSpan=1): if source is not None: editor = PythonEditor(self) editor.setPlainText(source) name = sheetName + ' @ %s%s' % (chr(ord('A') + col), row + 1) if rowSpan > 1 or colSpan > 1: name += ' to %s%s' % (chr(ord('A') + col + colSpan - 1), row + rowSpan) self.tabWidget.addTab(editor, name) self.tabWidget.setCurrentWidget(editor) if editor.__class__.__name__ != '_PythonEditor': editor.document().setModified(False) else: editor.setModified(False) editor.setFocus()