def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.resize(400,80)

        self.sectionNameEdit = QLineEdit(self)
        self.sectionNameEdit.setGeometry(QRect(0,5,110,30))
        self.sectionNameEdit.setPlaceholderText("Section name")
        self.sectionNameEdit.setToolTip("Name of new section")

        self.sizeEdit = QDoubleSpinBox(self)
        self.sizeEdit.setGeometry(QRect(115,5,65,30))
        self.sizeEdit.setMaximum(100.0)
        self.sizeEdit.setToolTip("Size of section in percent")

        self.colorLabel = ColorChooser(self)
        self.colorLabel.setGeometry(QRect(185,8,25,25))

        self.displayedNameCheckBox = QCheckBox(self)
        self.displayedNameCheckBox.setGeometry(215, 5, 185, 30)
        self.displayedNameCheckBox.setText("Change displayed name")
        self.displayedNameCheckBox.setStyleSheet("font-size:11px;")

        self.displayedNameEdit = QLineEdit(self)
        self.displayedNameEdit.setGeometry(QRect(235,5,120,30))
        self.displayedNameEdit.setPlaceholderText("Displayed name")
        self.displayedNameEdit.setToolTip("Displayed name of new section")
        self.displayedNameEdit.setVisible(False)

        self.removeButton = QPushButton(self)
        self.removeButton.setGeometry(QRect(385,5,35,30))
        self.removeButton.setToolTip("Remove section")
        pixmap = QPixmap("./removeIcon.png")
        buttonIcon = QIcon(pixmap)
        self.removeButton.setIcon(buttonIcon)
        self.removeButton.setIconSize(QSize(25,25))

        self.connect(self.displayedNameCheckBox, QtCore.SIGNAL("clicked()"), self.changeDisplayedName)
        self.connect(self.removeButton, QtCore.SIGNAL("clicked()"), QtCore.SIGNAL("remove()"))
        self.connect(self.sizeEdit, QtCore.SIGNAL("valueChanged(double)"), self.changeSizeValue)
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.setFixedWidth(500)
        self.setFixedHeight(400)
        self.setStyleSheet("font-size:20px;")

        self.vLayout = QVBoxLayout()
        self.setLayout(self.vLayout)

        settingsLabel = QLabel(self)
        settingsLabel.setText("Default settings")
        settingsLabel.setStyleSheet("font-size:25px;")
        settingsLabel.setFixedWidth(500)
        settingsLabel.setAlignment(Qt.AlignCenter)
        self.vLayout.addWidget(settingsLabel)

        sectionColorLabel = QLabel(self)
        sectionColorLabel.setText("Section colors:")
        self.sectionColorChooser = ColorChooser()
        self.sectionColorChooser.setMaximumWidth(50)
        self.sectionSecondColorChooser = ColorChooser()
        self.sectionSecondColorChooser.setMaximumWidth(50)
        self.putInHorizontalLayout(sectionColorLabel, self.sectionColorChooser,
                                   self.sectionSecondColorChooser)

        subsectionColorLabel = QLabel(self)
        subsectionColorLabel.setText("Subsection colors: ")
        self.subsectionColorChooser = ColorChooser(self)
        self.subsectionColorChooser.setMaximumWidth(50)
        self.subsectionSecondColorChooser = ColorChooser(self)
        self.subsectionSecondColorChooser.setMaximumWidth(50)
        self.putInHorizontalLayout(subsectionColorLabel,
                                   self.subsectionColorChooser,
                                   self.subsectionSecondColorChooser)

        linacSectionSizeLabel = QLabel(self)
        linacSectionSizeLabel.setText("Linac section size: ")
        self.linacSectionSizeSpinBox = QDoubleSpinBox(self)
        self.linacSectionSizeSpinBox.setFixedWidth(100)
        self.linacSectionSizeSpinBox.setMaximum(100.0)
        self.putInHorizontalLayout(linacSectionSizeLabel,
                                   self.linacSectionSizeSpinBox)

        linacSubsectionSizeLabel = QLabel(self)
        linacSubsectionSizeLabel.setText("Linac subsection size: ")
        self.linacSubsectionSizeSpinBox = QDoubleSpinBox(self)
        self.linacSubsectionSizeSpinBox.setFixedWidth(100)
        self.linacSubsectionSizeSpinBox.setMaximum(100.0)
        self.putInHorizontalLayout(linacSubsectionSizeLabel,
                                   self.linacSubsectionSizeSpinBox)

        ringSectionSizeLabel = QLabel(self)
        ringSectionSizeLabel.setText("Ring section size: ")
        self.ringSectionSizeSpinBox = QDoubleSpinBox(self)
        self.ringSectionSizeSpinBox.setFixedWidth(100)
        self.ringSectionSizeSpinBox.setMaximum(100.0)
        self.putInHorizontalLayout(ringSectionSizeLabel,
                                   self.ringSectionSizeSpinBox)

        ringSubectionSizeLabel = QLabel(self)
        ringSubectionSizeLabel.setText("Ring subsection size: ")
        self.ringSubsectionSizeSpinBox = QDoubleSpinBox(self)
        self.ringSubsectionSizeSpinBox.setFixedWidth(100)
        self.ringSubsectionSizeSpinBox.setMaximum(100.0)
        self.putInHorizontalLayout(ringSubectionSizeLabel,
                                   self.ringSubsectionSizeSpinBox)

        centerCoordinatesLabel = QLabel(self)
        centerCoordinatesLabel.setText("Real coordinates of ring center:")
        self.centerCoordinatesEditX = QLineEdit()
        self.centerCoordinatesEditX.setPlaceholderText("X")
        self.centerCoordinatesEditX.setFixedWidth(80)
        self.centerCoordinatesEditY = QLineEdit()
        self.centerCoordinatesEditY.setPlaceholderText("Y")
        self.centerCoordinatesEditY.setFixedWidth(80)
        self.putInHorizontalLayout(centerCoordinatesLabel,
                                   self.centerCoordinatesEditX,
                                   self.centerCoordinatesEditY)

        showDeviceCaptionsLabel = QLabel(self)
        showDeviceCaptionsLabel.setText("Show device captions:")
        showDeviceCaptionsLabel.setFixedWidth(500)
        self.showDeviceCaptionsCheckBox = QCheckBox(self)
        self.putInHorizontalLayout(showDeviceCaptionsLabel,
                                   self.showDeviceCaptionsCheckBox)

        useDbParametersLabel = QLabel(self)
        useDbParametersLabel.setText("Use parameters from database")
        useDbParametersLabel.setFixedWidth(500)
        self.useDbParametersCheckBox = QCheckBox(self)
        self.putInHorizontalLayout(useDbParametersLabel,
                                   self.useDbParametersCheckBox)

        tangoHostLabel = QLabel(self)
        tangoHostLabel.setText("Tango Host")
        self.tangoHostEdit = QLineEdit(self)
        self.tangoHostEdit.setFixedHeight(25)
        self.tangoHostEdit.setText("127.0.0.1:10000")
        self.tangoHostEdit.setStyleSheet("font-size:18px;")
        self.putInHorizontalLayout(tangoHostLabel, self.tangoHostEdit)

        self.setDefaultSettings()
