-
Notifications
You must be signed in to change notification settings - Fork 17
/
ReportGenerator.py
3157 lines (2954 loc) · 199 KB
/
ReportGenerator.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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (C) 2003 - 2015 The Board of Regents of the University of Wisconsin System
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# 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, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
"""This module implements the Report Generator. """
# This module combines functionality that used to be divided into Collection Summary Report and
# Keyword Usage Report modules.
__author__ = 'David K. Woods <[email protected]>'
DEBUG = False
# import Python's datetime module
import datetime
# import Python's locale module
import locale
# import the Python String module
import string
# import Python's sys module
import sys
# import the python xml-sax module
import xml.sax
# import wxPython
import wx
# import wxPython's Rich Text Ctrl module
import wx.richtext as richtext
# Import Transana's Clip object
import Clip
# import Transana's Collection Object
import Collection
# Import Transana's Database Interface
import DBInterface
# Import Transana's Dialog Boxes
import Dialogs
# import Transana's Document Object
import Document
# Import Transana's Episode object
import Episode
# import Transana's Filter Dialog
import FilterDialog
# Import Transana's Keyword object
import KeywordObject as Keyword
# Import Transana's Miscellaneous functions
import Misc
# Import Transana's Note object
import Note
# import the Transana XML-to-RTC Import Parser
import PyXML_RTCImportParser
# import Transana's Quote Object
import Quote
# Import Transana's Library Object
import Library
# import Transana's Snapshot Object
import Snapshot
# Import Transana's Snapshot Window for loading images
import SnapshotWindow
# Import Transana's Text Report infrastructure
import TextReport
# Import Transana's Constants
import TransanaConstants
# import Transana's Exceptions
import TransanaExceptions
# import Transana's Global variables
import TransanaGlobal
# import Transana's Transcript Object
import Transcript
# import Transana's Transcript Editor - Rich Text Ctrl version
import TranscriptEditor_RTC
class ReportGenerator(wx.Object):
""" This class creates and displays the Object Reports, formerly the Keyword Usage Report and the Collection Summary Report """
def __init__(self, **kwargs):
""" Create the Object Report
If a seriesName is passed, all Episodes and Document in that *Library* and their keywords should be listed.
If a documentName is passed, all Quotes from that Document, regardless of Collection, and their Document Keywords should be listed.
If an episodeName is passed, all Clips from that Episode, regardless of Collection, and their Clip keywords should be listed.
If a collection is passed, all Clips in that Collection, regardless of source Episode, and their Clip keywords should be listed.
If a searchSeries is passed, use the treeCtrl to determine the Episodes and Documents that should be included.
if a searchCollection is passed, use the treeCtrl to determine the Clips that should be included. """
# Parameters can include:
# controlObject=None
# title=''
# seriesName=None,
# documentName=None,
# episodeName=None,
# collection=None,
# searchSeries=None,
# searchColl=None,
# treeCtrl=None,
# showNested=False,
# showHypertext=False,
# showFile=True,
# showTime=True,
# showDocImportDate=True,
# showSourceInfo=True,
# showQuoteText=True,
# showTranscripts=False,
# showSnapshotImage=True,
# showSnapshotCoding=True,
# showKeywords=False,
# showComments=False,
# showCollectionNotes=False
# showDocumentNotes=False
# showClipNotes=False
# showSnapshotNotes=False
# Remember the parameters passed in and set values for all variables, even those NOT passed in.
if kwargs.has_key('controlObject'):
self.ControlObject = kwargs['controlObject']
else:
self.ControlObject = None
# Specify the Report Title
if kwargs.has_key('title'):
self.title = kwargs['title']
else:
self.title = ''
if kwargs.has_key('seriesName'):
self.seriesName = kwargs['seriesName']
else:
self.seriesName = None
if kwargs.has_key('documentName'):
self.documentName = kwargs['documentName']
else:
self.documentName = None
if kwargs.has_key('episodeName'):
self.episodeName = kwargs['episodeName']
else:
self.episodeName = None
if kwargs.has_key('collection'):
self.collection = kwargs['collection']
else:
self.collection = None
if kwargs.has_key('searchSeries'):
self.searchSeries = kwargs['searchSeries']
else:
self.searchSeries = None
if kwargs.has_key('searchColl'):
self.searchColl = kwargs['searchColl']
else:
self.searchColl = None
if kwargs.has_key('treeCtrl'):
self.treeCtrl = kwargs['treeCtrl']
else:
self.treeCtrl = None
if kwargs.has_key('showNested') and kwargs['showNested']:
self.showNested = True
else:
self.showNested = False
if kwargs.has_key('showHyperlink') and kwargs['showHyperlink']:
self.showHyperlink = True
else:
self.showHyperlink = False
if kwargs.has_key('showFile') and kwargs['showFile']:
self.showFile = True
else:
self.showFile = False
if kwargs.has_key('showTime') and kwargs['showTime']:
self.showTime = True
else:
self.showTime = False
if kwargs.has_key('showDocImportDate') and kwargs['showDocImportDate']:
self.showDocImportDate = True
else:
self.showDocImportDate = False
if kwargs.has_key('showSourceInfo') and kwargs['showSourceInfo']:
self.showSourceInfo = True
else:
self.showSourceInfo = False
if kwargs.has_key('showQuoteText') and kwargs['showQuoteText']:
self.showQuoteText = True
else:
self.showQuoteText = False
if kwargs.has_key('showTranscripts') and kwargs['showTranscripts']:
self.showTranscripts = True
else:
self.showTranscripts = False
if kwargs.has_key('showSnapshotImage'):
self.showSnapshotImage = kwargs['showSnapshotImage']
else:
self.showSnapshotImage = 0
if kwargs.has_key('showSnapshotCoding'):
self.showSnapshotCoding = kwargs['showSnapshotCoding']
else:
self.showSnapshotCoding = 0
if kwargs.has_key('showKeywords') and kwargs['showKeywords']:
self.showKeywords = True
else:
self.showKeywords = False
if kwargs.has_key('showComments') and kwargs['showComments']:
self.showComments = True
else:
self.showComments = False
if kwargs.has_key('showCollectionNotes') and kwargs['showCollectionNotes']:
self.showCollectionNotes = True
else:
self.showCollectionNotes = False
if kwargs.has_key('showQuoteNotes') and kwargs['showQuoteNotes']:
self.showQuoteNotes = True
else:
self.showQuoteNotes = False
if kwargs.has_key('showClipNotes') and kwargs['showClipNotes']:
self.showClipNotes = True
else:
self.showClipNotes = False
if kwargs.has_key('showSnapshotNotes') and kwargs['showSnapshotNotes']:
self.showSnapshotNotes = True
else:
self.showSnapshotNotes = False
# Filter Configuration Name -- initialize to nothing
self.configName = ''
# Get the local locale, which will set the appropriate date formatting for the %x parameter below.
locale.setlocale(locale.LC_ALL, '')
# Create the TextReport object, which forms the basis for text-based reports.
self.report = TextReport.TextReport(None, title=self.title, displayMethod=self.OnDisplay,
filterMethod=self.OnFilter, helpContext="Transana's Text Reports")
# If a Control Object has been passed in ...
if self.ControlObject != None:
# ... register this report with the Control Object (which adds it to the Windows Menu)
self.ControlObject.AddReportWindow(self.report)
# Register the Control Object with the Report
self.report.ControlObject = self.ControlObject
# Define the main (Episode or Clip) Filter List (which will differ depending on the report type)
self.filterList = []
# Define the Document Filter List, which will only be used for some reports
self.documentFilterList = []
# Define the Quote Filter List. This probably is redundant with the filterList, I'm not sure yet.
self.quoteFilterList = []
# Define the Snapshot Filter List, which will only be used for some reports
self.snapshotFilterList = []
# Define the Keyword Filter List as well, which does NOT differ based on report type
self.keywordFilterList = []
# To speed report creation, freeze GUI updates based on changes to the report text
self.report.reportText.Freeze()
# Trigger the ReportText method that causes the report to be displayed.
self.report.CallDisplay()
# Apply the Default Filter, if one exists
self.report.OnFilter(None)
# Now that we're done, remove the freeze
self.report.reportText.Thaw()
def OnDisplay(self, reportText):
""" This method, required by TextReport, populates the TextReport. The reportText parameter is
the wxSTC control from the TextReport object. It needs to be in the report parent because
the TextReport doesn't know anything about the actual data. """
# Create minorList as a blank Dictionary Object
minorList = {}
# We need variables to count the number of quotes displayed and to accumulate their total length.
self.quoteCount = 0
self.quoteTotalLength = 0
# We need variables to count the number of clips displayed and to accumulate their total time.
self.clipCount = 0
self.clipTotalTime = 0.0
# We need variables to count the number of snapshots displayed.
self.snapshotCount = 0
self.snapshotTotalTime = 0.0
# Determine if we need to populate the Filter Lists. If it hasn't already been done, we should do it.
# If it has already been done, no need to do it again.
if (self.filterList == []) and (self.documentFilterList == []) and \
(self.quoteFilterList == []) and (self.snapshotFilterList == []):
populateFilterList = True
else:
populateFilterList = False
# Initialize the variable that tracks the request to skip "Image Not Loaded" errors
skippingImageError = False
# Make the control writable
reportText.SetReadOnly(False)
# ... Set the Style for the Heading
reportText.SetTxtStyle(fontFace='Courier New', fontSize=16, fontBold=True, fontUnderline=True)
# Set report margins, the left and right margins to 0. The RichTextPrinting infrastructure handles that!
# Center the title, and add spacing after.
reportText.SetTxtStyle(parLeftIndent = 0, parRightIndent = 0, parAlign=wx.TEXT_ALIGNMENT_CENTER,
parSpacingBefore = 0, parSpacingAfter = 12)
# Add the Title to the page
reportText.WriteText(self.title + '\n')
# If a Collection is passed in ...
if self.collection != None:
# The major label for objects for the Collection report is Clip
majorLabel = _('Clip')
# An empty Collection (number == 0) signals the request for the Global report
if self.collection.number == 0:
# The global report has no subtitle.
self.subtitle = ''
# We initialize the major list to an empty list for the global report
majorList = []
# A non-empty collection signals a scoped report.
else:
# Add a subtitle and ...
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Collection: %s"), 'utf8')
else:
prompt = _("Collection: %s")
self.subtitle = prompt % self.collection.GetNodeString()
# initialize the Major List of report elements. Clips and Snapshots will be sorted and included.
majorList = []
# initialize a Dictionary for all Report Artifacts (for sorting!)
tmpDict = {}
# Get a list of all Clips in the Collection.
tmpClipList = DBInterface.list_of_clips_by_collectionnum(self.collection.number, includeSortOrder=True)
# For each Clip ...
for x in tmpClipList:
# ... add the Clip to the Dictionary with the Sort Order as the key and with the Object Type added
tmpDict[x[3]] = (('Clip',) + x)
if TransanaConstants.proVersion:
# Get a list of all Quotes in the Collection.
tmpQuoteList = DBInterface.list_of_quotes_by_collectionnum(self.collection.number, includeSortOrder=True)
# For each Quote ...
for x in tmpQuoteList:
# ... add the Quote to the Dictionary with the Sort Order as the key and with the Object Type added
tmpDict[x[3]] = (('Quote',) + x[:-1])
# Get a list of all Snapshots in the Collection.
tmpSnapshotList = DBInterface.list_of_snapshots_by_collectionnum(self.collection.number, includeSortOrder=True)
# For each Snapshot ...
for x in tmpSnapshotList:
# ... add the Snapshot to the Dictionary with the Sort Order as the key and with the Object Type added
tmpDict[x[3]] = (('Snapshot',) + x)
# Get the Dictionary's Keys
order = tmpDict.keys()
# Sort the Dictionary's Keys
order.sort()
# For each element in the sorted list of Keys ...
for x in order:
# Add the elemnt to the Major List.
majorList.append(tmpDict[x][:-1])
# If we're supposed to show Nested Collection data ...
if self.showNested:
# ... we first need to get the nested collections for the top level
nestedCollections = DBInterface.list_of_collections(self.collection.number)
# As long as there are entries in the list of nested collections that haven't been processed ...
while len(nestedCollections) > 0:
# ... extract the data from the top of the nested collection list ...
(collNum, collName, parentCollNum) = nestedCollections[0]
# ... and remove that entry from the list.
del(nestedCollections[0])
# initialize a Dictionary for all Report Artifacts (for sorting!)
tmpDict = {}
# Get a list of all Clips in the Collection.
tmpClipList = DBInterface.list_of_clips_by_collectionnum(collNum, includeSortOrder=True)
# For each Clip ...
for x in tmpClipList:
# ... add the Clip to the Dictionary with the Sort Order as the key and with the Object Type added
tmpDict[x[3]] = (('Clip',) + x)
if TransanaConstants.proVersion:
# Get a list of all Quotes in the Collection.
tmpQuoteList = DBInterface.list_of_quotes_by_collectionnum(collNum, includeSortOrder=True)
# For each Quote ...
for x in tmpQuoteList:
# ... add the Quote to the Dictionary with the Sort Order as the key and with the Object Type added
tmpDict[x[3]] = (('Quote',) + x[:-1])
# Get a list of all Snapshots in the Collection.
tmpSnapshotList = DBInterface.list_of_snapshots_by_collectionnum(collNum, includeSortOrder=True)
# For each Snapshot ...
for x in tmpSnapshotList:
# ... add the Snapshot to the Dictionary with the Sort Order as the key and with the Object Type added
tmpDict[x[3]] = (('Snapshot',) + x)
# Get the Dictionary's Keys
order = tmpDict.keys()
# Sort the Dictionary's Keys
order.sort()
# For each element in the sorted list of Keys ...
for x in order:
# Add the elemnt to the Major List.
majorList.append(tmpDict[x][:-1])
# Then get the nested collections under the new collection and add them to the Nested Collection list
# They get added at the FRONT of the list so that the report will mirror the organization of the
# database Tree.
nestedCollections = DBInterface.list_of_collections(collNum) + nestedCollections
# Put all the Keywords for the Clips and Snapshots in the majorList in the minorList.
# Start by iterating through the Major List
for (objType, objNo, objName, collNo) in majorList:
# Create a Minor List dictionary entry, indexed to clip or snapshot number, for the keywords.
if objType == 'Quote':
minorList[(objType, objNo)] = DBInterface.list_of_keywords(Quote = objNo)
elif objType == 'Clip':
minorList[(objType, objNo)] = DBInterface.list_of_keywords(Clip = objNo)
elif objType == 'Snapshot':
minorList[(objType, objNo)] = DBInterface.list_of_keywords(Snapshot = objNo)
# If we're populating Filter Lists ...
if populateFilterList:
# If we have a Quote ...
if objType == 'Quote':
# ... add it to the Quote Filter List
listToPopulate = self.quoteFilterList
# If we have a Clip ...
elif objType == 'Clip':
# ... add it to the regular Filter List
listToPopulate = self.filterList
# If we have a Snapshot ...
elif objType == 'Snapshot':
# ... add it to the Snapshot Filter List
listToPopulate = self.snapshotFilterList
# ... then add the Artifact data to the appropiate Filter List, initially checked ...
listToPopulate.append((objName, collNo, True))
# ... and iterate through that clip's keywords or the snapshot's whole snapshot keywords ...
for (kwg, kw, ex) in minorList[(objType, objNo)]:
# ... check to see if the entry is NOT already in the list ...
if (kwg, kw, True) not in self.keywordFilterList:
# ... and add the keyword entry to the Keyword Filter List if it's not already there.
self.keywordFilterList.append((kwg, kw, True))
# If we have a Snapshot ...
if objType == 'Snapshot':
# ... get a list of the Snapshot's Detail Coding
tmpList = DBInterface.list_of_snapshot_detail_keywords(Snapshot = objNo)
# For each Keyword Group : Keyword pair ...
for (kwg, kw) in tmpList:
# ... check to see if the entry is NOT already in the list ...
if (kwg, kw, True) not in self.keywordFilterList:
# ... and add the keyword entry to the Keyword Filter List if it's not already there.
self.keywordFilterList.append((kwg, kw, True))
# If a Document Name is passed in ...
elif self.documentName != None:
# ... add a subtitle
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Document: %s"), 'utf8')
else:
prompt = _("Episode: %s")
self.subtitle = prompt % self.documentName
# First, get the Document Object ...
docObj = Document.Document(libraryID=self.seriesName, documentID=self.documentName)
# initialize the Major List of report elements. Quotes and Snapshots will be sorted and included.
majorList = []
# initialize a Dictionary for all Report Artifacts (for sorting!)
tmpDict = {}
# Get a list of all Quotes created from the Document
tmpQuoteList = DBInterface.list_of_quotes_by_document(docObj.number)
# For each Quote ...
for x in tmpQuoteList:
# ... specify that this is a Quote
x['Type'] = 'Quote'
# ... add the Quote to the Dictionary with the Sort Order as the key and with the Object Type added
tmpDict[(x['StartChar'], x['EndChar'], x['CollectID'], x['CollectNum'], x['QuoteID'], 'Quote')] = x
## if TransanaConstants.proVersion:
## # Get a list of all Snapshots in the Collection.
## tmpSnapshotList = DBInterface.list_of_snapshots_by_episode(epObj.number)
## # For each Snapshot ...
## for x in tmpSnapshotList:
## # ... specify that this is a Snapshot
## x['Type'] = 'Snapshot'
## # ... add the Snapshot to the Dictionary with the Sort Order as the key and with the Object Type added
## tmpDict[(x['SnapshotStart'], x['SnapshotStop'], x['CollectID'], x['CollectNum'], x['SnapshotID'], 'Snapshot')] = x
# Get the Dictionary's Keys
order = tmpDict.keys()
# Sort the Dictionary's Keys
order.sort()
# For each element in the sorted list of Keys ...
for x in order:
# Add the elemnt to the Major List.
majorList.append(tmpDict[x])
# Put all the Keywords for the Quotes and Snapshots in the majorList in the minorList.
# Start by iterating through the Major List
for item in majorList:
# Create a Minor List dictionary entry, indexed to quote or snapshot number, for the keywords.
if item['Type'] == 'Quote':
minorList[(item['Type'], item['QuoteNum'])] = DBInterface.list_of_keywords(Quote = item['QuoteNum'])
## elif item['Type'] == 'Snapshot':
## minorList[(item['Type'], item['SnapshotNum'])] = DBInterface.list_of_keywords(Snapshot = item['SnapshotNum'])
# If we're populating Filter Lists ...
if populateFilterList:
# If we have a Snapshot ...
if item['Type'] == 'Snapshot':
# ... add it to the Snapshot Filter List
listToPopulate = self.snapshotFilterList
objName = item['SnapshotID']
objNo = item['SnapshotNum']
# If we DON'T have a Snapshot ...
else:
# ... add it to the Quote Filter List
listToPopulate = self.quoteFilterList
objName = item['QuoteID']
objNo = item['QuoteNum']
# ... then add the Artifact data to the appropiate Filter List, initially checked ...
listToPopulate.append((objName, item['CollectNum'], True))
# ... and iterate through that quote's keywords or the snapshot's whole snapshot keywords ...
for (kwg, kw, ex) in minorList[(item['Type'], objNo)]:
# ... check to see if the entry is NOT already in the list ...
if (kwg, kw, True) not in self.keywordFilterList:
# ... and add the keyword entry to the Keyword Filter List if it's not already there.
self.keywordFilterList.append((kwg, kw, True))
## # If we have a Snapshot ...
## if item['Type'] == 'Snapshot':
## # ... get a list of the Snapshot's Detail Coding
## tmpList = DBInterface.list_of_snapshot_detail_keywords(Snapshot = item['SnapshotNum'])
## # For each Keyword Group : Keyword pair ...
## for (kwg, kw) in tmpList:
## # ... check to see if the entry is NOT already in the list ...
## if (kwg, kw, True) not in self.keywordFilterList:
## # ... and add the keyword entry to the Keyword Filter List if it's not already there.
## self.keywordFilterList.append((kwg, kw, True))
# If an Episode Name is passed in ...
elif self.episodeName != None:
# ... add a subtitle
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Episode: %s"), 'utf8')
else:
prompt = _("Episode: %s")
self.subtitle = prompt % self.episodeName
# First, get the Episode Object ...
epObj = Episode.Episode(series = self.seriesName, episode = self.episodeName)
# initialize the Major List of report elements. Clips and Snapshots will be sorted and included.
majorList = []
# initialize a Dictionary for all Report Artifacts (for sorting!)
tmpDict = {}
# Get a list of all Clips created from the Episode
tmpClipList = DBInterface.list_of_clips_by_episode(epObj.number)
# For each Clip ...
for x in tmpClipList:
# ... specify that this is a Clip
x['Type'] = 'Clip'
# ... add the Clip to the Dictionary with the Sort Order as the key and with the Object Type added
tmpDict[(x['ClipStart'], x['ClipStop'], x['CollectID'], x['CollectNum'], x['ClipID'], 'Clip')] = x
if TransanaConstants.proVersion:
# Get a list of all Snapshots in the Collection.
tmpSnapshotList = DBInterface.list_of_snapshots_by_episode(epObj.number)
# For each Snapshot ...
for x in tmpSnapshotList:
# ... specify that this is a Snapshot
x['Type'] = 'Snapshot'
# ... add the Snapshot to the Dictionary with the Sort Order as the key and with the Object Type added
tmpDict[(x['SnapshotStart'], x['SnapshotStop'], x['CollectID'], x['CollectNum'], x['SnapshotID'], 'Snapshot')] = x
# Get the Dictionary's Keys
order = tmpDict.keys()
# Sort the Dictionary's Keys
order.sort()
# For each element in the sorted list of Keys ...
for x in order:
# Add the elemnt to the Major List.
majorList.append(tmpDict[x])
# Put all the Keywords for the Clips and Snapshots in the majorList in the minorList.
# Start by iterating through the Major List
for item in majorList:
# Create a Minor List dictionary entry, indexed to clip or snapshot number, for the keywords.
if item['Type'] == 'Clip':
minorList[(item['Type'], item['ClipNum'])] = DBInterface.list_of_keywords(Clip = item['ClipNum'])
elif item['Type'] == 'Snapshot':
minorList[(item['Type'], item['SnapshotNum'])] = DBInterface.list_of_keywords(Snapshot = item['SnapshotNum'])
# If we're populating Filter Lists ...
if populateFilterList:
# If we have a Snapshot ...
if item['Type'] == 'Snapshot':
# ... add it to the Snapshot Filter List
listToPopulate = self.snapshotFilterList
objName = item['SnapshotID']
objNo = item['SnapshotNum']
# If we DON'T have a Snapshot ...
else:
# ... add it to the regular Filter List
listToPopulate = self.filterList
objName = item['ClipID']
objNo = item['ClipNum']
# ... then add the Artifact data to the appropiate Filter List, initially checked ...
listToPopulate.append((objName, item['CollectNum'], True))
# ... and iterate through that clip's keywords or the snapshot's whole snapshot keywords ...
for (kwg, kw, ex) in minorList[(item['Type'], objNo)]:
# ... check to see if the entry is NOT already in the list ...
if (kwg, kw, True) not in self.keywordFilterList:
# ... and add the keyword entry to the Keyword Filter List if it's not already there.
self.keywordFilterList.append((kwg, kw, True))
# If we have a Snapshot ...
if item['Type'] == 'Snapshot':
# ... get a list of the Snapshot's Detail Coding
tmpList = DBInterface.list_of_snapshot_detail_keywords(Snapshot = item['SnapshotNum'])
# For each Keyword Group : Keyword pair ...
for (kwg, kw) in tmpList:
# ... check to see if the entry is NOT already in the list ...
if (kwg, kw, True) not in self.keywordFilterList:
# ... and add the keyword entry to the Keyword Filter List if it's not already there.
self.keywordFilterList.append((kwg, kw, True))
# If a Library Name is passed in ...
elif self.seriesName != None:
# ... add a subtitle
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Library: %s"), 'utf8')
else:
prompt = _("Library: %s")
self.subtitle = prompt % self.seriesName
# The label for our Major unit should reflect that these are Episodes
majorLabel = _('Episode')
# Initialize the Major List
majorList = []
# Get the Library Object
tmpLibraryObj = Library.Library(self.seriesName)
# Get a Dictionary of all items in this Library
tempDict = DBInterface.dictionary_of_documents_and_episodes(tmpLibraryObj)
# Get the keys to the dictionary
keys = tempDict.keys()
# Sort the keys so the report will be displayed in the correct order
keys.sort()
# For each Key in the data list ...
for key in keys:
# ... get the data object's Name from the dictionary Key ...
objName = key[0]
# ... and get the Object's Type, Number, and Parent Number from the dictionary Value
(objType, objNum, objParentNum) = tempDict[key]
# Put the Item in the Major List
majorList.append((objType, objNum, objName, objParentNum))
# If we have a Document ...
if objType == 'Document':
# Put all the Keywords for the Document in the majorList in the minorList
minorList[(objType, objNum)] = DBInterface.list_of_keywords(Document = objNum)
# If we have an Episode ...
elif objType == 'Episode':
# Put all the Keywords for the Episodes in the majorList in the minorList
minorList[(objType, objNum)] = DBInterface.list_of_keywords(Episode = objNum)
# If we're populating the Filter Lists ...
if populateFilterList:
if objType == 'Document':
# ... Add the Document data to the document Filter List ...
self.documentFilterList.append((objName, self.seriesName, True))
else:
# ... Add the Episode data to the main Filter List ...
self.filterList.append((objName, self.seriesName, True))
# ... Iterate through the keywords that were just added to the Minor List (only for this Key) ...
for (kwg, kw, ex) in minorList[(objType, objNum)]:
# .. and IF they're not already in the list ...
if (kwg, kw, True) not in self.keywordFilterList:
# ... add them to the Keyword Filter List
self.keywordFilterList.append((kwg, kw, True))
# If this report is called for a SearchLibraryResult, we build the majorList based on the contents of the Tree Control.
elif (self.searchSeries != None) and (self.treeCtrl != None):
# Get the Search Result Name for the subtitle
searchResultNode = self.searchSeries
# Start a loop to move up the tree. Keep going until interrupted.
while True:
# Move up to the Parent of the current node
searchResultNode = self.treeCtrl.GetItemParent(searchResultNode)
# Get the Data for the new node
tempData = self.treeCtrl.GetPyData(searchResultNode)
# If we are at the SearchResultsNode ...
if tempData.nodetype == 'SearchResultsNode':
# ... we can stop moving up. Break the loop.
break
# Now build the subtitle
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Search Library: %s"), 'utf8')
else:
prompt = _("Search Library: %s")
self.subtitle = prompt % (self.treeCtrl.GetItemText(self.searchSeries),)
# The majorLabel is for Episodes in this case
majorLabel = _('Episode')
# Initialize the majorList to an empty list
majorList = []
# Get the first Child node from the searchColl collection
(item, cookie) = self.treeCtrl.GetFirstChild(self.searchSeries)
# Process all children in the searchLibrary Library. (IsOk() fails when all children are processed.)
while item.IsOk():
# Get the child item's Name
itemText = self.treeCtrl.GetItemText(item)
# Get the child item's Node Data
itemData = self.treeCtrl.GetPyData(item)
# See if the item is a Document
if itemData.nodetype == 'SearchDocumentNode':
# If it's a Document, add the Document's Node Data to the majorList
majorList.append(('Document', itemData.recNum, itemText, itemData.parent))
# If we're populating the Filter Lists ...
if populateFilterList:
# ... Add the Episode data to the main Filter List ...
self.documentFilterList.append((itemText, self.treeCtrl.GetItemText(self.treeCtrl.GetItemParent(item)), True))
# See if the item is an Episode
elif itemData.nodetype == 'SearchEpisodeNode':
# If it's an Episode, add the Episode's Node Data to the majorList
majorList.append(('Episode', itemData.recNum, itemText, itemData.parent))
# If we're populating the Filter Lists ...
if populateFilterList:
# ... Add the Episode data to the main Filter List ...
self.filterList.append((itemText, self.treeCtrl.GetItemText(self.treeCtrl.GetItemParent(item)), True))
# Get the next Child Item and continue the loop
(item, cookie) = self.treeCtrl.GetNextChild(self.searchSeries, cookie)
## print "ReportGenerator.OnDisplay(): Search Library Report"
## print "majorList:"
## for x in range(len(majorList)):
## print x, majorList[x]
## print
# Once we have the Episodes in the majorList, we can gather their keywords into the minorList.
# Start by iterating through the Major List
for (objType, EpNo, epName, epParentNo) in majorList:
# If we have a Document ...
if objType == 'Document':
# Get all the keywords for the indicated Document and add them to the Minor List, keyed to the Document Name.
minorList[('Document', EpNo)] = DBInterface.list_of_keywords(Document = EpNo)
# If we have an Episode ...
elif objType == 'Episode':
# Get all the keywords for the indicated Episode and add them to the Minor List, keyed to the Episode Name.
minorList[('Episode', EpNo)] = DBInterface.list_of_keywords(Episode = EpNo)
# If we're populating the Filter Lists ...
if populateFilterList:
# ... Iterate through the keywords that were just added to the Minor List (only for this Key) ...
for (kwg, kw, ex) in minorList[(objType, EpNo)]:
# .. and IF they're not already in the list ...
if (kwg, kw, True) not in self.keywordFilterList:
# ... add them to the Keyword Filter List
self.keywordFilterList.append((kwg, kw, True))
## print "minorList:"
## for x in range(len(minorList)):
## print x, minorList[x]
## print
# If this report is called for a SearchCollectionResult, we build the majorList based on the contents of the Tree Control.
elif (self.searchColl != None) and (self.treeCtrl != None):
# Get the Search Result Name for the subtitle
searchResultNode = self.searchColl
# Start a loop to move up the tree. Keep going until interrupted.
while True:
# Move up to the Parent of the current node
searchResultNode = self.treeCtrl.GetItemParent(searchResultNode)
# Get the Data for the new node
tempData = self.treeCtrl.GetPyData(searchResultNode)
# If we are at the SearchResultsNode ...
if tempData.nodetype in ['SearchRootNode', 'SearchResultsNode']:
# ... we can stop moving up. Break the loop.
break
# Now build the subtitle
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Search Collection: %s"), 'utf8')
else:
prompt = _("Search Collection: %s")
self.subtitle = prompt % (self.treeCtrl.GetItemText(self.searchColl),)
# The majorLabel is for Clips in this case
majorLabel = _('Clip')
# Initialize the majorList to an empty list
majorList = []
# Extracting data from the treeCtrl requires a "cookie" value, which is initialized to 0
cookie = 0
# Get the first Child node from the searchColl collection
(item, cookie) = self.treeCtrl.GetFirstChild(self.searchColl)
# Create an empty list for Nested Collections so we can recurse through them
nestedCollections = []
# While looking at children, we need a pointer to the parent node
currentNode = self.searchColl
# Process all children in the searchColl collection
while item.IsOk():
# Get the item's Name
itemText = self.treeCtrl.GetItemText(item)
# Get the item's Node Data
itemData = self.treeCtrl.GetPyData(item)
# See if the item is a Clip
if itemData.nodetype in ['SearchQuoteNode', 'SearchClipNode', 'SearchSnapshotNode']:
if itemData.nodetype == 'SearchQuoteNode':
objType = 'Quote'
elif itemData.nodetype == 'SearchClipNode':
objType = 'Clip'
elif itemData.nodetype == 'SearchSnapshotNode':
objType = 'Snapshot'
# If it's a Clip, add the Clip's Node Data to the majorList
majorList.append((objType, itemData.recNum, itemText, itemData.parent))
# If we're populating the Filter List ...
if populateFilterList:
# If we have a Quote ...
if objType == 'Quote':
# ... add it to the regular Filter List
listToPopulate = self.quoteFilterList
# If we have a Clip ...
elif objType == 'Clip':
# ... add it to the regular Filter List
listToPopulate = self.filterList
# If we have a Snapshot ...
elif objType == 'Snapshot':
# ... add it to the Snapshot Filter List
listToPopulate = self.snapshotFilterList
# ... then add the Artifact data to the appropiate Filter List, initially checked ...
listToPopulate.append((itemText, itemData.parent, True))
# If we have a Collection Node ...
elif self.showNested and (itemData.nodetype == 'SearchCollectionNode'):
# ... add it to the list of nested Collections to be processed
nestedCollections.append(item)
# When we get to the last Child Item for the current node, ...
if item == self.treeCtrl.GetLastChild(currentNode):
# ... check to see if there are nested collections that need to be processed. If so ...
if len(nestedCollections) > 0:
# ... set the current node pointer to the first nested collection ...
currentNode = nestedCollections[0]
# ... get the first child node of the nested collection ...
(item, cookie) = self.treeCtrl.GetFirstChild(nestedCollections[0])
# ... and remove the nested collection from the list waiting to be processed
del(nestedCollections[0])
# If there are no nested collections to be processed ...
else:
# ... stop looping. We're done.
break
# If we're not at the Last Child Item ...
else:
# ... get the next Child Item and continue the loop
(item, cookie) = self.treeCtrl.GetNextChild(currentNode, cookie)
# Put all the Keywords for the Clips and Snapshots in the majorList in the minorList.
# Start by iterating through the Major List
for (objType, objNo, objName, collNo) in majorList:
# Create a Minor List dictionary entry, indexed to clip or snapshot number, for the keywords.
if objType == 'Quote':
minorList[(objType, objNo)] = DBInterface.list_of_keywords(Quote = objNo)
elif objType == 'Clip':
minorList[(objType, objNo)] = DBInterface.list_of_keywords(Clip = objNo)
elif objType == 'Snapshot':
minorList[(objType, objNo)] = DBInterface.list_of_keywords(Snapshot = objNo)
# If we're populating Filter Lists ...
if populateFilterList:
# ... and iterate through that clip's keywords or the snapshot's whole snapshot keywords ...
for (kwg, kw, ex) in minorList[(objType, objNo)]:
# ... check to see if the entry is NOT already in the list ...
if (kwg, kw, True) not in self.keywordFilterList:
# ... and add the keyword entry to the Keyword Filter List if it's not already there.
self.keywordFilterList.append((kwg, kw, True))
# If we have a Snapshot ...
if objType == 'Snapshot':
# ... get a list of the Snapshot's Detail Coding
tmpList = DBInterface.list_of_snapshot_detail_keywords(Snapshot = objNo)
# For each Keyword Group : Keyword pair ...
for (kwg, kw) in tmpList:
# ... check to see if the entry is NOT already in the list ...
if (kwg, kw, True) not in self.keywordFilterList:
# ... and add the keyword entry to the Keyword Filter List if it's not already there.
self.keywordFilterList.append((kwg, kw, True))
# ... add a subtitle
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Filter Configuration: %s"), 'utf8')
else:
prompt = _("Filter Configuration: %s")
# There's a problem in wxPython 2.8.12.0 on Windows. If you use too many format changes in too
# long a document, you run out of Windows GDI resources. This problem can be ameliorated (but not
# totally eliminated) by reducing the number of times BOLD text is used.
#
# So if we're on Windows and have more than 350 elements in the report, DON'T use BOLD as much!
# This flag is the signal.
useBold = True # not ((len(majorList) > 350) and ('wxMSW' in wx.PlatformInfo))
# If a subtitle is defined ...
if self.subtitle != '':
# ... set the subtitle font
reportText.SetTxtStyle(fontSize=12, fontBold=False, fontUnderline=False, parSpacingBefore = 0, parSpacingAfter = 0)
# Add the subtitle to the page
reportText.WriteText(self.subtitle + '\n')
# Finish the paragraph
# reportText.Newline()
if self.configName != '':
self.configLine = prompt % self.configName
# ... set the subtitle font
reportText.SetTxtStyle(fontSize=10, fontBold=False, fontUnderline=False, parSpacingBefore = 0, parSpacingAfter = 0)
# Add the subtitle to the page
reportText.WriteText(self.configLine + '\n')
# Initialize the initial data structure that will be turned into the report
self.data = []
# Create a Dictionary Data Structure to accumulate Keyword Counts
keywordCounts = {}
# Create a Dictionary Data Structure to accumulate Keyword Times
keywordTimes = {}
keywordLengths = {}
# Because Snapshot records are coded two different ways, we need to be able to keep track of what
# we've already counted in clipCount and ClipTotalTime so we don't count it twice.
self.itemsCounted = []
# The majorList and minorList are constructed differently for the Episode and Document versions of the report,
# and so the report must be built differently here too!
if (self.episodeName == None) and (self.documentName == None):
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
majorLabel = unicode(majorLabel, 'utf8')
# Let's keep track of the current collection name so we can tell when to print
# the Collection Header and Collection Notes if that's how the report is configured
# If we have a Collection-based Report ...
if (self.collection != None):
# ... put garbage into the workingCollection variable so it will trigger printing for the
# first Collection
workingCollection = ('NoCollectionString', 0)
# If we're not doing a Collection Report ...
else:
# Initialize workingCollection to an empty string, as we won't be using it.
workingCollection = ''
# If there are 20 or more items in the list, or at least 3 images ...
if (self.collection != None) and ((len(majorList) >= 20) or (len(self.snapshotFilterList) > 3)):
# ... create a Progress Dialog. (The PARENT is needed to prevent the report being hidden
# behind Transana!)
progress = wx.ProgressDialog(self.title, _('Assembling report contents'), parent=self.report)
# Iterate through the major list
for (objType, groupNo, group, parentCollNo) in majorList:
# If our majorLabel is Clip/Snapshot ...
if majorLabel.encode('utf8') in [_('Document'), _('Episode'), _('Clip'), _('Snapshot'), _('Quote')]:
# ... set the majorLabel to match the object type (but translated)
if objType == 'Document':
majorLabel = _('Document')
elif objType == 'Episode':
majorLabel = _('Episode')
elif objType == 'Clip':
majorLabel = _('Clip')
elif objType == 'Snapshot':
majorLabel = _('Snapshot')
elif objType == _('Quote'):
majorLabel = _('Quote')
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
majorLabel = unicode(majorLabel, 'utf8')
# If a Collection Name is passed in ...
if self.collection != None:
# ... then our Filter comparison is based on Clip data
filterVal = (group, parentCollNo, True)
# If a Library Name is passed in ...
elif self.seriesName != None:
# ... then our Filter comparison is based on Episode data
filterVal = (group, self.seriesName, True)
# If this report is called for a SearchLibraryResult ...
elif (self.searchSeries != None) and (self.treeCtrl != None):
# ... then our Filter comparison is based on the search Library from the TreeCtrl
filterVal = (group, self.treeCtrl.GetItemText(self.searchSeries), True)
# If this report is called for a SearchCollectionResult ...
elif (self.searchColl != None) and (self.treeCtrl != None):
# ... then our Filter comparison is based on Search Collection data
filterVal = (group, parentCollNo, True)
# now that we have the filter comparison data, we see if it's actually in the Filter List.
if ((objType == 'Document') and (filterVal in self.documentFilterList)) or \
((objType == 'Snapshot') and (filterVal in self.snapshotFilterList)) or \
((objType == 'Quote') and (filterVal in self.quoteFilterList)) or \
(filterVal in self.filterList):
# If we have Collection-based data ...
if (self.collection != None) or ((self.searchColl != None) and (self.treeCtrl != None)):
# ... load the collection the current clip is in
tempColl = Collection.Collection(parentCollNo)
# Check to see if we're showing Collection headers, if we're showing nested collections (since
# there's no point showing collection headers if there aren't different collections!), and
# see if the new collection is different from the collection of the last clip displayed.
if (workingCollection != '') and \
(self.showNested or self.showComments or self.showCollectionNotes) and \
(workingCollection[0] != tempColl.GetNodeString()):
# Format text for the next section of the report
reportText.SetTxtStyle(fontSize=12, fontBold=useBold, fontUnderline=False,
parAlign = wx.TEXT_ALIGNMENT_LEFT,
parLeftIndent = 0,
parSpacingBefore = 24, parSpacingAfter = 0)
# Add the Collections header and data to the report
reportText.WriteText(_('Collection: '))
# reportText.SetTxtStyle(fontBold=False)
reportText.WriteText('%s\n' % tempColl.GetNodeString())
# If we are supposed to show Comments ...
if self.showComments:
# ... if the collection has a comment ...
if tempColl.comment != u'':
# Set the font for the comments
reportText.SetTxtStyle(fontSize=10, fontBold=useBold, parLeftIndent=63, parRightIndent=63,