Wed, 18 Dec 2013 08:50:31 +0100
Started the 'Print Remover' project.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Wed Dec 18 08:50:31 2013 +0100 @@ -0,0 +1,17 @@ +glob:.eric5project +glob:_eric5project +glob:.eric4project +glob:_eric4project +glob:.ropeproject +glob:_ropeproject +glob:.directory +glob:**.pyc +glob:**.pyo +glob:**.orig +glob:**.bak +glob:**.rej +glob:**~ +glob:cur +glob:tmp +glob:__pycache__ +glob:**.DS_Store
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PluginPrintRemover.py Wed Dec 18 08:50:31 2013 +0100 @@ -0,0 +1,224 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2013 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing the Print Remover plug-in. +""" + +from __future__ import unicode_literals # __IGNORE_WARNING__ + +import os + +from PyQt4.QtCore import QObject, QTranslator, QCoreApplication +from PyQt4.QtGui import QAction + +from E5Gui.E5Application import e5App + +import Preferences + +# Start-Of-Header +name = "Print Remover Plug-in" +author = "Detlev Offenbach <detlev@die-offenbachs.de>" +autoactivate = True +deactivateable = True +version = "0.1.0" +className = "PrintRemoverPlugin" +packageName = "PrintRemover" +shortDescription = "Remove print() like debug statements." +longDescription = \ + """This plug-in implements a tool to remove lines starting with""" \ + """ a configurable string. This is mostly used to remove print()""" \ + """ like debug statements. The match is done after stripping all""" \ + """ whitespace from the beginning of a line. Lines containing the""" \ + """ string '__NO_REMOVE__' are preserved""" +needsRestart = False +pyqtApi = 2 +# End-Of-Header + +error = "" + +printRemoverPluginObject = None + + +def createPrintRemoverPage(configDlg): + """ + Module function to create the Print Remover configuration page. + + @param configDlg reference to the configuration dialog + @return reference to the configuration page + """ + global printRemoverPluginObject + from PrintRemover.ConfigurationPage.PrintRemoverPage import \ + PrintRemoverPage + page = PrintRemoverPage(printRemoverPluginObject) + return page + + +def getConfigData(): + """ + Module function returning data as required by the configuration dialog. + + @return dictionary containing the relevant data + """ + if e5App().getObject("UserInterface").versionIsNewer('5.2.99', '20121012'): + # TODO: add a sensible icon + return { + "printRemoverPage": [ + QCoreApplication.translate("PrintRemoverPlugin", + "Print Remover"), + os.path.join("PrintRemover", "icons", "clock.png"), + createPrintRemoverPage, None, None], + } + else: + return {} + + +def prepareUninstall(): + """ + Module function to prepare for an uninstallation. + """ + Preferences.Prefs.settings.remove(PrintRemoverPlugin.PreferencesKey) + + +class PrintRemoverPlugin(QObject): + """ + Class implementing the Print Remover plugin. + """ + PreferencesKey = "PrintRemover" + + def __init__(self, ui): + """ + Constructor + + @param ui reference to the user interface object (UI.UserInterface) + """ + QObject.__init__(self, ui) + self.__ui = ui + + self.__defaults = { + "StartswithStrings": [ + "print(", "print ", "console.log"], + } + + self.__translator = None + self.__loadTranslator() + + def activate(self): + """ + Public method to activate this plugin. + + @return tuple of None and activation status (boolean) + """ + global error + error = "" # clear previous error + + global printRemoverPluginObject + printRemoverPluginObject = self + + self.__ui.showMenu.connect(self.__populateMenu) + + return None, True + + def deactivate(self): + """ + Public method to deactivate this plugin. + """ + self.__ui.showMenu.disconnect(self.__populateMenu) + + def __loadTranslator(self): + """ + Private method to load the translation file. + """ + if self.__ui is not None: + loc = self.__ui.getLocale() + if loc and loc != "C": + locale_dir = os.path.join( + os.path.dirname(__file__), "PrintRemover", "i18n") + translation = "printremover_{0}".format(loc) + translator = QTranslator(None) + loaded = translator.load(translation, locale_dir) + if loaded: + self.__translator = translator + e5App().installTranslator(self.__translator) + else: + print("Warning: translation file '{0}' could not be" + " loaded.".format(translation)) + print("Using default.") + + def getPreferences(self, key): + """ + Public method to retrieve the various settings. + + @param key the key of the value to get (string) + @return the requested setting + """ + if key in ["StartswithStrings"]: + return Preferences.toList( + Preferences.Prefs.settings.value( + self.PreferencesKey + "/" + key, self.__defaults[key])) + else: + return Preferences.Prefs.settings.value( + self.PreferencesKey + "/" + key, self.__defaults[key]) + + def setPreferences(self, key, value): + """ + Public method to store the various settings. + + @param key the key of the setting to be set (string) + @param value the value to be set + """ + Preferences.Prefs.settings.setValue( + self.PreferencesKey + "/" + key, value) + + def __populateMenu(self, name, menu): + """ + Private slot to populate the tools menu with our entries. + + @param name name of the menu (string) + @param menu reference to the menu to be populated (QMenu) + """ + if name != "Tools": + return + + editor = e5App().getObject("ViewManager").activeWindow() + if editor is None: + return + + if not menu.isEmpty(): + menu.addSeparator() + + for string in self.getPreferences("StartswithStrings"): + act = menu.addAction( + self.tr("Remove '{0}'").format(string), + self.__removeLine) + act.setData(string) + + def __removeLine(self): + """ + Private slot to remove lines starting with the selected pattern. + """ + act = self.sender() + if act is None or not isinstance(act, QAction): + return + + editor = e5App().getObject("ViewManager").activeWindow() + if editor is None: + return + + pattern = act.data() + if not pattern: + return + + text = editor.text() + newText = "".join([ + line for line in text.splitlines(keepends=True) + if not line.lstrip().startswith(pattern) or + "__NO_REMOVE__" in line + ]) + if newText != text: + editor.beginUndoAction() + editor.selectAll() + editor.replaceSelectedText(newText) + editor.endUndoAction()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PrintRemover.e4p Wed Dec 18 08:50:31 2013 +0100 @@ -0,0 +1,151 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE Project SYSTEM "Project-5.1.dtd"> +<!-- eric5 project file for project PrintRemover --> +<Project version="5.1"> + <Language>en_US</Language> + <Hash>d994091d1e81ad5afcdcbc00ecea86f23163c696</Hash> + <ProgLanguage mixed="0">Python3</ProgLanguage> + <ProjectType>E4Plugin</ProjectType> + <Description>Plug-in to remove lines starting with a configurable string. Usually this is used to remove print() kind debug statements.</Description> + <Version>0.x</Version> + <Author>Detlev Offenbach</Author> + <Email>detlev@die-offenbachs.de</Email> + <TranslationPattern>PrintRemover/i18n/printremover_%language%.ts</TranslationPattern> + <Eol index="1"/> + <Sources> + <Source>__init__.py</Source> + <Source>PluginPrintRemover.py</Source> + <Source>PrintRemover/__init__.py</Source> + <Source>PrintRemover/ConfigurationPage/__init__.py</Source> + <Source>PrintRemover/ConfigurationPage/Ui_PrintRemoverPage.py</Source> + <Source>PrintRemover/ConfigurationPage/PrintRemoverPage.py</Source> + </Sources> + <Forms> + <Form>PrintRemover/ConfigurationPage/PrintRemoverPage.ui</Form> + </Forms> + <Translations/> + <Resources/> + <Interfaces/> + <Others> + <Other>.hgignore</Other> + </Others> + <MainScript>PluginPrintRemover.py</MainScript> + <Vcs> + <VcsType>Mercurial</VcsType> + <VcsOptions> + <dict> + <key> + <string>add</string> + </key> + <value> + <list> + <string></string> + </list> + </value> + <key> + <string>checkout</string> + </key> + <value> + <list> + <string></string> + </list> + </value> + <key> + <string>commit</string> + </key> + <value> + <list> + <string></string> + </list> + </value> + <key> + <string>diff</string> + </key> + <value> + <list> + <string></string> + </list> + </value> + <key> + <string>export</string> + </key> + <value> + <list> + <string></string> + </list> + </value> + <key> + <string>global</string> + </key> + <value> + <list> + <string></string> + </list> + </value> + <key> + <string>history</string> + </key> + <value> + <list> + <string></string> + </list> + </value> + <key> + <string>log</string> + </key> + <value> + <list> + <string></string> + </list> + </value> + <key> + <string>remove</string> + </key> + <value> + <list> + <string></string> + </list> + </value> + <key> + <string>status</string> + </key> + <value> + <list> + <string></string> + </list> + </value> + <key> + <string>tag</string> + </key> + <value> + <list> + <string></string> + </list> + </value> + <key> + <string>update</string> + </key> + <value> + <list> + <string></string> + </list> + </value> + </dict> + </VcsOptions> + <VcsOtherData> + <dict/> + </VcsOtherData> + </Vcs> + <FiletypeAssociations> + <FiletypeAssociation pattern="*.idl" type="INTERFACES"/> + <FiletypeAssociation pattern="*.py" type="SOURCES"/> + <FiletypeAssociation pattern="*.py3" type="SOURCES"/> + <FiletypeAssociation pattern="*.pyw" type="SOURCES"/> + <FiletypeAssociation pattern="*.pyw3" type="SOURCES"/> + <FiletypeAssociation pattern="*.qm" type="TRANSLATIONS"/> + <FiletypeAssociation pattern="*.qrc" type="RESOURCES"/> + <FiletypeAssociation pattern="*.ts" type="TRANSLATIONS"/> + <FiletypeAssociation pattern="*.ui" type="FORMS"/> + <FiletypeAssociation pattern="*.ui.h" type="FORMS"/> + </FiletypeAssociations> +</Project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PrintRemover/ConfigurationPage/PrintRemoverPage.py Wed Dec 18 08:50:31 2013 +0100 @@ -0,0 +1,90 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2013 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Module implementing the Print Remover configuration page. +""" + +from __future__ import unicode_literals # __IGNORE_WARNING__ + +from PyQt4.QtCore import pyqtSlot, Qt +from PyQt4.QtGui import QListWidgetItem + +from Preferences.ConfigurationPages.ConfigurationPageBase import \ + ConfigurationPageBase +from .Ui_PrintRemoverPage import Ui_PrintRemoverPage + + +class PrintRemoverPage(ConfigurationPageBase, Ui_PrintRemoverPage): + """ + Class implementing the Print Remover configuration page. + """ + def __init__(self, plugin): + """ + Constructor + + @param plugin reference to the plugin object + """ + super(PrintRemoverPage, self).__init__() + self.setupUi(self) + self.setObjectName("PrintRemoverPage") + + self.__plugin = plugin + + # set initial values + for pattern in self.__plugin.getPreferences("StartswithStrings"): + QListWidgetItem(pattern, self.patternList) + + def save(self): + """ + Public slot to save the Print Remover configuration. + """ + patterns = [] + for row in range(self.patternList.count()): + itm = self.patternList.item(row) + patterns.append(itm.text()) + self.__plugin.setPreferences("StartswithStrings", patterns) + + @pyqtSlot() + def on_patternList_itemSelectionChanged(self): + """ + Private slot to handle the selection of patterns. + """ + self.deletePatternButton.setEnabled( + len(self.patternList.selectedItems()) != 0) + + @pyqtSlot() + def on_deletePatternButton_clicked(self): + """ + Private slot to delete the selected items. + """ + for itm in self.patternList.selectedItems(): + self.patternList.takeItem(self.patternList.row(itm)) + del itm + + @pyqtSlot() + def on_addPatternButton_clicked(self): + """ + Private slot add a pattern to the list. + """ + pattern = self.patternEdit.text() + if pattern: + foundItems = self.patternList.findItems( + pattern, Qt.MatchCaseSensitive | Qt.MatchExactly) + if len(foundItems) == 0: + QListWidgetItem(pattern, self.patternList) + self.patternEdit.clear() + + @pyqtSlot(str) + def on_patternEdit_textChanged(self, pattern): + """ + Private slot to handle entering a pattern. + """ + enable = False + if pattern: + foundItems = self.patternList.findItems( + pattern, Qt.MatchCaseSensitive | Qt.MatchExactly) + enable = len(foundItems) == 0 + self.addPatternButton.setEnabled(enable)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PrintRemover/ConfigurationPage/PrintRemoverPage.ui Wed Dec 18 08:50:31 2013 +0100 @@ -0,0 +1,104 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PrintRemoverPage</class> + <widget class="QWidget" name="PrintRemoverPage"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>463</width> + <height>383</height> + </rect> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QLabel" name="headerLabel"> + <property name="text"> + <string><b>Configure Print Remover</b></string> + </property> + </widget> + </item> + <item> + <widget class="Line" name="line15"> + <property name="frameShape"> + <enum>QFrame::HLine</enum> + </property> + <property name="frameShadow"> + <enum>QFrame::Sunken</enum> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>Line Start Patterns:</string> + </property> + </widget> + </item> + <item> + <widget class="QListWidget" name="patternList"> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <property name="selectionMode"> + <enum>QAbstractItemView::ExtendedSelection</enum> + </property> + <property name="sortingEnabled"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QPushButton" name="deletePatternButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Press to delete the selected entries</string> + </property> + <property name="text"> + <string>Delete</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="addPatternButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="toolTip"> + <string>Press to add the entered pattern</string> + </property> + <property name="text"> + <string>Add</string> + </property> + </widget> + </item> + <item> + <widget class="QLineEdit" name="patternEdit"> + <property name="toolTip"> + <string>Enter the pattern to look for</string> + </property> + <property name="placeholderText"> + <string>Line Start Pattern</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + <tabstops> + <tabstop>patternList</tabstop> + <tabstop>deletePatternButton</tabstop> + <tabstop>addPatternButton</tabstop> + <tabstop>patternEdit</tabstop> + </tabstops> + <resources/> + <connections/> +</ui>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PrintRemover/ConfigurationPage/Ui_PrintRemoverPage.py Wed Dec 18 08:50:31 2013 +0100 @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'C:\Users\offedetl\DO\down\Eric5\eric5_plugins\Plugin_Tools_Print_Remover\PrintRemover\ConfigurationPage\PrintRemoverPage.ui' +# +# Created: Tue Dec 17 11:32:51 2013 +# by: PyQt4 UI code generator 4.10.3 +# +# WARNING! All changes made in this file will be lost! + +from PyQt4 import QtCore, QtGui + +try: + _fromUtf8 = QtCore.QString.fromUtf8 +except AttributeError: + def _fromUtf8(s): + return s + +try: + _encoding = QtGui.QApplication.UnicodeUTF8 + def _translate(context, text, disambig): + return QtGui.QApplication.translate(context, text, disambig, _encoding) +except AttributeError: + def _translate(context, text, disambig): + return QtGui.QApplication.translate(context, text, disambig) + +class Ui_PrintRemoverPage(object): + def setupUi(self, PrintRemoverPage): + PrintRemoverPage.setObjectName(_fromUtf8("PrintRemoverPage")) + PrintRemoverPage.resize(463, 383) + self.verticalLayout = QtGui.QVBoxLayout(PrintRemoverPage) + self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) + self.headerLabel = QtGui.QLabel(PrintRemoverPage) + self.headerLabel.setObjectName(_fromUtf8("headerLabel")) + self.verticalLayout.addWidget(self.headerLabel) + self.line15 = QtGui.QFrame(PrintRemoverPage) + self.line15.setFrameShape(QtGui.QFrame.HLine) + self.line15.setFrameShadow(QtGui.QFrame.Sunken) + self.line15.setFrameShape(QtGui.QFrame.HLine) + self.line15.setFrameShadow(QtGui.QFrame.Sunken) + self.line15.setObjectName(_fromUtf8("line15")) + self.verticalLayout.addWidget(self.line15) + self.label = QtGui.QLabel(PrintRemoverPage) + self.label.setObjectName(_fromUtf8("label")) + self.verticalLayout.addWidget(self.label) + self.patternList = QtGui.QListWidget(PrintRemoverPage) + self.patternList.setAlternatingRowColors(True) + self.patternList.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) + self.patternList.setObjectName(_fromUtf8("patternList")) + self.verticalLayout.addWidget(self.patternList) + self.horizontalLayout = QtGui.QHBoxLayout() + self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout")) + self.deletePatternButton = QtGui.QPushButton(PrintRemoverPage) + self.deletePatternButton.setEnabled(False) + self.deletePatternButton.setObjectName(_fromUtf8("deletePatternButton")) + self.horizontalLayout.addWidget(self.deletePatternButton) + self.addPatternButton = QtGui.QPushButton(PrintRemoverPage) + self.addPatternButton.setEnabled(False) + self.addPatternButton.setObjectName(_fromUtf8("addPatternButton")) + self.horizontalLayout.addWidget(self.addPatternButton) + self.patternEdit = QtGui.QLineEdit(PrintRemoverPage) + self.patternEdit.setObjectName(_fromUtf8("patternEdit")) + self.horizontalLayout.addWidget(self.patternEdit) + self.verticalLayout.addLayout(self.horizontalLayout) + + self.retranslateUi(PrintRemoverPage) + QtCore.QMetaObject.connectSlotsByName(PrintRemoverPage) + PrintRemoverPage.setTabOrder(self.patternList, self.deletePatternButton) + PrintRemoverPage.setTabOrder(self.deletePatternButton, self.addPatternButton) + PrintRemoverPage.setTabOrder(self.addPatternButton, self.patternEdit) + + def retranslateUi(self, PrintRemoverPage): + self.headerLabel.setText(_translate("PrintRemoverPage", "<b>Configure Print Remover</b>", None)) + self.label.setText(_translate("PrintRemoverPage", "Line Start Patterns:", None)) + self.patternList.setSortingEnabled(True) + self.deletePatternButton.setToolTip(_translate("PrintRemoverPage", "Press to delete the selected entries", None)) + self.deletePatternButton.setText(_translate("PrintRemoverPage", "Delete", None)) + self.addPatternButton.setToolTip(_translate("PrintRemoverPage", "Press to add the entered pattern", None)) + self.addPatternButton.setText(_translate("PrintRemoverPage", "Add", None)) + self.patternEdit.setToolTip(_translate("PrintRemoverPage", "Enter the pattern to look for", None)) + self.patternEdit.setPlaceholderText(_translate("PrintRemoverPage", "Line Start Pattern", None)) + + +if __name__ == "__main__": + import sys + app = QtGui.QApplication(sys.argv) + PrintRemoverPage = QtGui.QWidget() + ui = Ui_PrintRemoverPage() + ui.setupUi(PrintRemoverPage) + PrintRemoverPage.show() + sys.exit(app.exec_()) +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PrintRemover/ConfigurationPage/__init__.py Wed Dec 18 08:50:31 2013 +0100 @@ -0,0 +1,8 @@ +# -*- coding: utf-8 -*- + +# Copyright (c) 2013 Detlev Offenbach <detlev@die-offenbachs.de> +# + +""" +Package implementing the Print Remover plug-in configuration page. +"""