SqlBrowser/SqlConnectionWidget.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2847
1843ef6e2656
parent 2993
4933ac9daa80
child 3060
5883ce99ee12
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
17 17
18 class SqlConnectionWidget(QWidget): 18 class SqlConnectionWidget(QWidget):
19 """ 19 """
20 Class implementing a widget showing the SQL connections. 20 Class implementing a widget showing the SQL connections.
21 21
22 @signal tableActivated(str) emitted after the entry for a table has been activated 22 @signal tableActivated(str) emitted after the entry for a table has been
23 activated
23 @signal schemaRequested(str) emitted when the schema display is requested 24 @signal schemaRequested(str) emitted when the schema display is requested
24 @signal cleared() emitted after the connection tree has been cleared 25 @signal cleared() emitted after the connection tree has been cleared
25 """ 26 """
26 tableActivated = pyqtSignal(str) 27 tableActivated = pyqtSignal(str)
27 schemaRequested = pyqtSignal(str) 28 schemaRequested = pyqtSignal(str)
40 41
41 self.__connectionTree = QTreeWidget(self) 42 self.__connectionTree = QTreeWidget(self)
42 self.__connectionTree.setObjectName("connectionTree") 43 self.__connectionTree.setObjectName("connectionTree")
43 self.__connectionTree.setHeaderLabels([self.trUtf8("Database")]) 44 self.__connectionTree.setHeaderLabels([self.trUtf8("Database")])
44 if qVersion() >= "5.0.0": 45 if qVersion() >= "5.0.0":
45 self.__connectionTree.header().setSectionResizeMode(QHeaderView.Stretch) 46 self.__connectionTree.header().setSectionResizeMode(
47 QHeaderView.Stretch)
46 else: 48 else:
47 self.__connectionTree.header().setResizeMode(QHeaderView.Stretch) 49 self.__connectionTree.header().setResizeMode(QHeaderView.Stretch)
48 refreshAction = QAction(self.trUtf8("Refresh"), self.__connectionTree) 50 refreshAction = QAction(self.trUtf8("Refresh"), self.__connectionTree)
49 self.__schemaAction = QAction(self.trUtf8("Show Schema"), self.__connectionTree) 51 self.__schemaAction = QAction(
52 self.trUtf8("Show Schema"), self.__connectionTree)
50 53
51 refreshAction.triggered[()].connect(self.refresh) 54 refreshAction.triggered[()].connect(self.refresh)
52 self.__schemaAction.triggered[()].connect(self.showSchema) 55 self.__schemaAction.triggered[()].connect(self.showSchema)
53 56
54 self.__connectionTree.addAction(refreshAction) 57 self.__connectionTree.addAction(refreshAction)
58 layout.addWidget(self.__connectionTree) 61 layout.addWidget(self.__connectionTree)
59 62
60 self.__activating = False 63 self.__activating = False
61 64
62 self.__connectionTree.itemActivated.connect(self.__itemActivated) 65 self.__connectionTree.itemActivated.connect(self.__itemActivated)
63 self.__connectionTree.currentItemChanged.connect(self.__currentItemChanged) 66 self.__connectionTree.currentItemChanged.connect(
67 self.__currentItemChanged)
64 68
65 self.__activeDb = "" 69 self.__activeDb = ""
66 70
67 def refresh(self): 71 def refresh(self):
68 """ 72 """
123 def __currentItemChanged(self, current, previous): 127 def __currentItemChanged(self, current, previous):
124 """ 128 """
125 Private slot handling a change of the current item. 129 Private slot handling a change of the current item.
126 130
127 @param current reference to the new current item (QTreeWidgetItem) 131 @param current reference to the new current item (QTreeWidgetItem)
128 @param previous reference to the previous current item (QTreeWidgetItem) 132 @param previous reference to the previous current item
133 (QTreeWidgetItem)
129 """ 134 """
130 self.__schemaAction.setEnabled( 135 self.__schemaAction.setEnabled(
131 current is not None and current.parent() is not None) 136 current is not None and current.parent() is not None)
132 137
133 def __dbCaption(self, db): 138 def __dbCaption(self, db):
166 171
167 def __setActive(self, itm): 172 def __setActive(self, itm):
168 """ 173 """
169 Private slot to set an item to active. 174 Private slot to set an item to active.
170 175
171 @param itm reference to the item to set as the active item (QTreeWidgetItem) 176 @param itm reference to the item to set as the active item
177 (QTreeWidgetItem)
172 """ 178 """
173 for index in range(self.__connectionTree.topLevelItemCount()): 179 for index in range(self.__connectionTree.topLevelItemCount()):
174 if self.__connectionTree.topLevelItem(index).font(0).bold(): 180 if self.__connectionTree.topLevelItem(index).font(0).bold():
175 self.__setBold(self.__connectionTree.topLevelItem(index), False) 181 self.__setBold(
182 self.__connectionTree.topLevelItem(index), False)
176 183
177 if itm is None: 184 if itm is None:
178 return 185 return
179 186
180 self.__setBold(itm, True) 187 self.__setBold(itm, True)

eric ide

mercurial