def _fillTable(self): self._widgets = [] for track in self.tracks: item = QTreeWidgetItem([track['name'], 'ride']) self._list_widget.addTopLevelItem(item) cb = QComboBox() cb.addItems(['ride', 'run']) cb.setFocusPolicy(Qt.ClickFocus) cb.installEventFilter(self) self._list_widget.setItemWidget(item, 1, cb) self._widgets.append(cb)
def _init_layout(self): """ Create the GUI widgets (but leave them empty). """ hostname_combobox = QComboBox(parent=self) self._hostname_combobox = hostname_combobox hostname_combobox.setEditable(True) hostname_combobox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) for hostname in self._suggested_hostnames: hostname_combobox.addItem(hostname) # EventFilter is installed after everything else is initialized. (See below.) #hostname_combobox.installEventFilter(self) self._connect_button = QPushButton("Connect", parent=self, clicked=self._handle_new_hostname) hostname_layout = QHBoxLayout() hostname_layout.addWidget(hostname_combobox) hostname_layout.addWidget(self._connect_button) hostinfo_table = QTableWidget() hostinfo_table.setColumnCount(len(SERVER_INFO_FIELDS)) hostinfo_table.setHorizontalHeaderLabels(SERVER_INFO_FIELDS) hostinfo_table.horizontalHeader().setVisible(True) hostinfo_table.verticalHeader().setVisible(False) hostinfo_table.setRowCount(1) hostinfo_table.setItem(0, 0, QTableWidgetItem("Placeholder")) hostinfo_table.setVisible(False) hostinfo_table.resizeRowsToContents() hostinfo_table.horizontalHeader().setStretchLastSection(True) table_height = hostinfo_table.verticalHeader().sectionSize( 0) + hostinfo_table.rowHeight(0) hostinfo_table.resize(QSize(hostinfo_table.width(), table_height)) hostinfo_table.setMaximumSize(QSize(1000, table_height)) hostinfo_table.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) host_layout = QVBoxLayout() host_layout.addLayout(hostname_layout) host_layout.addWidget(hostinfo_table) host_groupbox = QGroupBox("DVID Host", parent=self) host_groupbox.setLayout(host_layout) host_groupbox.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) repo_treewidget = QTreeWidget(parent=self) repo_treewidget.setHeaderLabels( TREEVIEW_COLUMNS) # TODO: Add type, shape, axes, etc. repo_treewidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) repo_treewidget.itemSelectionChanged.connect( self._handle_data_selection) data_layout = QVBoxLayout() data_layout.addWidget(repo_treewidget) data_groupbox = QGroupBox("Data Volumes", parent=self) data_groupbox.setLayout(data_layout) node_listwidget = QListWidget(parent=self) node_listwidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) node_listwidget.itemSelectionChanged.connect(self._update_status) node_layout = QVBoxLayout() node_layout.addWidget(node_listwidget) node_groupbox = QGroupBox("Nodes", parent=self) node_groupbox.setLayout(node_layout) new_data_edit = QLineEdit(parent=self) new_data_edit.textEdited.connect(self._update_status) full_url_label = QLabel(parent=self) full_url_label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) text_flags = full_url_label.textInteractionFlags() full_url_label.setTextInteractionFlags(text_flags | Qt.TextSelectableByMouse) new_data_layout = QVBoxLayout() new_data_layout.addWidget(new_data_edit) new_data_groupbox = QGroupBox("New Data Volume", parent=self) new_data_groupbox.setLayout(new_data_layout) new_data_groupbox.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) buttonbox = QDialogButtonBox(Qt.Horizontal, parent=self) buttonbox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) buttonbox.accepted.connect(self.accept) buttonbox.rejected.connect(self.reject) buttonbox.button(QDialogButtonBox.Ok).setEnabled(False) layout = QVBoxLayout() layout.addWidget(host_groupbox) layout.addWidget(data_groupbox) layout.addWidget(node_groupbox) if self._mode == "specify_new": layout.addWidget(new_data_groupbox) else: new_data_groupbox.hide() layout.addWidget(full_url_label) layout.addWidget(buttonbox) # Stretch factors layout.setStretchFactor(data_groupbox, 3) layout.setStretchFactor(node_groupbox, 1) self.setLayout(layout) self.setWindowTitle("Select DVID Volume") self.resize(1000, 1000) # Initially disabled data_groupbox.setEnabled(False) node_groupbox.setEnabled(False) new_data_groupbox.setEnabled(False) # Set tab order self.setTabOrder(hostname_combobox, repo_treewidget) self.setTabOrder(repo_treewidget, node_listwidget) self.setTabOrder(node_listwidget, buttonbox) # Save instance members self._hostinfo_table = hostinfo_table self._data_groupbox = data_groupbox self._node_groupbox = node_groupbox self._new_data_groupbox = new_data_groupbox self._repo_treewidget = repo_treewidget self._node_listwidget = node_listwidget self._new_data_edit = new_data_edit self._full_url_label = full_url_label self._buttonbox = buttonbox # Finally install eventfilter (after everything is initialized) hostname_combobox.installEventFilter(self)
class ComboBoxDelegate(QItemDelegate): def __init__(self, parent, itemslist=["a", "b", "c"], db=""): QItemDelegate.__init__(self, parent) # itemslist = ["a", "b", "c"] self.itemslist = itemslist self.parent = parent self.db = db def createEditor(self, parent, option, index): self.editor = QComboBox(parent) self.editor.addItems(self.itemslist) self.editor.setCurrentIndex(0) self.editor.installEventFilter(self) # self.connect(self.editor, SIGNAL("currentIndexChanged(int)"), self.editorChanged) return self.editor def setEditorData(self, editor, index): curtxt = index.data(Qt.DisplayRole) # print(curtxt, "curtxt:---") # print(type(curtxt)== QPyNullVariant ) if type(curtxt) == type(1): curindx = int(index.data(Qt.DisplayRole)) curtxt = self.itemslist[curindx] elif type(curtxt)== QPyNullVariant: curtxt = "" pos = self.editor.findText(curtxt) if pos == -1: pos = 0 self.editor.setCurrentIndex(pos) def setModelData(self,editor,model,index): curindx = self.editor.currentIndex() text = self.itemslist[curindx] model.setData(index, text) # update the student sn newClassname = index.sibling(index.row(),1).data() stusn = index.sibling(index.row(),2).data() stuname = index.sibling(index.row(),3).data() query = QSqlQuery(self.db) strsql = "select count(*), stusn from student where classname='" + newClassname + "' and stuname='" + stuname + "'" query.exec_(strsql) query.next() if query.value(0) == 0: ## the student is not in this class # print(query.value(0), "count**", strsql) ret = query.exec_("select max(stusn) from student where classname = '" + newClassname + "'") query.next() tmpsn = query.value(0) if type(tmpsn)== QPyNullVariant: newstusn = "01" else: newstusn = str(int(query.value(0)) + 1).zfill(2) # if newClassname != self.oldclassname: model.setData(index.sibling(index.row(), 2), newstusn) else: model.setData(index.sibling(index.row(), 2), query.value(1))
def _init_layout(self): """ Create the GUI widgets (but leave them empty). """ hostname_combobox = QComboBox(parent=self) self._hostname_combobox = hostname_combobox hostname_combobox.setEditable(True) hostname_combobox.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) hostname_combobox.installEventFilter(self) for hostname in self._suggested_hostnames: hostname_combobox.addItem(hostname) self._connect_button = QPushButton("Connect", parent=self, clicked=self._handle_new_hostname) hostname_layout = QHBoxLayout() hostname_layout.addWidget(hostname_combobox) hostname_layout.addWidget(self._connect_button) hostname_groupbox = QGroupBox("DVID Host", parent=self) hostname_groupbox.setLayout(hostname_layout) hostname_groupbox.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) data_treewidget = QTreeWidget(parent=self) data_treewidget.setHeaderLabels( ["Data"]) # TODO: Add type, shape, axes, etc. data_treewidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) data_treewidget.itemSelectionChanged.connect( self._handle_data_selection) data_layout = QVBoxLayout() data_layout.addWidget(data_treewidget) data_groupbox = QGroupBox("Data Volumes", parent=self) data_groupbox.setLayout(data_layout) node_listwidget = QListWidget(parent=self) node_listwidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) node_listwidget.itemSelectionChanged.connect(self._update_display) node_layout = QVBoxLayout() node_layout.addWidget(node_listwidget) node_groupbox = QGroupBox("Nodes", parent=self) node_groupbox.setLayout(node_layout) new_data_edit = QLineEdit(parent=self) new_data_edit.textEdited.connect(self._update_display) full_url_label = QLabel(parent=self) full_url_label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) text_flags = full_url_label.textInteractionFlags() full_url_label.setTextInteractionFlags(text_flags | Qt.TextSelectableByMouse) new_data_layout = QVBoxLayout() new_data_layout.addWidget(new_data_edit) new_data_groupbox = QGroupBox("New Data Volume", parent=self) new_data_groupbox.setLayout(new_data_layout) new_data_groupbox.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) buttonbox = QDialogButtonBox(Qt.Horizontal, parent=self) buttonbox.setStandardButtons(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) buttonbox.accepted.connect(self.accept) buttonbox.rejected.connect(self.reject) buttonbox.button(QDialogButtonBox.Ok).setEnabled(False) layout = QVBoxLayout() layout.addWidget(hostname_groupbox) layout.addWidget(data_groupbox) layout.addWidget(node_groupbox) if self._mode == "specify_new": layout.addWidget(new_data_groupbox) else: new_data_groupbox.hide() layout.addWidget(full_url_label) layout.addWidget(buttonbox) # Stretch factors layout.setStretchFactor(data_groupbox, 3) layout.setStretchFactor(node_groupbox, 1) self.setLayout(layout) self.setWindowTitle("Select DVID Volume") # Initially disabled data_groupbox.setEnabled(False) node_groupbox.setEnabled(False) new_data_groupbox.setEnabled(False) # Save instance members self._data_groupbox = data_groupbox self._node_groupbox = node_groupbox self._new_data_groupbox = new_data_groupbox self._data_treewidget = data_treewidget self._node_listwidget = node_listwidget self._new_data_edit = new_data_edit self._full_url_label = full_url_label self._buttonbox = buttonbox
class ComboBoxDelegate(QItemDelegate): def __init__(self, parent, itemslist=["a", "b", "c"]): QItemDelegate.__init__(self, parent) # itemslist = ["a", "b", "c"] self.itemslist = itemslist self.parent = parent # def paint(self, painter, option, index): # # Get Item Data # value = index.data(Qt.DisplayRole).toInt()[0] # # value = self.itemslist[index.data(QtCore.Qt.DisplayRole).toInt()[0]] # # fill style options with item data # style = QApplication.style() # opt = QStyleOptionComboBox() # opt.currentText = str(self.itemslist[value]) # opt.rect = option.rect # # draw item data as ComboBox # style.drawComplexControl(QStyle.CC_ComboBox, opt, painter) # self.parent.openPersistentEditor(index) def createEditor(self, parent, option, index): ##get the "check" value of the row # for row in range(self.parent.model.rowCount(self.parent)): # print row self.editor = QComboBox(parent) self.editor.addItems(self.itemslist) self.editor.setCurrentIndex(0) self.editor.installEventFilter(self) # self.connect(self.editor, SIGNAL("currentIndexChanged(int)"), self.editorChanged) return self.editor # def setEditorData(self, editor, index): # value = index.data(QtCore.Qt.DisplayRole).toInt()[0] # editor.setCurrentIndex(value) def setEditorData(self, editor, index): curtxt = index.data(Qt.DisplayRole) # print(type(curtxt)== QPyNullVariant ) if type(curtxt) == type(1): curindx = int(index.data(Qt.DisplayRole)) curtxt = self.itemslist[curindx] elif type(curtxt)== QPyNullVariant: curtxt = "" pos = self.editor.findText(curtxt) if pos == -1: pos = 0 self.editor.setCurrentIndex(pos) def setModelData(self,editor,model,index): curindx = self.editor.currentIndex() text = self.itemslist[curindx] model.setData(index, text) def updateEditorGeometry(self, editor, option, index): self.editor.setGeometry(option.rect) def editorChanged(self, index): check = self.editor.itemText(index) id_seq = self.parent.selectedIndexes[0][0] update.updateCheckSeq(self.parent.db, id_seq, check)
def _init_layout(self): """ Create the GUI widgets (but leave them empty). """ hostname_combobox = QComboBox(parent=self) self._hostname_combobox = hostname_combobox hostname_combobox.setEditable(True) hostname_combobox.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Maximum ) for hostname in self._suggested_hostnames: hostname_combobox.addItem( hostname ) # EventFilter is installed after everything else is initialized. (See below.) #hostname_combobox.installEventFilter(self) self._connect_button = QPushButton("Connect", parent=self, clicked=self._handle_new_hostname) hostname_layout = QHBoxLayout() hostname_layout.addWidget( hostname_combobox ) hostname_layout.addWidget( self._connect_button ) hostinfo_table = QTableWidget() hostinfo_table.setColumnCount(len(SERVER_INFO_FIELDS)) hostinfo_table.setHorizontalHeaderLabels(SERVER_INFO_FIELDS) hostinfo_table.horizontalHeader().setVisible(True) hostinfo_table.verticalHeader().setVisible(False) hostinfo_table.setRowCount(1) hostinfo_table.setItem(0,0, QTableWidgetItem("Placeholder")) hostinfo_table.setVisible(False) hostinfo_table.resizeRowsToContents() hostinfo_table.horizontalHeader().setStretchLastSection(True) table_height = hostinfo_table.verticalHeader().sectionSize(0) + hostinfo_table.rowHeight(0) hostinfo_table.resize( QSize( hostinfo_table.width(), table_height ) ) hostinfo_table.setMaximumSize( QSize( 1000, table_height ) ) hostinfo_table.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed) host_layout = QVBoxLayout() host_layout.addLayout(hostname_layout) host_layout.addWidget(hostinfo_table) host_groupbox = QGroupBox("DVID Host", parent=self) host_groupbox.setLayout( host_layout ) host_groupbox.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Preferred ) repo_treewidget = QTreeWidget(parent=self) repo_treewidget.setHeaderLabels( TREEVIEW_COLUMNS ) # TODO: Add type, shape, axes, etc. repo_treewidget.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Preferred ) repo_treewidget.itemSelectionChanged.connect( self._handle_data_selection ) data_layout = QVBoxLayout() data_layout.addWidget( repo_treewidget ) data_groupbox = QGroupBox("Data Volumes", parent=self) data_groupbox.setLayout( data_layout ) node_listwidget = QListWidget(parent=self) node_listwidget.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Preferred ) node_listwidget.itemSelectionChanged.connect( self._update_status ) node_layout = QVBoxLayout() node_layout.addWidget( node_listwidget ) node_groupbox = QGroupBox("Nodes", parent=self) node_groupbox.setLayout( node_layout ) new_data_edit = QLineEdit(parent=self) new_data_edit.textEdited.connect( self._update_status ) full_url_label = QLabel(parent=self) full_url_label.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Maximum ) text_flags = full_url_label.textInteractionFlags() full_url_label.setTextInteractionFlags( text_flags | Qt.TextSelectableByMouse ) new_data_layout = QVBoxLayout() new_data_layout.addWidget( new_data_edit ) new_data_groupbox = QGroupBox("New Data Volume", parent=self) new_data_groupbox.setLayout( new_data_layout ) new_data_groupbox.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Maximum ) buttonbox = QDialogButtonBox( Qt.Horizontal, parent=self ) buttonbox.setStandardButtons( QDialogButtonBox.Ok | QDialogButtonBox.Cancel ) buttonbox.accepted.connect( self.accept ) buttonbox.rejected.connect( self.reject ) buttonbox.button(QDialogButtonBox.Ok).setEnabled(False) layout = QVBoxLayout() layout.addWidget( host_groupbox ) layout.addWidget( data_groupbox ) layout.addWidget( node_groupbox ) if self._mode == "specify_new": layout.addWidget( new_data_groupbox ) else: new_data_groupbox.hide() layout.addWidget( full_url_label ) layout.addWidget( buttonbox ) # Stretch factors layout.setStretchFactor(data_groupbox, 3) layout.setStretchFactor(node_groupbox, 1) self.setLayout(layout) self.setWindowTitle( "Select DVID Volume" ) self.resize(1000, 1000) # Initially disabled data_groupbox.setEnabled(False) node_groupbox.setEnabled(False) new_data_groupbox.setEnabled(False) # Set tab order self.setTabOrder(hostname_combobox, repo_treewidget) self.setTabOrder(repo_treewidget, node_listwidget) self.setTabOrder(node_listwidget, buttonbox) # Save instance members self._hostinfo_table = hostinfo_table self._data_groupbox = data_groupbox self._node_groupbox = node_groupbox self._new_data_groupbox = new_data_groupbox self._repo_treewidget = repo_treewidget self._node_listwidget = node_listwidget self._new_data_edit = new_data_edit self._full_url_label = full_url_label self._buttonbox = buttonbox # Finally install eventfilter (after everything is initialized) hostname_combobox.installEventFilter(self)
def _init_layout(self): """ Create the GUI widgets (but leave them empty). """ hostname_combobox = QComboBox(parent=self) self._hostname_combobox = hostname_combobox hostname_combobox.setEditable(True) hostname_combobox.setSizePolicy( QSizePolicy.Expanding, QSizePolicy.Maximum ) hostname_combobox.installEventFilter(self) for hostname in self._suggested_hostnames: hostname_combobox.addItem( hostname ) self._connect_button = QPushButton("Connect", parent=self, clicked=self._handle_new_hostname) hostname_layout = QHBoxLayout() hostname_layout.addWidget( hostname_combobox ) hostname_layout.addWidget( self._connect_button ) hostname_groupbox = QGroupBox("DVID Host", parent=self) hostname_groupbox.setLayout( hostname_layout ) hostname_groupbox.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Maximum ) data_treewidget = QTreeWidget(parent=self) data_treewidget.setHeaderLabels( ["Data"] ) # TODO: Add type, shape, axes, etc. data_treewidget.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Preferred ) data_treewidget.itemSelectionChanged.connect( self._handle_data_selection ) data_layout = QVBoxLayout() data_layout.addWidget( data_treewidget ) data_groupbox = QGroupBox("Data Volumes", parent=self) data_groupbox.setLayout( data_layout ) node_listwidget = QListWidget(parent=self) node_listwidget.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Preferred ) node_listwidget.itemSelectionChanged.connect( self._update_display ) node_layout = QVBoxLayout() node_layout.addWidget( node_listwidget ) node_groupbox = QGroupBox("Nodes", parent=self) node_groupbox.setLayout( node_layout ) new_data_edit = QLineEdit(parent=self) new_data_edit.textEdited.connect( self._update_display ) full_url_label = QLabel(parent=self) full_url_label.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Maximum ) text_flags = full_url_label.textInteractionFlags() full_url_label.setTextInteractionFlags( text_flags | Qt.TextSelectableByMouse ) new_data_layout = QVBoxLayout() new_data_layout.addWidget( new_data_edit ) new_data_groupbox = QGroupBox("New Data Volume", parent=self) new_data_groupbox.setLayout( new_data_layout ) new_data_groupbox.setSizePolicy( QSizePolicy.Preferred, QSizePolicy.Maximum ) buttonbox = QDialogButtonBox( Qt.Horizontal, parent=self ) buttonbox.setStandardButtons( QDialogButtonBox.Ok | QDialogButtonBox.Cancel ) buttonbox.accepted.connect( self.accept ) buttonbox.rejected.connect( self.reject ) buttonbox.button(QDialogButtonBox.Ok).setEnabled(False) layout = QVBoxLayout() layout.addWidget( hostname_groupbox ) layout.addWidget( data_groupbox ) layout.addWidget( node_groupbox ) if self._mode == "specify_new": layout.addWidget( new_data_groupbox ) else: new_data_groupbox.hide() layout.addWidget( full_url_label ) layout.addWidget( buttonbox ) # Stretch factors layout.setStretchFactor(data_groupbox, 3) layout.setStretchFactor(node_groupbox, 1) self.setLayout(layout) self.setWindowTitle( "Select DVID Volume" ) # Initially disabled data_groupbox.setEnabled(False) node_groupbox.setEnabled(False) new_data_groupbox.setEnabled(False) # Save instance members self._data_groupbox = data_groupbox self._node_groupbox = node_groupbox self._new_data_groupbox = new_data_groupbox self._data_treewidget = data_treewidget self._node_listwidget = node_listwidget self._new_data_edit = new_data_edit self._full_url_label = full_url_label self._buttonbox = buttonbox