ProjectFlask/ServerStartOptionsDialog.py

Sun, 15 Nov 2020 17:35:48 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 15 Nov 2020 17:35:48 +0100
changeset 10
506c78268b18
parent 9
79094fb72c18
child 60
02243723ac17
permissions
-rw-r--r--

Added a few more server start options.

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

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

"""
Module implementing a dialog to enter parameters to start the server.
"""

from PyQt5.QtWidgets import QDialog

from E5Gui.E5PathPicker import E5PathPickerModes
from E5Gui.E5Application import e5App

from .Ui_ServerStartOptionsDialog import Ui_ServerStartOptionsDialog


class ServerStartOptionsDialog(QDialog, Ui_ServerStartOptionsDialog):
    """
    Class implementing a dialog to enter parameters to start the server.
    """
    def __init__(self, options, parent=None):
        """
        Constructor
        
        @param options dictionary containing the current server start options
        @type dict
        @param parent reference to the parent widget
        @type QWidget
        """
        super(ServerStartOptionsDialog, self).__init__(parent)
        self.setupUi(self)
        
        e5project = e5App().getObject("Project")
        
        self.certFilePicker.setMode(E5PathPickerModes.OpenFileMode)
        self.certFilePicker.setFilters(self.tr(
            "Certificate Files (*.pem);;"
            "Certificate Files (*.cert *.cer *.crt)"
        ))
        self.certFilePicker.setDefaultDirectory(e5project.getProjectPath())
        
        self.keyFilePicker.setMode(E5PathPickerModes.OpenFileMode)
        self.keyFilePicker.setFilters(self.tr(
            "Key Files (*.pem *.key)"
        ))
        self.keyFilePicker.setDefaultDirectory(e5project.getProjectPath())
        
        self.developmentCheckBox.setChecked(options.get("development", False))
        self.hostEdit.setText(options.get("host", ""))
        self.portSpinBox.setValue(int(options.get("port", "5000")))
        
        msh = self.minimumSizeHint()
        self.resize(max(self.width(), msh.width()), msh.height())
    
    def getDataDict(self):
        """
        Public method to get a dictionary containing the entered data.
        
        @return dictionary containing the entered data
        @rtype dict
        """
        options = {}
        
        options["development"] = self.developmentCheckBox.isChecked()
        host = self.hostEdit.text()
        if host:
            options["host"] = host
        port = self.portSpinBox.value()
        if port != 5000:
            options["port"] = str(port)
        if self.certFilePicker.text():
            options["cert"] = self.certFilePicker.text()
        if self.keyFilePicker.text():
            options["key"] = self.keyFilePicker.text()
        
        return options

eric ide

mercurial