eric7/SqlBrowser/SqlConnectionDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8218
7c09585bd960
child 8318
962bce857696
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eric7/SqlBrowser/SqlConnectionDialog.py	Sat May 15 18:45:04 2021 +0200
@@ -0,0 +1,107 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2009 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog to enter the connection parameters.
+"""
+
+from PyQt5.QtCore import pyqtSlot
+from PyQt5.QtWidgets import QDialog, QDialogButtonBox
+from PyQt5.QtSql import QSqlDatabase
+
+from E5Gui.E5PathPicker import E5PathPickerModes
+
+from .Ui_SqlConnectionDialog import Ui_SqlConnectionDialog
+
+
+class SqlConnectionDialog(QDialog, Ui_SqlConnectionDialog):
+    """
+    Class implementing a dialog to enter the connection parameters.
+    """
+    def __init__(self, parent=None):
+        """
+        Constructor
+        
+        @param parent reference to the parent widget (QWidget)
+        """
+        super().__init__(parent)
+        self.setupUi(self)
+        
+        self.databasePicker.setMode(E5PathPickerModes.OpenFileMode)
+        
+        self.okButton = self.buttonBox.button(
+            QDialogButtonBox.StandardButton.Ok)
+        
+        drivers = QSqlDatabase.drivers()
+        
+        # remove compatibility names
+        if "QMYSQL3" in drivers:
+            drivers.remove("QMYSQL3")
+        if "QOCI8" in drivers:
+            drivers.remove("QOCI8")
+        if "QODBC3" in drivers:
+            drivers.remove("QODBC3")
+        if "QPSQL7" in drivers:
+            drivers.remove("QPSQL7")
+        if "QTDS7" in drivers:
+            drivers.remove("QTDS7")
+        
+        self.driverCombo.addItems(drivers)
+        
+        self.__updateDialog()
+        
+        msh = self.minimumSizeHint()
+        self.resize(max(self.width(), msh.width()), msh.height())
+    
+    def __updateDialog(self):
+        """
+        Private slot to update the dialog depending on its contents.
+        """
+        driver = self.driverCombo.currentText()
+        if driver.startswith("QSQLITE"):
+            self.databasePicker.setPickerEnabled(True)
+        else:
+            self.databasePicker.setPickerEnabled(False)
+        
+        if self.databasePicker.text() == "" or driver == "":
+            self.okButton.setEnabled(False)
+        else:
+            self.okButton.setEnabled(True)
+    
+    @pyqtSlot(int)
+    def on_driverCombo_activated(self, index):
+        """
+        Private slot handling the selection of a database driver.
+        
+        @param index index of the selected entry
+        @type int
+        """
+        self.__updateDialog()
+    
+    @pyqtSlot(str)
+    def on_databasePicker_textChanged(self, txt):
+        """
+        Private slot handling the change of the database name.
+        
+        @param txt text of the edit (string)
+        """
+        self.__updateDialog()
+    
+    def getData(self):
+        """
+        Public method to retrieve the connection data.
+        
+        @return tuple giving the driver name (string), the database name
+            (string), the user name (string), the password (string), the
+            host name (string) and the port (integer)
+        """
+        return (
+            self.driverCombo.currentText(),
+            self.databasePicker.text(),
+            self.usernameEdit.text(),
+            self.passwordEdit.text(),
+            self.hostnameEdit.text(),
+            self.portSpinBox.value(),
+        )

eric ide

mercurial