--- a/UI/SymbolsWidget.py Sat Jun 26 13:34:06 2010 +0200 +++ b/UI/SymbolsWidget.py Sat Jun 26 18:50:41 2010 +0200 @@ -11,10 +11,13 @@ import html.entities from PyQt4.QtCore import pyqtSlot, pyqtSignal, QAbstractTableModel, QModelIndex, Qt -from PyQt4.QtGui import QWidget, QHeaderView, QAbstractItemView, QColor +from PyQt4.QtGui import QWidget, QHeaderView, QAbstractItemView, QColor, \ + QItemSelectionModel from .Ui_SymbolsWidget import Ui_SymbolsWidget +import Preferences + class SymbolsModel(QAbstractTableModel): """ Class implementing the model for the symbols widget. @@ -32,17 +35,141 @@ self.trUtf8("Char"), self.trUtf8("Hex"), self.trUtf8("HTML"), + self.trUtf8("Name"), ] - self.__unicode = True + self.__tables = ( + # first last display name + (0x0, 0x1f, self.trUtf8("Control Characters")), + (0x20, 0x7f, self.trUtf8("Basic Latin")), + (0x80, 0x100, self.trUtf8("Latin-1 Supplement")), + (0x100, 0x180, self.trUtf8("Latin Extendet A")), + (0x180, 0x24f, self.trUtf8("Latin Extendet B")), + (0x250, 0x2af, self.trUtf8("IPA Extensions")), + (0x2b0, 0x2ff, self.trUtf8("Spacing Modifier Letters")), + (0x300, 0x36f, self.trUtf8("Combining Diacritical Marks")), + (0x370, 0x3ff, self.trUtf8("Greek and Coptic")), + (0x400, 0x4ff, self.trUtf8("Cyrillic")), + (0x500, 0x52f, self.trUtf8("Cyrillic Supplement")), + (0x530, 0x58f, self.trUtf8("Armenian")), + (0x590, 0x5ff, self.trUtf8("Hebrew")), + (0x600, 0x6ff, self.trUtf8("Arabic")), + (0x700, 0x74f, self.trUtf8("Syriac")), + (0x780, 0x7bf, self.trUtf8("Thaana")), + (0x900, 0x97f, self.trUtf8("Devanagari")), + (0x980, 0x9ff, self.trUtf8("Bengali")), + (0xa00, 0xa7f, self.trUtf8("Gurmukhi")), + (0xa80, 0xaff, self.trUtf8("Gujarati")), + (0xb00, 0xb7f, self.trUtf8("Oriya")), + (0xb80, 0xbff, self.trUtf8("Tamil")), + (0xc00, 0xc7f, self.trUtf8("Telugu")), + (0xc80, 0xcff, self.trUtf8("Kannada")), + (0xd00, 0xd7f, self.trUtf8("Malayalam")), + (0xd80, 0xdff, self.trUtf8("Sinhala")), + (0xe00, 0xe7f, self.trUtf8("Thai")), + (0xe80, 0xeff, self.trUtf8("Lao")), + (0xf00, 0xfff, self.trUtf8("Tibetan")), + (0x1000, 0x109f, self.trUtf8("Myanmar")), + (0x10a0, 0x10ff, self.trUtf8("Georgian")), + (0x1100, 0x11ff, self.trUtf8("Hangul Jamo")), + (0x1200, 0x137f, self.trUtf8("Ethiopic")), + (0x13a0, 0x13ff, self.trUtf8("Cherokee")), + (0x1400, 0x167f, self.trUtf8("Canadian Aboriginal Syllabics")), + (0x1680, 0x169f, self.trUtf8("Ogham")), + (0x16a0, 0x16ff, self.trUtf8("Runic")), + (0x1700, 0x171f, self.trUtf8("Tagalog")), + (0x1720, 0x173f, self.trUtf8("Hanunoo")), + (0x1740, 0x175f, self.trUtf8("Buhid")), + (0x1760, 0x177f, self.trUtf8("Tagbanwa")), + (0x1780, 0x17ff, self.trUtf8("Khmer")), + (0x1800, 0x18af, self.trUtf8("Mongolian")), + (0x1900, 0x194f, self.trUtf8("Limbu")), + (0x1950, 0x197f, self.trUtf8("Tai Le")), + (0x19e0, 0x19ff, self.trUtf8("Khmer Symbols")), + (0x1d00, 0x1d7f, self.trUtf8("Phonetic Extensions")), + (0x1e00, 0x1eff, self.trUtf8("Latin Extended Additional")), + (0x1f00, 0x1fff, self.trUtf8("Greek Extended")), + (0x2000, 0x206f, self.trUtf8("General Punctuation")), + (0x2070, 0x209f, self.trUtf8("Superscripts and Subscripts")), + (0x20a0, 0x20cf, self.trUtf8("Currency Symbols")), + (0x20d0, 0x20ff, self.trUtf8("Combining Diacritical Marks")), + (0x2100, 0x214f, self.trUtf8("Letterlike Symbols")), + (0x2150, 0x218f, self.trUtf8("Number Forms")), + (0x2190, 0x21ff, self.trUtf8("Arcolumns")), + (0x2200, 0x22ff, self.trUtf8("Mathematical Operators")), + (0x2300, 0x23ff, self.trUtf8("Miscelaneous Technical")), + (0x2400, 0x243f, self.trUtf8("Control Pictures")), + (0x2440, 0x245f, self.trUtf8("Optical Character Recognition")), + (0x2460, 0x24ff, self.trUtf8("Enclosed Alphanumerics")), + (0x2500, 0x257f, self.trUtf8("Box Drawing")), + (0x2580, 0x259f, self.trUtf8("Block Elements")), + (0x2600, 0x26ff, self.trUtf8("Miscelaneous Symbols")), + (0x2700, 0x27bf, self.trUtf8("Dingbats")), + (0x27c0, 0x27ef, self.trUtf8("Miscelaneous Mathematical Symbols-A")), + (0x27f0, 0x27ff, self.trUtf8("Supplement Arcolumns-A")), + (0x2800, 0x28ff, self.trUtf8("Braille Patterns")), + (0x2900, 0x297f, self.trUtf8("Supplement Arcolumns-B")), + (0x2980, 0x29ff, self.trUtf8("Miscelaneous Mathematical Symbols-B")), + (0x2a00, 0x2aff, self.trUtf8("Supplemental Mathematical Operators")), + (0x2b00, 0x2bff, self.trUtf8("Miscelaneous Symbols and Arcolumns")), + (0x2e80, 0x2eff, self.trUtf8("CJK Radicals Supplement")), + (0x2f00, 0x2fdf, self.trUtf8("KangXi Radicals")), + (0x2ff0, 0x2fff, self.trUtf8("Ideographic Description Chars")), + (0x3000, 0x303f, self.trUtf8("CJK Symbols and Punctuation")), + (0x3040, 0x309f, self.trUtf8("Hiragana")), + (0x30a0, 0x30ff, self.trUtf8("Katakana")), + (0x3100, 0x312f, self.trUtf8("Bopomofo")), + (0x3130, 0x318f, self.trUtf8("Hangul Compatibility Jamo")), + (0x3190, 0x319f, self.trUtf8("Kanbun")), + (0x31a0, 0x31bf, self.trUtf8("Bopomofo Extended")), + (0x31f0, 0x31ff, self.trUtf8("Katakana Phonetic Extensions")), + (0x3200, 0x32ff, self.trUtf8("Enclosed CJK Letters and Months")), + (0x3300, 0x33ff, self.trUtf8("CJK Compatibility")), + (0x3400, 0x4db5, self.trUtf8("CJK Unified Ideogr. Ext. A")), + (0x4dc0, 0x4dff, self.trUtf8("Yijing Hexagram Symbols")), + (0x4e00, 0x9fbb, self.trUtf8("CJK Unified Ideographs")), + (0xa000, 0xa48f, self.trUtf8("Yi Syllables")), + (0xa490, 0xa4cf, self.trUtf8("Yi Radicals")), + (0xac00, 0xd7a3, self.trUtf8("Hangul Syllables")), + (0xe000, 0xf8ff, self.trUtf8("Private Use Area")), + (0xf900, 0xfaff, self.trUtf8("CJK Compatibility Ideographs")), + (0xfb00, 0xfb4f, self.trUtf8("Alphabetic Presentation Forms")), + (0xfb50, 0xfdff, self.trUtf8("Arabic Presentation Forms-A")), + (0xfe00, 0xfe0f, self.trUtf8("Variation Selectors")), + (0xfe20, 0xfe2f, self.trUtf8("Combining Half Marks")), + (0xfe30, 0xfe4f, self.trUtf8("CJK Compatibility Forms")), + (0xfe50, 0xfe6f, self.trUtf8("Small Form Variants")), + (0xfe70, 0xfeff, self.trUtf8("Arabic Presentation Forms-B")), + (0xff00, 0xffef, self.trUtf8("Half- and Fullwidth Forms")), + (0xfff0, 0xffff, self.trUtf8("Specials")), + ) + self.__currentTableIndex = 0 - def setUnicode(self, u): + def getTableNames(self): """ - Public method to set the mode of the model. + Public method to get a list of table names. + + @return list of table names (list of strings) + """ + return [table[2] for table in self.__tables] + + def getTableBoundaries(self, index): + """ + Public method to get the first and last character position + of the given table. - @param u flag indicating unicode mode (boolean) + @param index index of the character table (integer) + @return first and last character position (integer, integer) """ - self.__unicode = u + return self.__tables[index][0], self.__tables[index][1] + + def selectTable(self, index): + """ + Public method to select the shown character table. + + @param index index of the character table (integer) + """ + self.__currentTableIndex = index self.reset() def headerData(self, section, orientation, role = Qt.DisplayRole): @@ -67,7 +194,7 @@ @param role role of the data to retrieve (integer) @return requested data """ - id = index.row() + id = self.__tables[self.__currentTableIndex][0] + index.row() if role == Qt.DisplayRole: col = index.column() @@ -80,6 +207,8 @@ elif col == 3: if id in html.entities.codepoint2name: return "&{0};".format(html.entities.codepoint2name[id]) + elif col == 4: + return unicodedata.name(chr(id), '').title() if role == Qt.BackgroundColorRole: if index.column() == 0: @@ -128,10 +257,8 @@ if parent.isValid(): return 0 else: - if self.__unicode: - return 65536 - else: - return 256 + first, last = self.__tables[self.__currentTableIndex][:2] + return last - first + 1 def __isDigit(self, char): """ @@ -197,15 +324,29 @@ self.__model = SymbolsModel(self) self.symbolsTable.setModel(self.__model) + self.symbolsTable.selectionModel().currentRowChanged.connect( + self.__currentRowChanged) + self.symbolsTable.horizontalHeader().setResizeMode(QHeaderView.Fixed) - fm = self.fontMetrics() em = fm.width("M") self.symbolsTable.horizontalHeader().resizeSection(0, em * 5) self.symbolsTable.horizontalHeader().resizeSection(1, em * 5) self.symbolsTable.horizontalHeader().resizeSection(2, em * 6) self.symbolsTable.horizontalHeader().resizeSection(3, em * 8) + self.symbolsTable.horizontalHeader().resizeSection(4, em * 85) self.symbolsTable.verticalHeader().setDefaultSectionSize(fm.height() + 4) + + tableIndex = int(Preferences.Prefs.settings.value("Symbols/CurrentTable", 1)) + self.tableCombo.addItems(self.__model.getTableNames()) + self.tableCombo.setCurrentIndex(tableIndex) + + index = self.__model.index( + int(Preferences.Prefs.settings.value("Symbols/Top", 0)), + 0) + self.symbolsTable.scrollTo(index, QAbstractItemView.PositionAtTop) + self.symbolsTable.selectionModel().select(index, + QItemSelectionModel.SelectCurrent | QItemSelectionModel.Rows) @pyqtSlot(QModelIndex) def on_symbolsTable_activated(self, index): @@ -218,17 +359,6 @@ if txt: self.insertSymbol.emit(txt) - @pyqtSlot(bool) - def on_unicodeButton_toggled(self, checked): - """ - Private slot to switch unicode mode. - - @param checked flag indicating that the button is pressed (boolean) - """ - self.symbolsTable.setUpdatesEnabled(False) - self.__model.setUnicode(checked) - self.symbolsTable.setUpdatesEnabled(True) - @pyqtSlot() def on_symbolSpinBox_editingFinished(self): """ @@ -238,3 +368,31 @@ self.symbolsTable.selectRow(id) self.symbolsTable.scrollTo( self.__model.index(id, 0), QAbstractItemView.PositionAtCenter) + + @pyqtSlot(int) + def on_tableCombo_currentIndexChanged(self, index): + """ + Private slot to select the current character table. + + @param index index of the character table (integer) + """ + self.symbolsTable.setUpdatesEnabled(False) + self.__model.selectTable(index) + self.symbolsTable.setUpdatesEnabled(True) + + first, last = self.__model.getTableBoundaries(index) + self.symbolSpinBox.setMinimum(first) + self.symbolSpinBox.setMaximum(last) + + Preferences.Prefs.settings.setValue("Symbols/CurrentTable", index) + + def __currentRowChanged(self, current, previous): + """ + Private slot recording the currently selected row. + + @param current current index (QModelIndex) + @param previous previous current index (QModelIndex) + """ + Preferences.Prefs.settings.setValue("Symbols/Top", current.row()) + self.symbolSpinBox.setValue(int( + self.__model.data(self.__model.index(current.row(), 0))))