src/eric7/SqlBrowser/SqlBrowser.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
24 24
25 class SqlBrowser(EricMainWindow): 25 class SqlBrowser(EricMainWindow):
26 """ 26 """
27 Class implementing the SQL Browser main window. 27 Class implementing the SQL Browser main window.
28 """ 28 """
29
29 def __init__(self, connections=None, parent=None): 30 def __init__(self, connections=None, parent=None):
30 """ 31 """
31 Constructor 32 Constructor
32 33
33 @param connections list of database connections to add 34 @param connections list of database connections to add
34 (list of strings) 35 (list of strings)
35 @param parent reference to the parent widget (QWidget) 36 @param parent reference to the parent widget (QWidget)
36 """ 37 """
37 super().__init__(parent) 38 super().__init__(parent)
38 self.setObjectName("SqlBrowser") 39 self.setObjectName("SqlBrowser")
39 40
40 if connections is None: 41 if connections is None:
41 connections = [] 42 connections = []
42 43
43 self.setWindowTitle(self.tr("SQL Browser")) 44 self.setWindowTitle(self.tr("SQL Browser"))
44 self.setWindowIcon(UI.PixmapCache.getIcon("eric")) 45 self.setWindowIcon(UI.PixmapCache.getIcon("eric"))
45 46
46 self.setStyle(Preferences.getUI("Style"), 47 self.setStyle(Preferences.getUI("Style"), Preferences.getUI("StyleSheet"))
47 Preferences.getUI("StyleSheet")) 48
48
49 from .SqlBrowserWidget import SqlBrowserWidget 49 from .SqlBrowserWidget import SqlBrowserWidget
50
50 self.__browser = SqlBrowserWidget(self) 51 self.__browser = SqlBrowserWidget(self)
51 self.setCentralWidget(self.__browser) 52 self.setCentralWidget(self.__browser)
52 53
53 self.__browser.statusMessage.connect(self.statusBar().showMessage) 54 self.__browser.statusMessage.connect(self.statusBar().showMessage)
54 55
55 self.__initActions() 56 self.__initActions()
56 self.__initMenus() 57 self.__initMenus()
57 self.__initToolbars() 58 self.__initToolbars()
58 59
59 self.resize(self.__browser.size()) 60 self.resize(self.__browser.size())
60 61
61 self.__warnings = [] 62 self.__warnings = []
62 63
63 for connection in connections: 64 for connection in connections:
64 url = QUrl(connection, QUrl.ParsingMode.TolerantMode) 65 url = QUrl(connection, QUrl.ParsingMode.TolerantMode)
65 if not url.isValid(): 66 if not url.isValid():
66 self.__warnings.append( 67 self.__warnings.append(self.tr("Invalid URL: {0}").format(connection))
67 self.tr("Invalid URL: {0}").format(connection))
68 continue 68 continue
69 69
70 err = self.__browser.addConnection(url.scheme(), url.path(), 70 err = self.__browser.addConnection(
71 url.userName(), url.password(), 71 url.scheme(),
72 url.host(), url.port(-1)) 72 url.path(),
73 url.userName(),
74 url.password(),
75 url.host(),
76 url.port(-1),
77 )
73 if err.type() != QSqlError.ErrorType.NoError: 78 if err.type() != QSqlError.ErrorType.NoError:
74 self.__warnings.append( 79 self.__warnings.append(
75 self.tr("Unable to open connection: {0}".format( 80 self.tr("Unable to open connection: {0}".format(err.text()))
76 err.text()))) 81 )
77 82
78 QTimer.singleShot(0, self.__uiStartUp) 83 QTimer.singleShot(0, self.__uiStartUp)
79 84
80 def __uiStartUp(self): 85 def __uiStartUp(self):
81 """ 86 """
82 Private slot to do some actions after the UI has started and the main 87 Private slot to do some actions after the UI has started and the main
83 loop is up. 88 loop is up.
84 """ 89 """
85 for warning in self.__warnings: 90 for warning in self.__warnings:
86 EricMessageBox.warning( 91 EricMessageBox.warning(
87 self, 92 self, self.tr("SQL Browser startup problem"), warning
88 self.tr("SQL Browser startup problem"), 93 )
89 warning) 94
90
91 if len(QSqlDatabase.connectionNames()) == 0: 95 if len(QSqlDatabase.connectionNames()) == 0:
92 self.__browser.addConnectionByDialog() 96 self.__browser.addConnectionByDialog()
93 97
94 def __initActions(self): 98 def __initActions(self):
95 """ 99 """
96 Private method to define the user interface actions. 100 Private method to define the user interface actions.
97 """ 101 """
98 # list of all actions 102 # list of all actions
99 self.__actions = [] 103 self.__actions = []
100 104
101 self.addConnectionAct = EricAction( 105 self.addConnectionAct = EricAction(
102 self.tr('Add Connection'), 106 self.tr("Add Connection"),
103 UI.PixmapCache.getIcon("databaseConnection"), 107 UI.PixmapCache.getIcon("databaseConnection"),
104 self.tr('Add &Connection...'), 108 self.tr("Add &Connection..."),
105 0, 0, self, 'sql_file_add_connection') 109 0,
106 self.addConnectionAct.setStatusTip(self.tr( 110 0,
107 'Open a dialog to add a new database connection')) 111 self,
108 self.addConnectionAct.setWhatsThis(self.tr( 112 "sql_file_add_connection",
109 """<b>Add Connection</b>""" 113 )
110 """<p>This opens a dialog to add a new database""" 114 self.addConnectionAct.setStatusTip(
111 """ connection.</p>""" 115 self.tr("Open a dialog to add a new database connection")
112 )) 116 )
113 self.addConnectionAct.triggered.connect( 117 self.addConnectionAct.setWhatsThis(
114 self.__browser.addConnectionByDialog) 118 self.tr(
119 """<b>Add Connection</b>"""
120 """<p>This opens a dialog to add a new database"""
121 """ connection.</p>"""
122 )
123 )
124 self.addConnectionAct.triggered.connect(self.__browser.addConnectionByDialog)
115 self.__actions.append(self.addConnectionAct) 125 self.__actions.append(self.addConnectionAct)
116 126
117 self.exitAct = EricAction( 127 self.exitAct = EricAction(
118 self.tr('Quit'), 128 self.tr("Quit"),
119 UI.PixmapCache.getIcon("exit"), 129 UI.PixmapCache.getIcon("exit"),
120 self.tr('&Quit'), 130 self.tr("&Quit"),
121 QKeySequence(self.tr("Ctrl+Q", "File|Quit")), 131 QKeySequence(self.tr("Ctrl+Q", "File|Quit")),
122 0, self, 'sql_file_quit') 132 0,
123 self.exitAct.setStatusTip(self.tr('Quit the SQL browser')) 133 self,
124 self.exitAct.setWhatsThis(self.tr( 134 "sql_file_quit",
125 """<b>Quit</b>""" 135 )
126 """<p>Quit the SQL browser.</p>""" 136 self.exitAct.setStatusTip(self.tr("Quit the SQL browser"))
127 )) 137 self.exitAct.setWhatsThis(
138 self.tr("""<b>Quit</b>""" """<p>Quit the SQL browser.</p>""")
139 )
128 self.exitAct.triggered.connect(ericApp().closeAllWindows) 140 self.exitAct.triggered.connect(ericApp().closeAllWindows)
129 141
130 self.aboutAct = EricAction( 142 self.aboutAct = EricAction(
131 self.tr('About'), 143 self.tr("About"), self.tr("&About"), 0, 0, self, "sql_help_about"
132 self.tr('&About'), 144 )
133 0, 0, self, 'sql_help_about') 145 self.aboutAct.setStatusTip(self.tr("Display information about this software"))
134 self.aboutAct.setStatusTip(self.tr( 146 self.aboutAct.setWhatsThis(
135 'Display information about this software')) 147 self.tr(
136 self.aboutAct.setWhatsThis(self.tr( 148 """<b>About</b>"""
137 """<b>About</b>""" 149 """<p>Display some information about this software.</p>"""
138 """<p>Display some information about this software.</p>""" 150 )
139 )) 151 )
140 self.aboutAct.triggered.connect(self.__about) 152 self.aboutAct.triggered.connect(self.__about)
141 self.__actions.append(self.aboutAct) 153 self.__actions.append(self.aboutAct)
142 154
143 self.aboutQtAct = EricAction( 155 self.aboutQtAct = EricAction(
144 self.tr('About Qt'), 156 self.tr("About Qt"), self.tr("About &Qt"), 0, 0, self, "sql_help_about_qt"
145 self.tr('About &Qt'), 157 )
146 0, 0, self, 'sql_help_about_qt')
147 self.aboutQtAct.setStatusTip( 158 self.aboutQtAct.setStatusTip(
148 self.tr('Display information about the Qt toolkit')) 159 self.tr("Display information about the Qt toolkit")
149 self.aboutQtAct.setWhatsThis(self.tr( 160 )
150 """<b>About Qt</b>""" 161 self.aboutQtAct.setWhatsThis(
151 """<p>Display some information about the Qt toolkit.</p>""" 162 self.tr(
152 )) 163 """<b>About Qt</b>"""
164 """<p>Display some information about the Qt toolkit.</p>"""
165 )
166 )
153 self.aboutQtAct.triggered.connect(self.__aboutQt) 167 self.aboutQtAct.triggered.connect(self.__aboutQt)
154 self.__actions.append(self.aboutQtAct) 168 self.__actions.append(self.aboutQtAct)
155 169
156 def __initMenus(self): 170 def __initMenus(self):
157 """ 171 """
158 Private method to create the menus. 172 Private method to create the menus.
159 """ 173 """
160 mb = self.menuBar() 174 mb = self.menuBar()
161 175
162 menu = mb.addMenu(self.tr('&File')) 176 menu = mb.addMenu(self.tr("&File"))
163 menu.setTearOffEnabled(True) 177 menu.setTearOffEnabled(True)
164 menu.addAction(self.addConnectionAct) 178 menu.addAction(self.addConnectionAct)
165 menu.addSeparator() 179 menu.addSeparator()
166 menu.addAction(self.exitAct) 180 menu.addAction(self.exitAct)
167 181
168 mb.addSeparator() 182 mb.addSeparator()
169 183
170 menu = mb.addMenu(self.tr('&Help')) 184 menu = mb.addMenu(self.tr("&Help"))
171 menu.setTearOffEnabled(True) 185 menu.setTearOffEnabled(True)
172 menu.addAction(self.aboutAct) 186 menu.addAction(self.aboutAct)
173 menu.addAction(self.aboutQtAct) 187 menu.addAction(self.aboutQtAct)
174 188
175 def __initToolbars(self): 189 def __initToolbars(self):
176 """ 190 """
177 Private method to create the toolbars. 191 Private method to create the toolbars.
178 """ 192 """
179 filetb = self.addToolBar(self.tr("File")) 193 filetb = self.addToolBar(self.tr("File"))
180 filetb.setObjectName("FileToolBar") 194 filetb.setObjectName("FileToolBar")
181 filetb.setIconSize(UI.Config.ToolBarIconSize) 195 filetb.setIconSize(UI.Config.ToolBarIconSize)
182 filetb.addAction(self.addConnectionAct) 196 filetb.addAction(self.addConnectionAct)
183 filetb.addSeparator() 197 filetb.addSeparator()
184 filetb.addAction(self.exitAct) 198 filetb.addAction(self.exitAct)
185 199
186 def __about(self): 200 def __about(self):
187 """ 201 """
188 Private slot to show the about information. 202 Private slot to show the about information.
189 """ 203 """
190 EricMessageBox.about( 204 EricMessageBox.about(
193 self.tr( 207 self.tr(
194 """<h3>About SQL Browser</h3>""" 208 """<h3>About SQL Browser</h3>"""
195 """<p>The SQL browser window is a little tool to examine """ 209 """<p>The SQL browser window is a little tool to examine """
196 """the data and the schema of a database and to execute """ 210 """the data and the schema of a database and to execute """
197 """queries on a database.</p>""" 211 """queries on a database.</p>"""
198 ) 212 ),
199 ) 213 )
200 214
201 def __aboutQt(self): 215 def __aboutQt(self):
202 """ 216 """
203 Private slot to show info about Qt. 217 Private slot to show info about Qt.
204 """ 218 """
205 EricMessageBox.aboutQt(self, self.tr("SQL Browser")) 219 EricMessageBox.aboutQt(self, self.tr("SQL Browser"))

eric ide

mercurial