def headerData(self, section, orientation, role=Qt.DisplayRole): """Set header data""" if role != Qt.DisplayRole: return to_qvariant() labels = self.xlabels if orientation == Qt.Horizontal else self.ylabels if labels is None: return to_qvariant(int(section)) else: return to_qvariant(labels[section])
def data(self, index, role=Qt.DisplayRole): """Return a model data element""" if not index.isValid(): return to_qvariant() if role == Qt.DisplayRole: return self._display_data(index) elif role == Qt.BackgroundColorRole: return to_qvariant(get_color(self._data[index.row()][index.column()], .2)) elif role == Qt.TextAlignmentRole: return to_qvariant(int(Qt.AlignRight|Qt.AlignVCenter)) return to_qvariant()
def data(self, index, role=Qt.DisplayRole): """Return a model data element""" if not index.isValid(): return to_qvariant() if role == Qt.DisplayRole: return self._display_data(index) elif role == Qt.BackgroundColorRole: return to_qvariant( get_color(self._data[index.row()][index.column()], .2)) elif role == Qt.TextAlignmentRole: return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter)) return to_qvariant()
def headerData(self, section, orientation, role=Qt.DisplayRole): if role == Qt.TextAlignmentRole: if orientation == Qt.Horizontal: return to_qvariant(int(Qt.AlignHCenter|Qt.AlignVCenter)) return to_qvariant(int(Qt.AlignRight|Qt.AlignVCenter)) if role != Qt.DisplayRole: return to_qvariant() if orientation == Qt.Horizontal: if section == CONTEXT: return to_qvariant(_("Context")) elif section == NAME: return to_qvariant(_("Name")) elif section == MOD1: return to_qvariant(_("Mod1")) elif section == MOD2: return to_qvariant(_("Mod2")) elif section == MOD3: return to_qvariant(_("Mod3")) elif section == KEY: return to_qvariant(_("Key")) return to_qvariant()
def createEditor(self, parent, option, index): """Create editor widget""" model = index.model() value = model.get_value(index) if model._data.dtype.name == "bool": value = not value model.setData(index, to_qvariant(value)) return elif value is not np.ma.masked: editor = QLineEdit(parent) editor.setFont(get_font("arrayeditor")) editor.setAlignment(Qt.AlignCenter) if is_number(self.dtype): editor.setValidator(QDoubleValidator(editor)) self.connect(editor, SIGNAL("returnPressed()"), self.commitAndCloseEditor) return editor
def createEditor(self, parent, option, index): """Create editor widget""" model = index.model() value = model.get_value(index) if model._data.dtype.name == "bool": value = not value model.setData(index, to_qvariant(value)) return elif value is not np.ma.masked: editor = QLineEdit(parent) editor.setFont(get_font('arrayeditor')) editor.setAlignment(Qt.AlignCenter) if is_number(self.dtype): editor.setValidator(QDoubleValidator(editor)) self.connect(editor, SIGNAL("returnPressed()"), self.commitAndCloseEditor) return editor
def data(self, index, role=Qt.DisplayRole): if not index.isValid() or \ not (0 <= index.row() < len(self.shortcuts)): return to_qvariant() shortcut = self.shortcuts[index.row()] key = shortcut.key column = index.column() if role == Qt.DisplayRole: if column == CONTEXT: return to_qvariant(shortcut.context) elif column == NAME: return to_qvariant(shortcut.name) elif column == MOD1: return to_qvariant(Key.MODIFIERNAMES[key.modifiers[0]]) elif column == MOD2: return to_qvariant(Key.MODIFIERNAMES[key.modifiers[1]]) elif column == MOD3: return to_qvariant(Key.MODIFIERNAMES[key.modifiers[2]]) elif column == KEY: return to_qvariant(Key.KEYS[key.key]) elif role == Qt.TextAlignmentRole: return to_qvariant(int(Qt.AlignHCenter|Qt.AlignVCenter)) return to_qvariant()
def create_combobox(self, text, choices, option, default=NoDefault, tip=None): """choices: couples (name, key)""" label = QLabel(text) combobox = QComboBox() if tip is not None: combobox.setToolTip(tip) for name, key in choices: combobox.addItem(name, to_qvariant(key)) self.comboboxes[combobox] = (option, default) layout = QHBoxLayout() for subwidget in (label, combobox): layout.addWidget(subwidget) layout.addStretch(1) layout.setContentsMargins(0, 0, 0, 0) widget = QWidget(self) widget.setLayout(layout) return widget
def data(self, index, role=Qt.DisplayRole): """Cell content""" if not index.isValid(): return to_qvariant() value = self.get_value(index) if role == Qt.DisplayRole: if value is np.ma.masked: return "" else: return to_qvariant(self._format % value) elif role == Qt.TextAlignmentRole: return to_qvariant(int(Qt.AlignCenter | Qt.AlignVCenter)) elif role == Qt.BackgroundColorRole and self.bgcolor_enabled and value is not np.ma.masked: hue = self.hue0 + self.dhue * (self.vmax - self.color_func(value)) / (self.vmax - self.vmin) hue = float(np.abs(hue)) color = QColor.fromHsvF(hue, self.sat, self.val, self.alp) return to_qvariant(color) elif role == Qt.FontRole: return to_qvariant(get_font("arrayeditor")) return to_qvariant()
def data(self, index, role=Qt.DisplayRole): """Cell content""" if not index.isValid(): return to_qvariant() value = self.get_value(index) if role == Qt.DisplayRole: if value is np.ma.masked: return '' else: return to_qvariant(self._format % value) elif role == Qt.TextAlignmentRole: return to_qvariant(int(Qt.AlignCenter|Qt.AlignVCenter)) elif role == Qt.BackgroundColorRole and self.bgcolor_enabled\ and value is not np.ma.masked: hue = self.hue0+\ self.dhue*(self.vmax-self.color_func(value))\ /(self.vmax-self.vmin) hue = float(np.abs(hue)) color = QColor.fromHsvF(hue, self.sat, self.val, self.alp) return to_qvariant(color) elif role == Qt.FontRole: return to_qvariant(get_font('arrayeditor')) return to_qvariant()
def setModelData(self, editor, model, index): if index.column() in (MOD1, MOD2, MOD3, KEY): model.setData(index, to_qvariant(editor.currentText())) else: QItemDelegate.setModelData(self, editor, model, index)
def load_from_conf(self): """Load settings from configuration file""" for checkbox, (option, default) in self.checkboxes.items(): checkbox.setChecked(self.get_option(option, default)) self.connect(checkbox, SIGNAL("clicked(bool)"), lambda _foo, opt=option: self.has_been_modified(opt)) for radiobutton, (option, default) in self.radiobuttons.items(): radiobutton.setChecked(self.get_option(option, default)) self.connect(radiobutton, SIGNAL("toggled(bool)"), lambda _foo, opt=option: self.has_been_modified(opt)) for lineedit, (option, default) in self.lineedits.items(): lineedit.setText(self.get_option(option, default)) self.connect(lineedit, SIGNAL("textChanged(QString)"), lambda _foo, opt=option: self.has_been_modified(opt)) for spinbox, (option, default) in self.spinboxes.items(): spinbox.setValue(self.get_option(option, default)) self.connect(spinbox, SIGNAL('valueChanged(int)'), lambda _foo, opt=option: self.has_been_modified(opt)) for combobox, (option, default) in self.comboboxes.items(): value = self.get_option(option, default) for index in range(combobox.count()): data = from_qvariant(combobox.itemData(index), unicode) # For PyQt API v2, it is necessary to convert `data` to # unicode in case the original type was not a string, like an # integer for example (see SMlib.qt.compat.from_qvariant): if unicode(data) == unicode(value): break combobox.setCurrentIndex(index) self.connect(combobox, SIGNAL('currentIndexChanged(int)'), lambda _foo, opt=option: self.has_been_modified(opt)) for (fontbox, sizebox), option in self.fontboxes.items(): font = self.get_font(option) fontbox.setCurrentFont(font) sizebox.setValue(font.pointSize()) if option is None: property = 'plugin_font' else: property = option self.connect(fontbox, SIGNAL('currentIndexChanged(int)'), lambda _foo, opt=property: self.has_been_modified(opt)) self.connect(sizebox, SIGNAL('valueChanged(int)'), lambda _foo, opt=property: self.has_been_modified(opt)) for clayout, (option, default) in self.coloredits.items(): property = to_qvariant(option) edit = clayout.lineedit btn = clayout.colorbtn edit.setText(self.get_option(option, default)) self.connect(btn, SIGNAL('clicked()'), lambda opt=option: self.has_been_modified(opt)) self.connect(edit, SIGNAL("textChanged(QString)"), lambda _foo, opt=option: self.has_been_modified(opt)) for (clayout, cb_bold, cb_italic ), (option, default) in self.scedits.items(): edit = clayout.lineedit btn = clayout.colorbtn color, bold, italic = self.get_option(option, default) edit.setText(color) cb_bold.setChecked(bold) cb_italic.setChecked(italic) self.connect(btn, SIGNAL('clicked()'), lambda opt=option: self.has_been_modified(opt)) self.connect(edit, SIGNAL("textChanged(QString)"), lambda _foo, opt=option: self.has_been_modified(opt)) self.connect(cb_bold, SIGNAL("clicked(bool)"), lambda _foo, opt=option: self.has_been_modified(opt)) self.connect(cb_italic, SIGNAL("clicked(bool)"), lambda _foo, opt=option: self.has_been_modified(opt))
def _display_data(self, index): """Return a data element""" return to_qvariant(self._data[index.row()][index.column()])