Wed, 05 Feb 2014 19:13:12 +0100
Implemented template tags 'f' to 'i' (except 'if').
# -*- coding: utf-8 -*- # Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de> # """ Module implementing a dialog to enter data for the creation of a tag. """ from PyQt4.QtCore import Qt from PyQt4.QtGui import QDialog, QDialogButtonBox, QVBoxLayout, QLabel from E5Gui.E5LineEdit import E5ClearableLineEdit class DjangoTagInputDialog(QDialog): """ Class implementing a dialog to enter data for the creation of a tag. """ def __init__(self, labels, defaults=None, parent=None): super(DjangoTagInputDialog, self).__init__(parent) assert 0 < len(labels) < 6 # max 5 entries allowed self.__inputs = [] self.__topLayout = QVBoxLayout(self) index = 0 for label in labels: self.__topLayout.addWidget(QLabel(label, self)) entry = E5ClearableLineEdit(self) if defaults and index < len(defaults): entry.setText(defaults[index]) self.__inputs.append(entry) self.__topLayout.addWidget(entry) index += 1 self.__buttonBox = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal, self) self.__topLayout.addWidget(self.__buttonBox) self.resize(400, self.minimumSizeHint().height()) self.setSizeGripEnabled(True) self.__buttonBox.accepted.connect(self.accept) self.__buttonBox.rejected.connect(self.reject) self.__inputs[0].selectAll() self.__inputs[0].setFocus() def getData(self): """ Public method to retrieve the entered data. @return tuple containing the text of all entries (tuple of string) """ data = [input.text().strip() for input in self.__inputs] return tuple(data) @staticmethod def getText(parent, title, labels, defaults=[]): """ Static method to create the dialog and return the entered data. @return tuple of a tuple containing the text of all entries (tuple of string) and a flag indicating the acceptance state (boolean) """ dlg = DjangoTagInputDialog(labels, defaults, parent) dlg.setWindowTitle(title) if dlg.exec_() == QDialog.Accepted: return dlg.getData(), True else: return tuple(), False