1
# -*- coding: utf-8 -*-
3
"""implementation of entity models. The module provides the following
6
ENTITY_MODEL_FACTORIES = list containing all entity model factories
8
from PyQt4 import QtCore, QtGui
9
from chartables_model_factory import ModelFactoryBase, ModelBase, ModelColumn
10
from chartables_model_options import Options
12
ENTITY_MODEL_FACTORIES = []
13
#*******************************************************************
15
#*******************************************************************
16
class CT_HeaderEntities(QtCore.QObject):
17
"""Header for entity models"""
19
def __init__(self, parent, cbName, cbChar, cbHex=None, cbInt=None):
20
QtCore.QObject.__init__(self)
24
title=self.trUtf8("Entity"),
25
doc=self.trUtf8("Displays the entity"),
26
flags=Options.CTF_NONE,
30
title=self.trUtf8("Char"),
31
doc=self.trUtf8("Dispays the char"),
32
flags=Options.CTF_NONE,
40
title=self.trUtf8("Hex"),
41
doc=self.trUtf8("Displays the hexadecimal entity"),
42
flags=Options.CTF_SHOWENTITYHEX,
49
title=self.trUtf8("Hex"),
50
doc=self.trUtf8("Displays the hexadecimal entity"),
51
flags=Options.CTF_SHOWENTITYINT,
56
def __getitem__(self, i):
57
return self.columns[i]
60
return len(self.columns)
62
#*******************************************************************
64
#*******************************************************************
66
class _HtmlControlChars(ModelBase):
67
"""Html controls entities model implementation"""
69
def __init__(self, parent, options=None):
73
@param parent parent of the model
82
header = CT_HeaderEntities(parent, self._toName, self._toChar,
83
cbHex=self._toHex, cbInt=self._toInt)
84
ModelBase.__init__(self,
92
def _toName(self, entity):
93
"""protected method to return the name of an entity"""
96
def _toChar(self, entity):
97
"""protected method to return the char an entity represents"""
98
return QtCore.QChar(entity[1])
100
def _toHex(self, entity):
101
"""protected method to return the hexadecimal representation of an entity"""
104
return "&#x%s;" % h[2:]
106
def _toInt(self, entity):
107
"""protected method to return the integer representation of an entity"""
113
class _HtmlIso(_HtmlControlChars):
114
"""Html ISO 8859-1 entities model implementation"""
117
def __init__(self, parent, options=None):
121
@param parent parent of the model
123
self.encoding = QtCore.QTextCodec.codecForName("ISO 8859-1")
129
("¤", 0x00a4),
131
("¦", 0x00a6),
142
("±", 0x00b1),
148
("·", 0x00b7),
153
("¼", 0x00bc),
154
("½", 0x00bd),
155
("¾", 0x00be),
156
("¿", 0x00bf),
157
("À", 0x00c0),
158
("Á", 0x00c1),
160
("Ã", 0x00c3),
164
("Ç", 0x00c7),
165
("È", 0x00c8),
166
("É", 0x00c9),
169
("Ì", 0x00cc),
170
("Í", 0x00cd),
174
("Ñ", 0x00d1),
175
("Ò", 0x00d2),
176
("Ó", 0x00d3),
178
("Õ", 0x00d5),
181
("Ø", 0x00d8),
182
("Ù", 0x00d9),
183
("Ú", 0x00da),
186
("Ý", 0x00dd),
189
("à", 0x00e0),
190
("á", 0x00e1),
192
("ã", 0x00e3),
196
("ç", 0x00e7),
197
("è", 0x00e8),
198
("é", 0x00e9),
201
("ì", 0x00ec),
202
("í", 0x00ed),
206
("ñ", 0x00f1),
207
("ò", 0x00f2),
208
("ó", 0x00f3),
210
("õ", 0x00f5),
212
("÷", 0x00f7),
213
("ø", 0x00f8),
214
("ù", 0x00f9),
215
("ú", 0x00fa),
218
("ý", 0x00fd),
222
header = CT_HeaderEntities(parent, self._toName, self._toChar,
223
cbHex=self._toHex, cbInt=self._toInt)
224
ModelBase.__init__(self,
232
class _HtmlLatinExtended(_HtmlControlChars):
233
"""Html latin extended entities model implementation"""
236
def __init__(self, parent, options=None):
240
@param parent parent of the model
245
("Š", 0x0160),
246
("š", 0x0161),
250
header = CT_HeaderEntities(parent, self._toName, self._toChar,
251
cbHex=self._toHex, cbInt=self._toInt)
252
ModelBase.__init__(self,
261
class _HtmlGreek(_HtmlControlChars):
262
"""Html greek entities model implementation"""
265
def __init__(self, parent, options=None):
269
@param parent parent of the model
276
("Ε", 0x0395),
282
("Λ", 0x039b),
286
("Ο", 0x039f),
291
("Υ", 0x03a5),
300
("ε", 0x03b5),
306
("λ", 0x03bb),
310
("ο", 0x03bf),
313
("ς", 0x03c2),
316
("υ", 0x03c5),
321
("ϑ", 0x03d1),
325
header = CT_HeaderEntities(parent, self._toName, self._toChar,
326
cbHex=self._toHex, cbInt=self._toInt)
327
ModelBase.__init__(self,
334
class _HtmlPunktuation(_HtmlControlChars):
335
"""Html general punktuation entities model implementation"""
338
def __init__(self, parent, options=None):
342
@param parent parent of the model
346
("…", 0x2026),
351
("℘", 0x2118),
355
("ℵ", 0x2135),
368
header = CT_HeaderEntities(parent, self._toName, self._toChar,
369
cbHex=self._toHex, cbInt=self._toInt)
370
ModelBase.__init__(self,
378
class _HtmlSymbols(_HtmlControlChars):
379
"""Html symbols entities model implementation"""
382
def __init__(self, parent, options=None):
386
@param parent parent of the model
389
("∀", 0x2200),
400
("∗", 0x2217),
410
("∴", 0x2234),
424
("⊗", 0x2297),
429
("⌊", 0x230a),
430
("⌋", 0x230b),
434
("♠", 0x2660),
436
("♥", 0x2665),
439
header = CT_HeaderEntities(parent, self._toName, self._toChar,
440
cbHex=self._toHex, cbInt=self._toInt)
441
ModelBase.__init__(self,
449
class _HtmlInternational(_HtmlControlChars):
450
"""Html international entities model implementation"""
454
def __init__(self, parent, options=None):
458
@param parent parent of the model
465
(" ", 0x2009),
478
("†", 0x2020),
479
("‡", 0x2021),
480
("‰", 0x2030),
481
("‹", 0x2039),
482
("›", 0x203a),
485
header = CT_HeaderEntities(parent, self._toName, self._toChar,
486
cbHex=self._toHex, cbInt=self._toInt)
487
ModelBase.__init__(self,
496
class CT_EntityFactoryHTML(ModelFactoryBase):
497
"""Html entities model factory"""
499
def trUtf8(self, what): return what
501
def __init__(self, parent, options=None):
502
ModelFactoryBase.__init__(self, parent, options=options)
504
self._name = self.trUtf8("Html")
506
(_HtmlControlChars, self.trUtf8("Controls")),
507
(_HtmlIso, self.trUtf8("ISO 8859-1")),
508
(_HtmlLatinExtended, self.trUtf8("Latin Extended")),
509
(_HtmlGreek, self.trUtf8("Greek")),
510
(_HtmlPunktuation, self.trUtf8("Punktuation and arrows")),
511
(_HtmlSymbols, self.trUtf8("Symbols")),
512
(_HtmlInternational, self.trUtf8("International")),
517
return len(self._models)
519
def __getitem__(self, i):
520
return self._models[i][0]
525
def displayName(self):
526
return QtCore.QObject.trUtf8(self, self._name)
528
def modelName(self, i):
529
return self._models[i][1]
531
def modelDisplayName(self, i):
532
return QtCore.QObject.trUtf8(self, self._models[i][1])
535
ENTITY_MODEL_FACTORIES.append(CT_EntityFactoryHTML)
537
#**********************************************************************
539
#**********************************************************************
540
def _xmlEntityColumns(clss):
541
"""Header for Xml entity models"""
545
flags=Options.CTF_NONE,
546
callback=clss._toName,
551
flags=Options.CTF_NONE,
552
callback=clss._toChar,
558
class _XMLEntities(_HtmlControlChars):
559
"""Xml entities model implementation"""
561
def __init__(self, parent, options=None):
565
@param parent parent of the model
567
entities = ( # name, ord, encoding
574
header = CT_HeaderEntities(parent, self._toName, self._toChar,
575
cbHex=None, cbInt=None)
576
ModelBase.__init__(self,
585
class CT_EntityFactoryXML(ModelFactoryBase):
586
"""Xml entities model factory"""
588
def trUtf8(self, what): return what
590
def __init__(self, parent, options=None):
591
ModelFactoryBase.__init__(self, parent, options=options)
593
self._name = self.trUtf8("Xml")
595
(_XMLEntities, self.trUtf8("Xml")),
599
return len(self._models)
601
def __getitem__(self, i):
602
return self._models[i][0]
607
def displayName(self):
608
return QtCore.QObject.trUtf8(self, self._name)
610
def modelName(self, i):
611
return self._models[i][1]
613
def modelDisplayName(self, i):
614
return QtCore.QObject.trUtf8(self, self._models[i][1])
617
ENTITY_MODEL_FACTORIES.append(CT_EntityFactoryXML)