|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a widget to select a symbol in various formats. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
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 |
|
22 import unicodedata |
|
23 |
|
24 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QAbstractTableModel, \ |
|
25 QModelIndex, Qt, QItemSelectionModel, QLocale |
|
26 from PyQt5.QtGui import QColor |
|
27 from PyQt5.QtWidgets import QWidget, QHeaderView, QAbstractItemView |
|
28 |
|
29 from .Ui_SymbolsWidget import Ui_SymbolsWidget |
|
30 |
|
31 import UI.PixmapCache |
|
32 import Preferences |
|
33 from Globals import qVersionTuple |
|
34 |
|
35 |
|
36 class SymbolsModel(QAbstractTableModel): |
|
37 """ |
|
38 Class implementing the model for the symbols widget. |
|
39 """ |
|
40 def __init__(self, parent=None): |
|
41 """ |
|
42 Constructor |
|
43 |
|
44 @param parent reference to the parent object (QObject) |
|
45 """ |
|
46 super(SymbolsModel, self).__init__(parent) |
|
47 |
|
48 self.__locale = QLocale() |
|
49 |
|
50 self.__headerData = [ |
|
51 self.tr("Code"), |
|
52 self.tr("Char"), |
|
53 self.tr("Hex"), |
|
54 self.tr("HTML"), |
|
55 self.tr("Name"), |
|
56 ] |
|
57 |
|
58 self.__tables = [ |
|
59 # first last display name |
|
60 (0x0, 0x1f, self.tr("Control Characters")), |
|
61 (0x20, 0x7f, self.tr("Basic Latin")), |
|
62 (0x80, 0xff, self.tr("Latin-1 Supplement")), |
|
63 (0x100, 0x17f, self.tr("Latin Extended-A")), |
|
64 (0x180, 0x24f, self.tr("Latin Extended-B")), |
|
65 (0x250, 0x2af, self.tr("IPA Extensions")), |
|
66 (0x2b0, 0x2ff, self.tr("Spacing Modifier Letters")), |
|
67 (0x300, 0x36f, self.tr("Combining Diacritical Marks")), |
|
68 (0x370, 0x3ff, self.tr("Greek and Coptic")), |
|
69 (0x400, 0x4ff, self.tr("Cyrillic")), |
|
70 (0x500, 0x52f, self.tr("Cyrillic Supplement")), |
|
71 (0x530, 0x58f, self.tr("Armenian")), |
|
72 (0x590, 0x5ff, self.tr("Hebrew")), |
|
73 (0x600, 0x6ff, self.tr("Arabic")), |
|
74 (0x700, 0x74f, self.tr("Syriac")), |
|
75 (0x780, 0x7bf, self.tr("Thaana")), |
|
76 (0x7c0, 0x7ff, self.tr("N'Ko")), |
|
77 (0x800, 0x83f, self.tr("Samaritan")), |
|
78 (0x840, 0x85f, self.tr("Mandaic")), |
|
79 (0x8a0, 0x8ff, self.tr("Arabic Extended-A")), |
|
80 (0x900, 0x97f, self.tr("Devanagari")), |
|
81 (0x980, 0x9ff, self.tr("Bengali")), |
|
82 (0xa00, 0xa7f, self.tr("Gurmukhi")), |
|
83 (0xa80, 0xaff, self.tr("Gujarati")), |
|
84 (0xb00, 0xb7f, self.tr("Oriya")), |
|
85 (0xb80, 0xbff, self.tr("Tamil")), |
|
86 (0xc00, 0xc7f, self.tr("Telugu")), |
|
87 (0xc80, 0xcff, self.tr("Kannada")), |
|
88 (0xd00, 0xd7f, self.tr("Malayalam")), |
|
89 (0xd80, 0xdff, self.tr("Sinhala")), |
|
90 (0xe00, 0xe7f, self.tr("Thai")), |
|
91 (0xe80, 0xeff, self.tr("Lao")), |
|
92 (0xf00, 0xfff, self.tr("Tibetan")), |
|
93 (0x1000, 0x109f, self.tr("Myanmar")), |
|
94 (0x10a0, 0x10ff, self.tr("Georgian")), |
|
95 (0x1100, 0x11ff, self.tr("Hangul Jamo")), |
|
96 (0x1200, 0x137f, self.tr("Ethiopic")), |
|
97 (0x1380, 0x139f, self.tr("Ethiopic Supplement")), |
|
98 (0x13a0, 0x13ff, self.tr("Cherokee")), |
|
99 (0x1400, 0x167f, |
|
100 self.tr("Unified Canadian Aboriginal Syllabics")), |
|
101 (0x1680, 0x169f, self.tr("Ogham")), |
|
102 (0x16a0, 0x16ff, self.tr("Runic")), |
|
103 (0x1700, 0x171f, self.tr("Tagalog")), |
|
104 (0x1720, 0x173f, self.tr("Hanunoo")), |
|
105 (0x1740, 0x175f, self.tr("Buhid")), |
|
106 (0x1760, 0x177f, self.tr("Tagbanwa")), |
|
107 (0x1780, 0x17ff, self.tr("Khmer")), |
|
108 (0x1800, 0x18af, self.tr("Mongolian")), |
|
109 (0x18b0, 0x18ff, |
|
110 self.tr("Unified Canadian Aboriginal Syllabics Extended")), |
|
111 (0x1900, 0x194f, self.tr("Limbu")), |
|
112 (0x1950, 0x197f, self.tr("Tai Le")), |
|
113 (0x19e0, 0x19ff, self.tr("Khmer Symbols")), |
|
114 (0x1a00, 0x1a1f, self.tr("Buginese")), |
|
115 (0x1a20, 0x1aaf, self.tr("Tai Tham")), |
|
116 (0x1b00, 0x1b7f, self.tr("Balinese")), |
|
117 (0x1b80, 0x1bbf, self.tr("Sundanese")), |
|
118 (0x1bc0, 0x1bff, self.tr("Batak")), |
|
119 (0x1c00, 0x1c4f, self.tr("Lepcha")), |
|
120 (0x1c50, 0x1c7f, self.tr("Ol Chiki")), |
|
121 (0x1cc0, 0x1ccf, self.tr("Sundanese Supplement")), |
|
122 (0x1cd0, 0x1cff, self.tr("Vedic Extensions")), |
|
123 (0x1d00, 0x1d7f, self.tr("Phonetic Extensions")), |
|
124 (0x1d80, 0x1dbf, self.tr("Phonetic Extensions Supplement")), |
|
125 (0x1dc0, 0x1dff, |
|
126 self.tr("Combining Diacritical Marks Supplement")), |
|
127 (0x1e00, 0x1eff, self.tr("Latin Extended Additional")), |
|
128 (0x1f00, 0x1fff, self.tr("Greek Extended")), |
|
129 (0x2000, 0x206f, self.tr("General Punctuation")), |
|
130 (0x2070, 0x209f, self.tr("Superscripts and Subscripts")), |
|
131 (0x20a0, 0x20cf, self.tr("Currency Symbols")), |
|
132 (0x20d0, 0x20ff, self.tr("Combining Diacritical Marks")), |
|
133 (0x2100, 0x214f, self.tr("Letterlike Symbols")), |
|
134 (0x2150, 0x218f, self.tr("Number Forms")), |
|
135 (0x2190, 0x21ff, self.tr("Arcolumns")), |
|
136 (0x2200, 0x22ff, self.tr("Mathematical Operators")), |
|
137 (0x2300, 0x23ff, self.tr("Miscellaneous Technical")), |
|
138 (0x2400, 0x243f, self.tr("Control Pictures")), |
|
139 (0x2440, 0x245f, self.tr("Optical Character Recognition")), |
|
140 (0x2460, 0x24ff, self.tr("Enclosed Alphanumerics")), |
|
141 (0x2500, 0x257f, self.tr("Box Drawing")), |
|
142 (0x2580, 0x259f, self.tr("Block Elements")), |
|
143 (0x25A0, 0x25ff, self.tr("Geometric Shapes")), |
|
144 (0x2600, 0x26ff, self.tr("Miscellaneous Symbols")), |
|
145 (0x2700, 0x27bf, self.tr("Dingbats")), |
|
146 (0x27c0, 0x27ef, |
|
147 self.tr("Miscellaneous Mathematical Symbols-A")), |
|
148 (0x27f0, 0x27ff, self.tr("Supplement Arcolumns-A")), |
|
149 (0x2800, 0x28ff, self.tr("Braille Patterns")), |
|
150 (0x2900, 0x297f, self.tr("Supplement Arcolumns-B")), |
|
151 (0x2980, 0x29ff, |
|
152 self.tr("Miscellaneous Mathematical Symbols-B")), |
|
153 (0x2a00, 0x2aff, |
|
154 self.tr("Supplemental Mathematical Operators")), |
|
155 (0x2b00, 0x2bff, |
|
156 self.tr("Miscellaneous Symbols and Arcolumns")), |
|
157 (0x2c00, 0x2c5f, self.tr("Glagolitic")), |
|
158 (0x2c60, 0x2c7f, self.tr("Latin Extended-C")), |
|
159 (0x2c80, 0x2cff, self.tr("Coptic")), |
|
160 (0x2d00, 0x2d2f, self.tr("Georgian Supplement")), |
|
161 (0x2d30, 0x2d7f, self.tr("Tifinagh")), |
|
162 (0x2d80, 0x2ddf, self.tr("Ethiopic Extended")), |
|
163 (0x2de0, 0x2dff, self.tr("Cyrillic Extended-A")), |
|
164 (0x2e00, 0x2e7f, self.tr("Supplemental Punctuation")), |
|
165 (0x2e80, 0x2eff, self.tr("CJK Radicals Supplement")), |
|
166 (0x2f00, 0x2fdf, self.tr("KangXi Radicals")), |
|
167 (0x2ff0, 0x2fff, self.tr("Ideographic Description Chars")), |
|
168 (0x3000, 0x303f, self.tr("CJK Symbols and Punctuation")), |
|
169 (0x3040, 0x309f, self.tr("Hiragana")), |
|
170 (0x30a0, 0x30ff, self.tr("Katakana")), |
|
171 (0x3100, 0x312f, self.tr("Bopomofo")), |
|
172 (0x3130, 0x318f, self.tr("Hangul Compatibility Jamo")), |
|
173 (0x3190, 0x319f, self.tr("Kanbun")), |
|
174 (0x31a0, 0x31bf, self.tr("Bopomofo Extended")), |
|
175 (0x31c0, 0x31ef, self.tr("CJK Strokes")), |
|
176 (0x31f0, 0x31ff, self.tr("Katakana Phonetic Extensions")), |
|
177 (0x3200, 0x32ff, self.tr("Enclosed CJK Letters and Months")), |
|
178 (0x3300, 0x33ff, self.tr("CJK Compatibility")), |
|
179 (0x3400, 0x4dbf, self.tr("CJK Unified Ideogr. Ext. A")), |
|
180 (0x4dc0, 0x4dff, self.tr("Yijing Hexagram Symbols")), |
|
181 (0x4e00, 0x9fff, self.tr("CJK Unified Ideographs")), |
|
182 (0xa000, 0xa48f, self.tr("Yi Syllables")), |
|
183 (0xa490, 0xa4cf, self.tr("Yi Radicals")), |
|
184 (0xa4d0, 0xa4ff, self.tr("Lisu")), |
|
185 (0xa500, 0xa63f, self.tr("Vai")), |
|
186 (0xa640, 0xa69f, self.tr("Cyrillic Extended-B")), |
|
187 (0xa6a0, 0xa6ff, self.tr("Bamum")), |
|
188 (0xa700, 0xa71f, self.tr("Modifier Tone Letters")), |
|
189 (0xa720, 0xa7ff, self.tr("Latin Extended-D")), |
|
190 (0xa800, 0xa82f, self.tr("Syloti Nagri")), |
|
191 (0xa830, 0xa83f, self.tr("Common Indic Number Forms")), |
|
192 (0xa840, 0xa87f, self.tr("Phags-pa")), |
|
193 (0xa880, 0xa8df, self.tr("Saurashtra")), |
|
194 (0xa8e0, 0xa8ff, self.tr("Devanagari Extended")), |
|
195 (0xa900, 0xa92f, self.tr("Kayah Li")), |
|
196 (0xa930, 0xa95f, self.tr("Rejang")), |
|
197 (0xa960, 0xa97f, self.tr("Hangul Jamo Extended-A")), |
|
198 (0xa980, 0xa9df, self.tr("Javanese")), |
|
199 (0xaa00, 0xaa5f, self.tr("Cham")), |
|
200 (0xaa60, 0xaa7f, self.tr("Myanmar Extended-A")), |
|
201 (0xaa80, 0xaadf, self.tr("Tai Viet")), |
|
202 (0xaae0, 0xaaff, self.tr("Meetei Mayek Extensions")), |
|
203 (0xab00, 0xab2f, self.tr("Ethiopic Extended-A")), |
|
204 (0xabc0, 0xabff, self.tr("Meetei Mayek")), |
|
205 (0xac00, 0xd7af, self.tr("Hangul Syllables")), |
|
206 (0xd7b0, 0xd7ff, self.tr("Hangul Jamo Extended-B")), |
|
207 (0xd800, 0xdb7f, self.tr("High Surrogates")), |
|
208 (0xdb80, 0xdbff, self.tr("High Private Use Surrogates")), |
|
209 (0xdc00, 0xdfff, self.tr("Low Surrogates")), |
|
210 (0xe000, 0xf8ff, self.tr("Private Use")), |
|
211 (0xf900, 0xfaff, self.tr("CJK Compatibility Ideographs")), |
|
212 (0xfb00, 0xfb4f, self.tr("Alphabetic Presentation Forms")), |
|
213 (0xfb50, 0xfdff, self.tr("Arabic Presentation Forms-A")), |
|
214 (0xfe00, 0xfe0f, self.tr("Variation Selectors")), |
|
215 (0xfe10, 0xfe1f, self.tr("Vertical Forms")), |
|
216 (0xfe20, 0xfe2f, self.tr("Combining Half Marks")), |
|
217 (0xfe30, 0xfe4f, self.tr("CJK Compatibility Forms")), |
|
218 (0xfe50, 0xfe6f, self.tr("Small Form Variants")), |
|
219 (0xfe70, 0xfeff, self.tr("Arabic Presentation Forms-B")), |
|
220 (0xff00, 0xffef, self.tr("Half- and Fullwidth Forms")), |
|
221 (0xfff0, 0xffff, self.tr("Specials")), |
|
222 ] |
|
223 if sys.maxunicode > 0xffff: |
|
224 self.__tables.extend([ |
|
225 (0x10000, 0x1007f, self.tr("Linear B Syllabary")), |
|
226 (0x10080, 0x100ff, self.tr("Linear B Ideograms")), |
|
227 (0x10100, 0x1013f, self.tr("Aegean Numbers")), |
|
228 (0x10140, 0x1018f, self.tr("Ancient Greek Numbers")), |
|
229 (0x10190, 0x101cf, self.tr("Ancient Symbols")), |
|
230 (0x101d0, 0x101ff, self.tr("Phaistos Disc")), |
|
231 (0x10280, 0x1029f, self.tr("Lycian")), |
|
232 (0x102a0, 0x102df, self.tr("Carian")), |
|
233 (0x10300, 0x1032f, self.tr("Old Italic")), |
|
234 (0x10330, 0x1034f, self.tr("Gothic")), |
|
235 (0x10380, 0x1039f, self.tr("Ugaritic")), |
|
236 (0x103a0, 0x103df, self.tr("Old Persian")), |
|
237 (0x10400, 0x1044f, self.tr("Deseret")), |
|
238 (0x10450, 0x1047f, self.tr("Shavian")), |
|
239 (0x10480, 0x104af, self.tr("Osmanya")), |
|
240 (0x10800, 0x1083f, self.tr("Cypriot Syllabary")), |
|
241 (0x10840, 0x1085f, self.tr("Imperial Aramaic")), |
|
242 (0x10900, 0x1091f, self.tr("Phoenician")), |
|
243 (0x10920, 0x1093f, self.tr("Lydian")), |
|
244 (0x10980, 0x1099f, self.tr("Meroitic Hieroglyphs")), |
|
245 (0x109a0, 0x109ff, self.tr("Meroitic Cursive")), |
|
246 (0x10a00, 0x10a5f, self.tr("Kharoshthi")), |
|
247 (0x10a60, 0x10a7f, self.tr("Old South Arabian")), |
|
248 (0x10b00, 0x10b3f, self.tr("Avestan")), |
|
249 (0x10b40, 0x10b5f, self.tr("Inscriptional Parthian")), |
|
250 (0x10b60, 0x10b7f, self.tr("Inscriptional Pahlavi")), |
|
251 (0x10c00, 0x10c4f, self.tr("Old Turkic")), |
|
252 (0x10e60, 0x10e7f, self.tr("Rumi Numeral Symbols")), |
|
253 (0x11000, 0x1107f, self.tr("Brahmi")), |
|
254 (0x11080, 0x110cf, self.tr("Kaithi")), |
|
255 (0x110d0, 0x110ff, self.tr("Sora Sompeng")), |
|
256 (0x11100, 0x1114f, self.tr("Chakma")), |
|
257 (0x11180, 0x111df, self.tr("Sharada")), |
|
258 (0x11680, 0x116cf, self.tr("Takri")), |
|
259 (0x12000, 0x123ff, self.tr("Cuneiform")), |
|
260 (0x12400, 0x1247f, |
|
261 self.tr("Cuneiform Numbers and Punctuation")), |
|
262 (0x13000, 0x1342f, self.tr("Egyptian Hieroglyphs")), |
|
263 (0x16800, 0x16a3f, self.tr("Bamum Supplement")), |
|
264 (0x16f00, 0x16f9f, self.tr("Miao")), |
|
265 (0x1b000, 0x1b0ff, self.tr("Kana Supplement")), |
|
266 (0x1d000, 0x1d0ff, self.tr("Byzantine Musical Symbols")), |
|
267 (0x1d100, 0x1d1ff, self.tr("Musical Symbols")), |
|
268 (0x1d200, 0x1d24f, |
|
269 self.tr("Ancient Greek Musical Notation")), |
|
270 (0x1d300, 0x1d35f, self.tr("Tai Xuan Jing Symbols")), |
|
271 (0x1d360, 0x1d37f, |
|
272 self.tr("Counting Rod Numerals")), |
|
273 (0x1d400, 0x1d7ff, |
|
274 self.tr("Mathematical Alphanumeric Symbols")), |
|
275 (0x1ee00, 0x1eeff, |
|
276 self.tr("Arabic Mathematical Alphabetic Symbols")), |
|
277 (0x1f000, 0x1f02f, self.tr("Mahjong Tiles")), |
|
278 (0x1f030, 0x1f09f, self.tr("Domino Tiles")), |
|
279 (0x1f0a0, 0x1f0ff, self.tr("Playing Cards")), |
|
280 (0x1f100, 0x1f1ff, |
|
281 self.tr("Enclosed Alphanumeric Supplement")), |
|
282 (0x1f200, 0x1f2ff, |
|
283 self.tr("Enclosed Ideographic Supplement")), |
|
284 (0x1f300, 0x1f5ff, |
|
285 self.tr("Miscellaneous Symbols And Pictographs")), |
|
286 (0x1f600, 0x1f64f, self.tr("Emoticons")), |
|
287 (0x1f680, 0x1f6ff, self.tr("Transport And Map Symbols")), |
|
288 (0x1f700, 0x1f77f, self.tr("Alchemical Symbols")), |
|
289 (0x20000, 0x2a6df, self.tr("CJK Unified Ideogr. Ext. B")), |
|
290 (0x2a700, 0x2b73f, |
|
291 self.tr("CJK Unified Ideographs Extension C")), |
|
292 (0x2b740, 0x2b81f, |
|
293 self.tr("CJK Unified Ideographs Extension D")), |
|
294 (0x2f800, 0x2fa1f, |
|
295 self.tr("CJK Compatapility Ideogr. Suppl.")), |
|
296 (0xe0000, 0xe007f, self.tr("Tags")), |
|
297 (0xe0100, 0xe01ef, |
|
298 self.tr("Variation Selectors Supplement")), |
|
299 (0xf0000, 0xfffff, |
|
300 self.tr("Supplementary Private Use Area-A")), |
|
301 (0x100000, 0x10ffff, |
|
302 self.tr("Supplementary Private Use Area-B")), |
|
303 ]) |
|
304 self.__currentTableIndex = 0 |
|
305 |
|
306 def getTableNames(self): |
|
307 """ |
|
308 Public method to get a list of table names. |
|
309 |
|
310 @return list of table names (list of strings) |
|
311 """ |
|
312 return [table[2] for table in self.__tables] |
|
313 |
|
314 def getTableBoundaries(self, index): |
|
315 """ |
|
316 Public method to get the first and last character position |
|
317 of the given table. |
|
318 |
|
319 @param index index of the character table (integer) |
|
320 @return first and last character position (integer, integer) |
|
321 """ |
|
322 return self.__tables[index][0], self.__tables[index][1] |
|
323 |
|
324 def getTableIndex(self): |
|
325 """ |
|
326 Public method to get the current table index. |
|
327 |
|
328 @return current table index (integer) |
|
329 """ |
|
330 return self.__currentTableIndex |
|
331 |
|
332 def selectTable(self, index): |
|
333 """ |
|
334 Public method to select the shown character table. |
|
335 |
|
336 @param index index of the character table (integer) |
|
337 """ |
|
338 self.beginResetModel() |
|
339 self.__currentTableIndex = index |
|
340 self.endResetModel() |
|
341 |
|
342 def headerData(self, section, orientation, role=Qt.DisplayRole): |
|
343 """ |
|
344 Public method to get header data from the model. |
|
345 |
|
346 @param section section number (integer) |
|
347 @param orientation orientation (Qt.Orientation) |
|
348 @param role role of the data to retrieve (integer) |
|
349 @return requested data |
|
350 """ |
|
351 if orientation == Qt.Horizontal and role == Qt.DisplayRole: |
|
352 return self.__headerData[section] |
|
353 |
|
354 return QAbstractTableModel.headerData(self, section, orientation, role) |
|
355 |
|
356 def data(self, index, role=Qt.DisplayRole): |
|
357 """ |
|
358 Public method to get data from the model. |
|
359 |
|
360 @param index index to get data for (QModelIndex) |
|
361 @param role role of the data to retrieve (integer) |
|
362 @return requested data |
|
363 """ |
|
364 symbolId = self.__tables[self.__currentTableIndex][0] + index.row() |
|
365 |
|
366 if role == Qt.DisplayRole: |
|
367 col = index.column() |
|
368 if col == 0: |
|
369 return self.__locale.toString(symbolId) |
|
370 elif col == 1: |
|
371 return chr(symbolId) |
|
372 elif col == 2: |
|
373 return "0x{0:04x}".format(symbolId) |
|
374 elif col == 3: |
|
375 if symbolId in html_entities.codepoint2name: |
|
376 return "&{0};".format( |
|
377 html_entities.codepoint2name[symbolId]) |
|
378 elif col == 4: |
|
379 return unicodedata.name(chr(symbolId), '').title() |
|
380 |
|
381 if role == Qt.BackgroundColorRole: |
|
382 if index.column() == 0: |
|
383 return QColor(Qt.lightGray) |
|
384 |
|
385 if role == Qt.TextColorRole: |
|
386 char = chr(symbolId) |
|
387 if self.__isDigit(char): |
|
388 return QColor(Qt.darkBlue) |
|
389 elif self.__isLetter(char): |
|
390 return QColor(Qt.darkGreen) |
|
391 elif self.__isMark(char): |
|
392 return QColor(Qt.darkRed) |
|
393 elif self.__isSymbol(char): |
|
394 return QColor(Qt.black) |
|
395 elif self.__isPunct(char): |
|
396 return QColor(Qt.darkMagenta) |
|
397 else: |
|
398 return QColor(Qt.darkGray) |
|
399 |
|
400 if role == Qt.TextAlignmentRole: |
|
401 if index.column() in [0, 1, 3]: |
|
402 return Qt.AlignHCenter |
|
403 |
|
404 return None |
|
405 |
|
406 def columnCount(self, parent): |
|
407 """ |
|
408 Public method to get the number of columns of the model. |
|
409 |
|
410 @param parent parent index (QModelIndex) |
|
411 @return number of columns (integer) |
|
412 """ |
|
413 if parent.column() > 0: |
|
414 return 0 |
|
415 else: |
|
416 return len(self.__headerData) |
|
417 |
|
418 def rowCount(self, parent): |
|
419 """ |
|
420 Public method to get the number of rows of the model. |
|
421 |
|
422 @param parent parent index (QModelIndex) |
|
423 @return number of columns (integer) |
|
424 """ |
|
425 if parent.isValid(): |
|
426 return 0 |
|
427 else: |
|
428 first, last = self.__tables[self.__currentTableIndex][:2] |
|
429 return last - first + 1 |
|
430 |
|
431 def __isDigit(self, char): |
|
432 """ |
|
433 Private method to check, if a character is a digit. |
|
434 |
|
435 @param char character to test (one character string) |
|
436 @return flag indicating a digit (boolean) |
|
437 """ |
|
438 return unicodedata.category(str(char)) == "Nd" |
|
439 |
|
440 def __isLetter(self, char): |
|
441 """ |
|
442 Private method to check, if a character is a letter. |
|
443 |
|
444 @param char character to test (one character string) |
|
445 @return flag indicating a letter (boolean) |
|
446 """ |
|
447 return unicodedata.category(str(char)) in ["Lu", "Ll", "Lt", "Lm", |
|
448 "Lo"] |
|
449 |
|
450 def __isMark(self, char): |
|
451 """ |
|
452 Private method to check, if a character is a mark character. |
|
453 |
|
454 @param char character to test (one character string) |
|
455 @return flag indicating a mark character (boolean) |
|
456 """ |
|
457 return unicodedata.category(str(char)) in ["Mn", "Mc", "Me"] |
|
458 |
|
459 def __isSymbol(self, char): |
|
460 """ |
|
461 Private method to check, if a character is a symbol. |
|
462 |
|
463 @param char character to test (one character string) |
|
464 @return flag indicating a symbol (boolean) |
|
465 """ |
|
466 return unicodedata.category(str(char)) in ["Sm", "Sc", "Sk", "So"] |
|
467 |
|
468 def __isPunct(self, char): |
|
469 """ |
|
470 Private method to check, if a character is a punctuation character. |
|
471 |
|
472 @param char character to test (one character string) |
|
473 @return flag indicating a punctuation character (boolean) |
|
474 """ |
|
475 return unicodedata.category(str(char)) in ["Pc", "Pd", "Ps", "Pe", |
|
476 "Pi", "Pf", "Po"] |
|
477 |
|
478 def getLocale(self): |
|
479 """ |
|
480 Public method to get the used locale. |
|
481 |
|
482 @return used locale |
|
483 @rtype QLocale |
|
484 """ |
|
485 return self.__locale |
|
486 |
|
487 |
|
488 class SymbolsWidget(QWidget, Ui_SymbolsWidget): |
|
489 """ |
|
490 Class implementing a widget to select a symbol in various formats. |
|
491 |
|
492 @signal insertSymbol(str) emitted after the user has selected a symbol |
|
493 """ |
|
494 insertSymbol = pyqtSignal(str) |
|
495 |
|
496 def __init__(self, parent=None): |
|
497 """ |
|
498 Constructor |
|
499 |
|
500 @param parent reference to the parent widget (QWidget) |
|
501 """ |
|
502 super(SymbolsWidget, self).__init__(parent) |
|
503 self.setupUi(self) |
|
504 |
|
505 self.setWindowIcon(UI.PixmapCache.getIcon("eric.png")) |
|
506 |
|
507 self.__model = SymbolsModel(self) |
|
508 self.symbolsTable.setModel(self.__model) |
|
509 self.symbolsTable.selectionModel().currentRowChanged.connect( |
|
510 self.__currentRowChanged) |
|
511 |
|
512 if qVersionTuple() >= (5, 0, 0): |
|
513 self.symbolsTable.horizontalHeader().setSectionResizeMode( |
|
514 QHeaderView.Fixed) |
|
515 else: |
|
516 self.symbolsTable.horizontalHeader().setResizeMode( |
|
517 QHeaderView.Fixed) |
|
518 fm = self.fontMetrics() |
|
519 em = fm.width("M") |
|
520 self.symbolsTable.horizontalHeader().resizeSection(0, em * 5) |
|
521 self.symbolsTable.horizontalHeader().resizeSection(1, em * 5) |
|
522 self.symbolsTable.horizontalHeader().resizeSection(2, em * 6) |
|
523 self.symbolsTable.horizontalHeader().resizeSection(3, em * 8) |
|
524 self.symbolsTable.horizontalHeader().resizeSection(4, em * 85) |
|
525 self.symbolsTable.verticalHeader().setDefaultSectionSize( |
|
526 fm.height() + 4) |
|
527 |
|
528 tableIndex = int( |
|
529 Preferences.Prefs.settings.value("Symbols/CurrentTable", 1)) |
|
530 self.tableCombo.addItems(self.__model.getTableNames()) |
|
531 self.tableCombo.setCurrentIndex(tableIndex) |
|
532 |
|
533 index = self.__model.index( |
|
534 int(Preferences.Prefs.settings.value("Symbols/Top", 0)), |
|
535 0) |
|
536 self.symbolsTable.scrollTo(index, QAbstractItemView.PositionAtTop) |
|
537 self.symbolsTable.selectionModel().setCurrentIndex( |
|
538 index, |
|
539 QItemSelectionModel.SelectCurrent | QItemSelectionModel.Rows) |
|
540 |
|
541 @pyqtSlot(QModelIndex) |
|
542 def on_symbolsTable_activated(self, index): |
|
543 """ |
|
544 Private slot to signal the selection of a symbol. |
|
545 |
|
546 @param index index of the selected symbol (QModelIndex) |
|
547 """ |
|
548 txt = self.__model.data(index) |
|
549 if txt: |
|
550 self.insertSymbol.emit(txt) |
|
551 |
|
552 @pyqtSlot() |
|
553 def on_symbolSpinBox_editingFinished(self): |
|
554 """ |
|
555 Private slot to move the table to the entered symbol id. |
|
556 """ |
|
557 symbolId = self.symbolSpinBox.value() |
|
558 first, last = self.__model.getTableBoundaries( |
|
559 self.__model.getTableIndex()) |
|
560 row = symbolId - first |
|
561 self.symbolsTable.selectRow(row) |
|
562 self.symbolsTable.scrollTo( |
|
563 self.__model.index(row, 0), QAbstractItemView.PositionAtCenter) |
|
564 |
|
565 @pyqtSlot(int) |
|
566 def on_tableCombo_currentIndexChanged(self, index): |
|
567 """ |
|
568 Private slot to select the current character table. |
|
569 |
|
570 @param index index of the character table (integer) |
|
571 """ |
|
572 self.symbolsTable.setUpdatesEnabled(False) |
|
573 self.__model.selectTable(index) |
|
574 self.symbolsTable.setUpdatesEnabled(True) |
|
575 self.symbolsTable.resizeColumnsToContents() |
|
576 |
|
577 first, last = self.__model.getTableBoundaries(index) |
|
578 self.symbolSpinBox.setMinimum(first) |
|
579 self.symbolSpinBox.setMaximum(last) |
|
580 |
|
581 Preferences.Prefs.settings.setValue("Symbols/CurrentTable", index) |
|
582 |
|
583 def __currentRowChanged(self, current, previous): |
|
584 """ |
|
585 Private slot recording the currently selected row. |
|
586 |
|
587 @param current current index (QModelIndex) |
|
588 @param previous previous current index (QModelIndex) |
|
589 """ |
|
590 Preferences.Prefs.settings.setValue("Symbols/Top", current.row()) |
|
591 self.symbolSpinBox.setValue(self.__model.getLocale().toInt( |
|
592 self.__model.data(self.__model.index(current.row(), 0)))[0]) |