eric7/UI/SymbolsWidget.py

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

eric ide

mercurial