def _create_item(self, path): """Helper to create a new list item.""" item = QListWidgetItem(path) item.setIcon(ima.icon('DirClosedIcon')) if path in self.read_only_path: item.setFlags(Qt.NoItemFlags | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) elif path in self.not_active_path: item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Unchecked) else: item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) return item
def update_list(self): """Update path list""" self.listwidget.clear() for name in self.pathlist + self.ro_pathlist: item = QListWidgetItem(name) item.setIcon(ima.icon('DirClosedIcon')) if name in self.ro_pathlist: item.setFlags(Qt.NoItemFlags | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) elif name in self.not_active_pathlist: item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Unchecked) else: item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) self.listwidget.addItem(item) self.refresh()
def update_list(self): """Update path list""" self.listwidget.clear() for name in self.pathlist+self.ro_pathlist: item = QListWidgetItem(name) item.setIcon(ima.icon('DirClosedIcon')) if name in self.ro_pathlist: item.setFlags(Qt.NoItemFlags | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) elif name in self.not_active_pathlist: item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Unchecked) else: item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) self.listwidget.addItem(item) self.refresh()
def add_data_item(self, data): """ Adds a `Data` object to the loaded data list widget. Parameters ---------- data : specutils.core.generic.Spectrum1DRef The `Data` object to add to the list widget. """ new_item = QListWidgetItem(data.name, self.contents.list_widget_data_list) new_item.setFlags(new_item.flags() | Qt.ItemIsEditable) new_item.setData(Qt.UserRole, data) self.contents.list_widget_data_list.setCurrentItem(new_item)
def _on_data_change(self, *event): components = getattr(type(self.state), 'component').get_choices(self.state) self.ui.list_component.clear() for component in components: if isinstance(component, ChoiceSeparator): item = QListWidgetItem(str(component)) item.setFlags(item.flags() & ~Qt.ItemIsSelectable) item.setForeground(Qt.gray) else: item = QListWidgetItem(component.label) item.setCheckState(Qt.Checked) self.ui.list_component.addItem(item)
def modelChanged(self): self._list.clear() items = self._model.getList() for item in items: list_item = QListWidgetItem(item) list_item.setFlags(list_item.flags() | Qt.ItemIsUserCheckable) if self._model.isValueSelected(item): list_item.setCheckState(Qt.Checked) else: list_item.setCheckState(Qt.Unchecked) self._list.addItem(list_item) self.filterList(self._search_box.filter())
def __init__(self, export_dict, viewer, parent=None): super().__init__(parent=parent) self.setWindowTitle("Export") self.export_dict = export_dict self.viewer = viewer() self.list_view = SearchableListWidget() self.check_state = np.zeros(len(export_dict), dtype=bool) self.check_state[...] = True for el in sorted(export_dict.keys()): item = QListWidgetItem(el) # noinspection PyTypeChecker item.setFlags(item.flags() | Qt.ItemIsUserCheckable) item.setCheckState(Qt.Checked) self.list_view.addItem(item) self.checked_num = len(export_dict) self.export_btn = QPushButton("Export") self.cancel_btn = QPushButton("Cancel") self.check_btn = QPushButton("Check all") self.uncheck_btn = QPushButton("Uncheck all") self.cancel_btn.clicked.connect(self.close) self.export_btn.clicked.connect(self.accept) self.check_btn.clicked.connect(self.check_all) self.uncheck_btn.clicked.connect(self.uncheck_all) self.list_view.itemSelectionChanged.connect(self.preview) self.list_view.itemChanged.connect(self.checked_change) layout = QVBoxLayout() info_layout = QHBoxLayout() info_layout.addWidget(self.list_view) info_layout.addWidget(self.viewer) layout.addLayout(info_layout) btn_layout = QHBoxLayout() btn_layout.addWidget(self.check_btn) btn_layout.addWidget(self.uncheck_btn) btn_layout.addStretch() btn_layout.addWidget(self.export_btn) btn_layout.addWidget(self.cancel_btn) layout.addLayout(btn_layout) self.setLayout(layout)
def _on_data_change(self, *event): components = getattr(type(self.state), 'component').get_choices(self.state) self.ui.list_component.clear() for (component, k) in zip(components, np.arange(0, len(components))): if isinstance(component, ChoiceSeparator): item = QListWidgetItem(str(component)) item.setFlags(item.flags() & ~Qt.ItemIsSelectable) item.setForeground(Qt.gray) else: item = QListWidgetItem(component.label) if self.checked_dictionary[self.state.data.label][k] == True: item.setCheckState(Qt.Checked) else: item.setCheckState(Qt.Unchecked) self.ui.list_component.addItem(item)
def _set_list_preview_items(self, *, items=None): """ Set items of the list for selecting channels in preview tab. If the list of items is not specified, then it is loaded from the respective data structure. Parameters ---------- items: list(str) The list of items. The list may be cleared by calling `self._set_cbox_channel_items(items=[])` """ self.list_preview.itemChanged.disconnect( self.list_preview_item_changed) self.list_preview.clear() if items is None: items = list(self.gpc.get_file_channel_list()) for s in items: wi = QListWidgetItem(s, self.list_preview) wi.setFlags(wi.flags() | Qt.ItemIsUserCheckable) wi.setFlags(wi.flags() & ~Qt.ItemIsSelectable) wi.setCheckState(Qt.Unchecked) # Adjust height so that it fits all the elements adjust_qlistwidget_height(self.list_preview, other_widgets=[self.group_preview, self]) # This will cause the preview data to be plotted (the plot is expected to be hidden, # since no channels were selected). Here we select the first channel in the list. for n, item in enumerate(items): state = Qt.Checked if self.gpc.is_dset_item_selected_for_preview( item) else Qt.Unchecked self.list_preview.item(n).setCheckState(state) self.list_preview.itemChanged.connect(self.list_preview_item_changed)
def __createListItem__(self, text: str): item = QListWidgetItem(text) item.setFlags(item.flags() | Qt.ItemIsEditable) return item