Exemplo n.º 1
0
class Second(QMainWindow):
    def __init__(self):
        super(Second, self).__init__()
        self.setWindowTitle("Add new device")

        self.nameLabel = QLabel(self)
        self.nameLabel.move(10, 10)
        self.nameLabel.setText("Device name")
        self.nameEntry = QLineEdit(self)
        self.nameEntry.move(10, 40)
        self.nameEntry.resize(100, 30)

        self.colorLabel = QLabel(self)
        self.colorLabel.move(120, 10)
        self.colorLabel.setText("Color cameras")
        self.colorEntry = QLineEdit(self)
        self.colorEntry.move(140, 40)
        self.colorEntry.resize(70, 30)
        self.colorEntry.setValidator(QtGui.QIntValidator())

        self.monoLabel = QLabel(self)
        self.monoLabel.move(230, 10)
        self.monoLabel.setText("Mono cameras")
        self.monoEntry = QLineEdit(self)
        self.monoEntry.move(250, 40)
        self.monoEntry.resize(70, 30)
        self.monoEntry.setValidator(QtGui.QIntValidator())

        self.depthPresent = QCheckBox("Include depth", self)
        self.depthPresent.move(10, 80)
        self.depthPresent.resize(150, 30)
        self.depthPresent.stateChanged.connect(self.toggle_depth)

        self.leftfovLabel = QLabel(self)
        self.leftfovLabel.move(10, 120)
        self.leftfovLabel.setText("Left FOV deg.")
        self.leftfovEntry = QLineEdit(self)
        self.leftfovEntry.move(180, 120)
        self.leftfovEntry.resize(140, 30)
        self.leftfovEntry.setValidator(QtGui.QDoubleValidator())

        self.rightfovLabel = QLabel(self)
        self.rightfovLabel.move(10, 160)
        self.rightfovLabel.setText("Right FOV deg.")
        self.rightfovEntry = QLineEdit(self)
        self.rightfovEntry.move(180, 160)
        self.rightfovEntry.resize(140, 30)
        self.rightfovEntry.setValidator(QtGui.QDoubleValidator())

        self.rgbfovLabel = QLabel(self)
        self.rgbfovLabel.move(10, 200)
        self.rgbfovLabel.setText("RGB FOV deg.")
        self.rgbfovEntry = QLineEdit(self)
        self.rgbfovEntry.move(180, 200)
        self.rgbfovEntry.resize(140, 30)
        self.rgbfovEntry.setValidator(QtGui.QDoubleValidator())

        self.lrdistanceLabel = QLabel(self)
        self.lrdistanceLabel.move(10, 240)
        self.lrdistanceLabel.resize(200, 30)
        self.lrdistanceLabel.setText("Left - Right distance cm.")
        self.lrdistanceEntry = QLineEdit(self)
        self.lrdistanceEntry.move(180, 240)
        self.lrdistanceEntry.resize(140, 30)
        self.lrdistanceEntry.setValidator(QtGui.QDoubleValidator())

        self.lrgbdistanceLabel = QLabel(self)
        self.lrgbdistanceLabel.move(10, 280)
        self.lrgbdistanceLabel.resize(200, 30)
        self.lrgbdistanceLabel.setText("Left - RGB distance cm.")
        self.lrgbdistanceEntry = QLineEdit(self)
        self.lrgbdistanceEntry.move(180, 280)
        self.lrgbdistanceEntry.resize(140, 30)
        self.lrgbdistanceEntry.setValidator(QtGui.QDoubleValidator())

        self.saveButton = QPushButton("Save", self)
        self.saveButton.resize(100, 30)
        self.saveButton.clicked.connect(self.save)

        self.cancelButton = QPushButton("Cancel", self)
        self.cancelButton.resize(100, 30)
        self.cancelButton.clicked.connect(self.cancel)

        self.toggle_depth(False)

    def toggle_depth(self, checked):
        if checked:
            self.leftfovLabel.setVisible(True)
            self.leftfovEntry.setVisible(True)
            self.rightfovLabel.setVisible(True)
            self.rightfovEntry.setVisible(True)
            self.rgbfovLabel.setVisible(True)
            self.rgbfovEntry.setVisible(True)
            self.lrdistanceLabel.setVisible(True)
            self.lrdistanceEntry.setVisible(True)
            self.lrgbdistanceLabel.setVisible(True)
            self.lrgbdistanceEntry.setVisible(True)
            self.saveButton.move(200, 330)
            self.cancelButton.move(30, 330)
            self.resize(330, 380)
        else:
            self.leftfovLabel.setVisible(False)
            self.leftfovEntry.setVisible(False)
            self.rightfovLabel.setVisible(False)
            self.rightfovEntry.setVisible(False)
            self.rgbfovLabel.setVisible(False)
            self.rgbfovEntry.setVisible(False)
            self.lrdistanceLabel.setVisible(False)
            self.lrdistanceEntry.setVisible(False)
            self.lrgbdistanceLabel.setVisible(False)
            self.lrgbdistanceEntry.setVisible(False)
            self.saveButton.move(200, 120)
            self.cancelButton.move(30, 120)
            self.resize(330, 170)

    def save(self, *args, **kwargs):
        try:
            data = {
                "name": self.nameEntry.text(),
                "color_count": int(self.colorEntry.text()),
                "mono_count": int(self.monoEntry.text()),
            }
            if self.depthPresent.isChecked():
                data.update({
                    "depth":
                    True,
                    "left_fov_deg":
                    float(self.leftfovEntry.text()),
                    "right_fov_deg":
                    float(self.rightfovEntry.text()),
                    "rgb_fov_deg":
                    float(self.rgbfovEntry.text()),
                    "left_to_right_distance_cm":
                    float(self.lrdistanceEntry.text()),
                    "left_to_rgb_distance_cm":
                    float(self.lrgbdistanceEntry.text()),
                })
            append_to_json(
                data,
                Path(__file__).parent.parent / Path('custom_devices.json'))
            self.close()
            INITIALIZE()
            self.instance.getRegisteredTools(['NodeBoxTool'])[0].refresh()
        except Exception as e:
            QMessageBox.warning(self, "Warning", str(e))

    def cancel(self):
        self.close()
