def createPortTable(self, has_inputs=True, has_outputs=True):
     if has_inputs:
         self.inputPortTable = PortTable(self)
         labels = QtCore.QStringList() << "Input Port Name" << "Type"
         self.inputPortTable.setHorizontalHeaderLabels(labels)
         self.inputPortTable.initializePorts(self.module.input_port_specs)
         self.layout().addWidget(self.inputPortTable)
     if has_outputs:
         self.outputPortTable = PortTable(self)
         labels = QtCore.QStringList() << "Output Port Name" << "Type"
         self.outputPortTable.setHorizontalHeaderLabels(labels)
         self.outputPortTable.initializePorts(self.module.output_port_specs, 
                                              True)
         self.layout().addWidget(self.outputPortTable)
     if has_inputs and has_outputs:
         self.performPortConnection(self.connect)
     if has_inputs:
         self.inputPortTable.fixGeometry()
     if has_outputs:
         self.outputPortTable.fixGeometry()
Example #2
0
 def createPortTable(self, has_inputs=True, has_outputs=True):
     if has_inputs:
         self.inputPortTable = PortTable(self)
         labels = QtCore.QStringList() << "Input Port Name" << "Type"
         self.inputPortTable.setHorizontalHeaderLabels(labels)
         self.inputPortTable.initializePorts(self.module.input_port_specs)
         self.layout().addWidget(self.inputPortTable)
     if has_outputs:
         self.outputPortTable = PortTable(self)
         labels = QtCore.QStringList() << "Output Port Name" << "Type"
         self.outputPortTable.setHorizontalHeaderLabels(labels)
         self.outputPortTable.initializePorts(self.module.output_port_specs,
                                              True)
         self.layout().addWidget(self.outputPortTable)
     if has_inputs and has_outputs:
         self.performPortConnection(self.connect)
     if has_inputs:
         self.inputPortTable.fixGeometry()
     if has_outputs:
         self.outputPortTable.fixGeometry()
class SourceWidget(PortTableConfigurationWidget):
    def __init__(self, module, controller, editor_class=None,
                 has_inputs=True, has_outputs=True, parent=None,
                 encode=True, portName='source'):
        PortTableConfigurationWidget.__init__(self, module, controller, parent)
        if editor_class is None:
            editor_class = SourceEditor
        self.codeEditor = editor_class(parent)
        self.setWindowTitle('%s Configuration' % module.name)
        self.setLayout(QtGui.QVBoxLayout())
        self.layout().setMargin(0)
        self.layout().setSpacing(0)
        self.has_inputs = has_inputs
        self.has_outputs = has_outputs
        self.sourcePortName = portName
        self.sourceEncode = encode
        self.createPortTable(has_inputs, has_outputs)
        self.setupEditor()
        self.adjustSize()
        
    def createPortTable(self, has_inputs=True, has_outputs=True):
        if has_inputs:
            self.inputPortTable = PortTable(self)
            labels = QtCore.QStringList() << "Input Port Name" << "Type"
            self.inputPortTable.setHorizontalHeaderLabels(labels)
            self.inputPortTable.initializePorts(self.module.input_port_specs)
            self.layout().addWidget(self.inputPortTable)
        if has_outputs:
            self.outputPortTable = PortTable(self)
            labels = QtCore.QStringList() << "Output Port Name" << "Type"
            self.outputPortTable.setHorizontalHeaderLabels(labels)
            self.outputPortTable.initializePorts(self.module.output_port_specs, 
                                                 True)
            self.layout().addWidget(self.outputPortTable)
        if has_inputs and has_outputs:
            self.performPortConnection(self.connect)
        if has_inputs:
            self.inputPortTable.fixGeometry()
        if has_outputs:
            self.outputPortTable.fixGeometry()
            
    def initializeCode(self):
        self.codeEditor.clear()
        fid = self.findSourceFunction()
        if fid!=-1:
            f = self.module.functions[fid]
            code = f.params[0].strValue
            if self.sourceEncode:
                code = urllib.unquote(code)
            self.codeEditor.setPlainText(code)
        if self.codeEditor.__class__.__name__ != '_PythonEditor':
            self.codeEditor.document().setModified(False)
        else:
            self.codeEditor.setModified(False)
        self.codeEditor.setFocus()
        
    def findSourceFunction(self):
        fid = -1
        for i in xrange(self.module.getNumFunctions()):
            if self.module.functions[i].name==self.sourcePortName:
                fid = i
                break
        return fid
    
    def setupEditor(self):
        self.initializeCode()
        self.layout().addWidget(self.codeEditor, 1)
        
        self.cursorLabel = QtGui.QLabel()
        self.layout().addWidget(self.cursorLabel)
        if self.codeEditor.__class__.__name__ != '_PythonEditor':
            self.connect(self.codeEditor,
                         QtCore.SIGNAL('cursorPositionChanged()'),
                         self.updateCursorLabel)
        else:
            self.connect(self.codeEditor,
                         QtCore.SIGNAL('cursorPositionChanged(int, int)'),
                         self.updateCursorLabel)
        self.updateCursorLabel()
            
    def updateCursorLabel(self, x=0, y=0):
        if self.codeEditor.__class__.__name__ != '_PythonEditor':
            cursor = self.codeEditor.textCursor()
            x = cursor.blockNumber()
            y = cursor.columnNumber()
            
        self.cursorLabel.setText('Line: %d / Col: %d' % (x+1, y+1))
    
    def sizeHint(self):
        return QtCore.QSize(512, 512)
    
    def performPortConnection(self, operation):
        operation(self.inputPortTable.horizontalHeader(),
                  QtCore.SIGNAL('sectionResized(int,int,int)'),
                  self.portTableResize)
        operation(self.outputPortTable.horizontalHeader(),
                  QtCore.SIGNAL('sectionResized(int,int,int)'),
                  self.portTableResize)

    def portTableResize(self, logicalIndex, oldSize, newSize):
        self.performPortConnection(self.disconnect)
        if self.inputPortTable.horizontalHeader().sectionSize(logicalIndex)!=newSize:
            self.inputPortTable.horizontalHeader().resizeSection(logicalIndex,newSize)
        if self.outputPortTable.horizontalHeader().sectionSize(logicalIndex)!=newSize:
            self.outputPortTable.horizontalHeader().resizeSection(logicalIndex,newSize)
        self.performPortConnection(self.connect)
    
    def activate(self):
        self.codeEditor.setFocus(QtCore.Qt.MouseFocusReason)
