eric7/EricWidgets/EricIconBar.py

branch
eric7
changeset 8724
6ee36599a1f8
parent 8591
7cf4b7bc3d5a
child 8725
842ba8a9dbbb
equal deleted inserted replaced
8723:0338c9ad59af 8724:6ee36599a1f8
270 @param index index of the icon to be removed 270 @param index index of the icon to be removed
271 @type int 271 @type int
272 """ 272 """
273 label = self.__layout.itemAt(index) 273 label = self.__layout.itemAt(index)
274 if label: 274 if label:
275 self.__layout.removeWidget(label.widget()) 275 # self.__layout.removeItem(label)
276 # self.__layout.removeWidget(label.widget())
276 with contextlib.suppress(IndexError): 277 with contextlib.suppress(IndexError):
277 del self.__icons[index] 278 del self.__icons[index]
279 itm = self.__layout.takeAt(index)
280 itm.widget().deleteLater()
281 del itm
278 282
279 if index == self.__currentIndex: 283 if index == self.__currentIndex:
280 self.setCurrentIndex(index) 284 self.setCurrentIndex(index)
281 elif index < self.__currentIndex: 285 elif index < self.__currentIndex:
282 self.setCurrentIndex(self.__currentIndex - 1) 286 self.setCurrentIndex(self.__currentIndex - 1)
288 292
289 @param label reference to the clicked label 293 @param label reference to the clicked label
290 @type EricClickableLabel 294 @type EricClickableLabel
291 """ 295 """
292 index = self.__layout.indexOf(label) 296 index = self.__layout.indexOf(label)
293 if index == self.__currentIndex: 297 if index >= 0:
294 self.currentClicked.emit(self.__currentIndex) 298 if index == self.__currentIndex:
295 else: 299 self.currentClicked.emit(self.__currentIndex)
296 self.setCurrentIndex(index) 300 else:
301 self.setCurrentIndex(index)
297 302
298 def setCurrentIndex(self, index): 303 def setCurrentIndex(self, index):
299 """ 304 """
300 Public method to set the current index. 305 Public method to set the current index.
301 306
303 @type int 308 @type int
304 """ 309 """
305 if index >= self.count(): 310 if index >= self.count():
306 index = -1 311 index = -1
307 312
308 if index != self.__currentIndex: 313 if index != self.__currentIndex and index >= 0:
309 # reset style of previous current icon 314 # reset style of previous current icon
310 oldLabel = self.__layout.itemAt(self.__currentIndex) 315 oldLabel = self.__layout.itemAt(self.__currentIndex)
311 if oldLabel: 316 if oldLabel:
312 oldLabel.widget().setStyleSheet("") 317 widget = oldLabel.widget()
318 if widget is not None:
319 widget.setStyleSheet("")
313 320
314 # set style of new current icon 321 # set style of new current icon
315 newLabel = self.__layout.itemAt(index) 322 newLabel = self.__layout.itemAt(index)
316 if newLabel: 323 if newLabel:
317 newLabel.widget().setStyleSheet( 324 newLabel.widget().setStyleSheet(

eric ide

mercurial