--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ProjectDjangoTagsMenu/FindTemplateTagDialog.py Sun Feb 02 20:02:23 2014 +0100 @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- + +""" +Module implementing a dialog to search foe template tags. +""" + +from PyQt4.QtCore import pyqtSignal, pyqtSlot +from PyQt4.QtGui import QDialog, QCompleter + +from .Ui_FindTemplateTagDialog import Ui_FindTemplateTagDialog + + +class FindTemplateTagDialog(QDialog, Ui_FindTemplateTagDialog): + """ + Class implementing a dialog to search foe template tags. + + @signal tag(str) emitted to indicate to generate template text for the + given tag name + """ + tag = pyqtSignal(str) + + def __init__(self, parent=None): + """ + Constructor + + @param parent reference to the parent widget (QWidget) + """ + super(FindTemplateTagDialog, self).__init__(parent) + self.setupUi(self) + + self.__completer = QCompleter(( + 'autoescape', 'block', 'comment', 'csrf_token', 'cycle', 'debug', + 'extends', 'filter', 'firstof', 'for', 'for...empty', 'if', + 'ifchanged', 'ifequal', 'ifnotequal', 'include', 'load', 'now', + 'regroup', 'spaceless', 'ssi', 'templatetag', 'verbatim', + 'in operator', 'not in operator', 'widthratio', 'with', 'add', + 'addslashes', 'capfirst', 'center', 'cut', 'date', 'default', + 'default_if_none', 'dictsort', 'dictsortreversed', 'divisibleby', + 'escape', 'escapejs', 'filesizeformat', 'first', 'fix_ampersands', + 'floatformat', 'force_escape', 'get_digit', 'iriencode', 'join', + 'last', 'lenght', 'lenght_is', 'linebreaks', 'linebreaksbr', + 'linenumbers', 'ljust', 'lower', 'make_list', 'phone2numeric', + 'pluralize', 'pprint', 'random', 'removetags', 'rjust', 'safe', + 'safeseq', 'slice', 'slugify', 'stringformat', 'striptags', + 'time', 'timesince', 'timeuntil', 'title', 'truncatechars', + 'truncatewords', 'truncatewords_html', 'htmlcomment', + 'unordered_list', 'upper', 'urlencode', 'urlize', 'urlizetrunc', + 'wordcount', 'wordwrap', 'yesno', 'apnumber', 'intcomma', + 'intword', 'naturalday', 'naturaltime', 'ordinal', 'lorem', + 'static', 'iecomment', 'get_static_prefix', 'get_media_prefix', + 'singlelinecomment', 'multilinecomment', 'singlelinecommentpopup', + 'multilinecommentpopup', 'singlelinecommentclipboard', + 'multilinecommentclipboard', 'multilinecommentfile', + 'singlelinecommentdatetime'), self) + self.__completer.setCompletionMode(QCompleter.PopupCompletion) + self.__completer.setCaseSensitivity(False) + self.tagEdit.setCompleter(self.__completer) + + @pyqtSlot() + def on_tagEdit_returnPressed(self): + """ + Private slot handling the user pressing the return key. + """ + self.on_createButton_clicked() + + @pyqtSlot() + def on_createButton_clicked(self): + """ + Private slot handling the user pressing the create button + """ + tagName = self.tagEdit.text().lower().strip() + if tagName: + self.tag.emit(tagName)