def __init__(self, fileName, controller, parent = None): super(TagStoreDialog, self).__init__(parent) self.set_controller(controller) # initially use an empty list wList = "" self.tagLine = TagStoreLineEdit() self.tagLine.selectAll() self.completer = TagStoreCompleter(wList, self.tagLine); self.completer.setCaseSensitivity(Qt.CaseInsensitive) QObject.connect(self.tagLine, SIGNAL("text_changed(PyQt_PyObject, PyQt_PyObject)"), self.completer.update) QObject.connect(self.completer, SIGNAL("activated(QString)"), self.tagLine.complete_text) fileLabel = QLabel(_("Add tag to new file: %s" % (fileName))) ## prepare a label for presenting the recently used tags recentLabel = QLabel(_("Recently used tags:")) self.recentValueLabel = QLabel("") ## prepare a label for presenting the mot popular tags incl. the usage count popularLabel = QLabel(_("Most popular Tags:")) self.popularValueLabel = QLabel("") self.completer.setWidget(self.tagLine) #self.tagLine.setCompleter(completer); layout = QVBoxLayout() layout.addWidget(fileLabel) layout.addWidget(recentLabel) layout.addWidget(self.recentValueLabel) layout.addWidget(popularLabel) layout.addWidget(self.popularValueLabel) layout.addWidget(self.tagLine) self.setLayout(layout) self.tagLine.setFocus() #self.connect(self.tagLine, SIGNAL("returnPressed()"), self.updateUi) self.setWindowTitle(_("Tagstore Dialog"))
class TagStoreDialog(QDialog): ''' class to build a simple dialog for testing purpose ''' def __init__(self, fileName, controller, parent = None): super(TagStoreDialog, self).__init__(parent) self.set_controller(controller) # initially use an empty list wList = "" self.tagLine = TagStoreLineEdit() self.tagLine.selectAll() self.completer = TagStoreCompleter(wList, self.tagLine); self.completer.setCaseSensitivity(Qt.CaseInsensitive) QObject.connect(self.tagLine, SIGNAL("text_changed(PyQt_PyObject, PyQt_PyObject)"), self.completer.update) QObject.connect(self.completer, SIGNAL("activated(QString)"), self.tagLine.complete_text) fileLabel = QLabel(_("Add tag to new file: %s" % (fileName))) ## prepare a label for presenting the recently used tags recentLabel = QLabel(_("Recently used tags:")) self.recentValueLabel = QLabel("") ## prepare a label for presenting the mot popular tags incl. the usage count popularLabel = QLabel(_("Most popular Tags:")) self.popularValueLabel = QLabel("") self.completer.setWidget(self.tagLine) #self.tagLine.setCompleter(completer); layout = QVBoxLayout() layout.addWidget(fileLabel) layout.addWidget(recentLabel) layout.addWidget(self.recentValueLabel) layout.addWidget(popularLabel) layout.addWidget(self.popularValueLabel) layout.addWidget(self.tagLine) self.setLayout(layout) self.tagLine.setFocus() #self.connect(self.tagLine, SIGNAL("returnPressed()"), self.updateUi) self.setWindowTitle(_("Tagstore Dialog")) def set_controller(self, controller): self.__controller = controller def get_controller(self): return self.__controller def set_recent_tags(self, tagString): self.recentValueLabel.setText(tagString) def set_popular_tags(self, tagString): self.popularValueLabel.setText(tagString) def closeEvent(self, event): ''' reimplementation of the closeEvent method check if there are tags provided by the user before quitting the dialog ''' if self.tagLine.text() == "": if not self.okToClose(): event.ignore() else: self.handle_tag_writing() def okToClose(self): reply = QMessageBox.question(self, _("No tag provided"), _("Sure you want to close the dialog?"), QMessageBox.Yes|QMessageBox.No) if reply == QMessageBox.Yes: return True return False def handle_tag_writing(self): ''' do the necessary actions to write tags of the textfield to ''' self.get_controller().write_tags(self.tagLine.text()) def set_taglist(self, newTagList): self.completer.set_taglist(newTagList)