~ubuntu-branches/ubuntu/karmic/eric/karmic

« back to all changes in this revision

Viewing changes to eric/ThirdParty/chartables/chartables_models_entities.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-01-28 18:02:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128180225-6nrox6yrworh2c4v
Tags: 4.0.4-1ubuntu1
* Add python-qt3 to build-depends becuase that's where Ubuntu puts 
  pyqtconfig
* Change maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
"""implementation of entity models. The module provides the following
 
4
public attribute:
 
5
 
 
6
ENTITY_MODEL_FACTORIES = list containing all entity model factories
 
7
"""
 
8
from PyQt4 import QtCore, QtGui
 
9
from chartables_model_factory import ModelFactoryBase, ModelBase, ModelColumn
 
10
from chartables_model_options import Options
 
11
 
 
12
ENTITY_MODEL_FACTORIES = []
 
13
#*******************************************************************
 
14
#
 
15
#*******************************************************************
 
16
class CT_HeaderEntities(QtCore.QObject):
 
17
    """Header for entity models"""
 
18
 
 
19
    def __init__(self, parent, cbName, cbChar, cbHex=None, cbInt=None):
 
20
        QtCore.QObject.__init__(self)
 
21
        
 
22
        self.columns = [
 
23
            ModelColumn(
 
24
                    title=self.trUtf8("Entity"),
 
25
                    doc=self.trUtf8("Displays the entity"),
 
26
                    flags=Options.CTF_NONE,
 
27
                    callback=cbName,
 
28
                    ),
 
29
            ModelColumn(
 
30
                    title=self.trUtf8("Char"),
 
31
                    doc=self.trUtf8("Dispays the char"),
 
32
                    flags=Options.CTF_NONE,
 
33
                    callback=cbChar,
 
34
                    ),
 
35
            ]
 
36
            
 
37
        if cbHex:
 
38
            self.columns.append(
 
39
                ModelColumn(
 
40
                        title=self.trUtf8("Hex"),
 
41
                        doc=self.trUtf8("Displays the hexadecimal entity"),
 
42
                        flags=Options.CTF_SHOWENTITYHEX,
 
43
                        callback=cbHex,
 
44
                        )
 
45
                    )
 
46
        if cbInt:
 
47
            self.columns.append(
 
48
                ModelColumn(
 
49
                            title=self.trUtf8("Hex"),
 
50
                            doc=self.trUtf8("Displays the hexadecimal entity"),
 
51
                            flags=Options.CTF_SHOWENTITYINT,
 
52
                            callback=cbInt,
 
53
                            )
 
54
                        )
 
55
 
 
56
    def __getitem__(self, i):
 
57
        return self.columns[i]
 
58
    
 
59
        def __len__(self):
 
60
            return len(self.columns)
 
61
 
 
62
#*******************************************************************
 
63
# Html entities
 
64
#*******************************************************************
 
65
 
 
66
class _HtmlControlChars(ModelBase):
 
67
    """Html controls entities model implementation"""
 
68
 
 
69
    def __init__(self, parent, options=None):
 
70
        """
 
71
        constructor
 
72
 
 
73
        @param parent parent of the model
 
74
        """
 
