UI/SymbolsWidget.py

changeset 945
8cd4d08fa9f6
parent 791
9ec2ac20e54e
child 1131
7781e396c903
equal deleted inserted replaced
944:1b59c4ba121e 945:8cd4d08fa9f6
16 16
17 from .Ui_SymbolsWidget import Ui_SymbolsWidget 17 from .Ui_SymbolsWidget import Ui_SymbolsWidget
18 18
19 import UI.PixmapCache 19 import UI.PixmapCache
20 import Preferences 20 import Preferences
21
21 22
22 class SymbolsModel(QAbstractTableModel): 23 class SymbolsModel(QAbstractTableModel):
23 """ 24 """
24 Class implementing the model for the symbols widget. 25 Class implementing the model for the symbols widget.
25 """ 26 """
26 def __init__(self, parent = None): 27 def __init__(self, parent=None):
27 """ 28 """
28 Constructor 29 Constructor
29 30
30 @param parent reference to the parent object (QObject) 31 @param parent reference to the parent object (QObject)
31 """ 32 """
32 QAbstractTableModel.__init__(self, parent) 33 QAbstractTableModel.__init__(self, parent)
33 34
34 self.__headerData = [ 35 self.__headerData = [
35 self.trUtf8("Code"), 36 self.trUtf8("Code"),
36 self.trUtf8("Char"), 37 self.trUtf8("Char"),
37 self.trUtf8("Hex"), 38 self.trUtf8("Hex"),
38 self.trUtf8("HTML"), 39 self.trUtf8("HTML"),
39 self.trUtf8("Name"), 40 self.trUtf8("Name"),
40 ] 41 ]
41 42
42 self.__tables = ( 43 self.__tables = (
43 # first last display name 44 # first last display name
44 (0x0, 0x1f, self.trUtf8("Control Characters")), 45 (0x0, 0x1f, self.trUtf8("Control Characters")),
179 @param index index of the character table (integer) 180 @param index index of the character table (integer)
180 """ 181 """
181 self.__currentTableIndex = index 182 self.__currentTableIndex = index
182 self.reset() 183 self.reset()
183 184
184 def headerData(self, section, orientation, role = Qt.DisplayRole): 185 def headerData(self, section, orientation, role=Qt.DisplayRole):
185 """ 186 """
186 Public method to get header data from the model. 187 Public method to get header data from the model.
187 188
188 @param section section number (integer) 189 @param section section number (integer)
189 @param orientation orientation (Qt.Orientation) 190 @param orientation orientation (Qt.Orientation)
193 if orientation == Qt.Horizontal and role == Qt.DisplayRole: 194 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
194 return self.__headerData[section] 195 return self.__headerData[section]
195 196
196 return QAbstractTableModel.headerData(self, section, orientation, role) 197 return QAbstractTableModel.headerData(self, section, orientation, role)
197 198
198 def data(self, index, role = Qt.DisplayRole): 199 def data(self, index, role=Qt.DisplayRole):
199 """ 200 """
200 Public method to get data from the model. 201 Public method to get data from the model.
201 202
202 @param index index to get data for (QModelIndex) 203 @param index index to get data for (QModelIndex)
203 @param role role of the data to retrieve (integer) 204 @param role role of the data to retrieve (integer)
312 @param char character to test (one character string) 313 @param char character to test (one character string)
313 @return flag indicating a punctuation character (boolean) 314 @return flag indicating a punctuation character (boolean)
314 """ 315 """
315 return unicodedata.category(char) in ["Pc", "Pd", "Ps", "Pe", "Pi", "Pf", "Po"] 316 return unicodedata.category(char) in ["Pc", "Pd", "Ps", "Pe", "Pi", "Pf", "Po"]
316 317
318
317 class SymbolsWidget(QWidget, Ui_SymbolsWidget): 319 class SymbolsWidget(QWidget, Ui_SymbolsWidget):
318 """ 320 """
319 Class implementing a widget to select a symbol in various formats. 321 Class implementing a widget to select a symbol in various formats.
320 322
321 @signal insertSymbol(str) emitted after the user has selected a symbol 323 @signal insertSymbol(str) emitted after the user has selected a symbol
322 """ 324 """
323 insertSymbol = pyqtSignal(str) 325 insertSymbol = pyqtSignal(str)
324 326
325 def __init__(self, parent = None): 327 def __init__(self, parent=None):
326 """ 328 """
327 Constructor 329 Constructor
328 330
329 @param parent reference to the parent widget (QWidget) 331 @param parent reference to the parent widget (QWidget)
330 """ 332 """
351 tableIndex = int(Preferences.Prefs.settings.value("Symbols/CurrentTable", 1)) 353 tableIndex = int(Preferences.Prefs.settings.value("Symbols/CurrentTable", 1))
352 self.tableCombo.addItems(self.__model.getTableNames()) 354 self.tableCombo.addItems(self.__model.getTableNames())
353 self.tableCombo.setCurrentIndex(tableIndex) 355 self.tableCombo.setCurrentIndex(tableIndex)
354 356
355 index = self.__model.index( 357 index = self.__model.index(
356 int(Preferences.Prefs.settings.value("Symbols/Top", 0)), 358 int(Preferences.Prefs.settings.value("Symbols/Top", 0)),
357 0) 359 0)
358 self.symbolsTable.scrollTo(index, QAbstractItemView.PositionAtTop) 360 self.symbolsTable.scrollTo(index, QAbstractItemView.PositionAtTop)
359 self.symbolsTable.selectionModel().setCurrentIndex(index, 361 self.symbolsTable.selectionModel().setCurrentIndex(index,
360 QItemSelectionModel.SelectCurrent | QItemSelectionModel.Rows) 362 QItemSelectionModel.SelectCurrent | QItemSelectionModel.Rows)
361 363
362 @pyqtSlot(QModelIndex) 364 @pyqtSlot(QModelIndex)
363 def on_symbolsTable_activated(self, index): 365 def on_symbolsTable_activated(self, index):
364 """ 366 """

eric ide

mercurial