class CaseList(QWidget): def __init__(self): QWidget.__init__(self) addHelpToWidget(self, "init/case_list") layout = QVBoxLayout() self._list = QListWidget(self) self._list.setMinimumHeight(100) self._list.setMaximumHeight(250) self._default_selection_mode = self._list.selectionMode() self.setSelectable(False) layout.addWidget(QLabel("Available Cases:")) layout.addWidget(self._list) self._addRemoveWidget = AddRemoveWidget(self.addItem, self.removeItem, horizontal=True) self._addRemoveWidget.enableRemoveButton(False) layout.addWidget(self._addRemoveWidget) self._title = "New keyword" self._description = "Enter name of keyword:" self.setLayout(layout) ERT.ertChanged.connect(self.updateList) self.updateList() def setSelectable(self, selectable): if selectable: self._list.setSelectionMode(self._default_selection_mode) else: self._list.setSelectionMode(QAbstractItemView.NoSelection) def addItem(self): dialog = ValidatedDialog("New case", "Enter name of new case:", getAllCases()) new_case_name = dialog.showAndTell() if not new_case_name == "": selectOrCreateNewCase(new_case_name) def removeItem(self): message = "Support for removal of items has not been implemented!" QMessageBox.information(self, "Not implemented!", message) def updateList(self): """Retrieves data from the model and inserts it into the list""" case_list = getAllCases() self._list.clear() for case in case_list: self._list.addItem(case)
class KeywordList(HelpedWidget): """Shows a list of keywords. The data structure expected and sent to the getter and setter is an array of values.""" def __init__(self, model, list_label="", help_link=""): HelpedWidget.__init__(self, list_label, help_link) assert isinstance(model, ListModelMixin) self.model = model self.keyword_list = [] self.list = QListWidget(self) self.list.setMinimumHeight(100) self.list.setMaximumHeight(150) self.default_selection_mode = self.list.selectionMode() self.addWidget(self.list) self.addRemoveWidget = AddRemoveWidget(self.addItem, self.removeItem) self.addWidget(self.addRemoveWidget) self.title = "New keyword" self.description = "Enter name of keyword:" self.model.observable().attach(ListModelMixin.LIST_CHANGED_EVENT, self.modelChanged) self.modelChanged() def setSelectable(self, selectable): if selectable: self.list.setSelectionMode(self.default_selection_mode) else: self.list.setSelectionMode(QAbstractItemView.NoSelection) def setPopupLabels(self, title, description): """Change the labels of the default popup.""" self.title = title self.description = description def newKeywordPopup(self, keyword_list): """ Pops up a message box asking for a new keyword. Override this and return a string to customize the input dialog - Empty string equals canceled. The provided list are the already defined keywords """ new_keyword, ok = QInputDialog.getText(self, self.tr(self.title), self.tr(self.description), QLineEdit.Normal) if ok: return str(new_keyword).strip() else: return "" def addItem(self): """Called by the add button to insert a new keyword""" new_keyword = self.newKeywordPopup(self.keyword_list) if not new_keyword == "": self.model.addItem(new_keyword) def removeItem(self): """Called by the remove button to remove a selected keyword""" if not self.list.currentItem() is None: row = self.list.currentRow() try: self.model.removeItem(self.keyword_list[row]) except NotImplementedError: message = "Support for removal of items has not been implemented!" QMessageBox.information(self, "Not implemented!", message) def modelChanged(self): """Retrieves data from the model and inserts it into the list""" keywords = self.model.getList() self.list.clear() self.keyword_list = keywords for keyword in keywords: self.list.addItem(keyword)
class KeywordList(HelpedWidget): """Shows a list of keywords. The data structure expected and sent to the getter and setter is an array of values.""" def __init__(self, model, list_label="", help_link=""): HelpedWidget.__init__(self, list_label, help_link) assert isinstance(model, ListModelMixin) self.model = model self.keyword_list = [] self.list = QListWidget(self) self.list.setMinimumHeight(100) self.list.setMaximumHeight(150) self.default_selection_mode = self.list.selectionMode() self.addWidget(self.list) self.addRemoveWidget = AddRemoveWidget(self.addItem, self.removeItem) self.addWidget(self.addRemoveWidget) self.title = "New keyword" self.description = "Enter name of keyword:" self.model.observable().attach(ListModelMixin.LIST_CHANGED_EVENT, self.modelChanged) self.modelChanged() def setSelectable(self, selectable): if selectable: self.list.setSelectionMode(self.default_selection_mode) else: self.list.setSelectionMode(QAbstractItemView.NoSelection) def setPopupLabels(self, title, description): """Change the labels of the default popup.""" self.title = title self.description = description def newKeywordPopup(self, keyword_list): """ Pops up a message box asking for a new keyword. Override this and return a string to customize the input dialog - Empty string equals canceled. The provided list are the already defined keywords """ new_keyword, ok = QInputDialog.getText(self, self.tr(self.title), self.tr(self.description), QLineEdit.Normal) if ok: return str(new_keyword).strip() else: return "" def addItem(self): """Called by the add button to insert a new keyword""" new_keyword = self.newKeywordPopup(self.keyword_list) if not new_keyword == "": self.model.addItem(new_keyword) def removeItem(self): """Called by the remove button to remove a selected keyword""" if not self.list.currentItem() is None: row = self.list.currentRow() try: self.model.removeItem(self.keyword_list[row]) except NotImplementedError: message = "Support for removal of items has not been implemented!" QMessageBox.information(self, "Not implemented!", message) def modelChanged(self): """Retrieves data from the model and inserts it into the list""" keywords = self.model.getList() self.list.clear() self.keyword_list = keywords for keyword in keywords: self.list.addItem(keyword) def cleanup(self): self.model.observable().detach(ListModelMixin.LIST_CHANGED_EVENT, self.modelChanged)