Exemplo n.º 2
0
    def addAttributeSlot(self):
        """ Adds a new attribute (column) to the table """

        dialog = QDialog(self)
        dialog.setModal(True)
        dialog.setWindowTitle('Add Attribute')

        layout = QVBoxLayout()
        dialog.setLayout(layout)

        form = QFormLayout()
        nameBox = QLineEdit()
        typeCombo = QComboBox()
        for attrType in _attrTypes:
            typeName = partio.TypeName(attrType)
            typeCombo.addItem(typeName)
        typeCombo.setCurrentIndex(partio.FLOAT)
        countBox = QLineEdit()
        countBox.setValidator(QIntValidator())
        countBox.setText('1')
        fixedCheckbox = QCheckBox()
        valueBox = QLineEdit()
        valueBox.setText('0')
        form.addRow('Name:', nameBox)
        form.addRow('Type:', typeCombo)
        form.addRow('Count:', countBox)
        form.addRow('Fixed:', fixedCheckbox)
        form.addRow('Default Value:', valueBox)
        layout.addLayout(form)

        buttons = QHBoxLayout()
        layout.addLayout(buttons)

        add = QPushButton('Add')
        add.clicked.connect(dialog.accept)
        buttons.addWidget(add)

        cancel = QPushButton('Cancel')
        cancel.clicked.connect(dialog.reject)
        buttons.addWidget(cancel)

        if not dialog.exec_():
            return

        name = str(nameBox.text())
        if not name:
            print 'Please supply a name for the new attribute' # TODO: prompt
            return

        attrType = typeCombo.currentIndex()
        count = int(countBox.text())
        fixed = fixedCheckbox.isChecked()
        values = list(str(valueBox.text()).strip().split())
        for i in range(count):
            if i < len(values):
                value = values[i]
            else:
                value = values[-1]
            if attrType == partio.INT or attrType == partio.INDEXEDSTR:
                values[i] = int(value)
            elif attrType == partio.FLOAT or attrType == partio.VECTOR:
                values[i] = float(value) # pylint:disable=R0204
            else:
                values[i] = 0.0 # pylint:disable=R0204
        value = tuple(values)

        self.data.addAttribute(name, attrType, count, fixed, value)
