Wed, 21 Sep 2022 16:38:40 +0200
Reformatted source code with 'Black'.
--- a/.hgignore Thu Dec 30 12:03:18 2021 +0100 +++ b/.hgignore Wed Sep 21 16:38:40 2022 +0200 @@ -1,6 +1,7 @@ glob:.eric7project glob:.eric6project glob:.ropeproject +glob:.jedi glob:.directory glob:**.pyc glob:**.pyo
--- a/PluginDjangoTagsMenu.epj Thu Dec 30 12:03:18 2021 +0100 +++ b/PluginDjangoTagsMenu.epj Wed Sep 21 16:38:40 2022 +0200 @@ -1,7 +1,7 @@ { "header": { "comment": "eric project file for project PluginDjangoTagsMenu", - "copyright": "Copyright (C) 2021 Detlev Offenbach, detlev@die-offenbachs.de" + "copyright": "Copyright (C) 2022 Detlev Offenbach, detlev@die-offenbachs.de" }, "project": { "AUTHOR": "Detlev Offenbach", @@ -129,6 +129,7 @@ } }, "EMAIL": "detlev@die-offenbachs.de", + "EMBEDDED_VENV": false, "EOL": 1, "FILETYPES": { "*.epj": "OTHERS", @@ -167,6 +168,7 @@ }, "INTERFACES": [], "LEXERASSOCS": {}, + "LICENSE": "GNU General Public License v3 or later (GPLv3+)", "MAINSCRIPT": "PluginProjectDjangoTagsMenu.py", "MAKEPARAMS": { "MakeEnabled": false, @@ -181,12 +183,29 @@ ".hgignore", "ChangeLog", "PKGLIST", + "PluginDjangoTagsMenu.epj", "PluginProjectDjangoTagsMenu.zip", "ProjectDjangoTagsMenu/Documentation/LICENSE.GPL3", - "ProjectDjangoTagsMenu/Documentation/source", - "PluginDjangoTagsMenu.epj" + "ProjectDjangoTagsMenu/Documentation/source" ], - "OTHERTOOLSPARMS": {}, + "OTHERTOOLSPARMS": { + "Black": { + "exclude": "/(\\.direnv|\\.eggs|\\.git|\\.hg|\\.mypy_cache|\\.nox|\\.tox|\\.venv|venv|\\.svn|_build|buck-out|build|dist|__pypackages__)/", + "extend-exclude": "", + "force-exclude": "", + "line-length": 88, + "skip-magic-trailing-comma": false, + "skip-string-normalization": false, + "source": "project", + "target-version": [ + "py311", + "py310", + "py39", + "py38", + "py37" + ] + } + }, "PACKAGERSPARMS": {}, "PROGLANGUAGE": "Python3", "PROJECTTYPE": "E7Plugin", @@ -215,6 +234,7 @@ "SPELLEXCLUDES": "", "SPELLLANGUAGE": "en_US", "SPELLWORDS": "", + "TESTING_FRAMEWORK": "", "TRANSLATIONEXCEPTIONS": [], "TRANSLATIONPATTERN": "ProjectDjangoTagsMenu/i18n/djangotagsmenu_%language%.ts", "TRANSLATIONS": [
--- a/PluginProjectDjangoTagsMenu.py Thu Dec 30 12:03:18 2021 +0100 +++ b/PluginProjectDjangoTagsMenu.py Wed Sep 21 16:38:40 2022 +0200 @@ -41,23 +41,24 @@ """ Class implementing the Django tags menu plugin. """ + def __init__(self, ui): """ Constructor - + @param ui reference to the user interface object @type UserInterface """ super().__init__(ui) self.__ui = ui - + self.__translator = None self.__loadTranslator() - + self.__handler = DjangoTagsMenuHandler(ui, self) - + self.__initMenu() - + def __initMenu(self): """ Private slot to initialize the tags menu. @@ -65,10 +66,10 @@ self.__menuAttached = False self.__menuAction = None self.__menuSeparator = None - + self.__menu = QMenu(self.tr("Template Tags")) self.__handler.initMenus(self.__menu) - + def __attachMenu(self): """ Private method to attach the menu to the Django menu. @@ -77,14 +78,15 @@ with contextlib.suppress(KeyError): pluginObject = ericApp().getPluginObject("ProjectDjango") djangoMenu = pluginObject.getMenu("main") - djangoDatabaseMenuAction = pluginObject.getMenu( - "database").menuAction() + djangoDatabaseMenuAction = pluginObject.getMenu("database").menuAction() self.__menuAction = djangoMenu.insertMenu( - djangoDatabaseMenuAction, self.__menu) + djangoDatabaseMenuAction, self.__menu + ) self.__menuSeparator = djangoMenu.insertSeparator( - djangoDatabaseMenuAction) + djangoDatabaseMenuAction + ) self.__menuAttached = True - + def __detachMenu(self): """ Private method to detach the menu from the Django menu. @@ -95,46 +97,46 @@ djangoMenu = pluginObject.getMenu("main") djangoMenu.removeAction(self.__menuAction) djangoMenu.removeAction(self.__menuSeparator) - + self.__menuAction = None self.__menuSeparator = None self.__menuAttached = False - + def activate(self): """ Public method to activate this plugin. - + @return tuple of None and activation status @rtype tuple of (None, bool) """ pluginManager = ericApp().getObject("PluginManager") pluginManager.pluginActivated.connect(self.__pluginActivated) pluginManager.pluginAboutToBeDeactivated.connect( - self.__pluginAboutToBeDeactivated) - + self.__pluginAboutToBeDeactivated + ) + if pluginManager.isPluginActive("PluginProjectDjango"): self.__attachMenu() - - ericApp().getObject("Project").projectClosed.connect( - self.__projectClosed) - + + ericApp().getObject("Project").projectClosed.connect(self.__projectClosed) + return None, True - + def deactivate(self): """ Public method to deactivate this plugin. """ - ericApp().getObject("Project").projectClosed.disconnect( - self.__projectClosed) - + ericApp().getObject("Project").projectClosed.disconnect(self.__projectClosed) + self.__handler.closeAllWindows() self.__detachMenu() - + pluginManager = ericApp().getObject("PluginManager") pluginManager.pluginActivated.disconnect(self.__pluginActivated) pluginManager.pluginAboutToBeDeactivated.disconnect( - self.__pluginAboutToBeDeactivated) - + self.__pluginAboutToBeDeactivated + ) + def __loadTranslator(self): """ Private method to load the translation file. @@ -143,7 +145,8 @@ loc = self.__ui.getLocale() if loc and loc != "C": locale_dir = os.path.join( - os.path.dirname(__file__), "ProjectDjangoTagsMenu", "i18n") + os.path.dirname(__file__), "ProjectDjangoTagsMenu", "i18n" + ) translation = "djangotagsmenu_{0}".format(loc) translator = QTranslator(None) loaded = translator.load(translation, locale_dir) @@ -151,20 +154,22 @@ self.__translator = translator ericApp().installTranslator(self.__translator) else: - print("Warning: translation file '{0}' could not be" - " loaded.".format(translation)) + print( + "Warning: translation file '{0}' could not be" + " loaded.".format(translation) + ) print("Using default.") - + def __projectClosed(self): """ Private slot to handle the projectClosed signal. """ self.__handler.closeAllWindows() - + def __pluginActivated(self, moduleName, pluginObject): """ Private slot to react on plugin activation of the Django plugin. - + @param moduleName name of the module activated @type str @param pluginObject reference to the activated plug-in object @@ -172,11 +177,11 @@ """ if moduleName == "PluginProjectDjango": self.__attachMenu() - + def __pluginAboutToBeDeactivated(self, moduleName, pluginObject): """ Private slot to react on the Django plugin about to be deactivated. - + @param moduleName name of the module about to be deactivated @type str @param pluginObject reference to the about to be deactivated @@ -187,5 +192,6 @@ self.__handler.closeAllWindows() self.__detachMenu() + # # eflag: noqa = M801
--- a/ProjectDjangoTagsMenu/DjangoTagInputDialog.py Thu Dec 30 12:03:18 2021 +0100 +++ b/ProjectDjangoTagsMenu/DjangoTagInputDialog.py Wed Sep 21 16:38:40 2022 +0200 @@ -8,19 +8,18 @@ """ from PyQt6.QtCore import Qt -from PyQt6.QtWidgets import ( - QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QLineEdit -) +from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout, QLabel, QLineEdit class DjangoTagInputDialog(QDialog): """ Class implementing a dialog to enter data for the creation of a tag. """ + def __init__(self, labels, defaults=None, parent=None): """ Constructor - + @param labels list of labels for the entry fields @type list of str @param defaults list of default values for the entry fields @@ -30,13 +29,12 @@ @exception RuntimeError raised to signal too many labels were given """ super().__init__(parent) - + if len(labels) == 0 or len(labels) > 5: - raise RuntimeError( - "Illegal number of labels given (max. 5 allowed)") - + raise RuntimeError("Illegal number of labels given (max. 5 allowed)") + self.__inputs = [] - + self.__topLayout = QVBoxLayout(self) for index, label in enumerate(labels): self.__topLayout.addWidget(QLabel(label, self)) @@ -47,37 +45,36 @@ self.__inputs.append(entry) self.__topLayout.addWidget(entry) self.__buttonBox = QDialogButtonBox( - QDialogButtonBox.StandardButton.Ok | - QDialogButtonBox.StandardButton.Cancel, + QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel, Qt.Orientation.Horizontal, - self + 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 @rtype tuple of str """ data = [input.text().strip() for input in self.__inputs] return tuple(data) - + @staticmethod def getText(parent, title, labels, defaults=None): """ Public static method to create the dialog and return the entered data. - + @param parent reference to the parent widget @type QWidget @param title title of the dialog @@ -92,7 +89,7 @@ """ if defaults is None: defaults = [] - + dlg = DjangoTagInputDialog(labels, defaults, parent) dlg.setWindowTitle(title) if dlg.exec() == QDialog.DialogCode.Accepted:
--- a/ProjectDjangoTagsMenu/DjangoTagsMenuHandler.py Thu Dec 30 12:03:18 2021 +0100 +++ b/ProjectDjangoTagsMenu/DjangoTagsMenuHandler.py Wed Sep 21 16:38:40 2022 +0200 @@ -25,10 +25,11 @@ """ Class implementing the Django tags menu handler. """ + def __init__(self, ui, parent=None): """ Constructor - + @param ui reference to the user interface object @type UserInterface @param parent reference to the parent object @@ -36,25 +37,26 @@ """ super().__init__(parent) self.__ui = ui - + self.__findDialog = None - + def closeAllWindows(self): """ Public method to close all dialogs managed by the handler. """ if self.__findDialog: self.__findDialog.close() - + def initMenus(self, mainMenu): """ Public method to initialize the various menus. - + @param mainMenu reference to the main tags menu @type QMenu """ - mainMenu.addAction(self.tr("Django Template Tags Locator"), - self.__findTemplateTag) + mainMenu.addAction( + self.tr("Django Template Tags Locator"), self.__findTemplateTag + ) mainMenu.addSeparator() mainMenu.addMenu(self.__initTagsMenu()) mainMenu.addMenu(self.__initFiltersMenu()) @@ -65,640 +67,754 @@ mainMenu.addMenu(self.__initInternationalizationMenu()) mainMenu.addMenu(self.__initLocalizationMenu()) mainMenu.addMenu(self.__initTimezoneMenu()) - + def __initTagsMenu(self): """ Private method to initialize the tags menu. - + @return generated menu @rtype QMenu """ menu = QMenu(self.tr("Tags")) menu.addAction( self.tr("autoescape - Auto Escape Characters"), - lambda: self.__applyTemplate("autoescape")) + lambda: self.__applyTemplate("autoescape"), + ) menu.addSeparator() menu.addAction( - self.tr("block - Named Block"), - lambda: self.__applyTemplate("block")) + self.tr("block - Named Block"), lambda: self.__applyTemplate("block") + ) menu.addSeparator() menu.addAction( self.tr("comment - Multiline Comment"), - lambda: self.__applyTemplate("comment")) + lambda: self.__applyTemplate("comment"), + ) menu.addAction( self.tr("csrf_token - Cross Site Request Forgery Token"), - lambda: self.__applyTemplate("csrf_token")) + lambda: self.__applyTemplate("csrf_token"), + ) menu.addAction( self.tr("cycle - Cycle variables each time used"), - lambda: self.__applyTemplate("cycle")) + lambda: self.__applyTemplate("cycle"), + ) menu.addSeparator() menu.addAction( self.tr("debug - Output Debug Information"), - lambda: self.__applyTemplate("debug")) + lambda: self.__applyTemplate("debug"), + ) menu.addSeparator() menu.addAction( self.tr("extends - Extend a template with variable contents"), - lambda: self.__applyTemplate("extendsvariable")) + lambda: self.__applyTemplate("extendsvariable"), + ) menu.addAction( self.tr("extends - Extend a template with file"), - lambda: self.__applyTemplate("extendsfile")) + lambda: self.__applyTemplate("extendsfile"), + ) menu.addSeparator() menu.addAction( self.tr("filter - Filtered Block for one or more filters"), - lambda: self.__applyTemplate("filter")) + lambda: self.__applyTemplate("filter"), + ) menu.addAction( self.tr("firstof - Outputs first argument variable that is True"), - lambda: self.__applyTemplate("firstof")) - menu.addAction( - self.tr("for - For Loop"), - lambda: self.__applyTemplate("for")) + lambda: self.__applyTemplate("firstof"), + ) + menu.addAction(self.tr("for - For Loop"), lambda: self.__applyTemplate("for")) menu.addAction( self.tr("for...empty - For Loop with fallback for empty loop"), - lambda: self.__applyTemplate("for...empty")) + lambda: self.__applyTemplate("for...empty"), + ) menu.addSeparator() menu.addAction( self.tr("if - if...elif...else... clauses"), - lambda: self.__applyTemplate("if")) + lambda: self.__applyTemplate("if"), + ) menu.addAction( self.tr("ifchanged - Check if a value has changed"), - lambda: self.__applyTemplate("ifchanged")) + lambda: self.__applyTemplate("ifchanged"), + ) menu.addAction( self.tr("ifequal - Output block if variables are equal"), - lambda: self.__applyTemplate("ifequal")) + lambda: self.__applyTemplate("ifequal"), + ) menu.addAction( self.tr("ifnotequal - Output block if variables are not equal"), - lambda: self.__applyTemplate("ifnotequal")) + lambda: self.__applyTemplate("ifnotequal"), + ) menu.addAction( self.tr("include - Render template given by variable"), - lambda: self.__applyTemplate("includevariable")) + lambda: self.__applyTemplate("includevariable"), + ) menu.addAction( self.tr("include - Render template given by file name"), - lambda: self.__applyTemplate("includefile")) + lambda: self.__applyTemplate("includefile"), + ) menu.addSeparator() menu.addAction( self.tr("load - Load a custom template tag set"), - lambda: self.__applyTemplate("load")) + lambda: self.__applyTemplate("load"), + ) menu.addSeparator() menu.addAction( self.tr("now - Display current date and time"), - lambda: self.__applyTemplate("now")) + lambda: self.__applyTemplate("now"), + ) menu.addSeparator() menu.addAction( - self.tr("regroup - Regroup list of alike objects by a common" - " attribute"), - lambda: self.__applyTemplate("regroup")) + self.tr("regroup - Regroup list of alike objects by a common" " attribute"), + lambda: self.__applyTemplate("regroup"), + ) menu.addSeparator() menu.addAction( self.tr("spaceless - Remove whitespace between HTML tags"), - lambda: self.__applyTemplate("spaceless")) + lambda: self.__applyTemplate("spaceless"), + ) menu.addAction( self.tr("ssi - Output contents of a given file into the page"), - lambda: self.__applyTemplate("ssi")) + lambda: self.__applyTemplate("ssi"), + ) menu.addAction( - self.tr("ssi - Output contents of a given file into the page" - " (dialog selection)"), - lambda: self.__applyTemplate("ssifile")) + self.tr( + "ssi - Output contents of a given file into the page" + " (dialog selection)" + ), + lambda: self.__applyTemplate("ssifile"), + ) menu.addSeparator() menu.addAction( - self.tr("templatetag - Output syntax characters used for" - " template"), - lambda: self.__applyTemplate("templatetag")) + self.tr("templatetag - Output syntax characters used for" " template"), + lambda: self.__applyTemplate("templatetag"), + ) menu.addSeparator() menu.addAction( self.tr("url - Return an absolute path reference"), - lambda: self.__applyTemplate("url")) + lambda: self.__applyTemplate("url"), + ) menu.addAction( self.tr("url...as - Return an absolute path reference"), - lambda: self.__applyTemplate("urlas")) + lambda: self.__applyTemplate("urlas"), + ) menu.addSeparator() menu.addAction( self.tr("verbatim - Output block contents without rendering"), - lambda: self.__applyTemplate("verbatim")) + lambda: self.__applyTemplate("verbatim"), + ) menu.addSeparator() menu.addAction( self.tr("widthratio - Calculate width ratio"), - lambda: self.__applyTemplate("verbatim")) + lambda: self.__applyTemplate("verbatim"), + ) menu.addAction( self.tr("with - Cache a complex variable under a simpler name"), - lambda: self.__applyTemplate("verbatim")) - + lambda: self.__applyTemplate("verbatim"), + ) + self.__tagsMenu = menu return menu - + def __initFiltersMenu(self): """ Private method to initialize the filters menu. - + @return generated menu @rtype QMenu """ mainMenu = QMenu(self.tr("Filters")) - + menu = QMenu(self.tr("A-I"), mainMenu) menu.addAction( - self.tr("add - Add variable or string"), - lambda: self.__applyTemplate("add")) + self.tr("add - Add variable or string"), lambda: self.__applyTemplate("add") + ) menu.addAction( self.tr("addslashes - Add slashes before quotes"), - lambda: self.__applyTemplate("addslashes")) + lambda: self.__applyTemplate("addslashes"), + ) menu.addSeparator() menu.addAction( self.tr("capfirst - Capitalize first character"), - lambda: self.__applyTemplate("capfirst")) + lambda: self.__applyTemplate("capfirst"), + ) menu.addAction( - self.tr("center - Center value"), - lambda: self.__applyTemplate("center")) + self.tr("center - Center value"), lambda: self.__applyTemplate("center") + ) menu.addAction( - self.tr("cut - Cut characters"), - lambda: self.__applyTemplate("cut")) + self.tr("cut - Cut characters"), lambda: self.__applyTemplate("cut") + ) menu.addSeparator() menu.addAction( - self.tr("date - Format date"), - lambda: self.__applyTemplate("date")) + self.tr("date - Format date"), lambda: self.__applyTemplate("date") + ) menu.addAction( self.tr("default - Use default if False"), - lambda: self.__applyTemplate("default")) + lambda: self.__applyTemplate("default"), + ) menu.addAction( self.tr("default_if_none - Use default if None"), - lambda: self.__applyTemplate("default_if_none")) + lambda: self.__applyTemplate("default_if_none"), + ) menu.addAction( self.tr("dictsort - Sort dictionaries"), - lambda: self.__applyTemplate("dictsort")) + lambda: self.__applyTemplate("dictsort"), + ) menu.addAction( self.tr("dictsortreversed - Sort dictionaries reversed"), - lambda: self.__applyTemplate("dictsortreversed")) + lambda: self.__applyTemplate("dictsortreversed"), + ) menu.addAction( self.tr("divisibleby - Check divisibility"), - lambda: self.__applyTemplate("divisibleby")) + lambda: self.__applyTemplate("divisibleby"), + ) menu.addSeparator() menu.addAction( - self.tr("escape - Escape as HTML"), - lambda: self.__applyTemplate("escape")) + self.tr("escape - Escape as HTML"), lambda: self.__applyTemplate("escape") + ) menu.addAction( self.tr("escapejs - Escape as JavaScript"), - lambda: self.__applyTemplate("escapejs")) + lambda: self.__applyTemplate("escapejs"), + ) menu.addSeparator() menu.addAction( self.tr("filesizeformat - Format file sizes"), - lambda: self.__applyTemplate("filesizeformat")) + lambda: self.__applyTemplate("filesizeformat"), + ) menu.addAction( self.tr("first - First item of a list"), - lambda: self.__applyTemplate("first")) + lambda: self.__applyTemplate("first"), + ) menu.addAction( self.tr("fix_ampersands - Replace ampersands"), - lambda: self.__applyTemplate("fix_ampersands")) + lambda: self.__applyTemplate("fix_ampersands"), + ) menu.addAction( self.tr("floatformat - Format floating numbers"), - lambda: self.__applyTemplate("floatformat")) + lambda: self.__applyTemplate("floatformat"), + ) menu.addAction( self.tr("force_escape - Escape as HTML immediately"), - lambda: self.__applyTemplate("force_escape")) + lambda: self.__applyTemplate("force_escape"), + ) menu.addSeparator() menu.addAction( self.tr("get_digit - Extract rightmost digit"), - lambda: self.__applyTemplate("get_digit")) + lambda: self.__applyTemplate("get_digit"), + ) menu.addSeparator() menu.addAction( self.tr("iriencode - Convert IRI to string"), - lambda: self.__applyTemplate("iriencode")) + lambda: self.__applyTemplate("iriencode"), + ) mainMenu.addMenu(menu) - + menu = QMenu(self.tr("J-R"), mainMenu) menu.addAction( - self.tr("join - Join list"), - lambda: self.__applyTemplate("join")) + self.tr("join - Join list"), lambda: self.__applyTemplate("join") + ) menu.addSeparator() menu.addAction( self.tr("last - Return last item in list"), - lambda: self.__applyTemplate("last")) + lambda: self.__applyTemplate("last"), + ) menu.addAction( self.tr("length - Return length of the value"), - lambda: self.__applyTemplate("length")) + lambda: self.__applyTemplate("length"), + ) menu.addAction( self.tr("length_is - Check length"), - lambda: self.__applyTemplate("length_is")) + lambda: self.__applyTemplate("length_is"), + ) menu.addAction( self.tr("linebreaks - Replace line breaks with HTML"), - lambda: self.__applyTemplate("linebreaks")) + lambda: self.__applyTemplate("linebreaks"), + ) menu.addAction( self.tr("linebreaksbr - Replace line breaks with <br/>"), - lambda: self.__applyTemplate("linebreaksbr")) + lambda: self.__applyTemplate("linebreaksbr"), + ) menu.addAction( self.tr("linenumbers - Display text with line numbers"), - lambda: self.__applyTemplate("linenumbers")) + lambda: self.__applyTemplate("linenumbers"), + ) menu.addAction( - self.tr("ljust - Left-align value"), - lambda: self.__applyTemplate("ljust")) + self.tr("ljust - Left-align value"), lambda: self.__applyTemplate("ljust") + ) menu.addAction( self.tr("lower - Convert to lowercase"), - lambda: self.__applyTemplate("lower")) + lambda: self.__applyTemplate("lower"), + ) menu.addSeparator() menu.addAction( self.tr("make_list - Turn value into a list"), - lambda: self.__applyTemplate("make_list")) + lambda: self.__applyTemplate("make_list"), + ) menu.addSeparator() menu.addAction( self.tr("phone2numeric - Convert phone number into numeric"), - lambda: self.__applyTemplate("phone2numeric")) + lambda: self.__applyTemplate("phone2numeric"), + ) menu.addAction( self.tr("pluralize - Return plural suffix"), - lambda: self.__applyTemplate("pluralize")) + lambda: self.__applyTemplate("pluralize"), + ) menu.addAction( - self.tr("pprint - Pretty Print"), - lambda: self.__applyTemplate("pprint")) + self.tr("pprint - Pretty Print"), lambda: self.__applyTemplate("pprint") + ) menu.addSeparator() menu.addAction( self.tr("random - Return random item from list"), - lambda: self.__applyTemplate("random")) + lambda: self.__applyTemplate("random"), + ) menu.addAction( self.tr("removetags - Remove HTML tags"), - lambda: self.__applyTemplate("removetags")) + lambda: self.__applyTemplate("removetags"), + ) menu.addAction( - self.tr("rjust - Right-align value"), - lambda: self.__applyTemplate("rjust")) + self.tr("rjust - Right-align value"), lambda: self.__applyTemplate("rjust") + ) mainMenu.addMenu(menu) - + menu = QMenu(self.tr("S-Z"), mainMenu) menu.addAction( self.tr("safe - Mark as not requiring HTML escaping "), - lambda: self.__applyTemplate("safe")) + lambda: self.__applyTemplate("safe"), + ) menu.addAction( self.tr("safeseq - Mark as a safe sequence"), - lambda: self.__applyTemplate("safeseq")) + lambda: self.__applyTemplate("safeseq"), + ) menu.addAction( self.tr("slice - Return a slice of a list"), - lambda: self.__applyTemplate("slice")) + lambda: self.__applyTemplate("slice"), + ) menu.addAction( self.tr("slugify - Return value slugified"), - lambda: self.__applyTemplate("slugify")) + lambda: self.__applyTemplate("slugify"), + ) menu.addAction( self.tr("stringformat - Format variable"), - lambda: self.__applyTemplate("stringformat")) + lambda: self.__applyTemplate("stringformat"), + ) menu.addAction( self.tr("striptags - Strip all HTML tags"), - lambda: self.__applyTemplate("striptags")) + lambda: self.__applyTemplate("striptags"), + ) menu.addSeparator() menu.addAction( - self.tr("time - Format time"), - lambda: self.__applyTemplate("time")) + self.tr("time - Format time"), lambda: self.__applyTemplate("time") + ) menu.addAction( self.tr("timesince - Format as time since"), - lambda: self.__applyTemplate("timesince")) + lambda: self.__applyTemplate("timesince"), + ) menu.addAction( self.tr("timeuntil - Format as time until"), - lambda: self.__applyTemplate("timeuntil")) + lambda: self.__applyTemplate("timeuntil"), + ) menu.addAction( self.tr("title - Convert to titlecase"), - lambda: self.__applyTemplate("title")) + lambda: self.__applyTemplate("title"), + ) menu.addAction( self.tr("truncatechars - Truncate after a number of characters"), - lambda: self.__applyTemplate("truncatechars")) + lambda: self.__applyTemplate("truncatechars"), + ) menu.addAction( self.tr("truncatewords - Truncate after a number of words"), - lambda: self.__applyTemplate("truncatewords")) + lambda: self.__applyTemplate("truncatewords"), + ) menu.addAction( - self.tr("truncatewords_html - Truncate after a number of words" - " (HTML aware)"), - lambda: self.__applyTemplate("truncatewords_html")) + self.tr( + "truncatewords_html - Truncate after a number of words" " (HTML aware)" + ), + lambda: self.__applyTemplate("truncatewords_html"), + ) menu.addSeparator() menu.addAction( self.tr("unordered_list - Return HTML unordered list"), - lambda: self.__applyTemplate("unordered_list")) + lambda: self.__applyTemplate("unordered_list"), + ) menu.addAction( self.tr("upper - Convert to uppercase"), - lambda: self.__applyTemplate("upper")) + lambda: self.__applyTemplate("upper"), + ) menu.addAction( self.tr("urlencode - Escape as URL"), - lambda: self.__applyTemplate("urlencode")) + lambda: self.__applyTemplate("urlencode"), + ) menu.addAction( self.tr("urlize - Convert URLs as clickable links"), - lambda: self.__applyTemplate("urlize")) + lambda: self.__applyTemplate("urlize"), + ) menu.addAction( - self.tr("urlizetrunc - Convert URLs as clickable links and" - " truncate"), - lambda: self.__applyTemplate("urlizetrunc")) + self.tr("urlizetrunc - Convert URLs as clickable links and" " truncate"), + lambda: self.__applyTemplate("urlizetrunc"), + ) menu.addSeparator() menu.addAction( self.tr("wordcount - Return number of word"), - lambda: self.__applyTemplate("wordcount")) + lambda: self.__applyTemplate("wordcount"), + ) menu.addAction( - self.tr("wordwrap - Wrap words"), - lambda: self.__applyTemplate("wordwrap")) + self.tr("wordwrap - Wrap words"), lambda: self.__applyTemplate("wordwrap") + ) menu.addSeparator() menu.addAction( self.tr("yesno - Map True, False and None"), - lambda: self.__applyTemplate("yesno")) + lambda: self.__applyTemplate("yesno"), + ) mainMenu.addMenu(menu) - + self.__filtersMenu = mainMenu return mainMenu - + def __initHumanizeMenu(self): """ Private method to initialize the humanize menu. - + @return generated menu @rtype QMenu """ menu = QMenu(self.tr("Humanize")) menu.addAction( - self.tr("Load Package"), - lambda: self.__applyTemplate("loadhumanize")) + self.tr("Load Package"), lambda: self.__applyTemplate("loadhumanize") + ) menu.addSeparator() menu.addAction( self.tr("apnumber - Format integer the Associated Press style"), - lambda: self.__applyTemplate("apnumber")) + lambda: self.__applyTemplate("apnumber"), + ) menu.addSeparator() menu.addAction( self.tr("intcomma - Format integer with commas"), - lambda: self.__applyTemplate("intcomma")) + lambda: self.__applyTemplate("intcomma"), + ) menu.addAction( self.tr("intword - Convert integer to word"), - lambda: self.__applyTemplate("intword")) + lambda: self.__applyTemplate("intword"), + ) menu.addSeparator() menu.addAction( self.tr("naturalday - Format date naturally"), - lambda: self.__applyTemplate("naturalday")) + lambda: self.__applyTemplate("naturalday"), + ) menu.addAction( self.tr("naturaltime - Format time naturally"), - lambda: self.__applyTemplate("naturaltime")) + lambda: self.__applyTemplate("naturaltime"), + ) menu.addSeparator() menu.addAction( self.tr("ordinal - Convert integer to ordinal"), - lambda: self.__applyTemplate("ordinal")) - + lambda: self.__applyTemplate("ordinal"), + ) + self.__humanizeMenu = menu return menu - + def __initWebDesignMenu(self): """ Private method to initialize the web design menu. - + @return generated menu @rtype QMenu """ menu = QMenu(self.tr("Web Design")) - menu.addAction( - self.tr("Load Package"), - lambda: self.__applyTemplate("loadweb")) + menu.addAction(self.tr("Load Package"), lambda: self.__applyTemplate("loadweb")) menu.addSeparator() menu.addAction( self.tr("lorem - Builtin Lorem Ipsum Generator"), - lambda: self.__applyTemplate("lorem")) - + lambda: self.__applyTemplate("lorem"), + ) + self.__webMenu = menu return menu - + def __initStaticMenu(self): """ Private method to initialize the static menu. - + @return generated menu @rtype QMenu """ menu = QMenu(self.tr("Static")) menu.addAction( - self.tr("Load Package"), - lambda: self.__applyTemplate("loadstatic")) + self.tr("Load Package"), lambda: self.__applyTemplate("loadstatic") + ) menu.addSeparator() menu.addAction( self.tr("static - Link to static file"), - lambda: self.__applyTemplate("staticfile")) + lambda: self.__applyTemplate("staticfile"), + ) menu.addAction( self.tr("static - Link to static file (via variable)"), - lambda: self.__applyTemplate("staticvariable")) + lambda: self.__applyTemplate("staticvariable"), + ) menu.addAction( self.tr("get_static_prefix - Insert static URL"), - lambda: self.__applyTemplate("get_static_prefix")) + lambda: self.__applyTemplate("get_static_prefix"), + ) menu.addAction( self.tr("get_media_prefix - Insert media URL"), - lambda: self.__applyTemplate("get_media_prefix")) - + lambda: self.__applyTemplate("get_media_prefix"), + ) + self.__staticMenu = menu return menu - + def __initCommentsMenu(self): """ Private method to initialize the comments menu. - + @return generated menu @rtype QMenu """ menu = QMenu(self.tr("Comment")) menu.addAction( self.tr("Single Line Comment Selected Text"), - lambda: self.__applyTemplate("singlelinecommentselect")) + lambda: self.__applyTemplate("singlelinecommentselect"), + ) menu.addAction( self.tr("Multi Line Comment Selected Text"), - lambda: self.__applyTemplate("multilinecommentselect")) + lambda: self.__applyTemplate("multilinecommentselect"), + ) menu.addSeparator() menu.addAction( self.tr("Single Line Comment from Input Dialog"), - lambda: self.__applyTemplate("singlelinecommentdialog")) + lambda: self.__applyTemplate("singlelinecommentdialog"), + ) menu.addAction( self.tr("Multi Line Comment from Input Dialog"), - lambda: self.__applyTemplate("multilinecommentdialog")) + lambda: self.__applyTemplate("multilinecommentdialog"), + ) menu.addSeparator() menu.addAction( self.tr("Single Line Comment from Clipboard"), - lambda: self.__applyTemplate("singlelinecommentclipboard")) + lambda: self.__applyTemplate("singlelinecommentclipboard"), + ) menu.addAction( self.tr("Multi Line Comment from Clipboard"), - lambda: self.__applyTemplate("multilinecommentclipboard")) + lambda: self.__applyTemplate("multilinecommentclipboard"), + ) menu.addSeparator() menu.addAction( self.tr("Multi Line Comment from File"), - lambda: self.__applyTemplate("multilinecommentfile")) + lambda: self.__applyTemplate("multilinecommentfile"), + ) menu.addSeparator() menu.addAction( self.tr("Single Line Comment from Date Time Now"), - lambda: self.__applyTemplate("singlelinecommentdatetime")) + lambda: self.__applyTemplate("singlelinecommentdatetime"), + ) menu.addSeparator() menu.addAction( self.tr("HTML Comment Out Selected Text"), - lambda: self.__applyTemplate("htmlcomment")) + lambda: self.__applyTemplate("htmlcomment"), + ) menu.addAction( self.tr("MS IE Conditional Comment Selected Text"), - lambda: self.__applyTemplate("iecomment")) - + lambda: self.__applyTemplate("iecomment"), + ) + self.__commentsMenu = menu return menu - + def __initInternationalizationMenu(self): """ Private method to initialize the static menu. - + @return generated menu @rtype QMenu """ mainMenu = QMenu(self.tr("Internationalization (i18n)")) mainMenu.addAction( - self.tr("Load Package"), - lambda: self.__applyTemplate("loadi18n")) + self.tr("Load Package"), lambda: self.__applyTemplate("loadi18n") + ) mainMenu.addSeparator() - + menu = QMenu(self.tr("Tags"), mainMenu) menu.addAction( self.tr("trans - Translate String or Variable"), - lambda: self.__applyTemplate("trans")) + lambda: self.__applyTemplate("trans"), + ) menu.addAction( self.tr("trans..as - Translate String into Variable"), - lambda: self.__applyTemplate("trans..as")) + lambda: self.__applyTemplate("trans..as"), + ) menu.addSeparator() menu.addAction( self.tr("blocktrans - Translate Block"), - lambda: self.__applyTemplate("blocktrans")) + lambda: self.__applyTemplate("blocktrans"), + ) menu.addAction( self.tr("blocktrans..with - Translate Block with Attributes"), - lambda: self.__applyTemplate("blocktrans..with")) + lambda: self.__applyTemplate("blocktrans..with"), + ) menu.addAction( - self.tr("plural - Plural Block"), - lambda: self.__applyTemplate("plural")) + self.tr("plural - Plural Block"), lambda: self.__applyTemplate("plural") + ) menu.addAction( self.tr("language - Switch language"), - lambda: self.__applyTemplate("language")) + lambda: self.__applyTemplate("language"), + ) menu.addSeparator() menu.addAction( self.tr("get_current_language - Current language"), - lambda: self.__applyTemplate("get_current_language")) + lambda: self.__applyTemplate("get_current_language"), + ) menu.addAction( self.tr("get_available_languages - Available languages"), - lambda: self.__applyTemplate("get_available_languages")) + lambda: self.__applyTemplate("get_available_languages"), + ) menu.addAction( - self.tr("get_current_language_bidi - Current language's" - " direction"), - lambda: self.__applyTemplate("get_current_language_bidi")) + self.tr("get_current_language_bidi - Current language's" " direction"), + lambda: self.__applyTemplate("get_current_language_bidi"), + ) menu.addAction( self.tr("get_language_info - Language Information"), - lambda: self.__applyTemplate("get_language_info")) + lambda: self.__applyTemplate("get_language_info"), + ) menu.addAction( - self.tr("get_language_info_list - Language Information for a list" - " of languages"), - lambda: self.__applyTemplate("get_language_info_list")) + self.tr( + "get_language_info_list - Language Information for a list" + " of languages" + ), + lambda: self.__applyTemplate("get_language_info_list"), + ) mainMenu.addMenu(menu) - + menu = QMenu(self.tr("Filters"), mainMenu) menu.addAction( self.tr("language_name - Language name"), - lambda: self.__applyTemplate("language_name")) + lambda: self.__applyTemplate("language_name"), + ) menu.addAction( self.tr("language_name_local - Language name translated"), - lambda: self.__applyTemplate("language_name_local")) + lambda: self.__applyTemplate("language_name_local"), + ) menu.addAction( - self.tr("bidi - Language's direction"), - lambda: self.__applyTemplate("bidi")) + self.tr("bidi - Language's direction"), lambda: self.__applyTemplate("bidi") + ) mainMenu.addMenu(menu) - + self.__internationalizationMenu = mainMenu return mainMenu - + def __initLocalizationMenu(self): """ Private method to initialize the static menu. - + @return generated menu @rtype QMenu """ mainMenu = QMenu(self.tr("Localization (l10n)")) mainMenu.addAction( - self.tr("Load Package"), - lambda: self.__applyTemplate("loadl10n")) + self.tr("Load Package"), lambda: self.__applyTemplate("loadl10n") + ) mainMenu.addSeparator() - + menu = QMenu(self.tr("Tags"), mainMenu) menu.addAction( self.tr("localize on - Activate Localization"), - lambda: self.__applyTemplate("localize_on")) + lambda: self.__applyTemplate("localize_on"), + ) menu.addAction( self.tr("localize off - Dectivate Localization"), - lambda: self.__applyTemplate("localize_off")) + lambda: self.__applyTemplate("localize_off"), + ) mainMenu.addMenu(menu) - + menu = QMenu(self.tr("Filters"), mainMenu) menu.addAction( self.tr("localize - Output value localized"), - lambda: self.__applyTemplate("localize")) + lambda: self.__applyTemplate("localize"), + ) menu.addAction( self.tr("unlocalize - Output value non-localized"), - lambda: self.__applyTemplate("unlocalize")) + lambda: self.__applyTemplate("unlocalize"), + ) mainMenu.addMenu(menu) - + self.__localizationMenu = mainMenu return mainMenu - + def __initTimezoneMenu(self): """ Private method to initialize the static menu. - + @return generated menu @rtype QMenu """ mainMenu = QMenu(self.tr("Timezone (tz)")) mainMenu.addAction( - self.tr("Load Package"), - lambda: self.__applyTemplate("loadtz")) + self.tr("Load Package"), lambda: self.__applyTemplate("loadtz") + ) mainMenu.addSeparator() - + menu = QMenu(self.tr("Tags"), mainMenu) menu.addAction( self.tr("localtime on - Activate date and time conversion"), - lambda: self.__applyTemplate("localtime_on")) + lambda: self.__applyTemplate("localtime_on"), + ) menu.addAction( self.tr("localtime off - Deactivate date and time conversion"), - lambda: self.__applyTemplate("localtime_off")) + lambda: self.__applyTemplate("localtime_off"), + ) menu.addAction( self.tr("timezone - Set timezone for date and time conversion"), - lambda: self.__applyTemplate("timezone_set")) + lambda: self.__applyTemplate("timezone_set"), + ) menu.addAction( - self.tr("timezone None - Unset timezone for date and time" - " conversion"), - lambda: self.__applyTemplate("timezone_unset")) + self.tr("timezone None - Unset timezone for date and time" " conversion"), + lambda: self.__applyTemplate("timezone_unset"), + ) menu.addAction( self.tr("get_current_timezone - Get current time zone"), - lambda: self.__applyTemplate("get_current_timezone")) + lambda: self.__applyTemplate("get_current_timezone"), + ) mainMenu.addMenu(menu) - + menu = QMenu(self.tr("Filters"), mainMenu) menu.addAction( self.tr("localtime - Convert to local time zone"), - lambda: self.__applyTemplate("localtime")) + lambda: self.__applyTemplate("localtime"), + ) menu.addAction( - self.tr("utc - Convert to UTC"), - lambda: self.__applyTemplate("utc")) + self.tr("utc - Convert to UTC"), lambda: self.__applyTemplate("utc") + ) menu.addAction( self.tr("timezone - Convert to a specific time zone"), - lambda: self.__applyTemplate("timezone")) + lambda: self.__applyTemplate("timezone"), + ) mainMenu.addMenu(menu) - + self.__timezoneMenu = mainMenu return mainMenu - + def __findTemplateTag(self): """ Private slot to find a template tag and insert its text. """ if self.__findDialog is None: from .FindTemplateTagDialog import FindTemplateTagDialog + self.__findDialog = FindTemplateTagDialog() self.__findDialog.tag.connect(self.__applyTemplate) self.__findDialog.show() self.__findDialog.raise_() self.__findDialog.activateWindow() - + def __applyTemplate(self, tag): """ Private slot to generate and insert the template text. - + @param tag name of the tag to insert @type str """ editor = ericApp().getObject("ViewManager").activeWindow() if editor is None: return - - templateText, replace = self.__generateTemplateText( - tag, editor.selectedText()) - + + templateText, replace = self.__generateTemplateText(tag, editor.selectedText()) + if templateText: editor.beginUndoAction() if replace: @@ -706,11 +822,11 @@ else: editor.insert(templateText) editor.endUndoAction() - + def __generateTemplateText(self, tag, selectedText): """ Private slot to generate the template text. - + @param tag name of the tag to insert @type str @param selectedText selected text of the current editor @@ -719,28 +835,30 @@ a replace operation @rtype tuple of (str, bool) """ - replace = False # safe value + replace = False # safe value ok = True templateText = "" - + #################################################### ## Template Tags ## #################################################### - + if tag == "autoescape": - templateText = ( - "{{% autoescape on %}} {0} {{% endautoescape %}}".format( - selectedText)) + templateText = "{{% autoescape on %}} {0} {{% endautoescape %}}".format( + selectedText + ) replace = True elif tag == "block": data, ok = DjangoTagInputDialog.getText( None, self.tr("Named Block"), [self.tr("Enter block name:")], - ["block_name"]) + ["block_name"], + ) if ok: templateText = "{{% block {0} %}} {1} {{% endblock %}}".format( - data[0], selectedText) + data[0], selectedText + ) replace = True elif tag == "csrf_token": templateText = "{% csrf_token %}" @@ -749,7 +867,8 @@ None, self.tr("Cycle Variables"), [self.tr("Enter items to cycle, space separated")], - ["item1 item2 item3"]) + ["item1 item2 item3"], + ) if ok: templateText = "{{% cycle {0} %}}".format(data[0]) elif tag == "debug": @@ -759,7 +878,8 @@ None, self.tr("Extends"), [self.tr("Enter variable name:")], - ["variable"]) + ["variable"], + ) if ok: templateText = "{{% extends {0} %}}".format(data[0]) elif tag == "extendsfile": @@ -767,7 +887,8 @@ None, self.tr("Extends"), [self.tr("Enter parent file name:")], - ["base.html"]) + ["base.html"], + ) if ok: templateText = '{{% extends "{0}" %}}'.format(data[0]) elif tag == "filter": @@ -775,53 +896,64 @@ None, self.tr("Tag Filters"), [self.tr("Multiple filters with arguments, pipes separated:")], - ["lower|safe"]) + ["lower|safe"], + ) if ok: - templateText = ( - "{{% filter {0} %}} {1} {{% endfilter %}}".format( - data[0], selectedText)) + templateText = "{{% filter {0} %}} {1} {{% endfilter %}}".format( + data[0], selectedText + ) replace = True elif tag == "firstof": data, ok = DjangoTagInputDialog.getText( None, self.tr("First Of"), - [self.tr("Enter multiple variables, space separated:"), - self.tr("Enter fallback value:")], - ["var1 var2", "fallback_value"]) + [ + self.tr("Enter multiple variables, space separated:"), + self.tr("Enter fallback value:"), + ], + ["var1 var2", "fallback_value"], + ) if ok: templateText = ( '{{% filter force_escape %}}{{% firstof {0} "{1}" %}}' - ' {2} {{% endfilter %}}'.format( - data[0], data[1], selectedText)) + " {2} {{% endfilter %}}".format(data[0], data[1], selectedText) + ) replace = True elif tag == "for": data, ok = DjangoTagInputDialog.getText( None, self.tr("For Loop"), - [self.tr("Enter variable to use for iteration:"), - self.tr("Enter sequence to iterate over:")], - ["item", "values"]) + [ + self.tr("Enter variable to use for iteration:"), + self.tr("Enter sequence to iterate over:"), + ], + ["item", "values"], + ) if ok: - templateText = ( - "{{% for {0} in {1} %}} {2} {{% endfor %}}".format( - data[0], data[1], selectedText)) + templateText = "{{% for {0} in {1} %}} {2} {{% endfor %}}".format( + data[0], data[1], selectedText + ) replace = True elif tag == "for...empty": data, ok = DjangoTagInputDialog.getText( None, self.tr("For Loop"), - [self.tr("Enter variable to use for iteration:"), - self.tr("Enter sequence to iterate over:"), - self.tr("Enter output to use if loop is empty:")], - ["item", "values", '"Nothing."']) + [ + self.tr("Enter variable to use for iteration:"), + self.tr("Enter sequence to iterate over:"), + self.tr("Enter output to use if loop is empty:"), + ], + ["item", "values", '"Nothing."'], + ) if ok: templateText = ( "{{% for {0} in {1} %}} {2} {{% empty %}} {3}" - " {{% endfor %}}".format( - data[0], data[1], selectedText, data[2])) + " {{% endfor %}}".format(data[0], data[1], selectedText, data[2]) + ) replace = True elif tag == "if": from .IfTagInputDialog import IfTagInputDialog + dlg = IfTagInputDialog() if dlg.exec() == QDialog.DialogCode.Accepted: templateText = dlg.getTag() @@ -830,50 +962,58 @@ None, self.tr("Check Variables for Changes"), [self.tr("Enter variables to check (space separated):")], - ["variable1 variable2"]) + ["variable1 variable2"], + ) if ok: - templateText = ( - '{{% ifchanged {0} %}}{1}{{% endifchanged %}}' - .format(data[0], selectedText)) + templateText = "{{% ifchanged {0} %}}{1}{{% endifchanged %}}".format( + data[0], selectedText + ) replace = True elif tag == "ifequal": data, ok = DjangoTagInputDialog.getText( None, self.tr("Check If Equal"), - [self.tr("Enter first variable or string to check:"), - self.tr("Enter second variable or string to check:")], - ["user.username", '"adrian"']) + [ + self.tr("Enter first variable or string to check:"), + self.tr("Enter second variable or string to check:"), + ], + ["user.username", '"adrian"'], + ) if ok: - templateText = ( - '{{% ifequal {0} {1} %}}{2}{{% endifequal %}}' - .format(data[0], data[1], selectedText)) + templateText = "{{% ifequal {0} {1} %}}{2}{{% endifequal %}}".format( + data[0], data[1], selectedText + ) replace = True elif tag == "ifnotequal": data, ok = DjangoTagInputDialog.getText( None, self.tr("Check If Not Equal"), - [self.tr("Enter first variable or string to check:"), - self.tr("Enter second variable or string to check:")], - ["user.username", '"adrian"']) + [ + self.tr("Enter first variable or string to check:"), + self.tr("Enter second variable or string to check:"), + ], + ["user.username", '"adrian"'], + ) if ok: templateText = ( - '{{% ifnotequal {0} {1} %}}{2}{{% endifnotequal %}}' - .format(data[0], data[1], selectedText)) + "{{% ifnotequal {0} {1} %}}{2}{{% endifnotequal %}}".format( + data[0], data[1], selectedText + ) + ) replace = True elif tag == "includevariable": data, ok = DjangoTagInputDialog.getText( None, self.tr("Include"), [self.tr("Enter variable name:")], - ["variable"]) + ["variable"], + ) if ok: - templateText = '{{% include {0} %}}'.format(data[0]) + templateText = "{{% include {0} %}}".format(data[0]) elif tag == "includefile": data, ok = DjangoTagInputDialog.getText( - None, - self.tr("Include"), - [self.tr("Enter file name:")], - ["other.html"]) + None, self.tr("Include"), [self.tr("Enter file name:")], ["other.html"] + ) if ok: templateText = '{{% include "{0}" %}}'.format(data[0]) elif tag == "load": @@ -881,7 +1021,8 @@ None, self.tr("Load"), [self.tr("Enter template tag set to load:")], - ["foo bar"]) + ["foo bar"], + ) if ok: templateText = '{{% load "{0}" %}}'.format(data[0]) elif tag == "now": @@ -889,39 +1030,50 @@ None, self.tr("Now"), self.tr("Current date time format:"), - ["DATETIME_FORMAT", "SHORT_DATETIME_FORMAT", - "SHORT_DATE_FORMAT", "DATE_FORMAT"], - 0, False) + [ + "DATETIME_FORMAT", + "SHORT_DATETIME_FORMAT", + "SHORT_DATE_FORMAT", + "DATE_FORMAT", + ], + 0, + False, + ) if ok: templateText = '{{% now "{0}" %}}'.format(dateformat) elif tag == "regroup": data, ok = DjangoTagInputDialog.getText( None, self.tr("Regroup List"), - [self.tr("List Variable:"), self.tr("Common Attribute:"), - self.tr("Name of resulting list:")], - ["cities", "country", "country_list"]) + [ + self.tr("List Variable:"), + self.tr("Common Attribute:"), + self.tr("Name of resulting list:"), + ], + ["cities", "country", "country_list"], + ) if ok: - templateText = '{{% regroup {0} by {1} as {2} %}}'.format( - data[0], data[1], data[2]) + templateText = "{{% regroup {0} by {1} as {2} %}}".format( + data[0], data[1], data[2] + ) elif tag == "spaceless": templateText = "{{% spaceless %}} {0} {{% endspaceless %}}".format( - selectedText) + selectedText + ) replace = True elif tag == "ssi": data, ok = DjangoTagInputDialog.getText( None, self.tr("SSI"), [self.tr("Full path to template:")], - ["/tmp/ssi_template.html"]) # secok + ["/tmp/ssi_template.html"], + ) # secok if ok: templateText = '{{% ssi "{0}" parsed %}}'.format(data[0]) elif tag == "ssifile": ssi = EricFileDialog.getOpenFileName( - None, - self.tr("SSI"), - os.path.expanduser("~"), - self.tr("All Files (*)")) + None, self.tr("SSI"), os.path.expanduser("~"), self.tr("All Files (*)") + ) if ssi: templateText = '{{% ssi "{0}" parsed %}}'.format(ssi) elif tag == "templatetag": @@ -930,73 +1082,89 @@ self.tr("Template Tag"), self.tr("Argument:"), ["block", "variable", "brace", "comment"], - 0, False) + 0, + False, + ) if ok: templateText = ( - '{{% templatetag open{0} %}} {1} {{% templatetag' - ' close{0} %}}'.format(templatetag, selectedText)) + "{{% templatetag open{0} %}} {1} {{% templatetag" + " close{0} %}}".format(templatetag, selectedText) + ) replace = True elif tag == "url": data, ok = DjangoTagInputDialog.getText( None, self.tr("URL"), - [self.tr("View method name:"), - self.tr("Optional arguments (space separated):")], - ["path.to.some_view", "var1 var2"]) + [ + self.tr("View method name:"), + self.tr("Optional arguments (space separated):"), + ], + ["path.to.some_view", "var1 var2"], + ) if ok: if data[1]: - data[1] = ' ' + data[1] - templateText = '{{% url "{0}"{1} %}}'.format( - data[0], data[1]) + data[1] = " " + data[1] + templateText = '{{% url "{0}"{1} %}}'.format(data[0], data[1]) elif tag == "urlas": data, ok = DjangoTagInputDialog.getText( None, self.tr("URL...as"), - [self.tr("View method name:"), - self.tr("Optional arguments (space separated):"), - self.tr("URL name:")], - ["path.to.some_view", "var1 var2", "url_name"]) + [ + self.tr("View method name:"), + self.tr("Optional arguments (space separated):"), + self.tr("URL name:"), + ], + ["path.to.some_view", "var1 var2", "url_name"], + ) if ok: if data[1]: - data[1] = ' ' + data[1] + data[1] = " " + data[1] templateText = '{{% url "{0}"{1} as {2} %}}'.format( - data[0], data[1], data[2]) + data[0], data[1], data[2] + ) elif tag == "verbatim": templateText = "{{% verbatim %}} {0} {{% endverbatim %}}".format( - selectedText) + selectedText + ) replace = True elif tag == "widthratio": data, ok = DjangoTagInputDialog.getText( None, self.tr("Width Ratio"), - [self.tr("Variable:"), - self.tr("Maximum Value:"), - self.tr("Maximum Width:")], - ["variable", "max_value", "max_width"]) + [ + self.tr("Variable:"), + self.tr("Maximum Value:"), + self.tr("Maximum Width:"), + ], + ["variable", "max_value", "max_width"], + ) if ok: templateText = "{{% widthratio {0} {1} {2} %}}".format( - data[0], data[1], data[2]) + data[0], data[1], data[2] + ) elif tag == "with": data, ok = DjangoTagInputDialog.getText( None, self.tr("Cache Variables"), - [self.tr("Variables to cache as key=value (space separated):") - ], - ["variable1=foo.bar variable2=bar.baz"]) + [self.tr("Variables to cache as key=value (space separated):")], + ["variable1=foo.bar variable2=bar.baz"], + ) if ok: - templateText = '{{% with {0} %}} {1} {{% endwith %}}'.format( - data[0], selectedText) - + templateText = "{{% with {0} %}} {1} {{% endwith %}}".format( + data[0], selectedText + ) + #################################################### ## Template Filters ## #################################################### - + elif tag == "add": data, ok = DjangoTagInputDialog.getText( None, self.tr("Add Variable or String"), [self.tr("Variables or String to add:")], - ["variable"]) + ["variable"], + ) if ok: templateText = "|add:{0}".format(data[0]) elif tag == "addslashes": @@ -1008,15 +1176,17 @@ None, self.tr("Center Value"), self.tr("Enter width of the output:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: templateText = '|center:"{0}"'.format(width) elif tag == "cut": data, ok = DjangoTagInputDialog.getText( - None, - self.tr("Cut Characters"), - [self.tr("Characters to cut:")], - [" "]) + None, self.tr("Cut Characters"), [self.tr("Characters to cut:")], [" "] + ) if ok: templateText = '|cut:"{0}"'.format(data[0]) elif tag == "date": @@ -1024,20 +1194,27 @@ None, self.tr("Format Date"), self.tr("Enter date format:"), - ["DATETIME_FORMAT", "SHORT_DATETIME_FORMAT", - "SHORT_DATE_FORMAT", "DATE_FORMAT"], - 0, True) + [ + "DATETIME_FORMAT", + "SHORT_DATETIME_FORMAT", + "SHORT_DATE_FORMAT", + "DATE_FORMAT", + ], + 0, + True, + ) if ok: if date: templateText = '|date:"{0}"'.format(date) else: - templateText = '|date' + templateText = "|date" elif tag == "default": data, ok = DjangoTagInputDialog.getText( None, self.tr("Default Value if False"), [self.tr("Enter default value if result is False:")], - ["nothing"]) + ["nothing"], + ) if ok: templateText = '|default:"{0}"'.format(data[0]) elif tag == "default_if_none": @@ -1045,7 +1222,8 @@ None, self.tr("Default Value if None"), [self.tr("Enter default value if result is None:")], - ["nothing"]) + ["nothing"], + ) if ok: templateText = '|default:"{0}"'.format(data[0]) elif tag == "dictsort": @@ -1053,7 +1231,8 @@ None, self.tr("Sort Dictionaries"), [self.tr("Enter key to sort on:")], - ["key"]) + ["key"], + ) if ok: templateText = '|dictsort:"{0}"'.format(data[0]) elif tag == "dictsortreversed": @@ -1061,7 +1240,8 @@ None, self.tr("Sort Dictionaries reversed"), [self.tr("Enter key to sort on:")], - ["key"]) + ["key"], + ) if ok: templateText = '|dictsortreversed:"{0}"'.format(data[0]) elif tag == "divisibleby": @@ -1069,100 +1249,123 @@ None, self.tr("Check Divisibility"), self.tr("Enter divisor value:"), - 2, 1, 99, 1) + 2, + 1, + 99, + 1, + ) if ok: templateText = '|divisibleby:"{0}"'.format(divisor) elif tag == "escape": - templateText = '|escape' + templateText = "|escape" elif tag == "escapejs": - templateText = '|escapejs' + templateText = "|escapejs" elif tag == "filesizeformat": - templateText = '|filesizeformat' + templateText = "|filesizeformat" elif tag == "first": - templateText = '|first' + templateText = "|first" elif tag == "fix_ampersands": - templateText = '|fix_ampersands' + templateText = "|fix_ampersands" elif tag == "floatformat": decimals, ok = QInputDialog.getInt( None, self.tr("Format Floating Number"), self.tr("Enter number of decimal places:"), - 2, -20, 20, 1) + 2, + -20, + 20, + 1, + ) if ok: templateText = '|floatformat:"{0}"'.format(decimals) elif tag == "force_escape": - templateText = '|force_escape' + templateText = "|force_escape" elif tag == "get_digit": digit, ok = QInputDialog.getInt( None, self.tr("Get Rightmost Digit"), self.tr("Enter index of digit:"), - 1, 1, 99, 1) + 1, + 1, + 99, + 1, + ) if ok: templateText = '|get_digit:"{0}"'.format(digit) elif tag == "iriencode": - templateText = '|iriencode' + templateText = "|iriencode" elif tag == "join": data, ok = DjangoTagInputDialog.getText( None, self.tr("Join List"), [self.tr("Enter string to join by:")], - ["//"]) + ["//"], + ) if ok: templateText = '|join:"{0}"'.format(data[0]) elif tag == "last": - templateText = '|last' + templateText = "|last" elif tag == "length": - templateText = '|length' + templateText = "|length" elif tag == "length_is": length, ok = QInputDialog.getInt( None, self.tr("Check Length"), self.tr("Enter desired length:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: templateText = '|length_is:"{0}"'.format(length) elif tag == "linebreaks": - templateText = '|linebreaks' + templateText = "|linebreaks" elif tag == "linebreaksbr": - templateText = '|linebreaksbr' + templateText = "|linebreaksbr" elif tag == "linenumbers": - templateText = '|linenumbers' + templateText = "|linenumbers" elif tag == "ljust": width, ok = QInputDialog.getInt( None, self.tr("Left-align Value"), self.tr("Enter width of the output:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: templateText = '|ljust:"{0}"'.format(width) elif tag == "lower": - templateText = '|lower' + templateText = "|lower" elif tag == "make_list": - templateText = '|make_list' + templateText = "|make_list" elif tag == "phone2numeric": - templateText = '|phone2numeric' + templateText = "|phone2numeric" elif tag == "pluralize": data, ok = DjangoTagInputDialog.getText( None, self.tr("Plural Suffix"), [self.tr("Enter plural suffix (nothing for default):")], - [""]) + [""], + ) if ok: if data[0]: templateText = '|pluralize:"{0}"'.format(data[0]) else: - templateText = '|pluralize' + templateText = "|pluralize" elif tag == "pprint": - templateText = '|pprint' + templateText = "|pprint" elif tag == "random": - templateText = '|random' + templateText = "|random" elif tag == "removetags": data, ok = DjangoTagInputDialog.getText( None, self.tr("Remove HTML Tags"), [self.tr("Enter HTML tags to remove (space separated):")], - ["b span"]) + ["b span"], + ) if ok: templateText = '|removetags:"{0}"'.format(data[0]) elif tag == "rjust": @@ -1170,422 +1373,472 @@ None, self.tr("Right-align Value"), self.tr("Enter width of the output:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: templateText = '|rjust:"{0}"'.format(width) elif tag == "safe": - templateText = '|safe' + templateText = "|safe" elif tag == "safeseq": - templateText = '|safeseq' + templateText = "|safeseq" elif tag == "slice": data, ok = DjangoTagInputDialog.getText( None, self.tr("Extract slice of a list"), [self.tr("Enter Python like slice expression:")], - ["1:5"]) + ["1:5"], + ) if ok: templateText = '|slice:"{0}"'.format(data[0]) elif tag == "slugify": - templateText = '|slugify' + templateText = "|slugify" elif tag == "stringformat": data, ok = DjangoTagInputDialog.getText( None, self.tr("Perform String Formatting"), [self.tr("Enter Python like string format:")], - [""]) + [""], + ) if ok: templateText = '|stringformat:"{0}"'.format(data[0]) elif tag == "striptags": - templateText = '|striptags' + templateText = "|striptags" elif tag == "time": time, ok = QInputDialog.getItem( None, self.tr("Format Date"), self.tr("Enter date format:"), ["TIME_FORMAT"], - 0, True) + 0, + True, + ) if ok: if time: templateText = '|time:"{0}"'.format(time) else: - templateText = '|time' + templateText = "|time" elif tag == "timesince": data[0], ok = DjangoTagInputDialog.getText( None, self.tr("Time Since"), [self.tr("Enter variable containing time reference:")], - ["comment_date"]) + ["comment_date"], + ) if ok: if data[0]: - templateText = '|timesince:{0}'.format(data[0]) + templateText = "|timesince:{0}".format(data[0]) else: - templateText = '|timesince' + templateText = "|timesince" elif tag == "timeuntil": data[0], ok = DjangoTagInputDialog.getText( None, self.tr("Time Until"), [self.tr("Enter variable containing time reference:")], - ["from_date"]) + ["from_date"], + ) if ok: if data[0]: - templateText = '|timeuntil:{0}'.format(data[0]) + templateText = "|timeuntil:{0}".format(data[0]) else: - templateText = '|timeuntil' + templateText = "|timeuntil" elif tag == "title": - templateText = '|title' + templateText = "|title" elif tag == "truncatechars": characters, ok = QInputDialog.getInt( None, self.tr("Truncate String"), self.tr("Enter number of characters:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: - templateText = '|truncatechars:{0}'.format(characters) + templateText = "|truncatechars:{0}".format(characters) elif tag == "truncatewords": words, ok = QInputDialog.getInt( None, self.tr("Truncate String"), self.tr("Enter number of words:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: - templateText = '|truncatewords:{0}'.format(words) + templateText = "|truncatewords:{0}".format(words) elif tag == "truncatewords_html": words, ok = QInputDialog.getInt( None, self.tr("Truncate String"), self.tr("Enter number of words:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: - templateText = '|truncatewords_html:{0}'.format(words) + templateText = "|truncatewords_html:{0}".format(words) elif tag == "unordered_list": - templateText = '|unordered_list' + templateText = "|unordered_list" elif tag == "upper": - templateText = '|upper' + templateText = "|upper" elif tag == "urlencode": - templateText = '|urlencode' + templateText = "|urlencode" elif tag == "urlize": - templateText = '|urlize' + templateText = "|urlize" elif tag == "urlizetrunc": characters, ok = QInputDialog.getInt( None, self.tr("Convert URLs as clickable links and truncate"), self.tr("Enter number of characters:"), - 10, 1, 199, 1) + 10, + 1, + 199, + 1, + ) if ok: - templateText = '|urlizetrunc:{0}'.format(characters) + templateText = "|urlizetrunc:{0}".format(characters) elif tag == "wordcount": - templateText = '|wordcount' + templateText = "|wordcount" elif tag == "wordwrap": characters, ok = QInputDialog.getInt( None, self.tr("Wrap words"), self.tr("Enter number of characters:"), - 10, 1, 99, 1) + 10, + 1, + 99, + 1, + ) if ok: - templateText = '|wordwrap:{0}'.format(characters) + templateText = "|wordwrap:{0}".format(characters) elif tag == "yesno": data, ok = DjangoTagInputDialog.getText( None, self.tr("Map True, False and None"), [self.tr("Enter mapping (comma separated):")], - ["yeah,no,maybe"]) + ["yeah,no,maybe"], + ) if ok: if data[0]: templateText = '|yesno:"{0}"'.format(data[0]) else: - templateText = '|yesno' - + templateText = "|yesno" + #################################################### ## Humanize Template Tags ## #################################################### - + elif tag == "loadhumanize": - templateText = '{% load humanize %}' + templateText = "{% load humanize %}" elif tag == "apnumber": - templateText = '|apnumber' + templateText = "|apnumber" elif tag == "intcomma": - templateText = '|intcomma' + templateText = "|intcomma" elif tag == "intword": - templateText = '|intword' + templateText = "|intword" elif tag == "naturalday": - templateText = '|naturalday' + templateText = "|naturalday" elif tag == "naturaltime": - templateText = '|naturaltime' + templateText = "|naturaltime" elif tag == "ordinal": - templateText = '|ordinal' - + templateText = "|ordinal" + #################################################### ## Web Design Template Tags ## #################################################### - + elif tag == "loadweb": - templateText = '{% load webdesign %}' + templateText = "{% load webdesign %}" elif tag == "lorem": from .LoremTagInputDialog import LoremTagInputDialog + dlg = LoremTagInputDialog() if dlg.exec() == QDialog.DialogCode.Accepted: templateText = "{{% {0} %}}".format(dlg.getTag()) - + #################################################### ## Static Template Tags ## #################################################### - + elif tag == "loadstatic": - templateText = '{% load static %}' + templateText = "{% load static %}" elif tag == "staticfile": data, ok = DjangoTagInputDialog.getText( None, self.tr("Link to static file"), [self.tr("Enter relative path of static file:")], - ["images/hi.jpg"]) + ["images/hi.jpg"], + ) if ok: templateText = '{{% static "{0}" %}}'.format(data[0]) elif tag == "staticvariable": data, ok = DjangoTagInputDialog.getText( None, self.tr("Link to static file"), - [self.tr("Enter variable containing relative path of" - " static file:")], - ["user_stylesheet"]) + [self.tr("Enter variable containing relative path of" " static file:")], + ["user_stylesheet"], + ) if ok: - templateText = '{{% static {0} %}}'.format(data[0]) + templateText = "{{% static {0} %}}".format(data[0]) elif tag == "get_static_prefix": - templateText = '{% get_static_prefix %}' + templateText = "{% get_static_prefix %}" elif tag == "get_media_prefix": - templateText = '{% get_media_prefix %}' - + templateText = "{% get_media_prefix %}" + #################################################### ## Comments ## #################################################### - + elif tag in ("comment", "multilinecommentselect"): - templateText = "{{% comment %}} {0} {{% endcomment %}}".format( - selectedText) + templateText = "{{% comment %}} {0} {{% endcomment %}}".format(selectedText) replace = True elif tag == "singlelinecommentselect": - templateText = '{{# {0} #}}'.format(selectedText) + templateText = "{{# {0} #}}".format(selectedText) replace = True elif tag == "singlelinecommentdialog": data, ok = DjangoTagInputDialog.getText( - None, - self.tr("Single Line Comment"), - [self.tr("Enter comment:")], - [""]) + None, self.tr("Single Line Comment"), [self.tr("Enter comment:")], [""] + ) if ok: - templateText = '{{# {0} #}}'.format(data[0]) + templateText = "{{# {0} #}}".format(data[0]) elif tag == "multilinecommentdialog": from .MultiLineInputDialog import MultiLineInputDialog + comment, ok = MultiLineInputDialog.getText( - None, self.tr("Multi Line Comment"), - self.tr("Enter comment:"), "") + None, self.tr("Multi Line Comment"), self.tr("Enter comment:"), "" + ) if ok: - templateText = '{{% comment %}} {0} {{% endcomment %}}'.format( - comment) + templateText = "{{% comment %}} {0} {{% endcomment %}}".format(comment) elif tag == "singlelinecommentclipboard": - templateText = '{{# {0} #}}'.format( - QApplication.clipboard().text().strip()) + templateText = "{{# {0} #}}".format(QApplication.clipboard().text().strip()) elif tag == "multilinecommentclipboard": - templateText = '{{% comment %}} {0} {{% endcomment %}}'.format( - QApplication.clipboard().text().strip()) + templateText = "{{% comment %}} {0} {{% endcomment %}}".format( + QApplication.clipboard().text().strip() + ) elif tag == "multilinecommentfile": filename = EricFileDialog.getOpenFileName( None, self.tr("Comment File"), Utilities.getHomeDir(), - self.tr("All Files (*)")) + self.tr("All Files (*)"), + ) if filename: try: with open(filename, "r", encoding="utf-8") as f: comment = f.read() - templateText = ( - '{{% comment %}} {0} {{% endcomment %}}'.format( - comment)) - except (IOError, OSError) as err: + templateText = "{{% comment %}} {0} {{% endcomment %}}".format( + comment + ) + except OSError as err: EricMessageBox.critical( None, self.tr("Comment File"), - self.tr("""<p>The file <b>{0}</b> could not be""" - """ read.</p><p>Reason: {1}</p>""").format( - str(err))) + self.tr( + """<p>The file <b>{0}</b> could not be""" + """ read.</p><p>Reason: {1}</p>""" + ).format(str(err)), + ) elif tag == "singlelinecommentdatetime": - templateText = '{{# {0} by {1} #}}'.format( - datetime.datetime.now().isoformat().split(), - Utilities.getUserName()) + templateText = "{{# {0} by {1} #}}".format( + datetime.datetime.now().isoformat().split(), Utilities.getUserName() + ) elif tag == "htmlcomment": - templateText = '<!-- {0} -->'.format(selectedText) + templateText = "<!-- {0} -->".format(selectedText) replace = True elif tag == "iecomment": from .IeCommentDialog import IeCommentDialog + tag, ok = IeCommentDialog.getTag(selectedText) if ok: - templateText = '<!--{0}-->'.format(tag) + templateText = "<!--{0}-->".format(tag) replace = True - + #################################################### ## Internationalization ## #################################################### - + elif tag == "loadi18n": - templateText = '{% load i18n %}' + templateText = "{% load i18n %}" ## Tags ## elif tag == "trans": - if ' ' in selectedText: + if " " in selectedText: selectedText = '"{0}"'.format(selectedText) - templateText = '{{% trans {0} %}}'.format(selectedText) + templateText = "{{% trans {0} %}}".format(selectedText) replace = True elif tag == "trans..as": data, ok = DjangoTagInputDialog.getText( None, self.tr("Translate String into Variable"), [self.tr("Enter variable receiving translation:")], - ["translation"]) + ["translation"], + ) if ok: templateText = '{{% trans "{0}" as {1} %}}'.format( - selectedText, data[0]) + selectedText, data[0] + ) replace = True elif tag == "blocktrans": - templateText = '{{% blocktrans %}}{0}{{% endblocktrans %}}'.format( - selectedText) + templateText = "{{% blocktrans %}}{0}{{% endblocktrans %}}".format( + selectedText + ) replace = True elif tag == "blocktrans..with": data, ok = DjangoTagInputDialog.getText( None, self.tr("Translate Block with Attributes"), - [self.tr("Enter attribute binding expressions" - " (space separated):")], - ["myvar1=value1 myvar2=value2"]) + [self.tr("Enter attribute binding expressions" " (space separated):")], + ["myvar1=value1 myvar2=value2"], + ) if ok: templateText = ( - '{{% blocktrans with {0} %}}{1}{{% endblocktrans %}}' - .format(data[0], selectedText)) + "{{% blocktrans with {0} %}}{1}{{% endblocktrans %}}".format( + data[0], selectedText + ) + ) replace = True elif tag == "plural": - templateText = '{{% plural %}} {0}'.format(selectedText) + templateText = "{{% plural %}} {0}".format(selectedText) replace = True elif tag == "language": data, ok = DjangoTagInputDialog.getText( - None, - self.tr("Switch language"), - [self.tr("Enter language:")], - ["en"]) + None, self.tr("Switch language"), [self.tr("Enter language:")], ["en"] + ) if ok: - templateText = ( - "{{% language '{0}' %}}{1}{{% endlanguage %}}" - .format(data[0], selectedText)) + templateText = "{{% language '{0}' %}}{1}{{% endlanguage %}}".format( + data[0], selectedText + ) replace = True elif tag == "get_current_language": - templateText = '{% get_current_language as LANGUAGE_CODE %}' + templateText = "{% get_current_language as LANGUAGE_CODE %}" elif tag == "get_available_languages": - templateText = '{% get_available_languages as LANGUAGES %}' + templateText = "{% get_available_languages as LANGUAGES %}" elif tag == "get_current_language_bidi": - templateText = '{% get_current_language_bidi as LANGUAGE_BIDI %}' + templateText = "{% get_current_language_bidi as LANGUAGE_BIDI %}" elif tag == "get_language_info": data, ok = DjangoTagInputDialog.getText( None, self.tr("Language Information"), - [self.tr("Enter language string or variable (empty for" - " LANGUAGE_CODE):")], - ['"en"']) + [ + self.tr( + "Enter language string or variable (empty for" + " LANGUAGE_CODE):" + ) + ], + ['"en"'], + ) if ok: if data[0]: + templateText = '{{% get_language_info for "{0}" as lang %}}'.format( + data[0] + ) + else: templateText = ( - '{{% get_language_info for "{0}" as lang %}}' - .format(data[0])) - else: - templateText = ("{% get_language_info for LANGUAGE_CODE" - " as lang %}") + "{% get_language_info for LANGUAGE_CODE" " as lang %}" + ) elif tag == "get_language_info_list": data, ok = DjangoTagInputDialog.getText( None, self.tr("Language Information for a list of languages"), - [self.tr("Enter language list variable (empty for" - " LANGUAGES):")], - ["available_languages"]) + [self.tr("Enter language list variable (empty for" " LANGUAGES):")], + ["available_languages"], + ) if ok: if data[0]: templateText = ( - '{{% get_language_info_list for {0} as langs %}}' - .format(data[0])) + "{{% get_language_info_list for {0} as langs %}}".format( + data[0] + ) + ) else: - templateText = ("{% get_language_info_list for LANGUAGES" - " as langs %}") + templateText = ( + "{% get_language_info_list for LANGUAGES" " as langs %}" + ) ## Filters ## elif tag == "language_name": - templateText = '|language_name' + templateText = "|language_name" elif tag == "language_name_local": - templateText = '|language_name_local' + templateText = "|language_name_local" elif tag == "bidi": - templateText = '|bidi' - + templateText = "|bidi" + #################################################### ## Localization ## #################################################### - + elif tag == "loadl10n": - templateText = '{% load l10n %}' + templateText = "{% load l10n %}" ## Tags ## elif tag == "localize_on": - templateText = '{{% localize on %}}{0}{{% endlocalize %}}'.format( - selectedText) + templateText = "{{% localize on %}}{0}{{% endlocalize %}}".format( + selectedText + ) replace = True elif tag == "localize_off": - templateText = '{{% localize off %}}{0}{{% endlocalize %}}'.format( - selectedText) + templateText = "{{% localize off %}}{0}{{% endlocalize %}}".format( + selectedText + ) replace = True ## Filters ## elif tag == "localize": - templateText = '|localize' + templateText = "|localize" elif tag == "unlocalize": - templateText = '|unlocalize' - + templateText = "|unlocalize" + #################################################### ## Timezone ## #################################################### - + elif tag == "loadtz": - templateText = '{% load tz %}' + templateText = "{% load tz %}" ## Tags ## elif tag == "localtime_on": - templateText = ( - '{{% localtime on %}}{0}{{% endlocaltime %}}'.format( - selectedText)) + templateText = "{{% localtime on %}}{0}{{% endlocaltime %}}".format( + selectedText + ) replace = True elif tag == "localtime_off": - templateText = ( - '{{% localtime off %}}{0}{{% endlocaltime %}}'.format( - selectedText)) + templateText = "{{% localtime off %}}{0}{{% endlocaltime %}}".format( + selectedText + ) replace = True elif tag == "timezone_set": from .TimezoneSelectionDialog import TimezoneSelectionDialog + timezone, ok = TimezoneSelectionDialog.getTimezone() if ok: - templateText = ( - '{{% timezone "{0}" %}}{1}{{% endtimezone %}}'.format( - timezone, selectedText)) + templateText = '{{% timezone "{0}" %}}{1}{{% endtimezone %}}'.format( + timezone, selectedText + ) replace = True elif tag == "timezone_unset": - templateText = ( - '{{% timezone None %}}{0}{{% endlocaltime %}}'.format( - selectedText)) + templateText = "{{% timezone None %}}{0}{{% endlocaltime %}}".format( + selectedText + ) replace = True elif tag == "get_current_timezone": - templateText = '{% get_current_timezone as TIME_ZONE %}' + templateText = "{% get_current_timezone as TIME_ZONE %}" ## Filters ## elif tag == "localtime": - templateText = '|localtime' + templateText = "|localtime" elif tag == "utc": - templateText = '|utc' + templateText = "|utc" elif tag == "timezone": from .TimezoneSelectionDialog import TimezoneSelectionDialog + timezone, ok = TimezoneSelectionDialog.getTimezone() if ok: templateText = '|timezone:"{0}"'.format(timezone) - + #################################################### ## Fallback: return just the tag name ## #################################################### - + else: templateText = tag - + return templateText, replace
--- a/ProjectDjangoTagsMenu/FindTemplateTagDialog.py Thu Dec 30 12:03:18 2021 +0100 +++ b/ProjectDjangoTagsMenu/FindTemplateTagDialog.py Wed Sep 21 16:38:40 2022 +0200 @@ -16,94 +16,191 @@ 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 = 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): """
--- a/ProjectDjangoTagsMenu/IeCommentDialog.py Thu Dec 30 12:03:18 2021 +0100 +++ b/ProjectDjangoTagsMenu/IeCommentDialog.py Wed Sep 21 16:38:40 2022 +0200 @@ -16,39 +16,46 @@ """ Class implementing a dialog to enter data for an IE comment. """ + def __init__(self, parent=None): """ Constructor - + @param parent reference to the parent widget @type QWidget """ super().__init__(parent) self.setupUi(self) - - for condStr, condData in [("==", ""), ("<=", " lte"), ("<", " lt"), - (">", " gt"), (">=", " gte")]: + + for condStr, condData in [ + ("==", ""), + ("<=", " lte"), + ("<", " lt"), + (">", " gt"), + (">=", " gte"), + ]: self.conditionalComboBox.addItem(condStr, condData) - + msh = self.minimumSizeHint() self.resize(max(self.width(), msh.width()), msh.height()) - + def getData(self): """ Public method to retrieve the entered data. - + @return tuple of condition and version @rtype tuple of (str, int) """ - return (self.conditionalComboBox.itemData( - self.conditionalComboBox.currentIndex()), - self.versionSpinBox.value()) - + return ( + self.conditionalComboBox.itemData(self.conditionalComboBox.currentIndex()), + self.versionSpinBox.value(), + ) + @staticmethod def getTag(selectedText): """ Public static method to get the formatted tag. - + @param selectedText selected text to embed @type str @return formatted tag and a flag indicating the acceptance state @@ -57,8 +64,9 @@ dlg = IeCommentDialog() if dlg.exec() == QDialog.DialogCode.Accepted: condition, version = dlg.getData() - tag = '[if{0} IE {1}]> {2} <![endif]'.format( - condition, version, selectedText) + tag = "[if{0} IE {1}]> {2} <![endif]".format( + condition, version, selectedText + ) return tag, True else: return "", False
--- a/ProjectDjangoTagsMenu/IfTagInputDialog.py Thu Dec 30 12:03:18 2021 +0100 +++ b/ProjectDjangoTagsMenu/IfTagInputDialog.py Wed Sep 21 16:38:40 2022 +0200 @@ -17,45 +17,44 @@ """ Class implementing a dialog to enter the parameters for the if tag. """ + def __init__(self, parent=None): """ Constructor - + @param parent reference to the parent widget @type QWidget """ super().__init__(parent) self.setupUi(self) - - self.buttonBox.button( - QDialogButtonBox.StandardButton.Ok).setEnabled(False) - + + self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) + @pyqtSlot(str) def on_ifEdit_textChanged(self, txt): """ Private slot to handle changes of the 'if' expression. - + @param txt text of the line edit @type str """ - self.buttonBox.button( - QDialogButtonBox.StandardButton.Ok).setEnabled(bool(txt)) - + self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(bool(txt)) + def getTag(self): """ Public method to retrieve the tag. - + @return tag @rtype str """ - tag = '{{% if {0} %}}\n'.format(self.ifEdit.text()) + tag = "{{% if {0} %}}\n".format(self.ifEdit.text()) elifText = self.elifEdit.toPlainText() if elifText: for expression in elifText.splitlines(): if expression.strip(): - tag += '{{% elif {0} %}}\n'.format(expression.strip()) + tag += "{{% elif {0} %}}\n".format(expression.strip()) if self.elseCheckBox.isChecked(): - tag += '{% else %}\n' - tag += '{% endif %}' - + tag += "{% else %}\n" + tag += "{% endif %}" + return tag
--- a/ProjectDjangoTagsMenu/LoremTagInputDialog.py Thu Dec 30 12:03:18 2021 +0100 +++ b/ProjectDjangoTagsMenu/LoremTagInputDialog.py Wed Sep 21 16:38:40 2022 +0200 @@ -16,30 +16,31 @@ """ Class implementing a dialog to enter the parameters for the lorem tag. """ + def __init__(self, parent=None): """ Constructor - + @param parent reference to the parent widget @type QWidget """ super().__init__(parent) self.setupUi(self) - + msh = self.minimumSizeHint() self.resize(max(self.width(), msh.width()), msh.height()) - + def getTag(self): """ Public method to get the generated tag string. - + @return tag string @rtype str """ count = "{0}".format(self.countSpinBox.value()) method = "{0}".format("bpw"[self.methodComboBox.currentIndex()]) random = "random" if self.randomCheckBox.isChecked() else "" - + if random: return "lorem {0} {1} {2}".format(count, method, random) elif method != "b":
--- a/ProjectDjangoTagsMenu/MultiLineInputDialog.py Thu Dec 30 12:03:18 2021 +0100 +++ b/ProjectDjangoTagsMenu/MultiLineInputDialog.py Wed Sep 21 16:38:40 2022 +0200 @@ -16,10 +16,11 @@ """ Class implementing a dialog for the input of multi line text. """ + def __init__(self, label, default, parent=None): """ Constructor - + @param label label for the entry field @type str @param default default value for the entry field @@ -29,22 +30,22 @@ """ super().__init__(parent) self.setupUi(self) - + def getData(self): """ Public method to retrieve the multi line text. - + @return multi line text @rtype str """ return self.multiLineEdit.toPlainText() - + @staticmethod def getText(parent, title, label, default=""): """ Public static method to create the dialog and return the multi line text. - + @param parent reference to the parent widget @type QWidget @param title title of the dialog
--- a/ProjectDjangoTagsMenu/TimezoneSelectionDialog.py Thu Dec 30 12:03:18 2021 +0100 +++ b/ProjectDjangoTagsMenu/TimezoneSelectionDialog.py Wed Sep 21 16:38:40 2022 +0200 @@ -17,6 +17,7 @@ """ Class implementing a dialog to select a time zone. """ + Timezones = { "Africa": [ "Abidjan", @@ -600,73 +601,70 @@ "Samoa", ], } - + def __init__(self, parent=None): """ Constructor - + @param parent reference to the parent widget @type QWidget """ super().__init__(parent) self.setupUi(self) - - self.buttonBox.button( - QDialogButtonBox.StandardButton.Ok).setEnabled(False) - + + self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) + self.regionCombo.addItems([" "] + sorted(self.Timezones.keys())) - + def __updateOK(self): """ Private method to update the OK button. """ self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( - bool(self.regionCombo.currentText()) and - len(self.cityList.selectedItems()) == 1 + bool(self.regionCombo.currentText()) + and len(self.cityList.selectedItems()) == 1 ) - + @pyqtSlot(str) def on_regionCombo_currentTextChanged(self, region): """ Private slot handling the selection of a time zone region. - + @param region selected region @type str """ self.cityList.clear() if region in self.Timezones: self.cityList.addItems(sorted(self.Timezones[region])) - + self.__updateOK() - + @pyqtSlot() def on_cityList_itemSelectionChanged(self): """ Private slot handling a change of the city selection. """ self.__updateOK() - + def getData(self): """ Public method to retrieve the data. - + @return selected time zone @rtype str """ - if (self.regionCombo.currentText() and - len(self.cityList.selectedItems()) == 1): + if self.regionCombo.currentText() and len(self.cityList.selectedItems()) == 1: return "{0}/{1}".format( - self.regionCombo.currentText(), - self.cityList.selectedItems()[0].text() + self.regionCombo.currentText(), self.cityList.selectedItems()[0].text() ) else: return "" - + @staticmethod def getTimezone(parent=None): """ Public static method to select a time zone. - + @param parent reference to the parent widget @type QWidget @return tuple of selected time zone and flag indicating the acceptance