7 Module implementing a widget to select a symbol in various formats. |
7 Module implementing a widget to select a symbol in various formats. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 try: |
|
13 # Py2 |
|
14 str = unicode |
|
15 chr = unichr |
|
16 import htmlentitydefs as html_entities |
|
17 except (NameError, ImportError): |
|
18 # Py3 |
|
19 import html.entities as html_entities |
|
20 |
|
21 import sys |
12 import sys |
22 import unicodedata |
13 import unicodedata |
|
14 import html.entities |
23 |
15 |
24 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QAbstractTableModel, \ |
16 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QAbstractTableModel, \ |
25 QModelIndex, Qt, QItemSelectionModel, QLocale |
17 QModelIndex, Qt, QItemSelectionModel, QLocale |
26 from PyQt5.QtGui import QColor |
18 from PyQt5.QtGui import QColor |
27 from PyQt5.QtWidgets import QWidget, QHeaderView, QAbstractItemView |
19 from PyQt5.QtWidgets import QWidget, QHeaderView, QAbstractItemView |
370 elif col == 1: |
362 elif col == 1: |
371 return chr(symbolId) |
363 return chr(symbolId) |
372 elif col == 2: |
364 elif col == 2: |
373 return "0x{0:04x}".format(symbolId) |
365 return "0x{0:04x}".format(symbolId) |
374 elif col == 3: |
366 elif col == 3: |
375 if symbolId in html_entities.codepoint2name: |
367 if symbolId in html.entities.codepoint2name: |
376 return "&{0};".format( |
368 return "&{0};".format( |
377 html_entities.codepoint2name[symbolId]) |
369 html.entities.codepoint2name[symbolId]) |
378 elif col == 4: |
370 elif col == 4: |
379 return unicodedata.name(chr(symbolId), '').title() |
371 return unicodedata.name(chr(symbolId), '').title() |
380 |
372 |
381 if role == Qt.BackgroundColorRole: |
373 if role == Qt.BackgroundColorRole: |
382 if index.column() == 0: |
374 if index.column() == 0: |