75
 
 
76
        entities = (
 
77
            (""", 0x0022),
 
78
            ("&", 0x0026),
 
79
            ("<", 0x003c),
 
80
            (">", 0x003e),
 
81
            )
 
82
        header = CT_HeaderEntities(parent, self._toName, self._toChar, 
 
83
                                            cbHex=self._toHex, cbInt=self._toInt)
 
84
        ModelBase.__init__(self,
 
85
                        parent,
 
86
                        header=header,
 
87
                        rows=entities,
 
88
                        options=options,
 
89
                        )
 
90
 
 
91
 
 
92
    def _toName(self, entity):
 
93
        """protected method to return the name of an entity"""
 
94
        return entity[0]
 
95
 
 
96
    def _toChar(self, entity):
 
97
        """protected method to return the char an entity represents"""
 
98
        return QtCore.QChar(entity[1])
 
99
 
 
100
    def _toHex(self, entity):
 
101
        """protected method to return the hexadecimal representation of an entity"""
 
102
        h = hex(entity[1])
 
103
        h = h.upper()
 
104
        return "&#x%s;" % h[2:]
 
105
 
 
106
    def _toInt(self, entity):
 
107
        """protected method to return the integer representation of an entity"""
 
108
        h = int(entity[1])
 
109
        return "&#%s;" % h
 
110
 
 
111
 
 
112
 
 
113
class _HtmlIso(_HtmlControlChars):
 
114
    """Html ISO 8859-1 entities model implementation"""
 
115
 
 
116
    
 
117
    def __init__(self, parent, options=None):
 
118
        """
 
119
        constructor
 
120
 
 
121
        @param parent parent of the model
 
122
        """
 
123
        self.encoding = QtCore.QTextCodec.codecForName("ISO 8859-1")
 
124
        entities = (
 
125
            (" ", 0x00a0),
 
126
            ("¡", 0x00a1),
 
127
            ("¢", 0x00a2),
 
128
            ("£", 0x00a3),
 
129
            ("¤", 0x00a4),
 
130
            ("¥", 0x00a5),
 
131
            ("¦", 0x00a6),
 
132
            ("§", 0x00a7),
 
133
            ("¨", 0x00a8),
 
134
            ("©", 0x00a9),
 
135
            ("ª", 0x00aa),
 
136
            ("«", 0x00ab),
 
137
            ("¬", 0x00ac),
 
138
            ("­", 0x00ad),
 
139
            ("®", 0x00ae),
 
140
            ("¯", 0x00af),
 
141
            ("°", 0x00b0),
 
142
            ("±", 0x00b1),
 
143
            ("²", 0x00b2),
 
144
            ("³", 0x00b3),
 
145
            ("´", 0x00b4),
 
146
            ("µ", 0x00b5),
 
147
            ("¶", 0x00b6),
 
148
            ("·", 0x00b7),
 
149
            ("¸", 0x00b8),
 
150
            ("¹", 0x00b9),
 
151
            ("º", 0x00ba),
 
152
            ("»", 0x00bb),
 
153
            ("¼", 0x00bc),
 
154
            ("½", 0x00bd),
 
155
            ("¾", 0x00be),
 
156
            ("¿", 0x00bf),
 
157
            ("À", 0x00c0),
 
158
            ("Á", 0x00c1),
 
159
            ("Â", 0x00c2),
 
160
            ("Ã", 0x00c3),
 
161
            ("Ä", 0x00c4),
 
162
            ("Å", 0x00c5),
 
163
            ("Æ", 0x00c6),
 
164
            ("Ç", 0x00c7),
 
165
            ("È", 0x00c8),
 
166
            ("É", 0x00c9),
 
167
            ("Ê", 0x00ca),
 
168
            ("Ë", 0x00cb),
 
169
            ("Ì", 0x00cc),
 
170
            ("Í", 0x00cd),
 
171
            ("Î", 0x00ce),
 
172
            ("Ï", 0x00cf),
 
173
            ("Ð", 0x00d0),
 
174
            ("Ñ", 0x00d1),
 
175
            ("Ò", 0x00d2),
 
176
            ("Ó", 0x00d3),
 
177
            ("Ô", 0x00d4),
 
178
            ("Õ", 0x00d5),
 
179
            ("Ö", 0x00d6),
 
180
            ("×", 0x00d7),
 
181
            ("Ø", 0x00d8),
 
182
            ("Ù", 0x00d9),
 
183
            ("Ú", 0x00da),
 
184
            ("Û", 0x00db),
 
185
            ("Ü", 0x00dc),
 
186
            ("Ý", 0x00dd),
 
187
            ("Þ", 0x00de),
 
188
            ("ß", 0x00df),
 
189
            ("à", 0x00e0),
 
190
            ("á", 0x00e1),
 
191
            ("â", 0x00e2),
 
192
            ("ã", 0x00e3),
 
193
            ("ä", 0x00e4),
 
194
            ("å", 0x00e5),
 
195
            ("æ", 0x00e6),
 
196
            ("ç", 0x00e7),
 
197
            ("è", 0x00e8),
 
198
            ("é", 0x00e9),
 
199
            ("ê", 0x00ea),
 
200
            ("ë", 0x00eb),
 
201
            ("ì", 0x00ec),
 
202
            ("í", 0x00ed),
 
203
            ("î", 0x00ee),
 
204
            ("ï", 0x00ef),
 
205
            ("ð", 0x00f0),
 
206
            ("ñ", 0x00f1),
 
207
            ("ò", 0x00f2),
 
208
            ("ó", 0x00f3),
 
209
            ("ô", 0x00f4),
 
210
            ("õ", 0x00f5),
 
211
            ("ö", 0x00f6),
 
212
            ("÷", 0x00f7),
 
213
            ("ø", 0x00f8),
 
214
            ("ù", 0x00f9),
 
215
            ("ú", 0x00fa),
 
216
            ("û", 0x00fb),
 
217
            ("ü", 0x00fc),
 
218
            ("ý", 0x00fd),
 
219
            ("þ", 0x00fe),
 
220
            ("ÿ", 0x00ff),
 
221
            )
 
222
        header = CT_HeaderEntities(parent, self._toName, self._toChar, 
 
223
                                            cbHex=self._toHex, cbInt=self._toInt)
 
224
        ModelBase.__init__(self,
 
225
                        parent,
 
226
                        header=header,
 
227
                        rows=entities,
 
228
                        options=options,
 
229
                        )
 
230
 
 
231
 
 
232
class _HtmlLatinExtended(_HtmlControlChars):
 
233
    """Html latin extended entities model implementation"""
 
234
 
 
235
         
 
236
    def __init__(self, parent, options=None):
 
237
        """
 
238
        constructor
 
239
 
 
240
        @param parent parent of the model
 
241
        """
 
242
        entities = (
 
243
            ("Œ", 0x0152),
 
244
            ("œ", 0x0153),
 
245
            ("Š", 0x0160),
 
246
            ("š", 0x0161),
 
247
            ("Ÿ", 0x0178),
 
248
            ("ƒ", 0x0192),
 
249
            )
 
250
        header = CT_HeaderEntities(parent, self._toName, self._toChar, 
 
251
                                            cbHex=self._toHex, cbInt=self._toInt)
 
252
        ModelBase.__init__(self,
 
253
                        parent,
 
254
                        header=header,
 
255
                        rows=entities,
 
256
                        options=options,
 
257
                        )
 
258
 
 
259
 
 
260
 
 
261
class _HtmlGreek(_HtmlControlChars):
 
262
    """Html greek entities model implementation"""
 
263
 
 
264
  
 
265
    def __init__(self, parent, options=None):
 
266
        """
 
267
        constructor
 
268
 
 
269
        @param parent parent of the model
 
270
        """
 
271
        entities = (
 
272
            ("Α", 0x0391),
 
273
            ("Β", 0x0392),
 
274
            ("Γ", 0x0393),
 
275
            ("Δ", 0x0394),
 
276
            ("Ε", 0x0395),
 
277
            ("Ζ", 0x0396),
 
278
            ("Η", 0x0397),
 
279
            ("Θ", 0x0398),
 
280
            ("Ι", 0x0399),
 
281
            ("Κ", 0x039a),
 
282
            ("Λ", 0x039b),
 
283
            ("Μ", 0x039c),
 
284
            ("Ν", 0x039d),
 
285
            ("Ξ", 0x039e),
 
286
            ("Ο", 0x039f),
 
287
            ("Π", 0x03a0),
 
288
            ("Ρ", 0x03a1),
 
289
            ("Σ", 0x03a3),
 
290
            ("Τ", 0x03a4),
 
291
            ("Υ", 0x03a5),
 
292
            ("Φ", 0x03a6),
 
293
            ("Χ", 0x03a7),
 
294
            ("Ψ", 0x03a8),
 
295
            ("Ω", 0x03a9),
 
296
            ("α", 0x03b1),
 
297
            ("β", 0x03b2),
 
298
            ("γ", 0x03b3),
 
299
            ("δ", 0x03b4),
 
300
            ("ε", 0x03b5),
 
301
            ("ζ", 0x03b6),
 
302
            ("η", 0x03b7),
 
303
            ("θ", 0x03b8),
 
304
            ("ι", 0x03b9),
 
305
            ("κ", 0x03ba),
 
306
            ("λ", 0x03bb),
 
307
            ("μ", 0x03bc),
 
308
            ("ν", 0x03bd),
 
309
            ("ξ", 0x03be),
 
310
            ("ο", 0x03bf),
 
311
            ("π", 0x03c0),
 
312
            ("ρ", 0x03c1),
 
313
            ("ς", 0x03c2),
 
314
            ("σ", 0x03c3),
 
315
            ("τ", 0x03c4),
 
316
            ("υ", 0x03c5),
 
317
            ("φ", 0x03c6),
 
318
            ("χ", 0x03c7),
 
319
            ("ψ", 0x03c8),
 
320
            ("ω", 0x03c9),
 
321
            ("ϑ", 0x03d1),
 
322
            ("ϒ", 0x03d2),
 
323
            ("ϖ", 0x03d6),
 
324
            )
 
325
        header = CT_HeaderEntities(parent, self._toName, self._toChar, 
 
326
                                            cbHex=self._toHex, cbInt=self._toInt)
 
327
        ModelBase.__init__(self,
 
328
                        parent,
 
329
                        header=header,
 
330
                        rows=entities,
 
331
                        options=options,
 
332
                        )
 
333
 
 
334
class _HtmlPunktuation(_HtmlControlChars):
 
335
    """Html general punktuation entities model implementation"""
 
336
 
 
337
      
 
338
    def __init__(self, parent, options=None):
 
339
        """
 
340
        constructor
 
341
 
 
342
        @param parent parent of the model
 
343
        """
 
344
        entities = (
 
345
            ("•", 0x2022),
 
346
            ("…", 0x2026),
 
347
            ("′", 0x2032),
 
348
            ("″", 0x2033),
 
349
            ("‾", 0x203e),
 
350
            ("⁄", 0x2044),
 
351
            ("℘", 0x2118),
 
352
            ("ℑ", 0x2111),
 
353
            ("ℜ", 0x211c),
 
354
            ("™", 0x2122),
 
355
            ("ℵ", 0x2135),
 
356
            ("←", 0x2190),
 
357
            ("↑", 0x2191),
 
358
            ("→", 0x2192),
 
359
            ("↓", 0x2193),
 
360
            ("↔", 0x2194),
 
361
            ("↵", 0x21b5),
 
362
            ("⇐", 0x21d0),
 
363
            ("⇑", 0x21d1),
 
364
            ("⇒", 0x21d2),
 
365
            ("⇓", 0x21d3),
 
366
            ("⇔", 0x21d4),
 
367
            )
 
368
        header = CT_HeaderEntities(parent, self._toName, self._toChar, 
 
369
                                            cbHex=self._toHex, cbInt=self._toInt)
 
370
        ModelBase.__init__(self,
 
371
                        parent,
 
372
                        header=header,
 
373
                        rows=entities,
 
374
                        options=options,
 
375
                        )
 
376
 
 
377
 
 
378
class _HtmlSymbols(_HtmlControlChars):
 
379
    """Html symbols entities model implementation"""
 
380
 
 
381
       
 
382
    def __init__(self, parent, options=None):
 
383
        """
 
384
        constructor
 
385
 
 
386
        @param parent parent of the model
 
387
        """
 
388
        entities = (
 
389
            ("∀", 0x2200),
 
390
            ("∂", 0x2202),
 
391
            ("∃", 0x2203),
 
392
            ("∅", 0x2205),
 
393
            ("∇", 0x2207),
 
394
            ("∈", 0x2208),
 
395
            ("∉", 0x2209),
 
396
            ("∋", 0x220b),
 
397
            ("∏", 0x220f),
 
398
            ("∑", 0x2211),
 
399
            ("−", 0x2212),
 
400
            ("∗", 0x2217),
 
401
            ("√", 0x221a),
 
402
            ("∝", 0x221d),
 
403
            ("∞", 0x221e),
 
404
            ("∠", 0x2220),
 
405
            ("∧", 0x2227),
 
406
            ("∨", 0x2228),
 
407
            ("∩", 0x2229),
 
408
            ("∪", 0x222a),
 
409
            ("∫", 0x222b),
 
410
            ("∴", 0x2234),
 
411
            ("∼", 0x223c),
 
412
            ("≅", 0x2245),
 
413
            ("≈", 0x2248),
 
414
            ("≠", 0x2260),
 
415
            ("≡", 0x2261),
 
416
            ("≤", 0x2264),
 
417
            ("≥", 0x2265),
 
418
            ("⊂", 0x2282),
 
419
            ("⊃", 0x2283),
 
420
            ("⊄", 0x2284),
 
421
            ("⊆", 0x2286),
 
422
            ("⊇", 0x2287),
 
423
            ("⊕", 0x2295),
 
424
            ("⊗", 0x2297),
 
425
            ("⊥", 0x22a5),
 
426
            ("⋅", 0x22c5),
 
427
            ("⌈", 0x2308),
 
428
            ("⌉", 0x2309),
 
429
            ("⌊", 0x230a),
 
430
            ("⌋", 0x230b),
 
431
            ("⟨", 0x2329),
 
432
            ("⟩", 0x232a),
 
433
            ("◊", 0x25ca),
 
434
            ("♠", 0x2660),
 
435
            ("♣", 0x2663),
 
436
            ("♥", 0x2665),
 
437
            ("♦", 0x2666),
 
438
            )
 
439
        header = CT_HeaderEntities(parent, self._toName, self._toChar, 
 
440
                                            cbHex=self._toHex, cbInt=self._toInt)
 
441
        ModelBase.__init__(self,
 
442
                        parent,
 
443
                        header=header,
 
444
                        rows=entities,
 
445
                        options=options,
 
446
                        )
 
447
 
 
448
 
 
449
class _HtmlInternational(_HtmlControlChars):
 
450
    """Html international entities model implementation"""
 
451
 
 
452
    
 
453
 
 
454
    def __init__(self, parent, options=None):
 
455
        """
 
456
        constructor
 
457
 
 
458
        @param parent parent of the model
 
459
        """
 
460
        entities = (
 
461
            ("ˆ", 0x02c6),
 
462
            ("˜", 0x02dc),
 
463
            (" ", 0x2002),
 
464
            (" ", 0x2003),
 
465
            (" ", 0x2009),
 
466
            ("‌", 0x200c),
 
467
            ("‍", 0x200d),
 
468
            ("‎", 0x200e),
 
469
            ("‏", 0x200f),
 
470
            ("–", 0x2013),
 
471
            ("—", 0x2014),
 
472
            ("‘", 0x2018),
 
473
            ("’", 0x2019),
 
474
            ("‚", 0x201a),
 
475
            ("“", 0x201c),
 
476
            ("”", 0x201d),
 
477
            ("„", 0x201e),
 
478
            ("†", 0x2020),
 
479
            ("‡", 0x2021),
 
480
            ("‰", 0x2030),
 
481
            ("‹", 0x2039),
 
482
            ("›", 0x203a),
 
483
            ("€", 0x20ac),
 
484
            )
 
485
        header = CT_HeaderEntities(parent, self._toName, self._toChar, 
 
486
                                            cbHex=self._toHex, cbInt=self._toInt)
 
487
        ModelBase.__init__(self,
 
488
                        parent,
 
489
                        header=header,
 
490
                        rows=entities,
 
491
                        options=options,
 
492
                        )
 
493
 
 
494
 
 
495
 
 
496
class CT_EntityFactoryHTML(ModelFactoryBase):
 
497
    """Html entities model factory"""
 
498
    
 
499
    def trUtf8(self, what): return what
 
500
            
 
501
    def __init__(self, parent, options=None):
 
502
        ModelFactoryBase.__init__(self, parent, options=options)
 
503
        
 
504
        self._name = self.trUtf8("Html")
 
505
        self._models = (
 
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")),
 
513
            )
 
514
        
 
515
 
 
516
    def __len__(self):
 
517
        return len(self._models)
 
518
 
 
519
    def __getitem__(self, i):
 
520
        return self._models[i][0]
 
521
    
 
522
    def name(self):
 
523
        return self._name
 
524
 
 
525
    def displayName(self):
 
526
        return QtCore.QObject.trUtf8(self, self._name)
 
527
        
 
528
    def modelName(self, i):
 
529
        return self._models[i][1]
 
530
 
 
531
    def modelDisplayName(self, i):
 
532
        return QtCore.QObject.trUtf8(self, self._models[i][1])
 
533
 
 
534
 
 
535
ENTITY_MODEL_FACTORIES.append(CT_EntityFactoryHTML)
 
536
 
 
537
#**********************************************************************
 
538
#
 
539
#**********************************************************************
 
540
def _xmlEntityColumns(clss):
 
541
    """Header for Xml entity models"""
 
542
    return [
 
543
            ModelColumn(
 
544
                    title=SZ.COLENTITY,
 
545
                    flags=Options.CTF_NONE,
 
546
                    callback=clss._toName,
 
547
                    doc=SZ.DOC_COLENTITY
 
548
                    ),
 
549
            ModelColumn(
 
550
                    title=SZ.COLCHAR,
 
551
                    flags=Options.CTF_NONE,
 
552
                    callback=clss._toChar,
 
553
                    doc=SZ.DOC_COLCHAR
 
554
                    ),
 
555
            ]
 
556
 
 
557
 
 
558
class _XMLEntities(_HtmlControlChars):
 
559
    """Xml entities model implementation"""
 
560
 
 
561
    def __init__(self, parent, options=None):
 
562
        """
 
563
        constructor
 
564
 
 
565
        @param parent parent of the model
 
566
        """
 
567
        entities = (       # name, ord, encoding
 
568
            (""", 0x0022),
 
569
            ("&", 0x0026),
 
570
            ("'", 0x0027),
 
571
            ("<", 0x003c),
 
572
            (">", 0x0003e),
 
573
            )
 
