UI/SymbolsWidget.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2677
3d4277929fb3
parent 3012
d177226027e2
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
15 import html.entities as html_entities 15 import html.entities as html_entities
16 except (ImportError): 16 except (ImportError):
17 chr = unichr 17 chr = unichr
18 import htmlentitydefs as html_entities # __IGNORE_WARNING__ 18 import htmlentitydefs as html_entities # __IGNORE_WARNING__
19 19
20 from PyQt4.QtCore import pyqtSlot, pyqtSignal, QAbstractTableModel, QModelIndex, Qt, \ 20 from PyQt4.QtCore import pyqtSlot, pyqtSignal, QAbstractTableModel, \
21 qVersion 21 QModelIndex, Qt, qVersion
22 from PyQt4.QtGui import QWidget, QHeaderView, QAbstractItemView, QColor, \ 22 from PyQt4.QtGui import QWidget, QHeaderView, QAbstractItemView, QColor, \
23 QItemSelectionModel 23 QItemSelectionModel
24 24
25 from .Ui_SymbolsWidget import Ui_SymbolsWidget 25 from .Ui_SymbolsWidget import Ui_SymbolsWidget
26 26
87 (0x10a0, 0x10ff, self.trUtf8("Georgian")), 87 (0x10a0, 0x10ff, self.trUtf8("Georgian")),
88 (0x1100, 0x11ff, self.trUtf8("Hangul Jamo")), 88 (0x1100, 0x11ff, self.trUtf8("Hangul Jamo")),
89 (0x1200, 0x137f, self.trUtf8("Ethiopic")), 89 (0x1200, 0x137f, self.trUtf8("Ethiopic")),
90 (0x1380, 0x139f, self.trUtf8("Ethiopic Supplement")), 90 (0x1380, 0x139f, self.trUtf8("Ethiopic Supplement")),
91 (0x13a0, 0x13ff, self.trUtf8("Cherokee")), 91 (0x13a0, 0x13ff, self.trUtf8("Cherokee")),
92 (0x1400, 0x167f, self.trUtf8("Unified Canadian Aboriginal Syllabics")), 92 (0x1400, 0x167f,
93 self.trUtf8("Unified Canadian Aboriginal Syllabics")),
93 (0x1680, 0x169f, self.trUtf8("Ogham")), 94 (0x1680, 0x169f, self.trUtf8("Ogham")),
94 (0x16a0, 0x16ff, self.trUtf8("Runic")), 95 (0x16a0, 0x16ff, self.trUtf8("Runic")),
95 (0x1700, 0x171f, self.trUtf8("Tagalog")), 96 (0x1700, 0x171f, self.trUtf8("Tagalog")),
96 (0x1720, 0x173f, self.trUtf8("Hanunoo")), 97 (0x1720, 0x173f, self.trUtf8("Hanunoo")),
97 (0x1740, 0x175f, self.trUtf8("Buhid")), 98 (0x1740, 0x175f, self.trUtf8("Buhid")),
98 (0x1760, 0x177f, self.trUtf8("Tagbanwa")), 99 (0x1760, 0x177f, self.trUtf8("Tagbanwa")),
99 (0x1780, 0x17ff, self.trUtf8("Khmer")), 100 (0x1780, 0x17ff, self.trUtf8("Khmer")),
100 (0x1800, 0x18af, self.trUtf8("Mongolian")), 101 (0x1800, 0x18af, self.trUtf8("Mongolian")),
101 (0x18b0, 0x18ff, self.trUtf8("Unified Canadian Aboriginal Syllabics Extended")), 102 (0x18b0, 0x18ff,
103 self.trUtf8("Unified Canadian Aboriginal Syllabics Extended")),
102 (0x1900, 0x194f, self.trUtf8("Limbu")), 104 (0x1900, 0x194f, self.trUtf8("Limbu")),
103 (0x1950, 0x197f, self.trUtf8("Tai Le")), 105 (0x1950, 0x197f, self.trUtf8("Tai Le")),
104 (0x19e0, 0x19ff, self.trUtf8("Khmer Symbols")), 106 (0x19e0, 0x19ff, self.trUtf8("Khmer Symbols")),
105 (0x1a00, 0x1a1f, self.trUtf8("Buginese")), 107 (0x1a00, 0x1a1f, self.trUtf8("Buginese")),
106 (0x1a20, 0x1aaf, self.trUtf8("Tai Tham")), 108 (0x1a20, 0x1aaf, self.trUtf8("Tai Tham")),
111 (0x1c50, 0x1c7f, self.trUtf8("Ol Chiki")), 113 (0x1c50, 0x1c7f, self.trUtf8("Ol Chiki")),
112 (0x1cc0, 0x1ccf, self.trUtf8("Sundanese Supplement")), 114 (0x1cc0, 0x1ccf, self.trUtf8("Sundanese Supplement")),
113 (0x1cd0, 0x1cff, self.trUtf8("Vedic Extensions")), 115 (0x1cd0, 0x1cff, self.trUtf8("Vedic Extensions")),
114 (0x1d00, 0x1d7f, self.trUtf8("Phonetic Extensions")), 116 (0x1d00, 0x1d7f, self.trUtf8("Phonetic Extensions")),
115 (0x1d80, 0x1dbf, self.trUtf8("Phonetic Extensions Supplement")), 117 (0x1d80, 0x1dbf, self.trUtf8("Phonetic Extensions Supplement")),
116 (0x1dc0, 0x1dff, self.trUtf8("Combining Diacritical Marks Supplement")), 118 (0x1dc0, 0x1dff,
119 self.trUtf8("Combining Diacritical Marks Supplement")),
117 (0x1e00, 0x1eff, self.trUtf8("Latin Extended Additional")), 120 (0x1e00, 0x1eff, self.trUtf8("Latin Extended Additional")),
118 (0x1f00, 0x1fff, self.trUtf8("Greek Extended")), 121 (0x1f00, 0x1fff, self.trUtf8("Greek Extended")),
119 (0x2000, 0x206f, self.trUtf8("General Punctuation")), 122 (0x2000, 0x206f, self.trUtf8("General Punctuation")),
120 (0x2070, 0x209f, self.trUtf8("Superscripts and Subscripts")), 123 (0x2070, 0x209f, self.trUtf8("Superscripts and Subscripts")),
121 (0x20a0, 0x20cf, self.trUtf8("Currency Symbols")), 124 (0x20a0, 0x20cf, self.trUtf8("Currency Symbols")),
131 (0x2500, 0x257f, self.trUtf8("Box Drawing")), 134 (0x2500, 0x257f, self.trUtf8("Box Drawing")),
132 (0x2580, 0x259f, self.trUtf8("Block Elements")), 135 (0x2580, 0x259f, self.trUtf8("Block Elements")),
133 (0x25A0, 0x25ff, self.trUtf8("Geometric Shapes")), 136 (0x25A0, 0x25ff, self.trUtf8("Geometric Shapes")),
134 (0x2600, 0x26ff, self.trUtf8("Miscellaneous Symbols")), 137 (0x2600, 0x26ff, self.trUtf8("Miscellaneous Symbols")),
135 (0x2700, 0x27bf, self.trUtf8("Dingbats")), 138 (0x2700, 0x27bf, self.trUtf8("Dingbats")),
136 (0x27c0, 0x27ef, self.trUtf8("Miscellaneous Mathematical Symbols-A")), 139 (0x27c0, 0x27ef,
140 self.trUtf8("Miscellaneous Mathematical Symbols-A")),
137 (0x27f0, 0x27ff, self.trUtf8("Supplement Arcolumns-A")), 141 (0x27f0, 0x27ff, self.trUtf8("Supplement Arcolumns-A")),
138 (0x2800, 0x28ff, self.trUtf8("Braille Patterns")), 142 (0x2800, 0x28ff, self.trUtf8("Braille Patterns")),
139 (0x2900, 0x297f, self.trUtf8("Supplement Arcolumns-B")), 143 (0x2900, 0x297f, self.trUtf8("Supplement Arcolumns-B")),
140 (0x2980, 0x29ff, self.trUtf8("Miscellaneous Mathematical Symbols-B")), 144 (0x2980, 0x29ff,
141 (0x2a00, 0x2aff, self.trUtf8("Supplemental Mathematical Operators")), 145 self.trUtf8("Miscellaneous Mathematical Symbols-B")),
142 (0x2b00, 0x2bff, self.trUtf8("Miscellaneous Symbols and Arcolumns")), 146 (0x2a00, 0x2aff,
147 self.trUtf8("Supplemental Mathematical Operators")),
148 (0x2b00, 0x2bff,
149 self.trUtf8("Miscellaneous Symbols and Arcolumns")),
143 (0x2c00, 0x2c5f, self.trUtf8("Glagolitic")), 150 (0x2c00, 0x2c5f, self.trUtf8("Glagolitic")),
144 (0x2c60, 0x2c7f, self.trUtf8("Latin Extended-C")), 151 (0x2c60, 0x2c7f, self.trUtf8("Latin Extended-C")),
145 (0x2c80, 0x2cff, self.trUtf8("Coptic")), 152 (0x2c80, 0x2cff, self.trUtf8("Coptic")),
146 (0x2d00, 0x2d2f, self.trUtf8("Georgian Supplement")), 153 (0x2d00, 0x2d2f, self.trUtf8("Georgian Supplement")),
147 (0x2d30, 0x2d7f, self.trUtf8("Tifinagh")), 154 (0x2d30, 0x2d7f, self.trUtf8("Tifinagh")),
241 (0x110d0, 0x110ff, self.trUtf8("Sora Sompeng")), 248 (0x110d0, 0x110ff, self.trUtf8("Sora Sompeng")),
242 (0x11100, 0x1114f, self.trUtf8("Chakma")), 249 (0x11100, 0x1114f, self.trUtf8("Chakma")),
243 (0x11180, 0x111df, self.trUtf8("Sharada")), 250 (0x11180, 0x111df, self.trUtf8("Sharada")),
244 (0x11680, 0x116cf, self.trUtf8("Takri")), 251 (0x11680, 0x116cf, self.trUtf8("Takri")),
245 (0x12000, 0x123ff, self.trUtf8("Cuneiform")), 252 (0x12000, 0x123ff, self.trUtf8("Cuneiform")),
246 (0x12400, 0x1247f, self.trUtf8("Cuneiform Numbers and Punctuation")), 253 (0x12400, 0x1247f,
254 self.trUtf8("Cuneiform Numbers and Punctuation")),
247 (0x13000, 0x1342f, self.trUtf8("Egyptian Hieroglyphs")), 255 (0x13000, 0x1342f, self.trUtf8("Egyptian Hieroglyphs")),
248 (0x16800, 0x16a3f, self.trUtf8("Bamum Supplement")), 256 (0x16800, 0x16a3f, self.trUtf8("Bamum Supplement")),
249 (0x16f00, 0x16f9f, self.trUtf8("Miao")), 257 (0x16f00, 0x16f9f, self.trUtf8("Miao")),
250 (0x1b000, 0x1b0ff, self.trUtf8("Kana Supplement")), 258 (0x1b000, 0x1b0ff, self.trUtf8("Kana Supplement")),
251 (0x1d000, 0x1d0ff, self.trUtf8("Byzantine Musical Symbols")), 259 (0x1d000, 0x1d0ff, self.trUtf8("Byzantine Musical Symbols")),
252 (0x1d100, 0x1d1ff, self.trUtf8("Musical Symbols")), 260 (0x1d100, 0x1d1ff, self.trUtf8("Musical Symbols")),
253 (0x1d200, 0x1d24f, self.trUtf8("Ancient Greek Musical Notation")), 261 (0x1d200, 0x1d24f,
262 self.trUtf8("Ancient Greek Musical Notation")),
254 (0x1d300, 0x1d35f, self.trUtf8("Tai Xuan Jing Symbols")), 263 (0x1d300, 0x1d35f, self.trUtf8("Tai Xuan Jing Symbols")),
255 (0x1d360, 0x1d37f, self.trUtf8("Counting Rod Numerals")), 264 (0x1d360, 0x1d37f,
256 (0x1d400, 0x1d7ff, self.trUtf8("Mathematical Alphanumeric Symbols")), 265 self.trUtf8("Counting Rod Numerals")),
257 (0x1ee00, 0x1eeff, self.trUtf8("Arabic Mathematical Alphabetic Symbols")), 266 (0x1d400, 0x1d7ff,
267 self.trUtf8("Mathematical Alphanumeric Symbols")),
268 (0x1ee00, 0x1eeff,
269 self.trUtf8("Arabic Mathematical Alphabetic Symbols")),
258 (0x1f000, 0x1f02f, self.trUtf8("Mahjong Tiles")), 270 (0x1f000, 0x1f02f, self.trUtf8("Mahjong Tiles")),
259 (0x1f030, 0x1f09f, self.trUtf8("Domino Tiles")), 271 (0x1f030, 0x1f09f, self.trUtf8("Domino Tiles")),
260 (0x1f0a0, 0x1f0ff, self.trUtf8("Playing Cards")), 272 (0x1f0a0, 0x1f0ff, self.trUtf8("Playing Cards")),
261 (0x1f100, 0x1f1ff, self.trUtf8("Enclosed Alphanumeric Supplement")), 273 (0x1f100, 0x1f1ff,
262 (0x1f200, 0x1f2ff, self.trUtf8("Enclosed Ideographic Supplement")), 274 self.trUtf8("Enclosed Alphanumeric Supplement")),
263 (0x1f300, 0x1f5ff, self.trUtf8("Miscellaneous Symbols And Pictographs")), 275 (0x1f200, 0x1f2ff,
276 self.trUtf8("Enclosed Ideographic Supplement")),
277 (0x1f300, 0x1f5ff,
278 self.trUtf8("Miscellaneous Symbols And Pictographs")),
264 (0x1f600, 0x1f64f, self.trUtf8("Emoticons")), 279 (0x1f600, 0x1f64f, self.trUtf8("Emoticons")),
265 (0x1f680, 0x1f6ff, self.trUtf8("Transport And Map Symbols")), 280 (0x1f680, 0x1f6ff, self.trUtf8("Transport And Map Symbols")),
266 (0x1f700, 0x1f77f, self.trUtf8("Alchemical Symbols")), 281 (0x1f700, 0x1f77f, self.trUtf8("Alchemical Symbols")),
267 (0x20000, 0x2a6df, self.trUtf8("CJK Unified Ideogr. Ext. B")), 282 (0x20000, 0x2a6df, self.trUtf8("CJK Unified Ideogr. Ext. B")),
268 (0x2a700, 0x2b73f, self.trUtf8("CJK Unified Ideographs Extension C")), 283 (0x2a700, 0x2b73f,
269 (0x2b740, 0x2b81f, self.trUtf8("CJK Unified Ideographs Extension D")), 284 self.trUtf8("CJK Unified Ideographs Extension C")),
270 (0x2f800, 0x2fa1f, self.trUtf8("CJK Compatapility Ideogr. Suppl.")), 285 (0x2b740, 0x2b81f,
286 self.trUtf8("CJK Unified Ideographs Extension D")),
287 (0x2f800, 0x2fa1f,
288 self.trUtf8("CJK Compatapility Ideogr. Suppl.")),
271 (0xe0000, 0xe007f, self.trUtf8("Tags")), 289 (0xe0000, 0xe007f, self.trUtf8("Tags")),
272 (0xe0100, 0xe01ef, self.trUtf8("Variation Selectors Supplement")), 290 (0xe0100, 0xe01ef,
273 (0xf0000, 0xfffff, self.trUtf8("Supplementary Private Use Area-A")), 291 self.trUtf8("Variation Selectors Supplement")),
274 (0x100000, 0x10ffff, self.trUtf8("Supplementary Private Use Area-B")), 292 (0xf0000, 0xfffff,
293 self.trUtf8("Supplementary Private Use Area-A")),
294 (0x100000, 0x10ffff,
295 self.trUtf8("Supplementary Private Use Area-B")),
275 ]) 296 ])
276 self.__currentTableIndex = 0 297 self.__currentTableIndex = 0
277 298
278 def getTableNames(self): 299 def getTableNames(self):
279 """ 300 """
439 Private method to check, if a character is a punctuation character. 460 Private method to check, if a character is a punctuation character.
440 461
441 @param char character to test (one character string) 462 @param char character to test (one character string)
442 @return flag indicating a punctuation character (boolean) 463 @return flag indicating a punctuation character (boolean)
443 """ 464 """
444 return unicodedata.category(char) in ["Pc", "Pd", "Ps", "Pe", "Pi", "Pf", "Po"] 465 return unicodedata.category(char) in ["Pc", "Pd", "Ps", "Pe", "Pi",
466 "Pf", "Po"]
445 467
446 468
447 class SymbolsWidget(QWidget, Ui_SymbolsWidget): 469 class SymbolsWidget(QWidget, Ui_SymbolsWidget):
448 """ 470 """
449 Class implementing a widget to select a symbol in various formats. 471 Class implementing a widget to select a symbol in various formats.
467 self.symbolsTable.setModel(self.__model) 489 self.symbolsTable.setModel(self.__model)
468 self.symbolsTable.selectionModel().currentRowChanged.connect( 490 self.symbolsTable.selectionModel().currentRowChanged.connect(
469 self.__currentRowChanged) 491 self.__currentRowChanged)
470 492
471 if qVersion() >= "5.0.0": 493 if qVersion() >= "5.0.0":
472 self.symbolsTable.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed) 494 self.symbolsTable.horizontalHeader().setSectionResizeMode(
495 QHeaderView.Fixed)
473 else: 496 else:
474 self.symbolsTable.horizontalHeader().setResizeMode(QHeaderView.Fixed) 497 self.symbolsTable.horizontalHeader().setResizeMode(
498 QHeaderView.Fixed)
475 fm = self.fontMetrics() 499 fm = self.fontMetrics()
476 em = fm.width("M") 500 em = fm.width("M")
477 self.symbolsTable.horizontalHeader().resizeSection(0, em * 5) 501 self.symbolsTable.horizontalHeader().resizeSection(0, em * 5)
478 self.symbolsTable.horizontalHeader().resizeSection(1, em * 5) 502 self.symbolsTable.horizontalHeader().resizeSection(1, em * 5)
479 self.symbolsTable.horizontalHeader().resizeSection(2, em * 6) 503 self.symbolsTable.horizontalHeader().resizeSection(2, em * 6)
480 self.symbolsTable.horizontalHeader().resizeSection(3, em * 8) 504 self.symbolsTable.horizontalHeader().resizeSection(3, em * 8)
481 self.symbolsTable.horizontalHeader().resizeSection(4, em * 85) 505 self.symbolsTable.horizontalHeader().resizeSection(4, em * 85)
482 self.symbolsTable.verticalHeader().setDefaultSectionSize(fm.height() + 4) 506 self.symbolsTable.verticalHeader().setDefaultSectionSize(
483 507 fm.height() + 4)
484 tableIndex = int(Preferences.Prefs.settings.value("Symbols/CurrentTable", 1)) 508
509 tableIndex = int(
510 Preferences.Prefs.settings.value("Symbols/CurrentTable", 1))
485 self.tableCombo.addItems(self.__model.getTableNames()) 511 self.tableCombo.addItems(self.__model.getTableNames())
486 self.tableCombo.setCurrentIndex(tableIndex) 512 self.tableCombo.setCurrentIndex(tableIndex)
487 513
488 index = self.__model.index( 514 index = self.__model.index(
489 int(Preferences.Prefs.settings.value("Symbols/Top", 0)), 515 int(Preferences.Prefs.settings.value("Symbols/Top", 0)),
507 def on_symbolSpinBox_editingFinished(self): 533 def on_symbolSpinBox_editingFinished(self):
508 """ 534 """
509 Private slot to move the table to the entered symbol id. 535 Private slot to move the table to the entered symbol id.
510 """ 536 """
511 id = self.symbolSpinBox.value() 537 id = self.symbolSpinBox.value()
512 first, last = self.__model.getTableBoundaries(self.__model.getTableIndex()) 538 first, last = self.__model.getTableBoundaries(
539 self.__model.getTableIndex())
513 row = id - first 540 row = id - first
514 self.symbolsTable.selectRow(row) 541 self.symbolsTable.selectRow(row)
515 self.symbolsTable.scrollTo( 542 self.symbolsTable.scrollTo(
516 self.__model.index(row, 0), QAbstractItemView.PositionAtCenter) 543 self.__model.index(row, 0), QAbstractItemView.PositionAtCenter)
517 544

eric ide

mercurial