Example #4
0
class SourceWidget(PortTableConfigurationWidget):
    def __init__(self,
                 module,
                 controller,
                 editor_class=None,
                 has_inputs=True,
                 has_outputs=True,
                 parent=None,
                 encode=True,
                 portName='source'):
        PortTableConfigurationWidget.__init__(self, module, controller, parent)
        if editor_class is None:
            editor_class = SourceEditor
        self.codeEditor = editor_class(parent)
        self.setWindowTitle('%s Configuration' % module.name)
        self.setLayout(QtGui.QVBoxLayout())
        self.layout().setMargin(0)
        self.layout().setSpacing(0)
        self.has_inputs = has_inputs
        self.has_outputs = has_outputs
        self.sourcePortName = portName
        self.sourceEncode = encode
        self.createPortTable(has_inputs, has_outputs)
        self.setupEditor()
        self.adjustSize()

    def createPortTable(self, has_inputs=True, has_outputs=True):
        if has_inputs:
            self.inputPortTable = PortTable(self)
            labels = QtCore.QStringList() << "Input Port Name" << "Type"
            self.inputPortTable.setHorizontalHeaderLabels(labels)
            self.inputPortTable.initializePorts(self.module.input_port_specs)
            self.layout().addWidget(self.inputPortTable)
        if has_outputs:
            self.outputPortTable = PortTable(self)
            labels = QtCore.QStringList() << "Output Port Name" << "Type"
            self.outputPortTable.setHorizontalHeaderLabels(labels)
            self.outputPortTable.initializePorts(self.module.output_port_specs,
                                                 True)
            self.layout().addWidget(self.outputPortTable)
        if has_inputs and has_outputs:
            self.performPortConnection(self.connect)
        if has_inputs:
            self.inputPortTable.fixGeometry()
        if has_outputs:
            self.outputPortTable.fixGeometry()

    def initializeCode(self):
        self.codeEditor.clear()
        fid = self.findSourceFunction()
        if fid != -1:
            f = self.module.functions[fid]
            code = f.params[0].strValue
            if self.sourceEncode:
                code = urllib.unquote(code)
            self.codeEditor.setPlainText(code)
        if self.codeEditor.__class__.__name__ != '_PythonEditor':
            self.codeEditor.document().setModified(False)
        else:
            self.codeEditor.setModified(False)
        self.codeEditor.setFocus()

    def findSourceFunction(self):
        fid = -1
        for i in xrange(self.module.getNumFunctions()):
            if self.module.functions[i].name == self.sourcePortName:
                fid = i
                break
        return fid

    def setupEditor(self):
        self.initializeCode()
        self.layout().addWidget(self.codeEditor, 1)

        self.cursorLabel = QtGui.QLabel()
        self.layout().addWidget(self.cursorLabel)
        if self.codeEditor.__class__.__name__ != '_PythonEditor':
            self.connect(self.codeEditor,
                         QtCore.SIGNAL('cursorPositionChanged()'),
                         self.updateCursorLabel)
        else:
            self.connect(self.codeEditor,
                         QtCore.SIGNAL('cursorPositionChanged(int, int)'),
                         self.updateCursorLabel)
        self.updateCursorLabel()

    def updateCursorLabel(self, x=0, y=0):
        if self.codeEditor.__class__.__name__ != '_PythonEditor':
            cursor = self.codeEditor.textCursor()
            x = cursor.blockNumber()
            y = cursor.columnNumber()

        self.cursorLabel.setText('Line: %d / Col: %d' % (x + 1, y + 1))

    def sizeHint(self):
        return QtCore.QSize(512, 512)

    def performPortConnection(self, operation):
        operation(self.inputPortTable.horizontalHeader(),
                  QtCore.SIGNAL('sectionResized(int,int,int)'),
                  self.portTableResize)
        operation(self.outputPortTable.horizontalHeader(),
                  QtCore.SIGNAL('sectionResized(int,int,int)'),
                  self.portTableResize)

    def portTableResize(self, logicalIndex, oldSize, newSize):
        self.performPortConnection(self.disconnect)
        if self.inputPortTable.horizontalHeader().sectionSize(
                logicalIndex) != newSize:
            self.inputPortTable.horizontalHeader().resizeSection(
                logicalIndex, newSize)
        if self.outputPortTable.horizontalHeader().sectionSize(
                logicalIndex) != newSize:
            self.outputPortTable.horizontalHeader().resizeSection(
                logicalIndex, newSize)
        self.performPortConnection(self.connect)

    def activate(self):
        self.codeEditor.setFocus(QtCore.Qt.MouseFocusReason)