forked from sanyaade-machine-learning/Transana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DatabaseTreeTab.py
12350 lines (11270 loc) · 717 KB
/
DatabaseTreeTab.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 DatabaseTreeTab class for the Data Display Objects."""
__author__ = 'David Woods <[email protected]>, Nathaniel Case'
DEBUG = False
if DEBUG:
print "DatabaseTreeTab DEBUG is ON!!"
import wx
import TransanaConstants
import TransanaGlobal
import TransanaImages
import Library
import LibraryPropertiesForm
import Document
import Episode
import EpisodePropertiesForm
import Transcript
import TranscriptPropertiesForm
import Collection
import CollectionPropertiesForm
import Quote
import Clip
import Snapshot
import ClipPropertiesForm
if TransanaConstants.proVersion:
import DocumentPropertiesForm
import QuotePropertiesForm
import SnapshotPropertiesForm
import Note
import NotePropertiesForm
import NotesBrowser
import KeywordObject as Keyword
import KeywordPropertiesForm
import ClipKeywordObject
import BatchFileProcessor
import ProcessSearch
from TransanaExceptions import *
import KWManager
import exceptions
import DBInterface
import Dialogs
import NoteEditor
# import Python's datetime module
import datetime
import os
import sys
import string
import time
import LibraryMap
import KeywordMapClass
import ReportGenerator
import KeywordSummaryReport
import AnalyticDataExport
import PlayAllClips
import DragAndDropObjects # Implements Drag and Drop logic and objects
import cPickle # Used in Drag and Drop
import Misc # Transana's Miscellaneous functions
import PropagateChanges # Transana's Change Propagation routines
import MediaConvert
class DatabaseTreeTab(wx.Panel):
"""This class defines the object for the "Database" tab of the Data
window."""
def __init__(self, parent):
"""Initialize a DatabaseTreeTab object."""
self.parent = parent
psize = parent.GetSizeTuple()
width = psize[0] - 13
height = psize[1] - 45
self.ControlObject = None # The ControlObject handles all inter-object communication, initialized to None
# Use WANTS_CHARS style so the panel doesn't eat the Enter key.
wx.Panel.__init__(self, parent, -1, style=wx.WANTS_CHARS, size=(width, height), name='DatabaseTreeTabPanel')
mainSizer = wx.BoxSizer(wx.VERTICAL)
tID = wx.NewId()
self.tree = _DBTreeCtrl(self, tID, wx.DefaultPosition, self.GetSizeTuple(), wx.TR_HAS_BUTTONS | wx.TR_EDIT_LABELS | wx.TR_MULTIPLE)
mainSizer.Add(self.tree, 1, wx.EXPAND)
self.tree.UnselectAll()
self.tree.SelectItem(self.tree.GetRootItem())
self.SetSizer(mainSizer)
self.SetAutoLayout(True)
self.Layout()
def Register(self, ControlObject=None):
""" Register a ControlObject for the DataaseTreeTab to interact with. """
self.ControlObject=ControlObject
def add_series(self):
"""User interface for adding a new Library."""
# Create the Library Properties Dialog Box to Add a Library
dlg = LibraryPropertiesForm.AddLibraryDialog(self, -1)
# Set the "continue" flag to True (used to redisplay the dialog if an exception is raised)
contin = True
# While the "continue" flag is True ...
while contin:
# Use "try", as exceptions could occur
try:
# Display the Library Properties Dialog Box and get the data from the user
library = dlg.get_input()
# If the user pressed OK ...
if library != None:
# Try to save the data from the form
self.save_series(library)
nodeData = (_('Libraries'), library.id)
self.tree.add_Node('LibraryNode', nodeData, library.number, 0)
# Now let's communicate with other Transana instances if we're in Multi-user mode
if not TransanaConstants.singleUserVersion:
if DEBUG:
print 'Message to send = "AS %s"' % nodeData[-1]
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage("AS %s" % nodeData[-1])
# If we do all this, we don't need to continue any more.
contin = False
# If the user pressed Cancel ...
else:
# ... then we don't need to continue any more.
contin = False
# Handle "SaveError" exception
except SaveError:
# Display the Error Message, allow "continue" flag to remain true
errordlg = Dialogs.ErrorDialog(None, sys.exc_info()[1].reason)
errordlg.ShowModal()
errordlg.Destroy()
# Handle other exceptions
except:
if DEBUG:
import traceback
traceback.print_exc(file=sys.stdout)
# Display the Exception Message, allow "continue" flag to remain true
prompt = "%s : %s"
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(prompt, 'utf8')
errordlg = Dialogs.ErrorDialog(None, prompt % (sys.exc_info()[0],sys.exc_info()[1]))
errordlg.ShowModal()
errordlg.Destroy()
def edit_series(self, library):
"""User interface for editing a Library."""
# use "try", as exceptions could occur
try:
# Try to get a Record Lock
library.lock_record()
# Handle the exception if the record is locked
except RecordLockedError, e:
self.handle_locked_record(e, _('Libraries'), library.id)
# If the record is not locked, keep going.
else:
# Create the Library Properties Dialog Box to edit the Library Properties
dlg = LibraryPropertiesForm.EditLibraryDialog(self, -1, library)
# Set the "continue" flag to True (used to redisplay the dialog if an exception is raised)
contin = True
# Note the current tree node
sel = self.tree.GetSelections()[0]
# While the "continue" flag is True ...
while contin:
# if the user pressed "OK" ...
try:
# Display the Library Properties Dialog Box and get the data from the user
if dlg.get_input() != None:
# Save the Library
self.save_series(library)
# remember the node's original name
originalName = self.tree.GetItemText(sel)
# See if the Library ID has been changed. If it has, update the tree.
if library.id != originalName:
# Change the name of the current tree node
self.tree.SetItemText(sel, library.id)
# If we're in Multi-user mode, we need to send a message about the change.
if not TransanaConstants.singleUserVersion:
# Build the message. The first element is the node type, the second element is
# the UNTRANSLATED Root Node name in order to avoid problems in mixed-language environents.
# the last element is the new name.
msg = "%s >|< %s >|< %s >|< %s" % ('LibraryNode', 'Libraries', originalName, library.id)
if DEBUG:
if 'unicode' in wx.PlatformInfo:
print 'Message to send = "RN %s"' % msg.encode('utf_8')
else:
print 'Message to send = "RN %s"' % msg
# Send the message.
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage("RN %s" % msg)
# If we do all this, we don't need to continue any more.
contin = False
# If the user pressed Cancel ...
else:
# ... then we don't need to continue any more.
contin = False
# Handle "SaveError" exception
except SaveError:
# Display the Error Message, allow "continue" flag to remain true
errordlg = Dialogs.ErrorDialog(None, sys.exc_info()[1].reason)
errordlg.ShowModal()
errordlg.Destroy()
# Handle other exceptions
except:
if DEBUG:
import traceback
traceback.print_exc(file=sys.stdout)
# Display the Exception Message, allow "continue" flag to remain true
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Exception %s : %s"), 'utf8')
else:
prompt = _("Exception %s : %s")
errordlg = Dialogs.ErrorDialog(None, prompt % (sys.exc_info()[0], sys.exc_info()[1]))
errordlg.ShowModal()
errordlg.Destroy()
# Unlock the record regardless of what happens
library.unlock_record()
def save_series(self, library):
"""Save/Update the Library object."""
# FIXME: Graceful exception handling
if library != None:
library.db_save()
def add_document(self, library_name):
"""User interface for adding a new document."""
# Load the Library which contains the Document
library = Library.Library(library_name)
try:
# Lock the Library, to prevent it from being deleted out from under the add.
library.lock_record()
libraryLocked = True
# Handle the exception if the record is already locked by someone else
except RecordLockedError, s:
# If we can't get a lock on the Library, it's really not that big a deal. We only try to get it
# to prevent someone from deleting it out from under us, which is pretty unlikely. But we should
# still be able to add Documents even if someone else is editing the Library properties.
libraryLocked = False
# Create the Document Properties Dialog Box to Add a Document
dlg = DocumentPropertiesForm.AddDocumentDialog(self, -1, library)
# Set the "continue" flag to True (used to redisplay the dialog if an exception is raised)
contin = True
# While the "continue" flag is True ...
while contin:
# Use "try", as exceptions could occur
try:
# Display the Document Properties Dialog Box and get the data from the user
document = dlg.get_input()
# If the user pressed OK ...
if document != None:
# Try to save the data from the form
self.save_document(document)
nodeData = (_('Libraries'), library.id, document.id)
self.tree.add_Node('DocumentNode', nodeData, document.number, library.number)
# Now let's communicate with other Transana instances if we're in Multi-user mode
if not TransanaConstants.singleUserVersion:
if DEBUG:
print 'Message to send = "AD %s >|< %s"' % (nodeData[-2], nodeData[-1])
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage("AD %s >|< %s" % (nodeData[-2], nodeData[-1]))
# If we do all this, we don't need to continue any more.
contin = False
# Unlock the Library, if we locked it.
if libraryLocked:
library.unlock_record()
# Return the Document Name
return document.id
# If the user pressed Cancel ...
else:
# ... then we don't need to continue any more.
contin = False
# Unlock the Library, if we locked it.
if libraryLocked:
library.unlock_record()
# If no Document is created, indicate this.
return None
# Handle "SaveError" exception
except SaveError:
if DEBUG:
import traceback
traceback.print_exc(file=sys.stdout)
# Display the Error Message, allow "continue" flag to remain true
errordlg = Dialogs.ErrorDialog(None, sys.exc_info()[1].reason)
errordlg.ShowModal()
errordlg.Destroy()
# Refresh the Keyword List, if it's a changed Keyword error
dlg.refresh_keywords()
# Highlight the first non-existent keyword in the Keywords control
dlg.highlight_bad_keyword()
# Handle other exceptions
except:
if DEBUG:
import traceback
traceback.print_exc(file=sys.stdout)
# Display the Exception Message, allow "continue" flag to remain true
prompt = "%s : %s"
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(prompt, 'utf8')
errordlg = Dialogs.ErrorDialog(None, prompt % (sys.exc_info()[0], sys.exc_info()[1]))
errordlg.ShowModal()
errordlg.Destroy()
def edit_document(self, document):
"""User interface for editing a document."""
# If the user tries to edit a currently-loaded Document, close it first.
self.ControlObject.CloseOpenTranscriptWindowObject(Document.Document, document.number)
# This could have let to a change in the document object! We better re-load it just to be safe.
document.db_load_by_num(document.number)
# use "try", as exceptions could occur
try:
# Try to get a Record Lock
document.lock_record()
# Handle the exception if the record is already locked by someone else
except RecordLockedError, e:
self.handle_locked_record(e, _("Document"), document.id)
# If the record is not locked, keep going.
else:
# Create the Document Properties Dialog Box to edit the Document Properties
dlg = DocumentPropertiesForm.EditDocumentDialog(self, -1, document)
# Set the "continue" flag to True (used to redisplay the dialog if an exception is raised)
contin = True
# Note the original Tree Selection (Before calling up the Properties Form, which can interfere with this!)
sel = self.tree.GetSelections()[0]
# While the "continue" flag is True ...
while contin:
# if the user pressed "OK" ...
try:
# Display the Document Properties Dialog Box and get the data from the user
if dlg.get_input() != None:
# Check to see if there are keywords to be propagated
self.ControlObject.PropagateObjectKeywords(_('Document'), document.number, document.keyword_list)
# Try to save the Document
self.save_document(document)
# Note the original name of the tree node
originalName = self.tree.GetItemText(sel)
# See if the Document ID has been changed. If it has, update the tree.
if document.id != originalName:
# Rename the Tree node
self.tree.SetItemText(sel, document.id)
# If we're in the Multi-User mode, we need to send a message about the change
if not TransanaConstants.singleUserVersion:
# Begin constructing the message with the old and new names for the node
msg = " >|< %s >|< %s" % (originalName, document.id)
# Get the full Node Branch by climbing it to two levels above the root
while (self.tree.GetItemParent(self.tree.GetItemParent(sel)) != self.tree.GetRootItem()):
# Update the selected node indicator
sel = self.tree.GetItemParent(sel)
# Prepend the new Node's name on the Message with the appropriate seperator
msg = ' >|< ' + self.tree.GetItemText(sel) + msg
# The first parameter is the Node Type. The second one is the UNTRANSLATED root node.
# This must be untranslated to avoid problems in mixed-language environments.
# Prepend these on the Messsage
msg = "DocumentNode >|< Libraries" + msg
if DEBUG:
print 'Message to send = "RN %s"' % msg
# Send the Rename Node message
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage("RN %s" % msg)
# Now let's communicate with other Transana instances if we're in Multi-user mode
if not TransanaConstants.singleUserVersion:
msg = 'Document %d' % document.number
if DEBUG:
print 'Message to send = "UKL %s"' % msg
if TransanaGlobal.chatWindow != None:
# Send the "Update Keyword List" message
TransanaGlobal.chatWindow.SendMessage("UKL %s" % msg)
# If we do all this, we don't need to continue any more.
contin = False
# If the user pressed Cancel ...
else:
# ... then we don't need to continue any more.
contin = False
# Handle "SaveError" exception
except SaveError:
# Display the Error Message, allow "continue" flag to remain true
errordlg = Dialogs.ErrorDialog(None, sys.exc_info()[1].reason)
errordlg.ShowModal()
errordlg.Destroy()
# Refresh the Keyword List, if it's a changed Keyword error
dlg.refresh_keywords()
# Highlight the first non-existent keyword in the Keywords control
dlg.highlight_bad_keyword()
# Handle other exceptions
except:
if DEBUG:
import traceback
traceback.print_exc(file=sys.stdout)
# Display the Exception Message, allow "continue" flag to remain true
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Exception %s: %s"), 'utf8')
else:
prompt = _("Exception %s: %s")
errordlg = Dialogs.ErrorDialog(None, prompt % (sys.exc_info()[0], sys.exc_info()[1]))
errordlg.ShowModal()
errordlg.Destroy()
# Unlock the record regardless of what happens
document.unlock_record()
def save_document(self, document):
"""Save/Update the Document object."""
if document != None:
document.db_save()
def add_episode(self, library_name):
"""User interface for adding a new episode."""
# Load the Library which contains the Episode
library = Library.Library(library_name)
try:
# Lock the Library, to prevent it from being deleted out from under the add.
library.lock_record()
libraryLocked = True
# Handle the exception if the record is already locked by someone else
except RecordLockedError, s:
# If we can't get a lock on the Library, it's really not that big a deal. We only try to get it
# to prevent someone from deleting it out from under us, which is pretty unlikely. But we should
# still be able to add Episodes even if someone else is editing the Library properties.
libraryLocked = False
# Create the Episode Properties Dialog Box to Add an Episode
dlg = EpisodePropertiesForm.AddEpisodeDialog(self, -1, library)
# Set the "continue" flag to True (used to redisplay the dialog if an exception is raised)
contin = True
# While the "continue" flag is True ...
while contin:
# Use "try", as exceptions could occur
try:
# Display the Episode Properties Dialog Box and get the data from the user
episode = dlg.get_input()
# If the user pressed OK ...
if episode != None:
# Try to save the data from the form
self.save_episode(episode)
nodeData = (_('Libraries'), library.id, episode.id)
self.tree.add_Node('EpisodeNode', nodeData, episode.number, library.number)
# Now let's communicate with other Transana instances if we're in Multi-user mode
if not TransanaConstants.singleUserVersion:
if DEBUG:
print 'Message to send = "AE %s >|< %s"' % (nodeData[-2], nodeData[-1])
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage("AE %s >|< %s" % (nodeData[-2], nodeData[-1]))
# If we do all this, we don't need to continue any more.
contin = False
# Unlock the Library, if we locked it.
if libraryLocked:
library.unlock_record()
# Return the Episode Name so that the Transcript can be added to the proper Episode
return episode.id
# If the user pressed Cancel ...
else:
# ... then we don't need to continue any more.
contin = False
# Unlock the Library, if we locked it.
if libraryLocked:
library.unlock_record()
# If no Episode is created, indicate this so that no Transcript will be created.
return None
# Handle "SaveError" exception
except SaveError:
if DEBUG:
import traceback
traceback.print_exc(file=sys.stdout)
# Display the Error Message, allow "continue" flag to remain true
errordlg = Dialogs.ErrorDialog(None, sys.exc_info()[1].reason)
errordlg.ShowModal()
errordlg.Destroy()
# Refresh the Keyword List, if it's a changed Keyword error
dlg.refresh_keywords()
# Highlight the first non-existent keyword in the Keywords control
dlg.highlight_bad_keyword()
# Handle other exceptions
except:
if DEBUG:
import traceback
traceback.print_exc(file=sys.stdout)
# Display the Exception Message, allow "continue" flag to remain true
prompt = "%s : %s"
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(prompt, 'utf8')
errordlg = Dialogs.ErrorDialog(None, prompt % (sys.exc_info()[0], sys.exc_info()[1]))
errordlg.ShowModal()
errordlg.Destroy()
def edit_episode(self, episode):
"""User interface for editing an episode."""
# use "try", as exceptions could occur
try:
# Try to get a Record Lock
episode.lock_record()
# Handle the exception if the record is already locked by someone else
except RecordLockedError, e:
self.handle_locked_record(e, _("Episode"), episode.id)
# If the record is not locked, keep going.
else:
# Create the Episode Properties Dialog Box to edit the Episode Properties
dlg = EpisodePropertiesForm.EditEpisodeDialog(self, -1, episode)
# Set the "continue" flag to True (used to redisplay the dialog if an exception is raised)
contin = True
# Note the original Tree Selection
sel = self.tree.GetSelections()[0]
# While the "continue" flag is True ...
while contin:
# if the user pressed "OK" ...
try:
# Display the Episode Properties Dialog Box and get the data from the user
if dlg.get_input() != None:
# Check to see if there are keywords to be propagated
self.ControlObject.PropagateObjectKeywords(_('Episode'), episode.number, episode.keyword_list)
# Try to save the Episode
self.save_episode(episode)
# Note the original name of the tree node
originalName = self.tree.GetItemText(sel)
# See if the Episode ID has been changed. If it has, update the tree.
if episode.id != originalName:
# Rename the Tree node
self.tree.SetItemText(sel, episode.id)
# If we're in the Multi-User mode, we need to send a message about the change
if not TransanaConstants.singleUserVersion:
# Begin constructing the message with the old and new names for the node
msg = " >|< %s >|< %s" % (originalName, episode.id)
# Get the full Node Branch by climbing it to two levels above the root
while (self.tree.GetItemParent(self.tree.GetItemParent(sel)) != self.tree.GetRootItem()):
# Update the selected node indicator
sel = self.tree.GetItemParent(sel)
# Prepend the new Node's name on the Message with the appropriate seperator
msg = ' >|< ' + self.tree.GetItemText(sel) + msg
# The first parameter is the Node Type. The second one is the UNTRANSLATED root node.
# This must be untranslated to avoid problems in mixed-language environments.
# Prepend these on the Messsage
msg = "EpisodeNode >|< Libraries" + msg
if DEBUG:
print 'Message to send = "RN %s"' % msg
# Send the Rename Node message
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage("RN %s" % msg)
# Now let's communicate with other Transana instances if we're in Multi-user mode
if not TransanaConstants.singleUserVersion:
msg = 'Episode %d' % episode.number
if DEBUG:
print 'Message to send = "UKL %s"' % msg
if TransanaGlobal.chatWindow != None:
# Send the "Update Keyword List" message
TransanaGlobal.chatWindow.SendMessage("UKL %s" % msg)
# If we do all this, we don't need to continue any more.
contin = False
# If the user pressed Cancel ...
else:
# ... then we don't need to continue any more.
contin = False
# Handle "SaveError" exception
except SaveError:
# Display the Error Message, allow "continue" flag to remain true
errordlg = Dialogs.ErrorDialog(None, sys.exc_info()[1].reason)
errordlg.ShowModal()
errordlg.Destroy()
# Refresh the Keyword List, if it's a changed Keyword error
dlg.refresh_keywords()
# Highlight the first non-existent keyword in the Keywords control
dlg.highlight_bad_keyword()
# Handle other exceptions
except:
if DEBUG:
import traceback
traceback.print_exc(file=sys.stdout)
# Display the Exception Message, allow "continue" flag to remain true
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Exception %s: %s"), 'utf8')
else:
prompt = _("Exception %s: %s")
errordlg = Dialogs.ErrorDialog(None, prompt % (sys.exc_info()[0], sys.exc_info()[1]))
errordlg.ShowModal()
errordlg.Destroy()
# Unlock the record regardless of what happens
episode.unlock_record()
def save_episode(self, episode):
"""Save/Update the Episode object."""
# FIXME: Graceful exception handling
if episode != None:
episode.db_save()
def add_transcript(self, library_name, episode_name):
"""User interface for adding a new transcript."""
# Load the Episode Object that parents the Transcript
episode = Episode.Episode(series=library_name, episode=episode_name)
try:
# Lock the Episode, to prevent it from being deleted out from under the add.
episode.lock_record()
episodeLocked = True
# Handle the exception if the record is already locked by someone else
except RecordLockedError, e:
# If we can't get a lock on the Episode, it's really not that big a deal. We only try to get it
# to prevent someone from deleting it out from under us, which is pretty unlikely. But we should
# still be able to add Transcripts even if someone else is editing the Episode properties.
episodeLocked = False
# Create the Transcript Properties Dialog Box to Add a Trancript
dlg = TranscriptPropertiesForm.AddTranscriptDialog(self, -1, episode)
# Set the "continue" flag to True (used to redisplay the dialog if an exception is raised)
contin = True
# While the "continue" flag is True ...
while contin:
# Use "try", as exceptions could occur
try:
# Display the Transcript Properties Dialog Box and get the data from the user
transcript = dlg.get_input()
# If the user pressed OK ...
if transcript != None:
# Try to save the data from the form
self.save_transcript(transcript)
nodeData = (_('Libraries'), library_name, episode_name, transcript.id)
self.tree.add_Node('TranscriptNode', nodeData, transcript.number, episode.number)
# Now let's communicate with other Transana instances if we're in Multi-user mode
if not TransanaConstants.singleUserVersion:
if DEBUG:
print 'Message to send = "AT %s >|< %s >|< %s"' % (nodeData[-3], nodeData[-2], nodeData[-1])
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage("AT %s >|< %s >|< %s" % (nodeData[-3], nodeData[-2], nodeData[-1]))
# If we do all this, we don't need to continue any more.
contin = False
# Unlock the record
if episodeLocked:
episode.unlock_record()
# Note the original Tree Selection
sel = self.tree.GetSelections()[0]
# Sort the Transcript Node
self.tree.SortChildren(sel)
# return the Transcript ID so that it can be loaded
return transcript.id
# If the user pressed Cancel ...
else:
# ... then we don't need to continue any more.
contin = False
# Unlock the record
if episodeLocked:
episode.unlock_record()
# Returning None signals that the user cancelled, so no Transcript can be loaded.
return None
# Handle "SaveError" exception
except SaveError:
# Display the Error Message, allow "continue" flag to remain true
errordlg = Dialogs.ErrorDialog(None, sys.exc_info()[1].reason)
errordlg.ShowModal()
errordlg.Destroy()
# Handle other exceptions
except:
# Display the Exception Message, allow "continue" flag to remain true
prompt = "%s\n%s"
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(prompt, 'utf8')
errordlg = Dialogs.ErrorDialog(None, prompt % sys.exc_info()[:2])
errordlg.ShowModal()
errordlg.Destroy()
def edit_transcript(self, transcript):
"""User interface for editing a transcript."""
# use "try", as exceptions could occur
try:
## # If the user tries to edit the currently-loaded Transcript ...
## if (transcript.number in self.ControlObject.TranscriptNum.keys()):
## # Bring the Transcript Window to the front
## self.ControlObject.BringTranscriptToFront()
## # ... first clear all the windows ...
## self.ControlObject.ClearAllWindows()
## # ... then reload the transcript in case it got changed (saved) during the ClearAllWindows call.
## transcript.db_load_by_num(transcript.number)
# If the user tries to edit a currently-loaded Transcript, close it first.
self.ControlObject.CloseOpenTranscriptWindowObject(Transcript.Transcript, transcript.number)
# This could have let to a change in the transcript object! We better re-load it just to be safe.
transcript.db_load_by_num(transcript.number)
# Try to get a Record Lock.
transcript.lock_record()
# If the record is not locked, keep going.
# Create the Transcript Properties Dialog Box to edit the Transcript Properties
dlg = TranscriptPropertiesForm.EditTranscriptDialog(self, -1, transcript)
# Set the "continue" flag to True (used to redisplay the dialog if an exception is raised)
contin = True
# Note the original Tree Selection
sel = self.tree.GetSelections()[0]
# While the "continue" flag is True ...
while contin:
# if the user pressed "OK" ...
try:
# Display the Transcript Properties Dialog Box and get the data from the user
if dlg.get_input() != None:
self.save_transcript(transcript)
# See if this affects the currently loaded
# Transcript, in which case we have to re-load the
# transcript if a new one was imported.
if transcript.number in self.ControlObject.TranscriptNum.keys():
self.ControlObject.LoadTranscript(transcript.series_id, transcript.episode_id, transcript.number)
# Note the original name of the tree node
originalName = self.tree.GetItemText(sel)
# See if the Transcript ID has been changed. If it has, update the tree.
if transcript.id != originalName:
# Rename the Tree node
self.tree.SetItemText(sel, transcript.id)
# If we're in the Multi-User mode, we need to send a message about the change
if not TransanaConstants.singleUserVersion:
# Begin constructing the message with the old and new names for the node
msg = " >|< %s >|< %s" % (originalName, transcript.id)
# Get the full Node Branch by climbing it to two levels above the root
while (self.tree.GetItemParent(self.tree.GetItemParent(sel)) != self.tree.GetRootItem()):
# Update the selected node indicator
sel = self.tree.GetItemParent(sel)
# Prepend the new Node's name on the Message with the appropriate seperator
msg = ' >|< ' + self.tree.GetItemText(sel) + msg
# The first parameter is the Node Type. The second one is the UNTRANSLATED root node.
# This must be untranslated to avoid problems in mixed-language environments.
# Prepend these on the Messsage
msg = "TranscriptNode >|< Libraries" + msg
if DEBUG:
print 'Message to send = "RN %s"' % msg
# Send the Rename Node message
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage("RN %s" % msg)
# If we do all this, we don't need to continue any more.
contin = False
# If the user pressed Cancel ...
else:
# ... then we don't need to continue any more.
contin = False
# Handle "SaveError" exception
except SaveError:
# Display the Error Message, allow "continue" flag to remain true
errordlg = Dialogs.ErrorDialog(None, sys.exc_info()[1].reason)
errordlg.ShowModal()
errordlg.Destroy()
import traceback
traceback.print_exc(file=sys.stdout)
# Handle other exceptions
except:
if DEBUG:
import traceback
traceback.print_exc(file=sys.stdout)
# Display the Exception Message, allow "continue" flag to remain true
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Exception %s: %s"), 'utf8')
else:
prompt = _("Exception %s: %s")
errordlg = Dialogs.ErrorDialog(None, prompt % (sys.exc_info()[0], sys.exc_info()[1]))
errordlg.ShowModal()
errordlg.Destroy()
import traceback
traceback.print_exc(file=sys.stdout)
# Unlock the record regardless of what happens
transcript.unlock_record()
# Handle the exception if the record is locked
except RecordLockedError, e:
self.handle_locked_record(e, _("Transcript"), transcript.id)
def save_transcript(self, transcript):
"""Save/Update the Transcript object."""
# FIXME: Graceful exception handling
if transcript != None:
transcript.db_save()
def add_collection(self, ParentNum):
"""User interface for adding a new collection."""
# If we're adding a nested Collection, we should lock the parent Collection
if ParentNum > 0:
# Get the Parent Collection
collection = Collection.Collection(ParentNum)
try:
# Lock the Collectoin, to prevent it from being deleted out from under the add.
collection.lock_record()
collectionLocked = True
# Handle the exception if the record is already locked by someone else
except RecordLockedError, c:
# If we can't get a lock on the Collection, it's really not that big a deal. We only try to get it
# to prevent someone from deleting it out from under us, which is pretty unlikely. But we should
# still be able to add Nested Collections even if someone else is editing the Collection properties.
collectionLocked = False
else:
collectionLocked = False
# Create the Collection Properties Dialog Box to Add a Collection
dlg = CollectionPropertiesForm.AddCollectionDialog(self, -1, ParentNum)
# Set the "continue" flag to True (used to redisplay the dialog if an exception is raised)
contin = True
# While the "continue" flag is True ...
while contin:
# Use "try", as exceptions could occur
try:
# Display the Collection Properties Dialog Box and get the data from the user
coll = dlg.get_input()
# If the user pressed OK ...
if coll != None:
# Try to save the data from the form
self.save_collection(coll)
nodeData = (_('Collections'),) + coll.GetNodeData()
# Add the new Collection to the data tree
self.tree.add_Node('CollectionNode', nodeData, coll.number, coll.parent)
# Now let's communicate with other Transana instances if we're in Multi-user mode
if not TransanaConstants.singleUserVersion:
msg = "AC %s"
data = (nodeData[1],)
for nd in nodeData[2:]:
msg += " >|< %s"
data += (nd, )
if DEBUG:
print 'Message to send =', msg % data
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage(msg % data)
# Unlock the parent collection
if collectionLocked:
collection.unlock_record()
# If we do all this, we don't need to continue any more.
contin = False
# If the user pressed Cancel ...
else:
# Unlock the parent collection
if collectionLocked:
collection.unlock_record()
# ... then we don't need to continue any more.
contin = False
# Note the original Tree Selection
sel = self.tree.GetSelections()[0]
# Sort the Collection Node
self.tree.SortChildren(sel)
# Handle "SaveError" exception
except SaveError:
# Display the Error Message, allow "continue" flag to remain true
errordlg = Dialogs.ErrorDialog(None, sys.exc_info()[1].reason)
errordlg.ShowModal()
errordlg.Destroy()
# Handle other exceptions
except:
if DEBUG:
import traceback
traceback.print_exc(file=sys.stdout)
# Display the Exception Message, allow "continue" flag to remain true
prompt = "%s : %s"
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(prompt, 'utf8')
errordlg = Dialogs.ErrorDialog(None, prompt % (sys.exc_info()[0], sys.exc_info()[1]))
errordlg.ShowModal()
errordlg.Destroy()
def edit_collection(self, coll):
"""User interface for editing a collection."""
# Assume failure unless proven otherwise
success = False
# Okay, when we're converting a Search Result to a Collection, we create a Collection named after the Search Results
# and then use this routine. That works well, except if there's a duplicate Collection ID in the Multi-user version,
# the other client's collection will get renamed rather than the new collection being added. Therefore, we need to
# detect that this is what's going on and avoid that problem. The following line detects that, as the Search Results
# collection hasn't actually been saved yet.
if coll.number == 0:
fakeEdit = True
else:
fakeEdit = False
# use "try", as exceptions could occur
try:
# Try to get a Record Lock
coll.lock_record()
# Handle the exception if the record is locked
except RecordLockedError, e:
self.handle_locked_record(e, _("Collection"), coll.id)
# If the record is not locked, keep going.
else:
# Create the Collection Properties Dialog Box to edit the Collection Properties
dlg = CollectionPropertiesForm.EditCollectionDialog(self, -1, coll)
# Set the "continue" flag to True (used to redisplay the dialog if an exception is raised)
contin = True
# Note the original Tree Selection
sel = self.tree.GetSelections()[0]
# While the "continue" flag is True ...
while contin:
# if the user pressed "OK" ...
try:
# Display the Collection Properties Dialog Box and get the data from the user
if dlg.get_input() != None:
# try to save the Collection
self.save_collection(coll)
# Note the original name of the tree node
originalName = self.tree.GetItemText(sel)
# See if the Collection ID has been changed. If it has, update the tree.
# That is, unless this is a Search Result conversion, as signalled by fakeEdit.
if (coll.id != originalName) and (not fakeEdit):
# Rename the Tree node
self.tree.SetItemText(sel, coll.id)
# If we're in the Multi-User mode, we need to send a message about the change
if not TransanaConstants.singleUserVersion:
# Begin constructing the message with the old and new names for the node
msg = " >|< %s >|< %s" % (originalName, coll.id)
# Get the full Node Branch by climbing it to two levels above the root
while (self.tree.GetItemParent(self.tree.GetItemParent(sel)) != self.tree.GetRootItem()):
# Update the selected node indicator
sel = self.tree.GetItemParent(sel)
# Prepend the new Node's name on the Message with the appropriate seperator
msg = ' >|< ' + self.tree.GetItemText(sel) + msg
# The first parameter is the Node Type. The second one is the UNTRANSLATED root node.
# This must be untranslated to avoid problems in mixed-language environments.
# Prepend these on the Messsage
msg = "CollectionNode >|< Collections" + msg
if DEBUG:
print 'Message to send = "RN %s"' % msg
# Send the Rename Node message
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage("RN %s" % msg)
# If we get here, the save worked!
success = True
# If we do all this, we don't need to continue any more.
contin = False
# If the user pressed Cancel ...
else:
# ... then we don't need to continue any more.
contin = False
# Handle "SaveError" exception
except SaveError:
# Display the Error Message, allow "continue" flag to remain true
errordlg = Dialogs.ErrorDialog(None, sys.exc_info()[1].reason)
errordlg.ShowModal()
errordlg.Destroy()
# Handle other exceptions
except:
if DEBUG:
import traceback
traceback.print_exc(file=sys.stdout)
# Display the Exception Message, allow "continue" flag to remain true
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Exception %s: %s"), 'utf8')
else:
prompt = _("Exception %s: %s")
errordlg = Dialogs.ErrorDialog(None, prompt % (sys.exc_info()[0], sys.exc_info()[1]))
errordlg.ShowModal()
errordlg.Destroy()
# Unlock the record regardless of what happens
coll.unlock_record()
# Return the "success" indicator to the calling routine
return success
def save_collection(self, collection):
"""Save/Update the Collection object."""
# FIXME: Graceful exception handling
if collection != None:
collection.db_save()