Started implementing the tags functionality.

Sun, 02 Feb 2014 20:02:23 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 02 Feb 2014 20:02:23 +0100
changeset 2
4be31b0908c7
parent 1
b2f26d630942
child 3
6d10c1249cb8

Started implementing the tags functionality.

.hgignore file | annotate | diff | comparison | revisions
PluginDjangoTagsMenu.e4p file | annotate | diff | comparison | revisions
PluginProjectDjangoTagsMenu.py file | annotate | diff | comparison | revisions
ProjectDjangoTagsMenu/DjangoTagsMenuHandler.py file | annotate | diff | comparison | revisions
ProjectDjangoTagsMenu/FindTemplateTagDialog.py file | annotate | diff | comparison | revisions
ProjectDjangoTagsMenu/FindTemplateTagDialog.ui file | annotate | diff | comparison | revisions
ProjectDjangoTagsMenu/__init__.py file | annotate | diff | comparison | revisions
--- a/.hgignore	Sun Feb 02 18:03:21 2014 +0100
+++ b/.hgignore	Sun Feb 02 20:02:23 2014 +0100
@@ -15,3 +15,4 @@
 glob:tmp
 glob:__pycache__
 glob:**.DS_Store
+glob:Ui_*.py
--- a/PluginDjangoTagsMenu.e4p	Sun Feb 02 18:03:21 2014 +0100
+++ b/PluginDjangoTagsMenu.e4p	Sun Feb 02 20:02:23 2014 +0100
@@ -2,7 +2,7 @@
 <!DOCTYPE Project SYSTEM "Project-5.1.dtd">
 <!-- eric5 project file for project PluginDjangoTagsMenu -->
 <Project version="5.1">
-  <Language>en</Language>
+  <Language>en_US</Language>
   <Hash>fac07f0675a7c77618ebfac9d2cbbfb763f751f3</Hash>
   <ProgLanguage mixed="0">Python3</ProgLanguage>
   <ProjectType>E4Plugin</ProjectType>
@@ -15,13 +15,19 @@
   <Sources>
     <Source>__init__.py</Source>
     <Source>PluginProjectDjangoTagsMenu.py</Source>
+    <Source>ProjectDjangoTagsMenu/__init__.py</Source>
+    <Source>ProjectDjangoTagsMenu/DjangoTagsMenuHandler.py</Source>
+    <Source>ProjectDjangoTagsMenu/FindTemplateTagDialog.py</Source>
   </Sources>
-  <Forms/>
+  <Forms>
+    <Form>ProjectDjangoTagsMenu/FindTemplateTagDialog.ui</Form>
+  </Forms>
   <Translations/>
   <Resources/>
   <Interfaces/>
   <Others>
     <Other>.hgignore</Other>
+    <Other>PluginDjangoTagsMenu.e4p</Other>
   </Others>
   <MainScript>PluginProjectDjangoTagsMenu.py</MainScript>
   <Vcs>
@@ -141,6 +147,7 @@
     <FiletypeAssociation pattern="*.ts" type="TRANSLATIONS"/>
     <FiletypeAssociation pattern="*.ui" type="FORMS"/>
     <FiletypeAssociation pattern="*.ui.h" type="FORMS"/>
+    <FiletypeAssociation pattern="Ui_*.py" type="__IGNORE__"/>
   </FiletypeAssociations>
   <Checkers>
     <CheckersParams>
--- a/PluginProjectDjangoTagsMenu.py	Sun Feb 02 18:03:21 2014 +0100
+++ b/PluginProjectDjangoTagsMenu.py	Sun Feb 02 20:02:23 2014 +0100
@@ -16,6 +16,8 @@
 
 from E5Gui.E5Application import e5App
 
