11 |
11 |
12 from PyQt5.QtCore import pyqtSlot |
12 from PyQt5.QtCore import pyqtSlot |
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
14 from PyQt5.QtSql import QSqlDatabase |
14 from PyQt5.QtSql import QSqlDatabase |
15 |
15 |
16 from E5Gui.E5Completers import E5FileCompleter |
16 from E5Gui.E5PathPicker import E5PathPickerModes |
17 from E5Gui import E5FileDialog |
|
18 |
17 |
19 from .Ui_SqlConnectionDialog import Ui_SqlConnectionDialog |
18 from .Ui_SqlConnectionDialog import Ui_SqlConnectionDialog |
20 |
|
21 import Utilities |
|
22 import UI.PixmapCache |
|
23 |
19 |
24 |
20 |
25 class SqlConnectionDialog(QDialog, Ui_SqlConnectionDialog): |
21 class SqlConnectionDialog(QDialog, Ui_SqlConnectionDialog): |
26 """ |
22 """ |
27 Class implementing a dialog to enter the connection parameters. |
23 Class implementing a dialog to enter the connection parameters. |
33 @param parent reference to the parent widget (QWidget) |
29 @param parent reference to the parent widget (QWidget) |
34 """ |
30 """ |
35 super(SqlConnectionDialog, self).__init__(parent) |
31 super(SqlConnectionDialog, self).__init__(parent) |
36 self.setupUi(self) |
32 self.setupUi(self) |
37 |
33 |
38 self.databaseFileButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
34 self.databasePicker.setMode(E5PathPickerModes.OpenFileMode) |
39 |
|
40 self.databaseFileCompleter = E5FileCompleter() |
|
41 |
35 |
42 self.okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
36 self.okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
43 |
37 |
44 drivers = QSqlDatabase.drivers() |
38 drivers = QSqlDatabase.drivers() |
45 |
39 |
66 """ |
60 """ |
67 Private slot to update the dialog depending on its contents. |
61 Private slot to update the dialog depending on its contents. |
68 """ |
62 """ |
69 driver = self.driverCombo.currentText() |
63 driver = self.driverCombo.currentText() |
70 if driver.startswith("QSQLITE"): |
64 if driver.startswith("QSQLITE"): |
71 self.databaseEdit.setCompleter(self.databaseFileCompleter) |
65 self.databasePicker.setPickerEnabled(True) |
72 self.databaseFileButton.setEnabled(True) |
|
73 else: |
66 else: |
74 self.databaseEdit.setCompleter(None) |
67 self.databasePicker.setPickerEnabled(False) |
75 self.databaseFileButton.setEnabled(False) |
|
76 |
68 |
77 if self.databaseEdit.text() == "" or driver == "": |
69 if self.databasePicker.text() == "" or driver == "": |
78 self.okButton.setEnabled(False) |
70 self.okButton.setEnabled(False) |
79 else: |
71 else: |
80 self.okButton.setEnabled(True) |
72 self.okButton.setEnabled(True) |
81 |
73 |
82 @pyqtSlot(str) |
74 @pyqtSlot(str) |
87 @param txt text of the driver combo (string) |
79 @param txt text of the driver combo (string) |
88 """ |
80 """ |
89 self.__updateDialog() |
81 self.__updateDialog() |
90 |
82 |
91 @pyqtSlot(str) |
83 @pyqtSlot(str) |
92 def on_databaseEdit_textChanged(self, txt): |
84 def on_databasePicker_textChanged(self, txt): |
93 """ |
85 """ |
94 Private slot handling the change of the database name. |
86 Private slot handling the change of the database name. |
95 |
87 |
96 @param txt text of the edit (string) |
88 @param txt text of the edit (string) |
97 """ |
89 """ |
98 self.__updateDialog() |
90 self.__updateDialog() |
99 |
|
100 @pyqtSlot() |
|
101 def on_databaseFileButton_clicked(self): |
|
102 """ |
|
103 Private slot to open a database file via a file selection dialog. |
|
104 """ |
|
105 startdir = self.databaseEdit.text() |
|
106 dbFile = E5FileDialog.getOpenFileName( |
|
107 self, |
|
108 self.tr("Select Database File"), |
|
109 startdir, |
|
110 self.tr("All Files (*)")) |
|
111 |
|
112 if dbFile: |
|
113 self.databaseEdit.setText(Utilities.toNativeSeparators(dbFile)) |
|
114 |
91 |
115 def getData(self): |
92 def getData(self): |
116 """ |
93 """ |
117 Public method to retrieve the connection data. |
94 Public method to retrieve the connection data. |
118 |
95 |
120 (string), the user name (string), the password (string), the |
97 (string), the user name (string), the password (string), the |
121 host name (string) and the port (integer) |
98 host name (string) and the port (integer) |
122 """ |
99 """ |
123 return ( |
100 return ( |
124 self.driverCombo.currentText(), |
101 self.driverCombo.currentText(), |
125 self.databaseEdit.text(), |
102 self.databasePicker.text(), |
126 self.usernameEdit.text(), |
103 self.usernameEdit.text(), |
127 self.passwordEdit.text(), |
104 self.passwordEdit.text(), |
128 self.hostnameEdit.text(), |
105 self.hostnameEdit.text(), |
129 self.portSpinBox.value(), |
106 self.portSpinBox.value(), |
130 ) |
107 ) |