eric6/SqlBrowser/SqlConnectionDialog.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter the connection parameters.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import pyqtSlot
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox
14 from PyQt5.QtSql import QSqlDatabase
15
16 from E5Gui.E5PathPicker import E5PathPickerModes
17
18 from .Ui_SqlConnectionDialog import Ui_SqlConnectionDialog
19
20
21 class SqlConnectionDialog(QDialog, Ui_SqlConnectionDialog):
22 """
23 Class implementing a dialog to enter the connection parameters.
24 """
25 def __init__(self, parent=None):
26 """
27 Constructor
28
29 @param parent reference to the parent widget (QWidget)
30 """
31 super(SqlConnectionDialog, self).__init__(parent)
32 self.setupUi(self)
33
34 self.databasePicker.setMode(E5PathPickerModes.OpenFileMode)
35
36 self.okButton = self.buttonBox.button(QDialogButtonBox.Ok)
37
38 drivers = QSqlDatabase.drivers()
39
40 # remove compatibility names
41 if "QMYSQL3" in drivers:
42 drivers.remove("QMYSQL3")
43 if "QOCI8" in drivers:
44 drivers.remove("QOCI8")
45 if "QODBC3" in drivers:
46 drivers.remove("QODBC3")
47 if "QPSQL7" in drivers:
48 drivers.remove("QPSQL7")
49 if "QTDS7" in drivers:
50 drivers.remove("QTDS7")
51
52 self.driverCombo.addItems(drivers)
53
54 self.__updateDialog()
55
56 msh = self.minimumSizeHint()
57 self.resize(max(self.width(), msh.width()), msh.height())
58
59 def __updateDialog(self):
60 """
61 Private slot to update the dialog depending on its contents.
62 """
63 driver = self.driverCombo.currentText()
64 if driver.startswith("QSQLITE"):
65 self.databasePicker.setPickerEnabled(True)
66 else:
67 self.databasePicker.setPickerEnabled(False)
68
69 if self.databasePicker.text() == "" or driver == "":
70 self.okButton.setEnabled(False)
71 else:
72 self.okButton.setEnabled(True)
73
74 @pyqtSlot(str)
75 def on_driverCombo_activated(self, txt):
76 """
77 Private slot handling the selection of a database driver.
78
79 @param txt text of the driver combo (string)
80 """
81 self.__updateDialog()
82
83 @pyqtSlot(str)
84 def on_databasePicker_textChanged(self, txt):
85 """
86 Private slot handling the change of the database name.
87
88 @param txt text of the edit (string)
89 """
90 self.__updateDialog()
91
92 def getData(self):
93 """
94 Public method to retrieve the connection data.
95
96 @return tuple giving the driver name (string), the database name
97 (string), the user name (string), the password (string), the
98 host name (string) and the port (integer)
99 """
100 return (
101 self.driverCombo.currentText(),
102 self.databasePicker.text(),
103 self.usernameEdit.text(),
104 self.passwordEdit.text(),
105 self.hostnameEdit.text(),
106 self.portSpinBox.value(),
107 )

eric ide

mercurial