Added a specialized dialog to show the configured routes.

Wed, 29 Aug 2012 17:41:43 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 29 Aug 2012 17:41:43 +0200
changeset 13
227a115ab2a1
parent 12
a8d87f7de3e1
child 14
e3cb581b4653

Added a specialized dialog to show the configured routes.

PluginProjectPyramid.py file | annotate | diff | comparison | revisions
PluginPyramid.e4p file | annotate | diff | comparison | revisions
ProjectPyramid/Project.py file | annotate | diff | comparison | revisions
ProjectPyramid/PyramidRoutesDialog.py file | annotate | diff | comparison | revisions
ProjectPyramid/PyramidRoutesDialog.ui file | annotate | diff | comparison | revisions
--- a/PluginProjectPyramid.py	Wed Aug 29 16:49:56 2012 +0200
+++ b/PluginProjectPyramid.py	Wed Aug 29 17:41:43 2012 +0200
@@ -114,7 +114,6 @@
         self.__ui = ui
         self.__initialize()
         
-        # TODO: get rid of the consoles
         self.__defaults = {
             "VirtualEnvironmentPy2" : "", 
             "VirtualEnvironmentPy3" : "", 
--- a/PluginPyramid.e4p	Wed Aug 29 16:49:56 2012 +0200
+++ b/PluginPyramid.e4p	Wed Aug 29 17:41:43 2012 +0200
@@ -23,6 +23,7 @@
     <Source>ProjectPyramid/CreateParametersDialog.py</Source>
     <Source>ProjectPyramid/PyramidDialog.py</Source>
     <Source>ProjectPyramid/DistributionTypeSelectionDialog.py</Source>
+    <Source>ProjectPyramid/PyramidRoutesDialog.py</Source>
   </Sources>
   <Forms>
     <Form>ProjectPyramid/ConfigurationPage/PyramidPage.ui</Form>
@@ -30,6 +31,7 @@
     <Form>ProjectPyramid/CreateParametersDialog.ui</Form>
     <Form>ProjectPyramid/PyramidDialog.ui</Form>
     <Form>ProjectPyramid/DistributionTypeSelectionDialog.ui</Form>
+    <Form>ProjectPyramid/PyramidRoutesDialog.ui</Form>
   </Forms>
   <Translations>
     <Translation>ProjectPyramid/i18n/pyramid_de.ts</Translation>
--- a/ProjectPyramid/Project.py	Wed Aug 29 16:49:56 2012 +0200
+++ b/ProjectPyramid/Project.py	Wed Aug 29 17:41:43 2012 +0200
@@ -22,6 +22,7 @@
 from .CreateParametersDialog import CreateParametersDialog
 from .PyramidDialog import PyramidDialog
 from .DistributionTypeSelectionDialog import DistributionTypeSelectionDialog
+from .PyramidRoutesDialog import PyramidRoutesDialog
 
 import Utilities
 from Globals import isWindowsPlatform
@@ -207,28 +208,28 @@
         self.showViewsAct.triggered[()].connect(self.__showMatchingViews)
         self.actions.append(self.showViewsAct)
         
-        self.showRoutesAct = E5Action(self.trUtf8('Show All Routes'),
-                self.trUtf8('Show All &Routes'), 
+        self.showRoutesAct = E5Action(self.trUtf8('Show Routes'),
+                self.trUtf8('Show &Routes'), 
                 0, 0,
                 self,'pyramid_show_routes')
         self.showRoutesAct.setStatusTip(self.trUtf8(
             'Show all URL dispatch routes used by a Pyramid application'))
         self.showRoutesAct.setWhatsThis(self.trUtf8(
-            """<b>Show All Routes</b>"""
+            """<b>Show Routes</b>"""
             """<p>Show all URL dispatch routes used by a Pyramid application"""
             """ in the order in which they are evaluated.</p>"""
         ))
         self.showRoutesAct.triggered[()].connect(self.__showRoutes)
         self.actions.append(self.showRoutesAct)
         
-        self.showTweensAct = E5Action(self.trUtf8('Show All Tween Objects'),
-                self.trUtf8('Show All &Tween Objects'), 
+        self.showTweensAct = E5Action(self.trUtf8('Show Tween Objects'),
+                self.trUtf8('Show &Tween Objects'), 
                 0, 0,
                 self,'pyramid_show_routes')
         self.showTweensAct.setStatusTip(self.trUtf8(
             'Show all implicit and explicit tween objects used by a Pyramid application'))
         self.showTweensAct.setWhatsThis(self.trUtf8(
-            """<b>Show All Tween Objects</b>"""
+            """<b>Show Tween Objects</b>"""
             """<p>Show all implicit and explicit tween objects used by a"""
             """ Pyramid application.</p>"""
         ))
@@ -952,8 +953,7 @@
         """
         Private slot showing all URL dispatch routes.
         """
-        # TODO: use a specialized dialog parsing the output of proutes
-        title = self.trUtf8("Show All Routes")
+        title = self.trUtf8("Show Routes")
         try:
             projectPath = self.__projectPath()
         except PyramidNoProjectSelectedException:
@@ -963,12 +963,8 @@
                             ' created yet. Aborting...'))
             return
         
-        cmd = self.getPyramidCommand("proutes")
-        args = []
-        args.append("development.ini")
-
-        dia = PyramidDialog(title, fixed=True, linewrap=False)
-        res = dia.startProcess(cmd, args, projectPath)
+        dia = PyramidRoutesDialog(self)
+        res = dia.start(projectPath)
         if res:
             dia.exec_()
     
@@ -976,7 +972,7 @@
         """
         Private slot showing all implicit and explicit tween objects.
         """
-        title = self.trUtf8("Show All Tween Objects")
+        title = self.trUtf8("Show Tween Objects")
         try:
             projectPath = self.__projectPath()
         except PyramidNoProjectSelectedException:
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ProjectPyramid/PyramidRoutesDialog.py	Wed Aug 29 17:41:43 2012 +0200
@@ -0,0 +1,244 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog showing the available routes.
+"""
+
+import os
+
+from PyQt4.QtCore import QProcess, QTimer, pyqtSlot, Qt, QCoreApplication
+from PyQt4.QtGui import QDialog, QDialogButtonBox, QLineEdit, QTreeWidgetItem
+
+from E5Gui import E5MessageBox
+
+from .Ui_PyramidRoutesDialog import Ui_PyramidRoutesDialog
+
+import Preferences
+
+
+class PyramidRoutesDialog(QDialog, Ui_PyramidRoutesDialog):
+    """
+    Class implementing a dialog showing the available routes.
+    """
+    def __init__(self, project, parent=None):
+        """
+        Constructor
+        
+        @param project reference to the project object (ProjectPyramid.Project.Project)
+        @param parent reference to the parent widget (QWidget)
+        """
+        super().__init__(parent)
+        self.setupUi(self)
+        
+        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
+        self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
+        
+        self.__project = project
+        self.proc = None
+        self.buffer = ""
+        
+        self.show()
+        QCoreApplication.processEvents()
+    
+    def finish(self):
+        """
+        Public slot called when the process finished or the user pressed the button.
+        """
+        if self.proc is not None and \
+           self.proc.state() != QProcess.NotRunning:
+            self.proc.terminate()
+            QTimer.singleShot(2000, self.proc.kill)
+            self.proc.waitForFinished(3000)
+        
+        self.inputGroup.setEnabled(False)
+        self.inputGroup.hide()
+        
+        self.proc = None
+        
+        self.__processBuffer()
+        
+        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
+        self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
+        self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
+        self.buttonBox.button(QDialogButtonBox.Close).setFocus(Qt.OtherFocusReason)
+    
+    def on_buttonBox_clicked(self, button):
+        """
+        Private slot called by a button of the button box clicked.
+        
+        @param button button that was clicked (QAbstractButton)
+        """
+        if button == self.buttonBox.button(QDialogButtonBox.Close):
+            self.close()
+        elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
+            self.finish()
+    
+    def __procFinished(self, exitCode, exitStatus):
+        """
+        Private slot connected to the finished signal.
+        
+        @param exitCode exit code of the process (integer)
+        @param exitStatus exit status of the process (QProcess.ExitStatus)
+        """
+        self.normal = (exitStatus == QProcess.NormalExit) and (exitCode == 0)
+        self.finish()
+    
+    def __processBuffer(self):
+        """
+        Private slot to process the output buffer of the proutes command.
+        """
+        self.routes.clear()
+        
+        if not self.buffer:
+            QTreeWidgetItem(self.routes, [self.trUtf8("No routes found.")])
+            self.routes.setHeaderHidden(True)
+        else:
+            lines = self.buffer.splitlines()
+            row = 0
+            headers = []
+            while row < len(lines):
+                if lines[row].strip().startswith("---"):
+                    headerLine = lines[row - 1]
+                    headers = headerLine.split()
+                    break
+                row += 1
+            if headers:
+                self.routes.setHeaderLabels(headers)
+                self.routes.setHeaderHidden(False)
+                row += 1
+                splitCount = len(headers) - 1
+                while row < len(lines):
+                    line = lines[row].strip()
+                    parts = line.split(None, splitCount)
+                    QTreeWidgetItem(self.routes, parts)
+                    row += 1
+                for column in range(len(headers)):
+                    self.routes.resizeColumnToContents(column)
+    
+    def start(self, projectPath):
+        """
+        Public slot used to start the process.
+        
+        @param command command to start (string)
+        @param projectPath path to the Pyramid project (string)
+        @return flag indicating a successful start of the process
+        """
+        QTreeWidgetItem(self.routes, [self.trUtf8("Getting routes...")])
+        self.routes.setHeaderHidden(True)
+        
+        self.errorGroup.hide()
+        self.normal = False
+        self.intercept = False
+        
+        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
+        self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True)
+        self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
+        self.buttonBox.button(QDialogButtonBox.Cancel).setFocus(Qt.OtherFocusReason)
+        
+        self.proc = QProcess()
+        
+        self.proc.finished.connect(self.__procFinished)
+        self.proc.readyReadStandardOutput.connect(self.__readStdout)
+        self.proc.readyReadStandardError.connect(self.__readStderr)
+        
+        cmd = self.__project.getPyramidCommand("proutes")
+        args = []
+        args.append("development.ini")
+
+        if projectPath:
+            self.proc.setWorkingDirectory(projectPath)
+        self.proc.start(cmd, args)
+        procStarted = self.proc.waitForStarted()
+        if not procStarted:
+            self.buttonBox.setFocus()
+            self.inputGroup.setEnabled(False)
+            E5MessageBox.critical(self,
+                self.trUtf8('Process Generation Error'),
+                self.trUtf8(
+                    'The process {0} could not be started. '
+                    'Ensure, that it is in the search path.'
+                ).format(cmd))
+        else:
+            self.inputGroup.setEnabled(True)
+            self.inputGroup.show()
+        return procStarted
+    
+    def __readStdout(self):
+        """
+        Private slot to handle the readyReadStandardOutput signal.
+        
+        It reads the output of the process and appends it to a buffer for
+        delayed processing.
+        """
+        if self.proc is not None:
+            out = str(self.proc.readAllStandardOutput(),
+                Preferences.getSystem("IOEncoding"),
+                'replace')
+            self.buffer += out
+    
+    def __readStderr(self):
+        """
+        Private slot to handle the readyReadStandardError signal.
+        
+        It reads the error output of the process and inserts it into the
+        error pane.
+        """
+        if self.proc is not None:
+            err = str(self.proc.readAllStandardError(),
+                Preferences.getSystem("IOEncoding"),
+                'replace')
+            self.errorGroup.show()
+            self.errors.insertPlainText(err)
+            self.errors.ensureCursorVisible()
+            
+            QCoreApplication.processEvents()
+    
+    def on_passwordCheckBox_toggled(self, isOn):
+        """
+        Private slot to handle the password checkbox toggled.
+        
+        @param isOn flag indicating the status of the check box (boolean)
+        """
+        if isOn:
+            self.input.setEchoMode(QLineEdit.Password)
+        else:
+            self.input.setEchoMode(QLineEdit.Normal)
+    
+    @pyqtSlot()
+    def on_sendButton_clicked(self):
+        """
+        Private slot to send the input to the subversion process.
+        """
+        input = self.input.text()
+        input += os.linesep
+        
+        if self.passwordCheckBox.isChecked():
+            self.errors.insertPlainText(os.linesep)
+            self.errors.ensureCursorVisible()
+        
+        self.proc.write(input)
+        
+        self.passwordCheckBox.setChecked(False)
+        self.input.clear()
+    
+    def on_input_returnPressed(self):
+        """
+        Private slot to handle the press of the return key in the input field.
+        """
+        self.intercept = True
+        self.on_sendButton_clicked()
+    
+    def keyPressEvent(self, evt):
+        """
+        Protected slot to handle a key press event.
+        
+        @param evt the key press event (QKeyEvent)
+        """
+        if self.intercept:
+            self.intercept = False
+            evt.accept()
+            return
+        super().keyPressEvent(evt)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ProjectPyramid/PyramidRoutesDialog.ui	Wed Aug 29 17:41:43 2012 +0200
@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>PyramidRoutesDialog</class>
+ <widget class="QDialog" name="PyramidRoutesDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>650</width>
+    <height>550</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Pyramid</string>
+  </property>
+  <property name="sizeGripEnabled">
+   <bool>true</bool>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QTreeWidget" name="routes">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+       <horstretch>0</horstretch>
+       <verstretch>2</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="alternatingRowColors">
+      <bool>true</bool>
+     </property>
+     <property name="selectionMode">
+      <enum>QAbstractItemView::NoSelection</enum>
+     </property>
+     <property name="rootIsDecorated">
+      <bool>false</bool>
+     </property>
+     <property name="itemsExpandable">
+      <bool>false</bool>
+     </property>
+     <property name="expandsOnDoubleClick">
+      <bool>false</bool>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="errorGroup">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+       <horstretch>0</horstretch>
+       <verstretch>1</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="title">
+      <string>Errors</string>
+     </property>
+     <layout class="QVBoxLayout">
+      <item>
+       <widget class="QTextEdit" name="errors">
+        <property name="sizePolicy">
+         <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+          <horstretch>0</horstretch>
+          <verstretch>1</verstretch>
+         </sizepolicy>
+        </property>
+        <property name="readOnly">
+         <bool>true</bool>
+        </property>
+        <property name="acceptRichText">
+         <bool>false</bool>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="inputGroup">
+     <property name="title">
+      <string>Input</string>
+     </property>
+     <layout class="QGridLayout">
+      <item row="1" column="1">
+       <spacer>
+        <property name="orientation">
+         <enum>Qt::Horizontal</enum>
+        </property>
+        <property name="sizeType">
+         <enum>QSizePolicy::Expanding</enum>
+        </property>
+        <property name="sizeHint" stdset="0">
+         <size>
+          <width>327</width>
+          <height>29</height>
+         </size>
+        </property>
+       </spacer>
+      </item>
+      <item row="1" column="2">
+       <widget class="QPushButton" name="sendButton">
+        <property name="toolTip">
+         <string>Press to send the input to the Pyramid process</string>
+        </property>
+        <property name="text">
+         <string>&amp;Send</string>
+        </property>
+        <property name="shortcut">
+         <string>Alt+S</string>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="0" colspan="3">
+       <widget class="QLineEdit" name="input">
+        <property name="toolTip">
+         <string>Enter data to be sent to the Pyramid process</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QCheckBox" name="passwordCheckBox">
+        <property name="toolTip">
+         <string>Select to switch the input field to password mode</string>
+        </property>
+        <property name="text">
+         <string>&amp;Password Mode</string>
+        </property>
+        <property name="shortcut">
+         <string>Alt+P</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Close</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <pixmapfunction>qPixmapFromMimeSource</pixmapfunction>
+ <tabstops>
+  <tabstop>routes</tabstop>
+  <tabstop>errors</tabstop>
+  <tabstop>input</tabstop>
+  <tabstop>passwordCheckBox</tabstop>
+  <tabstop>sendButton</tabstop>
+  <tabstop>buttonBox</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>

eric ide

mercurial