Exemplo n.º 3
0
    def addAttributeSlot(self):
        """ Adds a new attribute (column) to the table """

        dialog = QDialog(self)
        dialog.setModal(True)
        dialog.setWindowTitle('Add Attribute')

        layout = QVBoxLayout()
        dialog.setLayout(layout)

        form = QFormLayout()
        nameBox = QLineEdit()
        typeCombo = QComboBox()
        for attrType in _attrTypes:
            typeName = partio.TypeName(attrType)
            typeCombo.addItem(typeName)
        typeCombo.setCurrentIndex(partio.FLOAT)
        countBox = QLineEdit()
        countBox.setValidator(QIntValidator())
        countBox.setText('1')
        fixedCheckbox = QCheckBox()
        valueBox = QLineEdit()
        valueBox.setText('0')
        form.addRow('Name:', nameBox)
        form.addRow('Type:', typeCombo)
        form.addRow('Count:', countBox)
        form.addRow('Fixed:', fixedCheckbox)
        form.addRow('Default Value:', valueBox)
        layout.addLayout(form)

        buttons = QHBoxLayout()
        layout.addLayout(buttons)

        add = QPushButton('Add')
        add.clicked.connect(dialog.accept)
        buttons.addWidget(add)

        cancel = QPushButton('Cancel')
        cancel.clicked.connect(dialog.reject)
        buttons.addWidget(cancel)

        if not dialog.exec_():
            return

        name = str(nameBox.text())
        if not name:
            print('Please supply a name for the new attribute')  # TODO: prompt
            return

        attrType = typeCombo.currentIndex()
        count = int(countBox.text())
        fixed = fixedCheckbox.isChecked()
        values = list(str(valueBox.text()).strip().split())
        for i in range(count):
            if i < len(values):
                value = values[i]
            else:
                value = values[-1]
            if attrType == partio.INT or attrType == partio.INDEXEDSTR:
                values[i] = int(value)
            elif attrType == partio.FLOAT or attrType == partio.VECTOR:
                values[i] = float(value)  # pylint:disable=R0204
            else:
                values[i] = 0.0  # pylint:disable=R0204
        value = tuple(values)

        self.data.addAttribute(name, attrType, count, fixed, value)
Exemplo n.º 4
0
class EditableTearOffTabBar(TearOffTabBar, object):
    """
    Extended implementation of an editable tab bar with:
        - Rename functionality
        - Tear off functionality
    """

    tab_label_renamed = Signal(str, str)
    request_remove = Signal(int)
    tab_changed = Signal(int)

    def __init__(self, parent=None):
        super(EditableTearOffTabBar, self).__init__(parent=parent)

        self._editor = QLineEdit(self)
        self._editor.setWindowFlags(Qt.Popup)
        self._editor.setFocusProxy(self)
        self._editor.setFocusPolicy(Qt.StrongFocus)
        self._editor.editingFinished.connect(self.handle_editing_finished)
        self._editor.installEventFilter(self)
        self._editor.setValidator(QRegExpValidator(nameRegExp))
        self._edit_index = -1

    def edit_tab(self, index):
        """
        This set the tab in edit mode
        This method is called when double click on the tab
        :param index: int, Index of the tab to be renamed
        """

        # Show the editable line and position it on top of the selected tab
        rect = self.tabRect(index)
        self._editor.setFixedSize(rect.size())
        self._editor.move(self.parent().mapToGlobal(rect.topLeft()))
        self._editor.setText(self.tabText(index))
        if not self._editor.isVisible():
            self._editor.show()
            self._edit_index = index

    def handle_editing_finished(self):
        """
        This finish the edit of the tab name
        """

        # This method only works of we are editing any tab
        if self._edit_index >= 0:
            # Hide the text and update tab text
            self._editor.hide()
            old_text = self.tabText(self.__editIndex)
            new_text = self._editor.text()
            if old_text != new_text:
                names = [self.tabText(i) for i in range(self.count())]
                new_text = naming.get_numeric_name(new_text, names)
                self.setTabText(self._edit_index, new_text)
                self.tab_label_renamed.emit(old_text, new_text)
                self._edit_index = -1

    def eventFilter(self, widget, event):
        """
        If we click (with mouse or keyboard) on registered widgets we hide the editor
        """

        if event.type(
        ) == QEvent.MouseButtonPress and not self._editor.geometry().contains(
                event.globalPos()) or event.type(
                ) == QEvent.KeyPress and event.key() == Qt.Key_Escape:
            self._editor.hide()
            return False
        return QTabBar.eventFilter(self, widget, event)