574
        header = CT_HeaderEntities(parent, self._toName, self._toChar, 
 
575
                                            cbHex=None, cbInt=None)
 
576
        ModelBase.__init__(self,
 
577
                        parent,
 
578
                        header=header,
 
579
                        rows=entities,
 
580
                        options=options,
 
581
                        )
 
582
 
 
583
 
 
584
 
 
585
class CT_EntityFactoryXML(ModelFactoryBase):
 
586
    """Xml entities model factory"""
 
587
    
 
588
    def trUtf8(self, what): return what
 
589
            
 
590
    def __init__(self, parent, options=None):
 
591
        ModelFactoryBase.__init__(self, parent, options=options)
 
592
        
 
593
        self._name = self.trUtf8("Xml")
 
594
        self._models = (
 
595
            (_XMLEntities, self.trUtf8("Xml")),
 
596
            )
 
597
 
 
598
    def __len__(self):
 
599
        return len(self._models)
 
600
 
 
601
    def __getitem__(self, i):
 
602
        return self._models[i][0]
 
603
    
 
604
    def name(self):
 
605
        return self._name
 
606
 
 
607
    def displayName(self):
 
608
        return QtCore.QObject.trUtf8(self, self._name)
 
609
        
 
610
    def modelName(self, i):
 
611
        return self._models[i][1]
 
612
 
 
613
    def modelDisplayName(self, i):
 
614
        return QtCore.QObject.trUtf8(self, self._models[i][1])
 
615
 
 
616
 
 
617
ENTITY_MODEL_FACTORIES.append(CT_EntityFactoryXML)
 
618