ProjectFlask/RoutesDialog.py

Thu, 12 Nov 2020 19:43:14 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 12 Nov 2020 19:43:14 +0100
changeset 7
a140b2a8ba93
child 8
cfbd3a2757fd
permissions
-rw-r--r--

Started implementing the "flask routes" function.

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

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

"""
Module implementing a dialog to show the application routes.
"""

from PyQt5.QtCore import pyqtSlot, QProcess
from PyQt5.QtWidgets import QDialog

from E5Gui import E5MessageBox

from .Ui_RoutesDialog import Ui_RoutesDialog


class RoutesDialog(QDialog, Ui_RoutesDialog):
    """
    Class implementing a dialog to show the application routes.
    """
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent reference to the parent widget
        @type QWidget
        """
        super(RoutesDialog, self).__init__(parent)
        self.setupUi(self)
        
        self.__process = None
    
    def showRoutes(self, project):
        """
        Public method to show the list of routes.
        
        @param project reference to the project object
        @type Project
        @return flag indicating success
        @rtype bool
        """
        workdir, env = project.prepareRuntimeEnvironment()
        if env is not None:
            command = project.getFlaskCommand()
            
            self.__process = QProcess()
            self.__process.setProcessEnvironment(env)
            self.__process.setWorkingDirectory(workdir)
            self.__process.setProcessChannelMode(QProcess.MergedChannels)
            
            args = ["routes"]
            if self.matchButton.isChecked():
                sortorder = "match"
            elif self.endpointButton.isChecked():
                sortorder = "endpoint"
            elif self.methodsButton.isChecked():
                sortorder = "methods"
            elif self.ruleButton.isChecked():
                sortorder = "rule"
            else:
                sortorder = ""
            if sortorder:
                args += ["--sort", sortorder]
            if self.allMethodsCheckBox.isChecked():
                args.append("--all-methods")
            
            self.__process.start(command, args)
            ok = self.__process.waitForStarted(10000)
            if ok:
                ok = self.__process.waitForFinished(10000)
                if ok:
                    out = str(self.__process.readAllStandardOutput(), "utf-8")
                    self.__processOutput(out)
                else:
                    E5MessageBox.critical(
                        None,
                        self.tr("Flask Routes"),
                        self.tr("""The Flask process did not finish within"""
                                """ 10 seconds."""))
            else:
                E5MessageBox.critical(
                    None,
                    self.tr("Run Flask Server"),
                    self.tr("""The Flask process could not be started."""))
            return ok
        else:
            return False
    
    def __processOutput(self, output):
        """
        Private method to process the flask output and populate the routes
        list.
        
        @param output output of the flask process
        @type str
        """
        self.routesList.clear()
        
        # split output into lines
        # determine field width based on second line
        # split each line based on widths and populate list
        print(output)
    
    @pyqtSlot(bool)
    def on_matchButton_toggled(self, checked):
        """
        Slot documentation goes here.
        
        @param checked DESCRIPTION
        @type bool
        """
        # TODO: not implemented yet
        pass
    
    @pyqtSlot(bool)
    def on_endpointButton_toggled(self, checked):
        """
        Slot documentation goes here.
        
        @param checked DESCRIPTION
        @type bool
        """
        # TODO: not implemented yet
        pass
    
    @pyqtSlot(bool)
    def on_methodsButton_toggled(self, checked):
        """
        Slot documentation goes here.
        
        @param checked DESCRIPTION
        @type bool
        """
        # TODO: not implemented yet
        pass
    
    @pyqtSlot(bool)
    def on_ruleButton_toggled(self, checked):
        """
        Slot documentation goes here.
        
        @param checked DESCRIPTION
        @type bool
        """
        # TODO: not implemented yet
        pass
    
    @pyqtSlot(bool)
    def on_allMethodsCheckBox_toggled(self, checked):
        """
        Slot documentation goes here.
        
        @param checked DESCRIPTION
        @type bool
        """
        # TODO: not implemented yet
        pass

eric ide

mercurial