예제 #1
0
 def __init__(self, color, parent=None):
     QtGui.QHBoxLayout.__init__(self)
     assert isinstance(color, QtGui.QColor)
     self.lineedit = QtGui.QLineEdit(color.name(), parent)
     self.connect(self.lineedit, QtCore.SIGNAL("editingFinished()"),
                  self.update_color)
     self.addWidget(self.lineedit)
     self.colorbtn = ColorButton(parent)
     self.colorbtn.color = color
     self.connect(self.colorbtn, QtCore.SIGNAL("colorChanged(QColor)"),
                  self.update_text)
     self.addWidget(self.colorbtn)
예제 #2
0
    def __init__(self,
                 data,
                 title="",
                 comment="",
                 icon=None,
                 parent=None,
                 apply=None):
        QtGui.QDialog.__init__(self, parent)

        self.apply_callback = apply

        # Form
        if isinstance(data[0][0], (list, tuple)):
            self.formwidget = FormTabWidget(data, comment=comment, parent=self)
        elif len(data[0]) == 3:
            self.formwidget = FormComboWidget(data,
                                              comment=comment,
                                              parent=self)
        else:
            self.formwidget = FormWidget(data, comment=comment, parent=self)
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.formwidget)

        self.float_fields = []
        self.formwidget.setup()

        # Button box
        self.bbox = bbox = QtGui.QDialogButtonBox(
            QtGui.QDialogButtonBox.Ok
            | QtGui.QDialogButtonBox.Cancel)
        self.connect(self.formwidget, QtCore.SIGNAL('update_buttons()'),
                     self.update_buttons)
        if self.apply_callback is not None:
            apply_btn = bbox.addButton(QtGui.QDialogButtonBox.Apply)
            self.connect(apply_btn, QtCore.SIGNAL("clicked()"), self.apply)
        self.connect(bbox, QtCore.SIGNAL("accepted()"),
                     QtCore.SLOT("accept()"))
        self.connect(bbox, QtCore.SIGNAL("rejected()"),
                     QtCore.SLOT("reject()"))
        layout.addWidget(bbox)

        self.setLayout(layout)

        self.setWindowTitle(title)
        if not isinstance(icon, QtGui.QIcon):
            icon = QtGui.QWidget().style().standardIcon(
                QtGui.QStyle.SP_MessageBoxQuestion)
        self.setWindowIcon(icon)
예제 #3
0
 def set_color(self, color):
     if color != self._color:
         self._color = color
         self.emit(QtCore.SIGNAL("colorChanged(QColor)"), self._color)
         pixmap = QtGui.QPixmap(self.iconSize())
         pixmap.fill(color)
         self.setIcon(QtGui.QIcon(pixmap))
예제 #4
0
    def __init__(self, datalist, comment="", parent=None):
        QtGui.QWidget.__init__(self, parent)
        layout = QtGui.QVBoxLayout()
        self.setLayout(layout)
        self.combobox = QtGui.QComboBox()
        layout.addWidget(self.combobox)

        self.stackwidget = QtGui.QStackedWidget(self)
        layout.addWidget(self.stackwidget)
        self.connect(self.combobox, QtCore.SIGNAL("currentIndexChanged(int)"),
                     self.stackwidget, QtCore.SLOT("setCurrentIndex(int)"))

        self.widgetlist = []
        for data, title, comment in datalist:
            self.combobox.addItem(title)
            widget = FormWidget(data, comment=comment, parent=self)
            self.stackwidget.addWidget(widget)
            self.widgetlist.append(widget)
예제 #5
0
 def __init__(self, parent=None):
     QtGui.QPushButton.__init__(self, parent)
     self.setFixedSize(20, 20)
     self.setIconSize(QtCore.QSize(12, 12))
     self.connect(self, QtCore.SIGNAL("clicked()"), self.choose_color)
     self._color = QtGui.QColor()
예제 #6
0
 def setup(self):
     for label, value in self.data:
         if DEBUG:
             print("value:", value)
         if label is None and value is None:
             # Separator: (None, None)
             self.formlayout.addRow(QtGui.QLabel(" "), QtGui.QLabel(" "))
             self.widgets.append(None)
             continue
         elif label is None:
             # Comment
             self.formlayout.addRow(QtGui.QLabel(value))
             self.widgets.append(None)
             continue
         elif tuple_to_qfont(value) is not None:
             field = FontLayout(value, self)
         elif is_color_like(value):
             field = ColorLayout(to_qcolor(value), self)
         elif isinstance(value, six.string_types):
             field = QtGui.QLineEdit(value, self)
         elif isinstance(value, (list, tuple)):
             if isinstance(value, tuple):
                 value = list(value)
             selindex = value.pop(0)
             field = QtGui.QComboBox(self)
             if isinstance(value[0], (list, tuple)):
                 keys = [key for key, _val in value]
                 value = [val for _key, val in value]
             else:
                 keys = value
             field.addItems(value)
             if selindex in value:
                 selindex = value.index(selindex)
             elif selindex in keys:
                 selindex = keys.index(selindex)
             elif not isinstance(selindex, int):
                 print("Warning: '%s' index is invalid (label: " \
                                 "%s, value: %s)" % (selindex, label, value), file=STDERR)
                 selindex = 0
             field.setCurrentIndex(selindex)
         elif isinstance(value, bool):
             field = QtGui.QCheckBox(self)
             if value:
                 field.setCheckState(QtCore.Qt.Checked)
             else:
                 field.setCheckState(QtCore.Qt.Unchecked)
         elif isinstance(value, float):
             field = QtGui.QLineEdit(repr(value), self)
             field.setValidator(QtGui.QDoubleValidator(field))
             dialog = self.get_dialog()
             dialog.register_float_field(field)
             self.connect(field, QtCore.SIGNAL('textChanged(QString)'),
                          lambda text: dialog.update_buttons())
         elif isinstance(value, int):
             field = QtGui.QSpinBox(self)
             field.setRange(-1e9, 1e9)
             field.setValue(value)
         elif isinstance(value, datetime.datetime):
             field = QtGui.QDateTimeEdit(self)
             field.setDateTime(value)
         elif isinstance(value, datetime.date):
             field = QtGui.QDateEdit(self)
             field.setDate(value)
         else:
             field = QtGui.QLineEdit(repr(value), self)
         self.formlayout.addRow(label, field)
         self.widgets.append(field)