UI/SymbolsWidget.py

changeset 4467
fc6f2095a423
parent 4021
195a471c327b
child 4631
5c1a96925da4
equal deleted inserted replaced
4466:184660eecb94 4467:fc6f2095a423
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import sys 12 import sys
13 import unicodedata 13 import unicodedata
14 try: # Py3 14 try:
15 # Py3
15 import html.entities as html_entities 16 import html.entities as html_entities
16 except (ImportError): 17 except (ImportError):
17 chr = unichr # __IGNORE_WARNING__ 18 # Py2
18 import htmlentitydefs as html_entities # __IGNORE_WARNING__ 19 str = unicode # __IGNORE_WARNING__
20 chr = unichr # __IGNORE_WARNING__
21 import htmlentitydefs as html_entities # __IGNORE_WARNING__
19 22
20 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QAbstractTableModel, \ 23 from PyQt5.QtCore import pyqtSlot, pyqtSignal, QAbstractTableModel, \
21 QModelIndex, Qt, qVersion, QItemSelectionModel 24 QModelIndex, Qt, qVersion, QItemSelectionModel, QLocale
22 from PyQt5.QtGui import QColor 25 from PyQt5.QtGui import QColor
23 from PyQt5.QtWidgets import QWidget, QHeaderView, QAbstractItemView 26 from PyQt5.QtWidgets import QWidget, QHeaderView, QAbstractItemView
24 27
25 from .Ui_SymbolsWidget import Ui_SymbolsWidget 28 from .Ui_SymbolsWidget import Ui_SymbolsWidget
26 29
37 Constructor 40 Constructor
38 41
39 @param parent reference to the parent object (QObject) 42 @param parent reference to the parent object (QObject)
40 """ 43 """
41 super(SymbolsModel, self).__init__(parent) 44 super(SymbolsModel, self).__init__(parent)
45
46 self.__locale = QLocale()
42 47
43 self.__headerData = [ 48 self.__headerData = [
44 self.tr("Code"), 49 self.tr("Code"),
45 self.tr("Char"), 50 self.tr("Char"),
46 self.tr("Hex"), 51 self.tr("Hex"),
357 id = self.__tables[self.__currentTableIndex][0] + index.row() 362 id = self.__tables[self.__currentTableIndex][0] + index.row()
358 363
359 if role == Qt.DisplayRole: 364 if role == Qt.DisplayRole:
360 col = index.column() 365 col = index.column()
361 if col == 0: 366 if col == 0:
362 return str(id) 367 return self.__locale.toString(id)
363 elif col == 1: 368 elif col == 1:
364 return chr(id) 369 return chr(id)
365 elif col == 2: 370 elif col == 2:
366 return "0x{0:04x}".format(id) 371 return "0x{0:04x}".format(id)
367 elif col == 3: 372 elif col == 3:
425 Private method to check, if a character is a digit. 430 Private method to check, if a character is a digit.
426 431
427 @param char character to test (one character string) 432 @param char character to test (one character string)
428 @return flag indicating a digit (boolean) 433 @return flag indicating a digit (boolean)
429 """ 434 """
430 return unicodedata.category(char) == "Nd" 435 return unicodedata.category(str(char)) == "Nd"
431 436
432 def __isLetter(self, char): 437 def __isLetter(self, char):
433 """ 438 """
434 Private method to check, if a character is a letter. 439 Private method to check, if a character is a letter.
435 440
436 @param char character to test (one character string) 441 @param char character to test (one character string)
437 @return flag indicating a letter (boolean) 442 @return flag indicating a letter (boolean)
438 """ 443 """
439 return unicodedata.category(char) in ["Lu", "Ll", "Lt", "Lm", "Lo"] 444 return unicodedata.category(str(char)) in ["Lu", "Ll", "Lt", "Lm",
445 "Lo"]
440 446
441 def __isMark(self, char): 447 def __isMark(self, char):
442 """ 448 """
443 Private method to check, if a character is a mark character. 449 Private method to check, if a character is a mark character.
444 450
445 @param char character to test (one character string) 451 @param char character to test (one character string)
446 @return flag indicating a mark character (boolean) 452 @return flag indicating a mark character (boolean)
447 """ 453 """
448 return unicodedata.category(char) in ["Mn", "Mc", "Me"] 454 return unicodedata.category(str(char)) in ["Mn", "Mc", "Me"]
449 455
450 def __isSymbol(self, char): 456 def __isSymbol(self, char):
451 """ 457 """
452 Private method to check, if a character is a symbol. 458 Private method to check, if a character is a symbol.
453 459
454 @param char character to test (one character string) 460 @param char character to test (one character string)
455 @return flag indicating a symbol (boolean) 461 @return flag indicating a symbol (boolean)
456 """ 462 """
457 return unicodedata.category(char) in ["Sm", "Sc", "Sk", "So"] 463 return unicodedata.category(str(char)) in ["Sm", "Sc", "Sk", "So"]
458 464
459 def __isPunct(self, char): 465 def __isPunct(self, char):
460 """ 466 """
461 Private method to check, if a character is a punctuation character. 467 Private method to check, if a character is a punctuation character.
462 468
463 @param char character to test (one character string) 469 @param char character to test (one character string)
464 @return flag indicating a punctuation character (boolean) 470 @return flag indicating a punctuation character (boolean)
465 """ 471 """
466 return unicodedata.category(char) in ["Pc", "Pd", "Ps", "Pe", "Pi", 472 return unicodedata.category(str(char)) in ["Pc", "Pd", "Ps", "Pe",
467 "Pf", "Po"] 473 "Pi", "Pf", "Po"]
474
475 def getLocale(self):
476 """
477 Public method to get the used locale.
478
479 @return used locale
480 @rtype QLocale
481 """
482 return self.__locale
468 483
469 484
470 class SymbolsWidget(QWidget, Ui_SymbolsWidget): 485 class SymbolsWidget(QWidget, Ui_SymbolsWidget):
471 """ 486 """
472 Class implementing a widget to select a symbol in various formats. 487 Class implementing a widget to select a symbol in various formats.
552 @param index index of the character table (integer) 567 @param index index of the character table (integer)
553 """ 568 """
554 self.symbolsTable.setUpdatesEnabled(False) 569 self.symbolsTable.setUpdatesEnabled(False)
555 self.__model.selectTable(index) 570 self.__model.selectTable(index)
556 self.symbolsTable.setUpdatesEnabled(True) 571 self.symbolsTable.setUpdatesEnabled(True)
572 self.symbolsTable.resizeColumnsToContents()
557 573
558 first, last = self.__model.getTableBoundaries(index) 574 first, last = self.__model.getTableBoundaries(index)
559 self.symbolSpinBox.setMinimum(first) 575 self.symbolSpinBox.setMinimum(first)
560 self.symbolSpinBox.setMaximum(last) 576 self.symbolSpinBox.setMaximum(last)
561 577
567 583
568 @param current current index (QModelIndex) 584 @param current current index (QModelIndex)
569 @param previous previous current index (QModelIndex) 585 @param previous previous current index (QModelIndex)
570 """ 586 """
571 Preferences.Prefs.settings.setValue("Symbols/Top", current.row()) 587 Preferences.Prefs.settings.setValue("Symbols/Top", current.row())
572 self.symbolSpinBox.setValue(int( 588 self.symbolSpinBox.setValue(self.__model.getLocale().toInt(
573 self.__model.data(self.__model.index(current.row(), 0)))) 589 self.__model.data(self.__model.index(current.row(), 0)))[0])

eric ide

mercurial