ProjectDjangoTagsMenu/FindTemplateTagDialog.py

Sun, 30 May 2021 11:51:44 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 30 May 2021 11:51:44 +0200
branch
eric7
changeset 55
5390ef66c327
parent 52
c264091162a2
child 60
85d3931419d3
permissions
-rw-r--r--

Ported the plug-in to PyQt6 for eric7.

# -*- coding: utf-8 -*-

# Copyright (c) 2014 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to search foe template tags.
"""

from PyQt6.QtCore import pyqtSignal, pyqtSlot
from PyQt6.QtWidgets 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
        @type QWidget
        """
        super().__init__(parent)
        self.setupUi(self)
        
        self.__completer = QCompleter((
            # template tags
            'autoescape', 'block', 'comment', 'csrf_token', 'cycle', 'debug',
            'extendsvariable', 'extendsfile', 'filter', 'firstof', 'for',
            'for...empty', 'if', 'ifchanged', 'ifequal', 'ifnotequal',
            'includevariable', 'includefile', 'load', 'now', 'regroup',
            'spaceless', 'ssi', 'ssifile', 'templatetag', 'url', 'urlas',
            'verbatim', 'widthratio', 'with',
            
            # template filters
            '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',
            'unordered_list', 'upper', 'urlencode', 'urlize', 'urlizetrunc',
            'wordcount', 'wordwrap', 'yesno',
            
            # humanize tags
            'loadhumanize', 'apnumber', 'intcomma', 'intword', 'naturalday',
            'naturaltime', 'ordinal',
            
            # web design tags
            'loadweb', 'lorem',
            
            # static tags
            'loadstatic', 'staticfile', 'staticvariable', 'get_static_prefix',
            'get_media_prefix',
            
            # comments
            'singlelinecommentselect', 'multilinecommentselect',
            'singlelinecommentdialog', 'multilinecommentdialog',
            'singlelinecommentclipboard', 'multilinecommentclipboard',
            'multilinecommentfile', 'singlelinecommentdatetime',
            'htmlcomment', 'iecomment',
            
            # internationalisation
            'loadi18n', 'trans', 'trans..as', 'blocktrans', 'blocktrans..with',
            'plural', 'language', 'get_current_language',
            'get_available_languages', 'get_current_language_bidi',
            'get_language_info', 'get_language_info_list', 'language_name',
            'language_name_local', 'bidi',
            
            # localization
            'loadl10n', 'localize_on', 'localize_off', 'localize',
            'unlocalize',
            
            # timezone
            'loadtz', 'localtime_on', 'localtime_off', 'timezone_set',
            'timezone_unset', 'get_current_timezone', 'localtime', 'utc',
            'timezone',
        ), self)
        self.__completer.setCompletionMode(
            QCompleter.CompletionMode.PopupCompletion)
        self.__completer.setCaseSensitivity(False)
        self.tagEdit.setCompleter(self.__completer)
        
        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())
    
    @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)

eric ide

mercurial