Esempio n. 1
0
 def createPortTable(self, has_inputs=True, has_outputs=True):
     if has_inputs:
         self.inputPortTable = PortTable(self)
         labels = ["Input Port Name", "Type", "List Depth"]
         self.inputPortTable.setHorizontalHeaderLabels(labels)
         self.inputPortTable.initializePorts(self.module.input_port_specs)
         self.layout().addWidget(self.inputPortTable)
         horiz = self.inputPortTable.horizontalHeader()
         horiz.setResizeMode(1, QtGui.QHeaderView.Stretch)
     if has_outputs:
         self.outputPortTable = PortTable(self)
         labels = ["Output Port Name", "Type", "List Depth"]
         self.outputPortTable.setHorizontalHeaderLabels(labels)
         self.outputPortTable.initializePorts(self.module.output_port_specs, True)
         self.layout().addWidget(self.outputPortTable)
         horiz = self.outputPortTable.horizontalHeader()
         horiz.setResizeMode(1, QtGui.QHeaderView.Stretch)
     if has_inputs:
         self.inputPortTable.fixGeometry()
         # resize input ports in case there are no output ports
         self.inputPortTable.resizeColumnToContents(0)
         self.inputPortTable.resizeColumnToContents(2)
     if has_inputs and has_outputs:
         self.performPortConnection(self.connect)
     if has_outputs:
         self.outputPortTable.fixGeometry()
         # Resize output (because it is largest) and trigger sync
         self.outputPortTable.resizeColumnToContents(0)
         self.outputPortTable.resizeColumnToContents(2)
 def createPortTable(self, has_inputs=True, has_outputs=True):
     if has_inputs:
         self.inputPortTable = PortTable(self)
         labels = ["Input Port Name", "Type", "List Depth"]
         self.inputPortTable.setHorizontalHeaderLabels(labels)
         self.inputPortTable.initializePorts(self.module.input_port_specs)
         self.layout().addWidget(self.inputPortTable)
         horiz = self.inputPortTable.horizontalHeader()
         horiz.setResizeMode(1, QtGui.QHeaderView.Stretch)
     if has_outputs:
         self.outputPortTable = PortTable(self)
         labels = ["Output Port Name", "Type", "List Depth"]
         self.outputPortTable.setHorizontalHeaderLabels(labels)
         self.outputPortTable.initializePorts(self.module.output_port_specs,
                                              True)
         self.layout().addWidget(self.outputPortTable)
         horiz = self.outputPortTable.horizontalHeader()
         horiz.setResizeMode(1, QtGui.QHeaderView.Stretch)
     if has_inputs:
         self.inputPortTable.fixGeometry()
         # resize input ports in case there are no output ports
         self.inputPortTable.resizeColumnToContents(0)
         self.inputPortTable.resizeColumnToContents(2)
     if has_inputs and has_outputs:
         self.performPortConnection(self.connect)
     if has_outputs:
         self.outputPortTable.fixGeometry()
         # Resize output (because it is largest) and trigger sync
         self.outputPortTable.resizeColumnToContents(0)
         self.outputPortTable.resizeColumnToContents(2)
Esempio n. 3
0
 def createPortTable(self, has_inputs=True, has_outputs=True):
     if has_inputs:
         self.inputPortTable = PortTable(self)
         labels = ["Input Port Name", "Type", "List Depth"]
         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 = ["Output Port Name", "Type", "List Depth"]
         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()
Esempio n. 4
0
 def createPortTable(self, has_inputs=True, has_outputs=True):
     if has_inputs:
         self.inputPortTable = PortTable(self)
         labels = ["Input Port Name", "Type", "List Depth"]
         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 = ["Output Port Name", "Type", "List Depth"]
         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()
Esempio n. 5
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 = ["Input Port Name", "Type", "List Depth"]
            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 = ["Output Port Name", "Type", "List Depth"]
            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()
        code = None
        # Get code from a function
        if fid != -1:
            f = self.module.functions[fid]
            code = f.params[0].strValue
        # Get code from the default on the port
        else:
            port = self.module.get_port_spec(self.sourcePortName, 'input')
            if port.defaults:
                code, = port.defaults
        if code is not None:
            if self.sourceEncode:
                code = urllib.unquote(code).decode('utf-8')
            self.codeEditor.setPlainText(code)
        if self.codeEditor.__class__.__name__ not in [
                '_PythonEditor', '_TextEditor'
        ]:
            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__ not in [
                '_PythonEditor', '_TextEditor'
        ]:
            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__ not in [
                '_PythonEditor', '_TextEditor'
        ]:
            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)
Esempio n. 6
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 = ["Input Port Name", "Type", "List Depth"]
            self.inputPortTable.setHorizontalHeaderLabels(labels)
            self.inputPortTable.initializePorts(self.module.input_port_specs)
            self.layout().addWidget(self.inputPortTable)
            horiz = self.inputPortTable.horizontalHeader()
            horiz.setResizeMode(1, QtGui.QHeaderView.Stretch)
        if has_outputs:
            self.outputPortTable = PortTable(self)
            labels = ["Output Port Name", "Type", "List Depth"]
            self.outputPortTable.setHorizontalHeaderLabels(labels)
            self.outputPortTable.initializePorts(self.module.output_port_specs, True)
            self.layout().addWidget(self.outputPortTable)
            horiz = self.outputPortTable.horizontalHeader()
            horiz.setResizeMode(1, QtGui.QHeaderView.Stretch)
        if has_inputs:
            self.inputPortTable.fixGeometry()
            # resize input ports in case there are no output ports
            self.inputPortTable.resizeColumnToContents(0)
            self.inputPortTable.resizeColumnToContents(2)
        if has_inputs and has_outputs:
            self.performPortConnection(self.connect)
        if has_outputs:
            self.outputPortTable.fixGeometry()
            # Resize output (because it is largest) and trigger sync
            self.outputPortTable.resizeColumnToContents(0)
            self.outputPortTable.resizeColumnToContents(2)

    def initializeCode(self):
        self.codeEditor.clear()
        fid = self.findSourceFunction()
        code = None
        # Get code from a function
        if fid != -1:
            f = self.module.functions[fid]
            code = f.params[0].strValue
        # Get code from the default on the port
        else:
            port = self.module.get_port_spec(self.sourcePortName, "input")
            if port.defaults:
                code, = port.defaults
        if code is not None:
            if self.sourceEncode:
                code = urllib.unquote(code).decode("utf-8")
            self.codeEditor.setPlainText(code)
        if self.codeEditor.__class__.__name__ not in ["_PythonEditor", "_TextEditor"]:
            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__ not in ["_PythonEditor", "_TextEditor"]:
            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__ not in ["_PythonEditor", "_TextEditor"]:
            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)
        QtGui.QApplication.processEvents()
        self.performPortConnection(self.connect)

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