UI/SymbolsWidget.py

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

eric ide

mercurial