def __init__(self, mobject, undolen=defaults.OBJECT_EDIT_UNDO_LENGTH, parent=None): QTableView.__init__(self, parent) #self.setEditTriggers(self.DoubleClicked | self.SelectedClicked | self.EditKeyPressed) vh = self.verticalHeader() vh.setVisible(False) hh = self.horizontalHeader() hh.setStretchLastSection(True) self.setAlternatingRowColors(True) self.resizeColumnsToContents() self.setModel(ObjectEditModel(mobject, undolen=undolen)) self.colorButton = QPushButton() self.colorDialog = QColorDialog() self.textEdit = QTextEdit() try: notesIndex = self.model().fields.index("Notes") self.setIndexWidget(self.model().index(notesIndex, 1), self.textEdit) info = moose.Annotator(self.model().mooseObject.path + '/info') self.textEdit.setText((info.getField('notes'))) self.setRowHeight(notesIndex, self.rowHeight(notesIndex) * 3) # self.colorDialog.colorSelected.connect( # lambda color: # # self.setColor(getColor(self.model().mooseObject.path+'/info')[1]) except: pass try: colorIndex = self.model().fields.index("Color") self.colorButton.clicked.connect(self.colorDialog.show) self.colorButton.setFocusPolicy(PyQt5.QtCore.Qt.NoFocus) self.colorDialog.colorSelected.connect( lambda color: self.colorButton.setStyleSheet( "QPushButton {" + "background-color: {0}; color: {0};". format(color.name()) + "}")) self.setIndexWidget(self.model().index(colorIndex, 1), self.colorButton) # self.colorDialog.colorSelected.connect( # lambda color: # self.setColor(getColor(self.model().mooseObject.path + '/info')[1]) except: pass print('Created view with %s' % (mobject))
def __init__(self, mobject, undolen=defaults.OBJECT_EDIT_UNDO_LENGTH, parent=None): QtGui.QTableView.__init__(self, parent) #self.setEditTriggers(self.DoubleClicked | self.SelectedClicked | self.EditKeyPressed) vh = self.verticalHeader() vh.setVisible(False) hh = self.horizontalHeader() hh.setStretchLastSection(True) self.setAlternatingRowColors(True) self.resizeColumnsToContents() self.setModel(ObjectEditModel(mobject, undolen=undolen)) self.colorButton = QtGui.QPushButton() self.colorDialog = QtGui.QColorDialog() self.textEdit = QTextEdit() try: notesIndex = self.model().fields.index("Notes") self.setIndexWidget(self.model().index(notesIndex,1), self.textEdit) info = moose.Annotator(self.model().mooseObject.path+'/info') self.textEdit.setText(QtCore.QString(info.getField('notes'))) self.setRowHeight(notesIndex, self.rowHeight(notesIndex) * 3) # self.colorDialog.colorSelected.connect( # lambda color: # # self.setColor(getColor(self.model().mooseObject.path+'/info')[1]) except: pass try: colorIndex = self.model().fields.index("Color") self.colorButton.clicked.connect(self.colorDialog.show) self.colorButton.setFocusPolicy(PyQt4.QtCore.Qt.NoFocus) self.colorDialog.colorSelected.connect( lambda color: self.colorButton.setStyleSheet( "QPushButton {" + "background-color: {0}; color: {0};".format(color.name()) + "}" ) ) self.setIndexWidget(self.model().index(colorIndex,1), self.colorButton) # self.colorDialog.colorSelected.connect( # lambda color: # self.setColor(getColor(self.model().mooseObject.path+'/info')[1]) except: pass print 'Created view with', mobject