forked from Freely-Given-org/BibleOrgSys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BibleStylesheets.py
executable file
·577 lines (498 loc) · 31.8 KB
/
BibleStylesheets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# BibleStylesheets.py
#
# Module handling Bible (including Paratext) stylesheets
#
# Copyright (C) 2013-2018 Robert Hunt
# Author: Robert Hunt <Freely.Given.org@gmail.com>
# License: See gpl-3.0.txt
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
"""
from gettext import gettext as _
LastModifiedDate = '2018-12-02' # by RJH
ShortProgName = "BibleStylesheets"
ProgName = "Bible stylesheet handler"
ProgVersion = '0.16'
ProgNameVersion = '{} v{}'.format( ShortProgName, ProgVersion )
ProgNameVersionDate = '{} {} {}'.format( ProgNameVersion, _("last modified"), LastModifiedDate )
debuggingThisModule = False
#from singleton import singleton
import os, logging
import BibleOrgSysGlobals
import SFMFile
def exp( messageString ):
"""
Expands the message string in debug mode.
Prepends the module name to a error or warning message string
if we are in debug mode.
Returns the new string.
"""
try: nameBit, errorBit = messageString.split( ': ', 1 )
except ValueError: nameBit, errorBit = '', messageString
if BibleOrgSysGlobals.debugFlag or debuggingThisModule:
nameBit = '{}{}{}'.format( ShortProgName, '.' if nameBit else '', nameBit )
return '{}{}'.format( nameBit+': ' if nameBit else '', errorBit )
# end of exp
#self.textBox.tag_configure( 'verseNumberFormat', foreground='blue', font='helvetica 8', relief='raised', offset='3' )
#self.textBox.tag_configure( 'versePreSpaceFormat', background='pink', font='helvetica 8' )
#self.textBox.tag_configure( 'versePostSpaceFormat', background='pink', font='helvetica 4' )
#self.textBox.tag_configure( 'verseTextFormat', font='sil-doulos 12' )
#self.textBox.tag_configure( 'otherVerseTextFormat', font='sil-doulos 9' )
#self.textBox.tag_configure( 'heading1Format', foreground='red', font='sil-doulos 10' )
#self.textBox.tag_configure( 'verseText', background='yellow', font='helvetica 14 bold', relief='raised' )
#"background", "bgstipple", "borderwidth", "elide", "fgstipple", "font", "foreground", "justify", "lmargin1",
#"lmargin2", "offset", "overstrike", "relief", "rmargin", "spacing1", "spacing2", "spacing3",
#"tabs", "tabstyle", "underline", and "wrap".
INDENT_SIZE = 12
DEFAULT_FONTNAME = 'helvetica'
DEFAULT_HEBREW_FONTNAME = 'Ezra' # 'Ezra SIL' seems to fail later when used in a text box
VERSENUMBER_FONTSIZE = 6
CURRENT_VERSE_FONTSIZE = 12
CHAPTERNUMBER_FONTSIZE = 13
DEFAULT_FONTSIZE = 9
HEADING_FONTSIZE = 11
SUBHEADING_FONTSIZE = HEADING_FONTSIZE - 1
TITLE_FONTSIZE = HEADING_FONTSIZE + 2
VERSENUMBER_COLOUR = 'blue'
CHAPTERNUMBER_COLOUR = 'orange'
HEADING_COLOUR = 'red'
SUBHEADING_COLOUR = 'sienna1'
SECTION_REFERENCE_COLOUR = 'green'
EXTRA_COLOUR = 'royalBlue1'
SUPERSCRIPT_OFFSET = '4'
# NOTE: Should we add fields from "leadingText", "trailingText" ???
# These are the styles for formatted mode
# Asterisk in front of a tag name indicates the currently selected verse
# Hash sign after a tag name indicates "unformatted" mode
DEFAULT_STYLE_DICT = { # earliest entries have the highest priority
# The following fields from InternalBible all contain their own (self-contained) text (in _processedLines)
# File beginning
'id': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'firebrick1', },
'ide': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'tan1', },
'h': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'foreground':'green4', },
'rem': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'foreground':'lightBlue', },
'toc1': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'ivory2', },
'toc2': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'ivory3', },
'toc3': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'ivory4', },
# Our added fields
'intro': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'lightYellow', },
'chapters': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'lightYellow', },
# Headings
'mt1': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, TITLE_FONTSIZE ), 'foreground':'gold', 'justify':'center', },
'mt2': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, TITLE_FONTSIZE ), 'foreground':'gold2', 'justify':'center', },
'mt3': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, TITLE_FONTSIZE ), 'foreground':'gold3', 'justify':'center', },
'mt4': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, TITLE_FONTSIZE ), 'foreground':'gold4', 'justify':'center', },
's1': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, 'justify':'center', },
's2': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, 'justify':'center', },
's3': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, 'justify':'center', },
's4': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, 'justify':'center', },
'ms1': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, 'justify':'center', },
'ms2': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, 'justify':'center', },
'ms3': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, 'justify':'center', },
'ms4': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, 'justify':'center', },
'cl': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, 'justify':'center', },
# Other
'd': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, SUBHEADING_FONTSIZE ), 'foreground':SUBHEADING_COLOUR, },
'sp': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, SUBHEADING_FONTSIZE ), 'foreground':EXTRA_COLOUR, },
'c': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, CHAPTERNUMBER_FONTSIZE ), 'foreground':CHAPTERNUMBER_COLOUR, },
'r': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':SECTION_REFERENCE_COLOUR, 'justify':'center', },
'mr': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':SECTION_REFERENCE_COLOUR, 'justify':'center', },
'sr': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':SECTION_REFERENCE_COLOUR, 'justify':'center', },
'c#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, CHAPTERNUMBER_FONTSIZE ), 'foreground':CHAPTERNUMBER_COLOUR, },
'c~': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, CHAPTERNUMBER_FONTSIZE ), 'foreground':CHAPTERNUMBER_COLOUR, },
'v': { 'font':'{} {}'.format( DEFAULT_FONTNAME, VERSENUMBER_FONTSIZE ), 'foreground':VERSENUMBER_COLOUR, 'offset':SUPERSCRIPT_OFFSET, },
# Introduction
'iq1': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':1*INDENT_SIZE, 'lmargin2':1*INDENT_SIZE, },
'iq2': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':2*INDENT_SIZE, 'lmargin2':2*INDENT_SIZE, },
'iq3': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':3*INDENT_SIZE, 'lmargin2':3*INDENT_SIZE, },
'iq4': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':4*INDENT_SIZE, 'lmargin2':4*INDENT_SIZE, },
'*iq1': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':1*INDENT_SIZE, 'lmargin2':1*INDENT_SIZE, },
'*iq2': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':2*INDENT_SIZE, 'lmargin2':2*INDENT_SIZE, },
'*iq3': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':3*INDENT_SIZE, 'lmargin2':3*INDENT_SIZE, },
'*iq4': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':4*INDENT_SIZE, 'lmargin2':4*INDENT_SIZE, },
# The next two should theoretically never be used in formatted Bibles
# (because v~ fields should take on the previous paragraph tag)
'v~': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), },
'*v~': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'lightYellow', },
# The following paragraph level fields can contain text, or can influence the next v~/p~ text
# These are for formatted view
'p': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':1*INDENT_SIZE, 'lmargin2':0*INDENT_SIZE, },
'*p': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':1*INDENT_SIZE, 'lmargin2':0*INDENT_SIZE, },
'q1': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':1*INDENT_SIZE, 'lmargin2':1*INDENT_SIZE, },
'q2': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':2*INDENT_SIZE, 'lmargin2':2*INDENT_SIZE, },
'q3': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':3*INDENT_SIZE, 'lmargin2':3*INDENT_SIZE, },
'q4': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':4*INDENT_SIZE, 'lmargin2':4*INDENT_SIZE, },
'*q1': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':1*INDENT_SIZE, 'lmargin2':1*INDENT_SIZE, 'background':'yellow', },
'*q2': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':2*INDENT_SIZE, 'lmargin2':2*INDENT_SIZE, },
'*q3': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':3*INDENT_SIZE, 'lmargin2':3*INDENT_SIZE, },
'*q4': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':4*INDENT_SIZE, 'lmargin2':4*INDENT_SIZE, },
'm': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':0*INDENT_SIZE, 'lmargin2':0*INDENT_SIZE, },
'*m': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':0*INDENT_SIZE, 'lmargin2':0*INDENT_SIZE, },
'mi': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'pink', 'lmargin1':1*INDENT_SIZE, 'lmargin2':1*INDENT_SIZE, },
'*mi': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'pink', 'lmargin1':1*INDENT_SIZE, 'lmargin2':1*INDENT_SIZE, },
'pi1': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'pink', 'lmargin1':2*INDENT_SIZE, 'lmargin2':1*INDENT_SIZE, },
'pi2': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'purple', 'lmargin1':3*INDENT_SIZE, 'lmargin2':3*INDENT_SIZE, },
'pi3': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'green', 'lmargin1':4*INDENT_SIZE, 'lmargin2':3*INDENT_SIZE, },
'pi4': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'brown', 'lmargin1':5*INDENT_SIZE, 'lmargin2':4*INDENT_SIZE, },
'*pi1': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'pink', 'lmargin1':2*INDENT_SIZE, 'lmargin2':1*INDENT_SIZE, },
'*pi2': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'purple', 'lmargin1':3*INDENT_SIZE, 'lmargin2':2*INDENT_SIZE, },
'*pi3': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'green', 'lmargin1':4*INDENT_SIZE, 'lmargin2':3*INDENT_SIZE, },
'*pi4': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'brown', 'lmargin1':5*INDENT_SIZE, 'lmargin2':4*INDENT_SIZE, },
# Lists (for formatted view)
'li1': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':1*INDENT_SIZE, 'lmargin2':2*INDENT_SIZE, },
'*li1': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':1*INDENT_SIZE, 'lmargin2':2*INDENT_SIZE, },
'li2': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':2*INDENT_SIZE, 'lmargin2':3*INDENT_SIZE, },
'*li2': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':2*INDENT_SIZE, 'lmargin2':3*INDENT_SIZE, },
'li3': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':3*INDENT_SIZE, 'lmargin2':4*INDENT_SIZE, },
'*li3': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':3*INDENT_SIZE, 'lmargin2':4*INDENT_SIZE, },
'li4': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'lmargin1':4*INDENT_SIZE, 'lmargin2':5*INDENT_SIZE, },
'*li4': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'lmargin1':4*INDENT_SIZE, 'lmargin2':5*INDENT_SIZE, },
# These are the styles for unformatted mode that are different from above
# Headings (for unformatted view)
'mt1#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, TITLE_FONTSIZE ), 'foreground':'gold', },
'mt2#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, TITLE_FONTSIZE ), 'foreground':'gold2', },
'mt3#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, TITLE_FONTSIZE ), 'foreground':'gold3', },
'mt4#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, TITLE_FONTSIZE ), 'foreground':'gold4', },
's1#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, },
's2#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, },
's3#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, },
's4#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, },
'ms1#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, },
'ms2#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, },
'ms3#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, },
'ms4#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, },
'cl#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':HEADING_COLOUR, },
# Other (for unformatted view)
'r#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':SECTION_REFERENCE_COLOUR, },
'mr#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':SECTION_REFERENCE_COLOUR, },
'sr#': { 'font':'{} {} bold'.format( DEFAULT_FONTNAME, HEADING_FONTSIZE ), 'foreground':SECTION_REFERENCE_COLOUR, },
# Paragraph level fields can contain text, or can influence the next v~ text (for unformatted view)
'p#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), },
'*p#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), },
'q1#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), },
'q2#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), },
'q3#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), },
'q4#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), },
'*q1#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), },
'*q2#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), },
'*q3#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), },
'*q4#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), },
'mi#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'pink', },
'*mi#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'pink', },
'pi1#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'pink', },
'pi2#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'purple', },
'pi3#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'green', },
'pi4#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'background':'brown', },
'*pi1#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'pink', },
'*pi2#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'purple', },
'*pi3#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'green', },
'*pi4#': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'brown', },
# Lines without markers (continuation lines)
'###': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), 'foreground':'blue', },
# Hebrew interlinear fields
'WordRef': { 'font':'{} {}'.format( DEFAULT_HEBREW_FONTNAME, DEFAULT_FONTSIZE ) },
'HebWord': { 'font':'{} {}'.format( DEFAULT_HEBREW_FONTNAME, DEFAULT_FONTSIZE + 4 ), 'foreground':'brown', },
'HebStrong': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), },
'HebMorph': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE ), },
'HebGenericGloss': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE + 2 ), 'foreground':'green', },
'HebSpecificGloss': { 'font':'{} {}'.format( DEFAULT_FONTNAME, DEFAULT_FONTSIZE + 2 ), 'foreground':'orange', },
'WordRefSelected': { 'font':'{} {}'.format( DEFAULT_HEBREW_FONTNAME, DEFAULT_FONTSIZE + 1 ) },
'HebWordSelected': { 'font':'{} {}'.format( DEFAULT_HEBREW_FONTNAME, CURRENT_VERSE_FONTSIZE + 4 ), 'background':'yellow', },
'HebStrongSelected': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'yellow', },
'HebMorphSelected': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE ), 'background':'yellow', },
'HebGenericGlossSelected': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE + 2 ), 'background':'yellow', },
'HebSpecificGlossSelected': { 'font':'{} {}'.format( DEFAULT_FONTNAME, CURRENT_VERSE_FONTSIZE + 2 ), 'background':'yellow', },
}
class BibleStylesheet():
"""
Class to load a Bible stylesheet into a dictionary.
"""
def __init__( self ):
"""
"""
self.dataDict = None
self.filepath = None
self.smallestSize = self.largestSize = self.markerList = self.markerSets = None
self.name = None
self.recordsDB = None
# end of BibleStylesheet.__init__
def loadDefault( self ):
"""
Load the above styles
and copy any unformatted styles not explicitly declared.
"""
self.dataDict = DEFAULT_STYLE_DICT
self.name = 'Default'
for marker,style in self.dataDict.copy().items():
if marker[0]!='*' and marker[-1]!='#':
if marker+'#' not in self.dataDict:
self.dataDict[marker+'#'] = style
self.validate()
return self # So this command can be chained after the object creation
# end of BibleStylesheet.loadDefault
def load( self, sourceFolder, filename ):
"""
"""
self.sourceFolder = sourceFolder
self.filename = filename
assert os.path.exists( self.sourceFolder )
assert os.path.exists( self.sourceFolder )
self.filepath = os.path.join( self.sourceFolder, self.filename )
assert os.path.exists( self.filepath )
assert os.path.exists( self.filepath )
self.name = os.path.splitext( self.filename )[0]
recordsDB = SFMFile.SFMRecords()
recordsDB.read( self.filepath, 'Marker' ) #, encoding=self.encoding )
#print( "\nRecords", recordsDB.records )
self.smallestSize, self.largestSize, self.markerList, self.markerSets = recordsDB.analyze()
self.dataDict = recordsDB.copyToDict( "dict" )
#print( "\nData", self.dataDict )
self.validate()
return self # So this command can be chained after the object creation
# end of BibleStylesheet.load
def validate( self ):
"""
"""
from InternalBibleInternals import BOS_ALL_ADDED_MARKERS
for USFMMarker, styleData in self.dataDict.items():
if BibleOrgSysGlobals.debugFlag and debuggingThisModule:
print( exp("validate"), USFMMarker, styleData )
if USFMMarker.startswith( 'Heb' ) or USFMMarker.startswith( 'WordRef' ): continue
if USFMMarker in ( '###', ): continue # ignore
if USFMMarker[0] == '*': USFMMarker = USFMMarker[1:] # Remove any leading asterisk for the check
if USFMMarker[-1] == '#': USFMMarker = USFMMarker[:-1] # Remove any trailing hash for the check
#print( USFMMarker )
assert USFMMarker in BibleOrgSysGlobals.USFMMarkers or USFMMarker in BOS_ALL_ADDED_MARKERS
# end of BibleStylesheet.load
def importParatextStylesheet( self, folder, filename, encoding='utf-8' ):
"""
"""
if BibleOrgSysGlobals.verbosityLevel > 1: print( "Importing {} Paratext stylesheet…".format( filename ) )
PTSS = ParatextStylesheet().load( folder, filename, encoding )
self.name = PTSS.name
self.filepath = PTSS.filepath
self.dataDict = {}
for marker in BibleOrgSysGlobals.USFMMarkers:
#print( marker )
try: PTFormatting = PTSS.getDict( marker )
except KeyError: PTFormatting = None # Just ignore the error
if PTFormatting:
formatSpecification = {}
for field, value in PTFormatting.items():
#print( marker, field, repr(value) )
formatSpecification[field] = value
self.dataDict[marker] = formatSpecification
elif BibleOrgSysGlobals.debugFlag: print( "USFM {} marker not included in {} Paratext stylesheet".format( marker, filename ) )
#export the marker
# end of BibleStylesheet.importParatextStylesheet
def __eq__( self, other ):
if type( other ) is type( self ): return self.__dict__ == other.__dict__
return False
def __ne__(self, other): return not self.__eq__(other)
def __len__( self ):
if self.recordsDB: return len( self.recordsDB.records )
return 0
# end of BibleStylesheet.__len__
def __str__( self ):
"""
This method returns the string representation of a USFM stylesheet object.
@return: the name of a Bible object formatted as a string
@rtype: string
"""
result = "BibleStylesheet object"
if BibleOrgSysGlobals.debugFlag or BibleOrgSysGlobals.verbosityLevel>2: result += ' v' + ProgVersion
if self.name: result += ('\n' if result else '') + " Name: " + self.name
if self.filepath: result += ('\n' if result else '') + " From: " + self.filepath
if self.dataDict:
result += ('\n' if result else '') + " Number of records = " + str( len(self.dataDict) )
if BibleOrgSysGlobals.debugFlag or BibleOrgSysGlobals.verbosityLevel>2:
if self.smallestSize:
result += ('\n' if result else '') + " Smallest record size: {} markers".format( self.smallestSize )
if self.largestSize:
result += ('\n' if result else '') + " Largest record size: {} markers".format( self.largestSize )
if self.markerList: result += ('\n' if result else '') + " Marker list: {}".format( self.markerList )
if BibleOrgSysGlobals.debugFlag or BibleOrgSysGlobals.verbosityLevel>3:
if self.markerSets: result += ('\n' if result else '') + " Marker sets: {}".format( self.markerSets )
return result
# end of BibleStylesheet.__str__
def getTKStyleDict( self, USFMKey ):
"""
Returns the dictionary with the information for the given USFM marker key.
Raises a KeyError if the key is not specified in the stylesheet.
"""
return self.dataDict[USFMKey]
# end of BibleStylesheet.getDict
def getValue( self, USFMKey, StyleKey ):
"""
Returns the value (string) with the information for the given USFM marker key and the requested stylename.
Raises a KeyError if either key is not specified in the stylesheet.
"""
return self.dataDict[USFMKey][StyleKey]
# end of BibleStylesheet.getValue
def getTKStyles( self ):
"""
Returns a dictionary of USFM codes paired with the corresponding tkinter style dictionary.
"""
results = {}
for USFMKey in self.dataDict:
results[USFMKey] = self.getTKStyleDict( USFMKey )
return results
# end of BibleStylesheet.getTKStyles
# end of class BibleStylesheet
class ParatextStylesheet():
"""
Class to load a Paratext stylesheet into a dictionary.
"""
def __init__( self ):
self.sourceFolder = self.filename = self.encoding = None
self.filepath = self.name = None
self.recordsDB = self.dataDict = None
self.smallestSize = self.largestSize = self.markerList = self.markerSets = None
# end of ParatextStylesheet.__init__
def load( self, sourceFolder, filename, encoding='utf-8' ):
self.sourceFolder = sourceFolder
self.filename = filename
self.encoding = encoding
assert os.path.exists( self.sourceFolder )
assert os.path.exists( self.sourceFolder )
self.filepath = os.path.join( self.sourceFolder, self.filename )
assert os.path.exists( self.filepath )
assert os.path.exists( self.filepath )
self.name = os.path.splitext( self.filename )[0]
recordsDB = SFMFile.SFMRecords()
recordsDB.read( self.filepath, 'Marker', encoding=self.encoding )
#print( "\nRecords", recordsDB.records )
self.smallestSize, self.largestSize, self.markerList, self.markerSets = recordsDB.analyze()
self.dataDict = recordsDB.copyToDict( "dict" )
#print( "\nData", self.dataDict )
self.validate()
return self # So this command can be chained after the object creation
# end of ParatextStylesheet.load
def validate( self ):
for USFMMarker in self.dataDict:
#print( USFMMarker )
if USFMMarker not in BibleOrgSysGlobals.USFMMarkers:
logging.warning( exp("ParatextStylesheet validate: found unexpected {!r} marker").format( USFMMarker ) )
# end of ParatextStylesheet.load
def __eq__( self, other ):
if type( other ) is type( self ): return self.__dict__ == other.__dict__
return False
def __ne__(self, other): return not self.__eq__(other)
def __len__( self ):
if self.recordsDB: return len( self.recordsDB.records )
return 0
# end of ParatextStylesheet.__len__
def __str__( self ):
"""
This method returns the string representation of a USFM stylesheet object.
@return: the name of a Bible object formatted as a string
@rtype: string
"""
result = "ParatextStylesheet object"
if BibleOrgSysGlobals.debugFlag or BibleOrgSysGlobals.verbosityLevel>2: result += ' v' + ProgVersion
if self.name: result += ('\n' if result else '') + " Name: " + self.name
if self.filepath: result += ('\n' if result else '') + " From: " + self.filepath
if self.dataDict:
result += ('\n' if result else '') + " Number of records = " + str( len(self.dataDict) )
if BibleOrgSysGlobals.debugFlag or BibleOrgSysGlobals.verbosityLevel>2:
if self.smallestSize:
result += ('\n' if result else '') + " Smallest record size: {} markers".format( self.smallestSize )
if self.largestSize:
result += ('\n' if result else '') + " Largest record size: {} markers".format( self.largestSize )
if self.markerList: result += ('\n' if result else '') + " Marker list: {}".format( self.markerList )
if BibleOrgSysGlobals.debugFlag or BibleOrgSysGlobals.verbosityLevel>3:
if self.markerSets: result += ('\n' if result else '') + " Marker sets: {}".format( self.markerSets )
return result
# end of ParatextStylesheet.__str__
def getDict( self, USFMKey ):
"""
Returns the dictionary with the information for the given USFM marker key.
Raises a KeyError if the key is not specified in the stylesheet.
"""
return self.dataDict[USFMKey]
# end of ParatextStylesheet.getDict
def getValue( self, USFMKey, StyleKey ):
"""
Returns the value (string) with the information for the given USFM marker key and the requested stylename.
Raises a KeyError if either key is not specified in the stylesheet.
"""
return self.dataDict[USFMKey][StyleKey]
# end of ParatextStylesheet.getValue
# end of class ParatextStylesheet
def demo():
"""
Short program to demonstrate/test the above class(es).
"""
if BibleOrgSysGlobals.verbosityLevel > 0: print( ProgNameVersion )
if 1: # Try the default one
print( "\nTrying default Bible stylesheet…" )
#folder = "../../../../../Data/Work/VirtualBox_Shared_Folder/PTStylesheets/"
#filename = "LD.sty"
ss = BibleStylesheet()
#print( ss )
#ss.importParatextStylesheet( folder, filename, encoding='latin-1' )
ss.loadDefault()
print( ss )
print( "h style:", ss.getTKStyleDict( 'h' ) )
try: print( "s1 font:", ss.getValue( 's1', 'font' ) )
except KeyError: print( "No s1 or font in stylesheet!" )
try: print( ss.getTKStyleDict( 'hijkl' ) )
except KeyError: print( "No hijkl in stylesheet!" )
try: print( ss.getValue( 'h', 'FontSizeImaginary' ) )
except KeyError: print( "No h or FontSizeImaginary in stylesheet!" )
if debuggingThisModule: print( ss.dataDict )
if 1: # Try importing one
print( "\nTrying Bible stylesheet import…" )
folder = "../../../../../Data/Work/VirtualBox_Shared_Folder/PTStylesheets/"
filename = "LD.sty"
ss = BibleStylesheet()
print( ss )
ss.importParatextStylesheet( folder, filename, encoding='latin-1' )
print( ss )
if debuggingThisModule: print( ss.dataDict )
print( "h style:", ss.getTKStyleDict( 'h' ) )
try: print( "h FontSize:", ss.getValue( 'h', 'FontSize' ) )
except KeyError: print( "No h or FontSize in stylesheet!" )
if 1: # Try a small one
print( "\nTrying small PT stylesheet…" )
folder = "../../../../../Data/Work/VirtualBox_Shared_Folder/PTStylesheets/"
filename = "LD.sty"
ss = ParatextStylesheet().load( folder, filename, encoding='latin-1' )
print( ss )
print( "h style:", ss.getDict( 'h' ) )
print( "h fontsize:", ss.getValue( 'h', 'FontSize' ) )
if debuggingThisModule: print( ss.dataDict )
if 1: # Try a full one
print( "\nTrying full PT stylesheet…" )
folder = "../../../../../Data/Work/VirtualBox_Shared_Folder/PTStylesheets/"
filename = "usfm.sty"
ss = ParatextStylesheet()
ss.load( folder, filename )
print( ss )
print( "h style:", ss.getDict( 'h' ) )
print( "h fontsize:", ss.getValue( 'h', 'FontSize' ) )
if debuggingThisModule: print( ss.dataDict )
# end of demo
if __name__ == '__main__':
#multiprocessing.freeze_support() # Multiprocessing support for frozen Windows executables
# Configure basic Bible Organisational System (BOS) set-up
parser = BibleOrgSysGlobals.setup( ProgName, ProgVersion )
BibleOrgSysGlobals.addStandardOptionsAndProcess( parser )
demo()
BibleOrgSysGlobals.closedown( ProgName, ProgVersion )
# end of BibleStylesheets.py