class BaseSectionWidget(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.resize(400,80)

        self.sectionNameEdit = QLineEdit(self)
        self.sectionNameEdit.setGeometry(QRect(0,5,110,30))
        self.sectionNameEdit.setPlaceholderText("Section name")
        self.sectionNameEdit.setToolTip("Name of new section")

        self.sizeEdit = QDoubleSpinBox(self)
        self.sizeEdit.setGeometry(QRect(115,5,65,30))
        self.sizeEdit.setMaximum(100.0)
        self.sizeEdit.setToolTip("Size of section in percent")

        self.colorLabel = ColorChooser(self)
        self.colorLabel.setGeometry(QRect(185,8,25,25))

        self.displayedNameCheckBox = QCheckBox(self)
        self.displayedNameCheckBox.setGeometry(215, 5, 185, 30)
        self.displayedNameCheckBox.setText("Change displayed name")
        self.displayedNameCheckBox.setStyleSheet("font-size:11px;")

        self.displayedNameEdit = QLineEdit(self)
        self.displayedNameEdit.setGeometry(QRect(235,5,120,30))
        self.displayedNameEdit.setPlaceholderText("Displayed name")
        self.displayedNameEdit.setToolTip("Displayed name of new section")
        self.displayedNameEdit.setVisible(False)

        self.removeButton = QPushButton(self)
        self.removeButton.setGeometry(QRect(385,5,35,30))
        self.removeButton.setToolTip("Remove section")
        pixmap = QPixmap("./removeIcon.png")
        buttonIcon = QIcon(pixmap)
        self.removeButton.setIcon(buttonIcon)
        self.removeButton.setIconSize(QSize(25,25))

        self.connect(self.displayedNameCheckBox, QtCore.SIGNAL("clicked()"), self.changeDisplayedName)
        self.connect(self.removeButton, QtCore.SIGNAL("clicked()"), QtCore.SIGNAL("remove()"))
        self.connect(self.sizeEdit, QtCore.SIGNAL("valueChanged(double)"), self.changeSizeValue)

    def changeSizeValue(self):
        self.emit(QtCore.SIGNAL("sizeValueChanged(QWidget*)"), self)

    def changeDisplayedName(self):
        if self.displayedNameCheckBox.isChecked():
            self.displayedNameEdit.setVisible(True)
            self.displayedNameCheckBox.setText("")
        else:
            self.displayedNameEdit.setVisible((False))
            self.displayedNameCheckBox.setText("Change displayed name")

    def getName(self):
        return self.sectionNameEdit.text()

    def setSize(self, size):
        self.sizeEdit.setValue(size)

    def getSize(self):
        return self.sizeEdit.value()

    def getSectionData(self):
        name = self.sectionNameEdit.text()
        size = self.sizeEdit.text()
        color = self.colorLabel.getSelectedColor()
        displayedNameFlag = self.displayedNameCheckBox.isChecked()
        displayedName = self.displayedNameEdit.text()
        return [name, size, color, displayedNameFlag, displayedName]
class SettingsWidget(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)

        self.setFixedWidth(500)
        self.setFixedHeight(400)
        self.setStyleSheet("font-size:20px;")

        self.vLayout = QVBoxLayout()
        self.setLayout(self.vLayout)

        settingsLabel = QLabel(self)
        settingsLabel.setText("Default settings")
        settingsLabel.setStyleSheet("font-size:25px;")
        settingsLabel.setFixedWidth(500)
        settingsLabel.setAlignment(Qt.AlignCenter)
        self.vLayout.addWidget(settingsLabel)

        sectionColorLabel = QLabel(self)
        sectionColorLabel.setText("Section colors:")
        self.sectionColorChooser = ColorChooser()
        self.sectionColorChooser.setMaximumWidth(50)
        self.sectionSecondColorChooser = ColorChooser()
        self.sectionSecondColorChooser.setMaximumWidth(50)
        self.putInHorizontalLayout(sectionColorLabel, self.sectionColorChooser,
                                   self.sectionSecondColorChooser)

        subsectionColorLabel = QLabel(self)
        subsectionColorLabel.setText("Subsection colors: ")
        self.subsectionColorChooser = ColorChooser(self)
        self.subsectionColorChooser.setMaximumWidth(50)
        self.subsectionSecondColorChooser = ColorChooser(self)
        self.subsectionSecondColorChooser.setMaximumWidth(50)
        self.putInHorizontalLayout(subsectionColorLabel,
                                   self.subsectionColorChooser,
                                   self.subsectionSecondColorChooser)

        linacSectionSizeLabel = QLabel(self)
        linacSectionSizeLabel.setText("Linac section size: ")
        self.linacSectionSizeSpinBox = QDoubleSpinBox(self)
        self.linacSectionSizeSpinBox.setFixedWidth(100)
        self.linacSectionSizeSpinBox.setMaximum(100.0)
        self.putInHorizontalLayout(linacSectionSizeLabel,
                                   self.linacSectionSizeSpinBox)

        linacSubsectionSizeLabel = QLabel(self)
        linacSubsectionSizeLabel.setText("Linac subsection size: ")
        self.linacSubsectionSizeSpinBox = QDoubleSpinBox(self)
        self.linacSubsectionSizeSpinBox.setFixedWidth(100)
        self.linacSubsectionSizeSpinBox.setMaximum(100.0)
        self.putInHorizontalLayout(linacSubsectionSizeLabel,
                                   self.linacSubsectionSizeSpinBox)

        ringSectionSizeLabel = QLabel(self)
        ringSectionSizeLabel.setText("Ring section size: ")
        self.ringSectionSizeSpinBox = QDoubleSpinBox(self)
        self.ringSectionSizeSpinBox.setFixedWidth(100)
        self.ringSectionSizeSpinBox.setMaximum(100.0)
        self.putInHorizontalLayout(ringSectionSizeLabel,
                                   self.ringSectionSizeSpinBox)

        ringSubectionSizeLabel = QLabel(self)
        ringSubectionSizeLabel.setText("Ring subsection size: ")
        self.ringSubsectionSizeSpinBox = QDoubleSpinBox(self)
        self.ringSubsectionSizeSpinBox.setFixedWidth(100)
        self.ringSubsectionSizeSpinBox.setMaximum(100.0)
        self.putInHorizontalLayout(ringSubectionSizeLabel,
                                   self.ringSubsectionSizeSpinBox)

        centerCoordinatesLabel = QLabel(self)
        centerCoordinatesLabel.setText("Real coordinates of ring center:")
        self.centerCoordinatesEditX = QLineEdit()
        self.centerCoordinatesEditX.setPlaceholderText("X")
        self.centerCoordinatesEditX.setFixedWidth(80)
        self.centerCoordinatesEditY = QLineEdit()
        self.centerCoordinatesEditY.setPlaceholderText("Y")
        self.centerCoordinatesEditY.setFixedWidth(80)
        self.putInHorizontalLayout(centerCoordinatesLabel,
                                   self.centerCoordinatesEditX,
                                   self.centerCoordinatesEditY)

        showDeviceCaptionsLabel = QLabel(self)
        showDeviceCaptionsLabel.setText("Show device captions:")
        showDeviceCaptionsLabel.setFixedWidth(500)
        self.showDeviceCaptionsCheckBox = QCheckBox(self)
        self.putInHorizontalLayout(showDeviceCaptionsLabel,
                                   self.showDeviceCaptionsCheckBox)

        useDbParametersLabel = QLabel(self)
        useDbParametersLabel.setText("Use parameters from database")
        useDbParametersLabel.setFixedWidth(500)
        self.useDbParametersCheckBox = QCheckBox(self)
        self.putInHorizontalLayout(useDbParametersLabel,
                                   self.useDbParametersCheckBox)

        tangoHostLabel = QLabel(self)
        tangoHostLabel.setText("Tango Host")
        self.tangoHostEdit = QLineEdit(self)
        self.tangoHostEdit.setFixedHeight(25)
        self.tangoHostEdit.setText("127.0.0.1:10000")
        self.tangoHostEdit.setStyleSheet("font-size:18px;")
        self.putInHorizontalLayout(tangoHostLabel, self.tangoHostEdit)

        self.setDefaultSettings()

    def putInHorizontalLayout(self, label, edit, secondEdit=None):
        layout = QHBoxLayout()
        layout.addWidget(label, Qt.AlignLeft)
        layout.addWidget(edit, Qt.AlignRight)
        if secondEdit is not None:
            layout.addWidget(secondEdit, Qt.AlignRight)
        self.vLayout.addLayout(layout)

    def setDefaultSettings(self):
        self.linacSectionSizeSpinBox.setValue(25)
        self.linacSubsectionSizeSpinBox.setValue(50)
        self.ringSectionSizeSpinBox.setValue(25)
        self.ringSubsectionSizeSpinBox.setValue(33.33)
        self.centerCoordinatesEditX.setText("0")
        self.centerCoordinatesEditY.setText("0")
        self.showDeviceCaptionsCheckBox.setChecked(True)
        self.useDbParametersCheckBox.setChecked(True)

    def saveSettings(self):
        sectionFirstColor = str(self.sectionColorChooser.getSelectedColor())
        sectionSecondColor = str(
            self.sectionSecondColorChooser.getSelectedColor())
        subsectionColor = str(self.subsectionColorChooser.getSelectedColor())
        subsectionSecondColor = str(
            self.subsectionSecondColorChooser.getSelectedColor())
        linacSectionSize = float(self.linacSectionSizeSpinBox.value())
        linacSubsectionSize = float(self.linacSubsectionSizeSpinBox.value())
        ringSectionSize = float(self.ringSectionSizeSpinBox.value())
        ringSubsectionSize = float(self.ringSubsectionSizeSpinBox.value())
        centerCoordinateX = float(self.centerCoordinatesEditX.text())
        centerCoordinateY = float(self.centerCoordinatesEditY.text())
        deviceCaptions = bool(self.showDeviceCaptionsCheckBox.isChecked())
        parametersFromDb = bool(self.useDbParametersCheckBox.isChecked())
        tangoHost = str(self.tangoHostEdit.text())

        SettingsCloud.setParameter("sectionFirstColor", sectionFirstColor)
        SettingsCloud.setParameter("sectionSecondColor", sectionSecondColor)
        SettingsCloud.setParameter("subsectionFirstColor", subsectionColor)
        SettingsCloud.setParameter("subsectionSecondColor",
                                   subsectionSecondColor)
        SettingsCloud.setParameter("linacSectionSize", linacSectionSize)
        SettingsCloud.setParameter("linacSubsectionSize", linacSubsectionSize)
        SettingsCloud.setParameter("ringSectionSize", ringSectionSize)
        SettingsCloud.setParameter("ringSubsectionSize", ringSubsectionSize)
        SettingsCloud.setParameter("centerCoordinateX", centerCoordinateX)
        SettingsCloud.setParameter("centerCoordinateY", centerCoordinateY)
        SettingsCloud.setParameter("deviceCaptions", deviceCaptions)
        SettingsCloud.setParameter("parameterFromDb", parametersFromDb)
        TangoDeviceManager.setTangoDatabaseAddress(tangoHost)