eric6/UI/SymbolsWidget.py

changeset 8143
2c730d5fd177
parent 7923
91e843545d9a
child 8218
7c09585bd960
equal deleted inserted replaced
8141:27f636beebad 8143:2c730d5fd177
328 """ 328 """
329 self.beginResetModel() 329 self.beginResetModel()
330 self.__currentTableIndex = index 330 self.__currentTableIndex = index
331 self.endResetModel() 331 self.endResetModel()
332 332
333 def headerData(self, section, orientation, role=Qt.DisplayRole): 333 def headerData(self, section, orientation,
334 role=Qt.ItemDataRole.DisplayRole):
334 """ 335 """
335 Public method to get header data from the model. 336 Public method to get header data from the model.
336 337
337 @param section section number (integer) 338 @param section section number (integer)
338 @param orientation orientation (Qt.Orientation) 339 @param orientation orientation (Qt.Orientation)
339 @param role role of the data to retrieve (integer) 340 @param role role of the data to retrieve (Qt.ItemDataRole)
340 @return requested data 341 @return requested data
341 """ 342 """
342 if orientation == Qt.Horizontal and role == Qt.DisplayRole: 343 if (
344 orientation == Qt.Orientation.Horizontal and
345 role == Qt.ItemDataRole.DisplayRole
346 ):
343 return self.__headerData[section] 347 return self.__headerData[section]
344 348
345 return QAbstractTableModel.headerData(self, section, orientation, role) 349 return QAbstractTableModel.headerData(self, section, orientation, role)
346 350
347 def data(self, index, role=Qt.DisplayRole): 351 def data(self, index, role=Qt.ItemDataRole.DisplayRole):
348 """ 352 """
349 Public method to get data from the model. 353 Public method to get data from the model.
350 354
351 @param index index to get data for (QModelIndex) 355 @param index index to get data for (QModelIndex)
352 @param role role of the data to retrieve (integer) 356 @param role role of the data to retrieve (integer)
353 @return requested data 357 @return requested data
354 """ 358 """
355 symbolId = self.__tables[self.__currentTableIndex][0] + index.row() 359 symbolId = self.__tables[self.__currentTableIndex][0] + index.row()
356 360
357 if role == Qt.DisplayRole: 361 if role == Qt.ItemDataRole.DisplayRole:
358 col = index.column() 362 col = index.column()
359 if col == 0: 363 if col == 0:
360 return self.__locale.toString(symbolId) 364 return self.__locale.toString(symbolId)
361 elif col == 1: 365 elif col == 1:
362 return chr(symbolId) 366 return chr(symbolId)
367 return "&{0};".format( 371 return "&{0};".format(
368 html.entities.codepoint2name[symbolId]) 372 html.entities.codepoint2name[symbolId])
369 elif col == 4: 373 elif col == 4:
370 return unicodedata.name(chr(symbolId), '').title() 374 return unicodedata.name(chr(symbolId), '').title()
371 375
372 if role == Qt.BackgroundColorRole: 376 if role == Qt.ItemDataRole.BackgroundColorRole:
373 if index.column() == 0: 377 if index.column() == 0:
374 return QColor(Qt.lightGray) 378 return QColor(Qt.GlobalColor.lightGray)
375 379
376 if role == Qt.TextColorRole: 380 if role == Qt.ItemDataRole.TextColorRole:
377 char = chr(symbolId) 381 char = chr(symbolId)
378 if self.__isDigit(char): 382 if self.__isDigit(char):
379 return QColor(Qt.darkBlue) 383 return QColor(Qt.GlobalColor.darkBlue)
380 elif self.__isLetter(char): 384 elif self.__isLetter(char):
381 return QColor(Qt.darkGreen) 385 return QColor(Qt.GlobalColor.darkGreen)
382 elif self.__isMark(char): 386 elif self.__isMark(char):
383 return QColor(Qt.darkRed) 387 return QColor(Qt.GlobalColor.darkRed)
384 elif self.__isSymbol(char): 388 elif self.__isSymbol(char):
385 return QColor(Qt.black) 389 return QColor(Qt.GlobalColor.black)
386 elif self.__isPunct(char): 390 elif self.__isPunct(char):
387 return QColor(Qt.darkMagenta) 391 return QColor(Qt.GlobalColor.darkMagenta)
388 else: 392 else:
389 return QColor(Qt.darkGray) 393 return QColor(Qt.GlobalColor.darkGray)
390 394
391 if role == Qt.TextAlignmentRole: 395 if role == Qt.ItemDataRole.TextAlignmentRole:
392 if index.column() in [0, 1, 3]: 396 if index.column() in [0, 1, 3]:
393 return Qt.AlignHCenter 397 return Qt.AlignmentFlag.AlignHCenter
394 398
395 return None 399 return None
396 400
397 def columnCount(self, parent): 401 def columnCount(self, parent):
398 """ 402 """
499 self.symbolsTable.setModel(self.__model) 503 self.symbolsTable.setModel(self.__model)
500 self.symbolsTable.selectionModel().currentRowChanged.connect( 504 self.symbolsTable.selectionModel().currentRowChanged.connect(
501 self.__currentRowChanged) 505 self.__currentRowChanged)
502 506
503 self.symbolsTable.horizontalHeader().setSectionResizeMode( 507 self.symbolsTable.horizontalHeader().setSectionResizeMode(
504 QHeaderView.Fixed) 508 QHeaderView.ResizeMode.Fixed)
505 fm = self.fontMetrics() 509 fm = self.fontMetrics()
506 try: 510 try:
507 em = fm.horizontalAdvance("M") 511 em = fm.horizontalAdvance("M")
508 except AttributeError: 512 except AttributeError:
509 em = fm.width("M") 513 em = fm.width("M")
521 self.tableCombo.setCurrentIndex(tableIndex) 525 self.tableCombo.setCurrentIndex(tableIndex)
522 526
523 index = self.__model.index( 527 index = self.__model.index(
524 int(Preferences.Prefs.settings.value("Symbols/Top", 0)), 528 int(Preferences.Prefs.settings.value("Symbols/Top", 0)),
525 0) 529 0)
526 self.symbolsTable.scrollTo(index, QAbstractItemView.PositionAtTop) 530 self.symbolsTable.scrollTo(
531 index, QAbstractItemView.ScrollHint.PositionAtTop)
527 self.symbolsTable.selectionModel().setCurrentIndex( 532 self.symbolsTable.selectionModel().setCurrentIndex(
528 index, 533 index,
529 QItemSelectionModel.SelectCurrent | QItemSelectionModel.Rows) 534 QItemSelectionModel.SelectionFlag.SelectCurrent |
535 QItemSelectionModel.SelectionFlag.Rows
536 )
530 537
531 @pyqtSlot(QModelIndex) 538 @pyqtSlot(QModelIndex)
532 def on_symbolsTable_activated(self, index): 539 def on_symbolsTable_activated(self, index):
533 """ 540 """
534 Private slot to signal the selection of a symbol. 541 Private slot to signal the selection of a symbol.
548 first, last = self.__model.getTableBoundaries( 555 first, last = self.__model.getTableBoundaries(
549 self.__model.getTableIndex()) 556 self.__model.getTableIndex())
550 row = symbolId - first 557 row = symbolId - first
551 self.symbolsTable.selectRow(row) 558 self.symbolsTable.selectRow(row)
552 self.symbolsTable.scrollTo( 559 self.symbolsTable.scrollTo(
553 self.__model.index(row, 0), QAbstractItemView.PositionAtCenter) 560 self.__model.index(row, 0),
561 QAbstractItemView.ScrollHint.PositionAtCenter)
554 562
555 @pyqtSlot(int) 563 @pyqtSlot(int)
556 def on_tableCombo_currentIndexChanged(self, index): 564 def on_tableCombo_currentIndexChanged(self, index):
557 """ 565 """
558 Private slot to select the current character table. 566 Private slot to select the current character table.

eric ide

mercurial