+from ProjectDjangoTagsMenu.DjangoTagsMenuHandler import DjangoTagsMenuHandler
+
 # Start-of-Header
 name = "Django Tags Menu Plugin"
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
@@ -45,9 +47,11 @@
         
         @param ui reference to the user interface object (UI.UserInterface)
         """
-        QObject.__init__(self, ui)
+        super(ProjectDjangoTagsMenuPlugin, self).__init__(ui)
         self.__ui = ui
         
+        self.__handler = DjangoTagsMenuHandler(ui, self)
+        
         self.__initMenu()
     
     def __initMenu(self):
@@ -59,6 +63,7 @@
         self.__menuSeparator = None
         
         self.__menu = QMenu(self.tr("Template Tags"))
+        self.__handler.initMenus(self.__menu)
     
     def __attachMenu(self):
         """
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ProjectDjangoTagsMenu/DjangoTagsMenuHandler.py	Sun Feb 02 20:02:23 2014 +0100
@@ -0,0 +1,72 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the Django tags menu handler.
+"""
+
+from PyQt4.QtCore import QObject
+
+from E5Gui.E5Application import e5App
+
+class DjangoTagsMenuHandler(QObject):
+    """
+    Class implementing the Django tags menu handler.
+    """
+    def __init__(self, ui, parent=None):
+        """
+        Constructor
+        
+        @param ui reference to the user interface object (UI.UserInterface)
+        @param parent reference to the parent object (QObject)
+        """
+        super(DjangoTagsMenuHandler, self).__init__(parent)
+        self.__ui = ui
+        
+        self.__findDialog = None
+    
+    def initMenus(self, mainMenu):
+        """
+        Public method to initialize the various menus.
+        
+        @param mainMenu reference to the main tags menu (QMenu)
+        """
+        mainMenu.addAction(self.tr("Django Template Tags Locator"),
+                           self.__findTemplateTag)
+    
+    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.__ui)
+            self.__findDialog.tag.connect(self.__applyTemplate)
+        self.__findDialog.show()
+    
+    def __applyTemplate(self, tag):
+        """
+        Private slot to generate and insert the template text.
+        
+        @param tag name of the tag to insert (string)
+        """
+        editor = e5App().getObject("ViewManager").activeWindow()
+        if editor is None:
+            return
+        
+        templateText = self.__generateTemplateText(tag)
+        
+        editor.beginUndoAction()
+        editor.replaceSelectedText(templateText)
+        editor.endUndoAction()
+    
+    def __generateTemplateText(self, tag):
+        """
+        Private slot to generate the template text.
+        
+        @param tag name of the tag to insert (string)
+        """
+        # TODO: implement the tag generation logic
+        return "needs real tags"
--- /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)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ProjectDjangoTagsMenu/FindTemplateTagDialog.ui	Sun Feb 02 20:02:23 2014 +0100
@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>FindTemplateTagDialog</class>
+ <widget class="QDialog" name="FindTemplateTagDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>500</width>
+    <height>132</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Find Template Tag</string>
+  </property>
+  <property name="sizeGripEnabled">
+   <bool>true</bool>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>&lt;b&gt;Find Tags and Filters while Typing:&lt;/b&gt;</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="E5ClearableLineEdit" name="tagEdit">
+     <property name="toolTip">
+      <string>Type to find tag</string>
+     </property>
+     <property name="placeholderText">
+      <string>Type to find tag</string>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QPushButton" name="createButton">
+       <property name="minimumSize">
+        <size>
+         <width>250</width>
+         <height>0</height>
+        </size>
+       </property>
+       <property name="toolTip">
+        <string>Press to create the entered template tag</string>
+       </property>
+       <property name="text">
+        <string>Create Template Tag</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Close</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>E5ClearableLineEdit</class>
+   <extends>QLineEdit</extends>
+   <header>E5Gui/E5LineEdit.h</header>
+  </customwidget>
+ </customwidgets>
+ <tabstops>
+  <tabstop>tagEdit</tabstop>
+  <tabstop>createButton</tabstop>
+  <tabstop>buttonBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>accepted()</signal>
+   <receiver>FindTemplateTagDialog</receiver>
+   <slot>accept()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>248</x>
+     <y>254</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>157</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+  <connection>
+   <sender>buttonBox</sender>
+   <signal>rejected()</signal>
+   <receiver>FindTemplateTagDialog</receiver>
+   <slot>reject()</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>316</x>
+     <y>260</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>286</x>
+     <y>274</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ProjectDjangoTagsMenu/__init__.py	Sun Feb 02 20:02:23 2014 +0100
@@ -0,0 +1,8 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Package implementing the Django tags menu handler and associated dialogs.
+"""

eric ide

mercurial