Example #1
0
    def createElement(line: str, widget_gallery) -> 'AbstractClass':
        els = line.split('"')
        els = [el.strip() for el in els]

        button_type, button_label, _discard, button_text, other = els

        try:
            button_type = ButtonType(button_type)
        except:
            button_type = None

        if button_label != "":
            label = QLabel(button_label)
        else:
            label = None

        var_name, val_value, initial_setting, ticked_state = other.split(' ')

        if val_value == "None":
            val_value = None
        elif val_value.find('/'):
            val_value = val_value.split('/')

        if button_type == ButtonType.RADIO_BUTTON:
            inputButton = None
            button = QRadioButton(button_text)
            if initial_setting == "off":
                button.setEnabled(False)

        elif button_type == ButtonType.TEXT_EDIT_BUTTON:
            inputButton = QLineEdit(widget_gallery)
            inputButton.setPlaceholderText(var_name)
            button = QRadioButton(button_text)
            if initial_setting == "off":
                button.setEnabled(False)
                inputButton.setEnabled(False)

        elif button_type == ButtonType.TEXT_EDIT_BOX:
            inputButton = QLineEdit(widget_gallery)
            inputButton.setPlaceholderText(var_name)
            button = None
            if initial_setting == "off":
                inputButton.setEnabled(False)

        elif button_type == ButtonType.FILE_INPUT:
            inputButton = QLineEdit(widget_gallery)
            inputButton.setPlaceholderText(var_name)
            # commented this line for now, since the "choose file" option doesn't work from inside container
            #button = QPushButton(button_text)
            button = None
            if initial_setting == "off":
                inputButton.setEnabled(False)
                # commented this line for now, since the "choose file" option doesn't work from inside container
                #button.setEnabled(False)

        elif button_type == ButtonType.TOGGLE_BUTTON:
            inputButton = None
            button = QCheckBox(button_text)
            if initial_setting == "off":
                button.setEnabled(False)
            if ticked_state == "ticked":
                button.setChecked(True)

        elif button_type == ButtonType.DROPDOWN_LIST:
            inputButton = None
            button = QComboBox(widget_gallery)
            for _value in val_value:
                button.addItem(_value)
            button.move(50, 250)
            if initial_setting == "off":
                button.setEnabled(False)

        elif button_type == ButtonType.PUSH_BUTTON:
            inputButton = None
            pixmap = QPixmap('images/audioicon.png')
            button = QPushButton(button_text)
            button.setGeometry(200, 150, 50, 50)
            button.setIcon(QIcon(pixmap))
            button.setIconSize(QSize(50, 50))

        elif button_type == ButtonType.AUDIO_INPUT:
            inputButton = None
            pixmap = QPixmap('images/audioicon.png')
            button = QPushButton(button_text)
            button.setGeometry(200, 150, 50, 50)
            button.setIcon(QIcon(pixmap))
            button.setIconSize(QSize(50, 50))

        return OptionButton(button_type.value, button, var_name, inputButton,
                            val_value, label)