forked from sanyaade-machine-learning/Transana
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDragAndDropObjects.py
More file actions
6270 lines (5818 loc) · 373 KB
/
Copy pathDragAndDropObjects.py
File metadata and controls
6270 lines (5818 loc) · 373 KB
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 objects that are used in Drag-and-Drop and Cut-andPaste functions. <BR><BR>
DragAndDropObjects is made up of the following:<BR><BR>
DragDropEvaluation(source, destination) -- A Boolean FUNCTION that indicates whether the specified
source object, a DatabaseTreeTab Node, can be legally dropped on the destination, another
DatabaseTreeTab Node. This is implemented as a function because it is used in the DropSource's
GiveFeedback method and in the DropTarget's OnData method.<BR><BR>
DataTreeDragDropData -- a Python Object that contains the data that is encapsulated in a
DatabaseTreeTab Node. This encapsulates the essential information for what is being dragged.<BR><BR>
DataTreeDropSource -- an Object derived from wxDropSource. It is implemented in such a way as to
provide visual feedback to the user to indicate whether a proposed Drop is legal or not.<BR><BR>
DataTreeDropTarget -- an Object derived from wxDropTarget. It is designed to handle data drops on
the DatabaseTreeTab.<BR><BR>
ClipDragDropData -- a Python Object that contains the data that is needed for creating a Clip
by dragging text (and other information) from the Transcript to the Database Tree.<BR><BR>
ProcessPasteDrop(treeCtrl, sourceData, destNode, action): -- a method that processes a Paste or
Drop request. It is a stand-alone method so that as much logic as possible can be shared by
Drag-and-Drop routines and Cut-and-Paste routines.<BR><BR>
CopyMoveClip(treeCtrl, destNode, sourceClip, sourceCollection, destCollection, action): -- a method
used by ProcessPasteDrop to implement the copy and move operations for Clips. It is a stand-alone
method to allow code reuse between several different methods of copying and moving clips.<BR><BR>
ChangeClipOrder(treeCtrl, destNode, sourceClip, sourceCollection): -- a method used by
ProcessPasteDrop to implement the altering of Clip Sort Order when desired. It is a stand-alone
method to allow code resuse by several different methods related to dropping and pasting clips.
CreateQuickClip(clipData, kwg, kw, dbTree): -- a method used to implement Open Coding via Quick Clips. """
__author__ = 'David Woods <dwoods@wcer.wisc.edu>'
DEBUG = False
if DEBUG:
print "DragAndDropObjects DEBUG is ON!!"
import wx # Import wxPython
import cPickle # use Python's fast cPickle tool instead of the regular Pickle
import sys # import Python's sys module
import DBInterface # Import Transana's Database Interface
import Library # Import the Transana Library object
import Document # Import the Transana Document object
import Episode # Import the Transana Episode Object
import Transcript # Import the Transana Transcript Object
import Collection # Import the Transana Collection Object
import Quote # Import the Transana Quote Object
import Clip # Import the Transana Clip Object
import Snapshot # Import the Transana Snapshot Object
import Note # Import the Transana Note Object
import ClipPropertiesForm # Import the Transana Clip Properties Form for adding Clips on Transcript Text Drop
import QuotePropertiesForm # Import the Transana Quote Properties Form for adding Quotes on Document Text Drop
import KeywordObject as Keyword # Import the Transana Keyword Object
import KeywordPropertiesForm # Import the Trasnana Keyword Properties Form for adding Keywords on Transcript Text Drop
import DatabaseTreeTab # Import the Transana Database Tree Tab Object (for setting _NodeData in manipulating the tree)
import Misc # Import the Transana Miscellaneous routines
import Dialogs # Import the Transana Dialog Boxes
import TransanaConstants # Import the Transana Constants
import TransanaGlobal # Import Transana's Globals
import TransanaExceptions # Import Transana's Exceptions
# initialize a GLOBAL variable called YESTOALL to handle cross-object communication required for Copy / Move requests
YESTOALL = False
def DragDropEvaluation(source, destination):
""" This boolean function indicates whether the source tree node can legally be dropped (or pasted) on the destination
tree node. This function is encapsulated because it needs to be called from several different locations
during the Drag-and-Drop process, including the DropSource's GiveFeedback() Method and the DropTarget's
OnData() Method, as well as the DBTree's OnRightClick() to enable or disable the "Paste" option. """
if DEBUG:
print "DragDropEvaluation():"
print source
print destination
print
# If the SOURCE data is not a list but IS a CLIP ...
if (not isinstance(source, list)) and (source.nodetype == 'ClipNode'):
# Start exception handling
try:
# Try to load the Clip to know that it hasn't been deleted after a COPY.
# (Trying to paste a clip that's been deleted can trash the database!)
# Don't load the Clip Transcript to save time.
tmpClip = Clip.Clip(source.recNum, skipText=True)
# If the clips does not exist ...
except:
# ... then we can't PASTE it, can we?
return False
# Return True if the drop is legal, false if it is not.
# To be legal, we must have a legitimate source and be on a legitimate drop target.
# If the source is the Database Tree Tab (nodetype = DataTreeDragDropData), then we compare
# the nodetypes for the source and destination nodes to see if the pairing is compatible.
# Next, either the record numbers or the nodetype must be different, so you can't drop a node on itself.
if (source != None) and \
(destination != None) and \
(not isinstance(source, ClipDragDropData)) and \
(not isinstance(source, QuoteDragDropData)) and \
(not isinstance(source, list)) and \
((source.nodetype == 'DocumentNode' and destination.nodetype == 'LibraryNode' and source.parent != destination.recNum) or \
(source.nodetype == 'EpisodeNode' and destination.nodetype == 'LibraryNode' and source.parent != destination.recNum) or \
(source.nodetype == 'CollectionNode' and destination.nodetype == 'CollectionNode' and source.parent != destination.recNum) or \
(source.nodetype == 'CollectionNode' and destination.nodetype == 'CollectionsRootNode' and source.parent != 0) or \
(source.nodetype == 'QuoteNode' and destination.nodetype == 'CollectionNode' and source.parent != destination.recNum) or \
(source.nodetype == 'QuoteNode' and destination.nodetype == 'QuoteNode') or \
(source.nodetype == 'QuoteNode' and destination.nodetype == 'ClipNode') or \
(source.nodetype == 'QuoteNode' and destination.nodetype == 'SnapshotNode') or \
(source.nodetype == 'ClipNode' and destination.nodetype == 'CollectionNode' and source.parent != destination.recNum) or \
(source.nodetype == 'ClipNode' and destination.nodetype == 'QuoteNode') or \
(source.nodetype == 'ClipNode' and destination.nodetype == 'ClipNode') or \
(source.nodetype == 'ClipNode' and destination.nodetype == 'SnapshotNode') or \
(source.nodetype == 'ClipNode' and destination.nodetype == 'KeywordNode') or \
(source.nodetype == 'SnapshotNode' and destination.nodetype == 'CollectionNode' and source.parent != destination.recNum) or \
(source.nodetype == 'SnapshotNode' and destination.nodetype == 'QuoteNode') or \
(source.nodetype == 'SnapshotNode' and destination.nodetype == 'ClipNode') or \
(source.nodetype == 'SnapshotNode' and destination.nodetype == 'SnapshotNode') or \
(source.nodetype == 'KeywordNode' and destination.nodetype == 'LibraryNode') or \
(source.nodetype == 'KeywordNode' and destination.nodetype == 'DocumentNode') or \
(source.nodetype == 'KeywordNode' and destination.nodetype == 'EpisodeNode') or \
(source.nodetype == 'KeywordNode' and destination.nodetype == 'CollectionNode') or \
(source.nodetype == 'KeywordNode' and destination.nodetype == 'QuoteNode') or \
(source.nodetype == 'KeywordNode' and destination.nodetype == 'ClipNode') or \
(source.nodetype == 'KeywordNode' and destination.nodetype == 'SnapshotNode') or \
(source.nodetype == 'KeywordNode' and destination.nodetype == 'KeywordGroupNode') or \
(source.nodetype == 'LibraryNoteNode' and destination.nodetype == 'LibraryNode') or \
(source.nodetype == 'DocumentNoteNode' and destination.nodetype == 'DocumentNode') or \
(source.nodetype == 'EpisodeNoteNode' and destination.nodetype == 'EpisodeNode') or \
(source.nodetype == 'TranscriptNoteNode' and destination.nodetype == 'TranscriptNode') or \
(source.nodetype == 'CollectionNoteNode' and destination.nodetype == 'CollectionNode') or \
(source.nodetype == 'QuoteNoteNode' and destination.nodetype == 'QuoteNode') or \
(source.nodetype == 'ClipNoteNode' and destination.nodetype == 'ClipNode') or \
(source.nodetype == 'SnapshotNoteNode' and destination.nodetype == 'SnapshotNode') or \
(source.nodetype == 'SearchCollectionNode' and destination.nodetype == 'SearchResultsNode') or \
(source.nodetype == 'SearchCollectionNode' and destination.nodetype == 'SearchCollectionNode' and source.parent != destination.recNum) or \
(source.nodetype == 'SearchQuoteNode' and destination.nodetype == 'SearchCollectionNode' and source.parent != destination.recNum) or \
(source.nodetype == 'SearchQuoteNode' and destination.nodetype == 'SearchQuoteNode') or \
(source.nodetype == 'SearchQuoteNode' and destination.nodetype == 'SearchClipNode') or \
(source.nodetype == 'SearchQuoteNode' and destination.nodetype == 'SearchSnapshotNode') or \
(source.nodetype == 'SearchClipNode' and destination.nodetype == 'SearchCollectionNode' and source.parent != destination.recNum) or \
(source.nodetype == 'SearchClipNode' and destination.nodetype == 'SearchQuoteNode') or \
(source.nodetype == 'SearchClipNode' and destination.nodetype == 'SearchClipNode') or \
(source.nodetype == 'SearchClipNode' and destination.nodetype == 'SearchSnapshotNode') or \
(source.nodetype == 'SearchSnapshotNode' and destination.nodetype == 'SearchCollectionNode' and source.parent != destination.recNum) or \
(source.nodetype == 'SearchSnapshotNode' and destination.nodetype == 'SearchQuoteNode') or \
(source.nodetype == 'SearchSnapshotNode' and destination.nodetype == 'SearchClipNode') or \
(source.nodetype == 'SearchSnapshotNode' and destination.nodetype == 'SearchSnapshotNode')) and \
((source.recNum != destination.recNum) or (source.nodetype != destination.nodetype)):
return True
# If we have a Clip Creation Object (dragged transcript text, type == ClipDragDropData),
# or we have a Quote Creation Object (dragged document text, type === QuoteDragDropData),
# then we can drop it on a Collection or a Quote or a Clip or a Keyword only.
elif (source != None) and \
(destination != None) and \
((isinstance(source, ClipDragDropData)) or (isinstance(source, QuoteDragDropData))) and \
((destination.nodetype == 'CollectionNode') or \
(destination.nodetype == 'QuoteNode') or \
(destination.nodetype == 'ClipNode') or \
(destination.nodetype == 'KeywordNode')):
return True
# If the source data is a LIST, we have multiple selections!
elif (source != None) and \
(destination != None) and \
(isinstance(source, list)) and \
((source[0].nodetype == 'DocumentNode' and destination.nodetype == 'LibraryNode') or \
(source[0].nodetype == 'EpisodeNode' and destination.nodetype == 'LibraryNode') or \
(source[0].nodetype == 'QuoteNode' and destination.nodetype == 'CollectionNode') or \
(source[0].nodetype == 'QuoteNode' and destination.nodetype == 'QuoteNode') or \
(source[0].nodetype == 'QuoteNode' and destination.nodetype == 'ClipNode') or \
(source[0].nodetype == 'QuoteNode' and destination.nodetype == 'SnapshotNode') or \
(source[0].nodetype == 'ClipNode' and destination.nodetype == 'CollectionNode') or \
(source[0].nodetype == 'ClipNode' and destination.nodetype == 'QuoteNode') or \
(source[0].nodetype == 'ClipNode' and destination.nodetype == 'ClipNode') or \
(source[0].nodetype == 'ClipNode' and destination.nodetype == 'SnapshotNode') or \
(source[0].nodetype == 'SnapshotNode' and destination.nodetype == 'CollectionNode') or \
(source[0].nodetype == 'SnapshotNode' and destination.nodetype == 'QuoteNode') or \
(source[0].nodetype == 'SnapshotNode' and destination.nodetype == 'ClipNode') or \
(source[0].nodetype == 'SnapshotNode' and destination.nodetype == 'SnapshotNode') or \
(source[0].nodetype == 'KeywordNode' and destination.nodetype == 'LibraryNode') or \
(source[0].nodetype == 'KeywordNode' and destination.nodetype == 'DocumentNode') or \
(source[0].nodetype == 'KeywordNode' and destination.nodetype == 'EpisodeNode') or \
(source[0].nodetype == 'KeywordNode' and destination.nodetype == 'CollectionNode') or \
(source[0].nodetype == 'KeywordNode' and destination.nodetype == 'QuoteNode') or \
(source[0].nodetype == 'KeywordNode' and destination.nodetype == 'ClipNode') or \
(source[0].nodetype == 'KeywordNode' and destination.nodetype == 'SnapshotNode') or \
(source[0].nodetype == 'KeywordNode' and destination.nodetype == 'KeywordGroupNode') or \
(source[0].nodetype == 'LibraryNoteNode' and destination.nodetype == 'LibraryNode') or \
(source[0].nodetype == 'DocumentNoteNode' and destination.nodetype == 'DocumentNode') or \
(source[0].nodetype == 'EpisodeNoteNode' and destination.nodetype == 'EpisodeNode') or \
(source[0].nodetype == 'TranscriptNoteNode' and destination.nodetype == 'TranscriptNode') or \
(source[0].nodetype == 'CollectionNoteNode' and destination.nodetype == 'CollectionNode') or \
(source[0].nodetype == 'QuoteNoteNode' and destination.nodetype == 'QuoteNode') or \
(source[0].nodetype == 'ClipNoteNode' and destination.nodetype == 'ClipNode') or \
(source[0].nodetype == 'SearchQuoteNode' and destination.nodetype == 'SearchCollectionNode') or \
(source[0].nodetype == 'SearchQuoteNode' and destination.nodetype == 'SearchQuoteNode') or \
(source[0].nodetype == 'SearchQuoteNode' and destination.nodetype == 'SearchClipNode') or \
(source[0].nodetype == 'SearchQuoteNode' and destination.nodetype == 'SearchSnapshotNode') or \
(source[0].nodetype == 'SearchClipNode' and destination.nodetype == 'SearchCollectionNode') or \
(source[0].nodetype == 'SearchClipNode' and destination.nodetype == 'SearchQuoteNode') or \
(source[0].nodetype == 'SearchClipNode' and destination.nodetype == 'SearchClipNode') or \
(source[0].nodetype == 'SearchClipNode' and destination.nodetype == 'SearchSnapshotNode') or \
(source[0].nodetype == 'SearchSnapshotNode' and destination.nodetype == 'SearchCollectionNode') or \
(source[0].nodetype == 'SearchSnapshotNode' and destination.nodetype == 'SearchQuoteNode') or \
(source[0].nodetype == 'SearchSnapshotNode' and destination.nodetype == 'SearchClipNode') or \
(source[0].nodetype == 'SearchSnapshotNode' and destination.nodetype == 'SearchSnapshotNode')):
# Assume success
result = True
# Iterate through the source list
for src in source:
# Check to see if the destination node is IN the source list. (NODETYPES MUST MATCH TOO!! recNums aren't enough.)
if ((src.recNum == destination.recNum) and (source[0].nodetype == destination.nodetype)) and \
(src.recNum != 0):
# If so, the evaluation FAILS
result = False
# ... and we can stop looking
break
# return the result
return result
else:
return False
class DataTreeDragDropData(object):
""" This is a custom DragDropData object. It allows the drag to "carry" the information from a node
from the Database Tree Control. """
# NOTE: _NodeType and DataTreeDragDropData have very similar structures so that they can be
# used interchangably. If you alter one, please also alter the other.
def __init__(self, text='', nodetype='Unknown', nodeList=None, recNum=0, parent=0):
self.text = text # The source node's text/label
self.nodetype = nodetype # The source node's nodetype
self.nodeList = nodeList # The Source Node's nodeList (for SearchCollectionNode, SearchQuoteNode, SearchClipNode, and SearchSnapshotNode Cut and Paste)
self.recNum = recNum # the source node's record number
self.parent = parent # The source node's parent's record number (or Keyword Group name, if the node is a Keyword)
def __repr__(self):
""" Return a String Representation of the contents of the DataTreeDragDrop Object """
str = 'Node %s of type %s, recNum %s, parent %s' % (self.text, self.nodetype, self.recNum, self.parent)
if self.nodeList != None:
str = str + '\nnodeList = %s' % (self.nodeList,)
return str
class DataTreeDropSource(wx.DropSource):
""" This is a custom DropSource object designed to drag objects from the Data Tree tab and to
provide feedback to the user during the drag. """
def __init__(self, tree):
# Create a Standard wxDropSource Object
wx.DropSource.__init__(self, tree)
# Remember the control that initiate the Drag for later use
self.tree = tree
# SetData accepts an object (obj) that has been prepared for the DropSource SetData() method
# by being put into a wxCustomDataObject
def SetData(self, obj):
# Set the prepared object as the wxDropSource Data
wx.DropSource.SetData(self, obj)
# hold onto the original data, in a usable form, for later use
self.data = cPickle.loads(obj.GetData())
def InTranscript(self, windowx, windowy):
"""Determine if the given X/Y position is within the Transcript editor."""
(transLeft, transTop, transWidth, transHeight) = self.tree.parent.ControlObject.GetTranscriptDims()
transRight = transLeft + transWidth
transBot = transTop + transHeight
return (windowx >= transLeft and windowx <= transRight and windowy >= transTop and windowy <= transBot)
# I want to provide the user with feedback about whether their drop will work or not.
def GiveFeedback(self, effect):
# NOTE: This method was generating an exception when moving off the data tree. Thus, exception handling
# was added.
try:
# This method does not provide the x, y coordinates of the mouse within the control, so we
# have to figure that out the hard way. (Contrast with DropTarget's OnDrop and OnDragOver methods)
# Get the Mouse Position on the Screen
(windowx, windowy) = wx.GetMousePosition()
if self.InTranscript(windowx, windowy):
if self.data.nodetype == 'KeywordNode':
# Make sure the cursor reflects an acceptable drop. (This resets it if it was previously changed
# to indicate a bad drop.)
self.tree.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
# FALSE indicates that feedback is NOT being overridden, and thus that the drop is GOOD!
return False
else:
# Set the cursor to give visual feedback that the drop will fail.
self.tree.SetCursor(wx.StockCursor(wx.CURSOR_NO_ENTRY))
# Setting the Effect to wxDragNone has absolutely no effect on the drop, if I understand this correctly.
effect = wx.DragNone
# returning TRUE indicates that the default feedback IS being overridden, thus that the drop is BAD!
return True
# Translate the Mouse's Screen Position to the Mouse's Control Position
(x, y) = self.tree.ScreenToClientXY(windowx, windowy)
# Now use the tree's HitTest method to find out about the potential drop target for the current mouse position
(id, flag) = self.tree.HitTest((x, y))
# I'm using GetItemText() here, but could just as easily use GetPyData()
destData = self.tree.GetPyData(id)
# See if we need to scroll the database tree up or down here. (DatabaseTreeTab.OnMotion used to handle this, but
# that method no longer gets called during a Drag.)
(w, h) = self.tree.GetClientSizeTuple()
# If we are dragging at the top of the window, scroll down
if y < 8:
# The wxWindow.ScrollLines() method is only implemented on Windows. We must use something different on the Mac.
if "wxMSW" in wx.PlatformInfo:
self.tree.ScrollLines(-2)
else:
# Suggested by Robin Dunn
first = self.tree.GetFirstVisibleItem()
prev = self.tree.GetPrevSibling(first)
if prev:
# drill down to find last expanded child
while self.tree.IsExpanded(prev):
prev = self.tree.GetLastChild(prev)
else:
# if no previous sub then try the parent
prev = self.tree.GetItemParent(first)
if prev:
self.tree.ScrollTo(prev)
else:
self.tree.EnsureVisible(first)
# If we are dragging at the bottom of the window, scroll up
elif y > h - 8:
# The wxWindow.ScrollLines() method is only implemented on Windows. We must use something different on the Mac.
if "wxMSW" in wx.PlatformInfo:
self.tree.ScrollLines(2)
else:
# Suggested by Robin Dunn
# first find last visible item by starting with the first
next = None
last = None
item = self.tree.GetFirstVisibleItem()
while item:
if not self.tree.IsVisible(item): break
last = item
item = self.tree.GetNextVisible(item)
# figure out what the next visible item should be,
# either the first child, the next sibling, or the
# parent's sibling
if last:
if self.tree.IsExpanded(last):
next = self.tree.GetFirstChild(last)[0]
else:
next = self.tree.GetNextSibling(last)
if not next:
prnt = self.tree.GetItemParent(last)
if prnt:
next = self.tree.GetNextSibling(prnt)
if next:
self.tree.ScrollTo(next)
elif last:
self.tree.EnsureVisible(last)
# This line compares the data being dragged (self.data) to the potential drop site given by the current
# mouse position (destData). If the drop is legal,
# we return FALSE to indicate that we should use the default drag-and-drop feedback, which will indicate
# that the drop is legal. If not, we return TRUE to indicate we are using our own feedback, which is
# implemented by changing the cursor to a "No_Entry" cursor to indicate the drop is not allowed.
# Note that this code here does not prevent the drop. That has to be implemented in the Drop Target
# object. It just provides visual feedback to the user. The same evaluatoin function is called elsewhere
# (in OnData) when the drop is actually processed.
if DragDropEvaluation(self.data, destData):
# Make sure the cursor reflects an acceptable drop. (This resets it if it was previously changed
# to indicate a bad drop.)
self.tree.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
# FALSE indicates that feedback is NOT being overridden, and thus that the drop is GOOD!
return False
else:
# Set the cursor to give visual feedback that the drop will fail.
self.tree.SetCursor(wx.StockCursor(wx.CURSOR_NO_ENTRY))
# Setting the Effect to wxDragNone has absolutely no effect on the drop, if I understand this correctly.
effect = wx.DragNone
# returning TRUE indicates that the default feedback IS being overridden, thus that the drop is BAD!
return True
except:
if DEBUG:
print "DragAndDropObjects.GiveFeedback(): Exception!!"
print sys.exc_info()[0]
print sys.exc_info()[1]
import traceback
traceback.print_exc(file=sys.stdout)
print
# We don't need anything fancy here. If there's a problem, it's not a valid drop, that's all.
# Set the cursor to give visual feedback that the drop will fail.
self.tree.SetCursor(wx.StockCursor(wx.CURSOR_NO_ENTRY))
# Setting the Effect to wxDragNone has absolutely no effect on the drop, if I understand this correctly.
effect = wx.DragNone
# returning TRUE indicates that the default feedback IS being overridden, thus that the drop is BAD!
return True
class DataTreeDropTarget(wx.PyDropTarget):
""" This is a custom DropTarget object designed to match drop behavior to the feedback given by the custom
Drag Object's GiveFeedback() method. """
def __init__(self, tree):
# use a normal wxPyDropTarget
wx.PyDropTarget.__init__(self)
# Remember the source Tree Control for later use
self.tree = tree
# specify the data format to accept Data from Tree Nodes
self.dfNode = wx.CustomDataFormat('DataTreeDragData')
# Specify the data object to accept data for this format
self.sourceNodeData = wx.CustomDataObject(self.dfNode)
# specify the data format to accept Data from Transcripts to create Clips
self.dfClip = wx.CustomDataFormat('ClipDragDropData')
# Specify the data object to accept data for this format
self.clipData = wx.CustomDataObject(self.dfClip)
# specify the data format to accept Data from Documents to create Quotes
self.dfQuote = wx.CustomDataFormat('QuoteDragDropData')
# Specify the data object to accept data for this format
self.quoteData = wx.CustomDataObject(self.dfQuote)
# Create a Composite Data Object
self.doc = wx.DataObjectComposite()
# Add the Tree Node Data Object
self.doc.Add(self.sourceNodeData)
# Add the Clip Data Object
self.doc.Add(self.clipData)
# Add the Quote Data Object
self.doc.Add(self.quoteData)
# Set the Composite Data object defined above as the DataObject for the PyDropTarget
self.SetDataObject(self.doc)
# Now let's put empty objects in both parts of the wx.DataObjectComposite, so that
# the OnData logic doesn't blow up when it tries to sort out what's been dropped.
# (Everything worked OK on Win2K without this, but not on WinXP.)
self.ClearSourceNodeData()
self.ClearClipData()
def ClearSourceNodeData(self):
""" Clears Data from the Tree Node Data Object """
# Create a blank Tree Node Data object
tempData = DataTreeDragDropData()
# Pickle it
pickledTempData = cPickle.dumps(tempData, 1)
# Replace the old Tree Node Data Object with the new empty one
self.sourceNodeData.SetData(pickledTempData)
def ClearClipData(self):
""" Clears Data from the Clip Creation Data Object """
# Create a blank Clip Creation Data object
tempData = ClipDragDropData()
# Pickle it
pickledTempData = cPickle.dumps(tempData, 1)
# Replace the old Clip Creation Data Object with the new empty one
self.clipData.SetData(pickledTempData)
# Create a blank Quote Creation Data object
tempData2 = QuoteDragDropData()
# Pickle it
pickledTempData2 = cPickle.dumps(tempData2, 1)
# Replace the old Quote Creation Data Object with the new empty one
self.quoteData.SetData(pickledTempData2)
def OnEnter(self, x, y, dragResult):
# Just allow the normal wxDragResult to pass through here
return dragResult
def OnLeave(self):
pass
def OnDrop(self, x, y):
# Process the "Drop" event
# If you drop off the Database Tree, you get an exception here
try:
# Use the tree's HitTest method to find out about the potential drop target for the current mouse position
(self.dropNode, flag) = self.tree.HitTest((x, y))
# Remember the Drop Location for later Processing (in OnData())
self.dropData = self.tree.GetPyData(self.dropNode)
# We don't yet have enough information to veto the drop, so return TRUE to indicate
# that we should proceed to the OnData method
return True
except:
# If an exception is raised, Veto the drop as there is no Drop Target.
return False
def OnData(self, x, y, dragResult):
# once OnDrop returns TRUE, this method is automatically called.
global YESTOALL
YESTOALL = False
# Let's get the data being dropped so we can do some processing logic
if self.GetData():
# First, extract the actual data passed in by the DataTreeDropSource, which used cPickle to pack it.
try:
# Try to unPickle the Tree Node Data Object. If the first Drag is for Clip Creation, this
# will raise an exception. If there is a good Tree Node Data Object being dragged, or if
# one from a previous drag has been Cleared, this will be successful.
sourceDataList = cPickle.loads(self.sourceNodeData.GetData())
# This line compares the data being dragged (sourceData) to the drop site determined in OnDrop and
# passed here as self.dropData.
if DragDropEvaluation(sourceDataList, self.dropData):
# if the sourceDataList is NOT a list (i.e. a single tree node item instead of mulitple selections) ...
if not isinstance(sourceDataList, list):
# ... then make it into a list so we can iterate through it
sourceDataList = [sourceDataList]
# if there's only one item being dropped and we're dealing with Keywords, we want confirmation dialogs
# from the DropKeyword() method
confirmations = (len(sourceDataList) == 1) and (sourceDataList[0].nodetype == 'KeywordNode')
# If we DON'T want confirmation dialogs from within DropKeyword(), we want a single confirmation up front,
# BUT ONLY IF WE ARE DROPPING KEYWORDS!! AND WE'RE NOT DROPPING ON A KEYWORD GROUP NODE!!!
if not confirmations and (sourceDataList[0].nodetype == 'KeywordNode') and (self.dropData.nodetype != 'KeywordGroupNode'):
# Prepare the prompt information
if self.dropData.nodetype == 'LibraryNode':
# Get user confirmation of the Keyword Add request
prompt = unicode(_('Do you want to add multiple Keywords to all %s in %s "%s"?'), 'utf8')
data1 = unicode(_('Items'), 'utf8')
data2 = unicode(_('Library'), 'utf8')
data = (data1, data2, self.tree.GetItemText(self.dropNode))
elif self.dropData.nodetype == 'DocumentNode':
# Get user confirmation of the Keyword Add request
prompt = unicode(_('Do you want to add multiple Keywords to %s "%s"?'), 'utf8')
data1 = unicode(_('Document'), 'utf8')
data = (data1, self.tree.GetItemText(self.dropNode))
elif self.dropData.nodetype == 'EpisodeNode':
# Get user confirmation of the Keyword Add request
prompt = unicode(_('Do you want to add multiple Keywords to %s "%s"?'), 'utf8')
data1 = unicode(_('Episode'), 'utf8')
data = (data1, self.tree.GetItemText(self.dropNode))
elif self.dropData.nodetype == 'CollectionNode':
# Get user confirmation of the Keyword Add request
prompt = unicode(_('Do you want to add multiple Keywords to all %s in %s "%s"?'), 'utf8')
data1 = unicode(_('Items'), 'utf8')
data2 = unicode(_('Collection'), 'utf8')
data = (data1, data2, self.tree.GetItemText(self.dropNode))
elif self.dropData.nodetype == 'QuoteNode':
# Get user confirmation of the Keyword Add request
prompt = unicode(_('Do you want to add multiple Keywords to %s "%s"?'), 'utf8')
data1 = unicode(_('Quote'), 'utf8')
data = (data1, self.tree.GetItemText(self.dropNode))
elif self.dropData.nodetype == 'ClipNode':
# Get user confirmation of the Keyword Add request
prompt = unicode(_('Do you want to add multiple Keywords to %s "%s"?'), 'utf8')
data1 = unicode(_('Clip'), 'utf8')
data = (data1, self.tree.GetItemText(self.dropNode))
elif self.dropData.nodetype == 'SnapshotNode':
# Get user confirmation of the Keyword Add request
prompt = unicode(_('Do you want to add multiple Keywords to %s "%s"?'), 'utf8')
data1 = unicode(_('Snapshot'), 'utf8')
data = (data1, self.tree.GetItemText(self.dropNode))
else:
prompt = unicode('DataTreeDropTarget.OnData(): Unknown dropData.nodetype.\nPlease press "No".', 'utf8')
data = ()
# Display the prompt for user feedback
dlg = Dialogs.QuestionDialog(None, prompt % data)
result = dlg.LocalShowModal()
dlg.Destroy()
# If we will be collecting confirmation later, ...
else:
# ... act as if the user pressed Yes to be able to continue
result = wx.ID_YES
# If the user said yes, or we didn't ask anything ...
if result == wx.ID_YES:
# If we have multiple Keywords dropped on a Library Node ...
if (len(sourceDataList) > 1) and \
(sourceDataList[0].nodetype == 'KeywordNode') and \
(self.dropData.nodetype in ['LibraryNode', 'EpisodeNode', 'DocumentNode']):
# Create a Keyword List
kwList = []
# Iterate through the source data list
for sourceData in sourceDataList:
# Create a temporary keyword
tmpKeyword = Keyword.Keyword(sourceData.parent, sourceData.text)
# Append the keyword to the Keyword List
kwList.append(tmpKeyword)
# Start handling Exceptions
try:
# If we're dropping on a Library ...
if self.dropData.nodetype == 'LibraryNode':
# Load the dropped-on Library
tmpLibrary = Library.Library(self.dropData.recNum)
# If we're not in the Standard version ...
if TransanaConstants.proVersion:
# Now get a list of all Documents in the Library and iterate through them
for tempDocumentNum, tempDocumentID, tempLibraryNum in DBInterface.list_of_documents(tmpLibrary.number):
# ... propagating the new Document Keywords to all Quotes from that Document
TransanaGlobal.menuWindow.ControlObject.PropagateObjectKeywords(_('Document'), tempDocumentNum, kwList)
# Now get a list of all Episodes in the Library and iterate through them
for tempEpisodeNum, tempEpisodeID, tempLibraryNum in DBInterface.list_of_episodes_for_series(tmpLibrary.id):
# Propagate the Keyword List to each Episode in the Library
TransanaGlobal.menuWindow.ControlObject.PropagateObjectKeywords(_('Episode'), tempEpisodeNum, kwList)
# If we're dropping on a Document ...
elif self.dropData.nodetype == 'DocumentNode':
# Propagate the Keyword List to the Document Quotes
TransanaGlobal.menuWindow.ControlObject.PropagateObjectKeywords(_('Document'), self.dropData.recNum, kwList)
# If we're dropping on an Episode ...
elif self.dropData.nodetype == 'EpisodeNode':
# Propagate the Keyword List to the Episode Clips
TransanaGlobal.menuWindow.ControlObject.PropagateObjectKeywords(_('Episode'), self.dropData.recNum, kwList)
# If an exception arises ...
except:
# ... add the exception to the error log
print "EXCEPTION:"
print sys.exc_info()[0]
print sys.exc_info()[1]
import traceback
traceback.print_exc(file=sys.stdout)
# Iterate through the source data list
for sourceData in sourceDataList:
# If a previous drag of a Tree Node Data Object has been cleared, the sourceData.nodetype
# will be "Unknown", which indicated that the current Drag is NOT a node from the Database
# Tree Tab, and therefore should be processed elsewhere. If it is NOT "Unknown", we should
# process it here. The Type comparison was added to get this working on the Mac.
if (type(sourceData) == type(DataTreeDragDropData())) and \
(sourceData.nodetype != 'Unknown'):
# If we meet the criteria, we process the drop. We do that here because we have full
# knowledge of the Dragged Data and the Drop Target's data here and nowhere else.
# Determine if we're copying or moving data. (In some instances, the 'action' is ignored.)
if dragResult == wx.DragCopy:
ProcessPasteDrop(self.tree, sourceData, self.dropNode, 'Copy', confirmations=confirmations)
elif dragResult == wx.DragMove:
ProcessPasteDrop(self.tree, sourceData, self.dropNode, 'Move', confirmations=confirmations)
else:
# If the DragDropEvaluation() test fails, we prevent the drop process by altering the wxDropResult (dragResult)
dragResult = wx.DragNone
else:
# If the DragDropEvaluation() test fails, we prevent the drop process by altering the wxDropResult (dragResult)
dragResult = wx.DragNone
# Once the drop is done or rejected, we must clear the Tree Node data out of the DropTarget.
# If we don't, this data will still be there if a Clip drag occurs, and there is no way in that
# circumstance to know which of the dragged objects to process! Clearing avoids that problem.
self.ClearSourceNodeData()
# Reset the cursor, regardless of whether the drop succeeded or failed.
self.tree.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
except:
# If an expection occurs here, it's no big deal. Forget about it.
# Reset the cursor, regardless of whether the drop succeeded or failed.
self.tree.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
pass
try:
# Try to unPickle the Clip Creation Data Object. If the first Drag is from the Database Tree, this
# will raise an exception. If there is a good Clip Creation Data Object being dragged, or if
# one from a previous drag has been Cleared, this will be successful.
clipData = cPickle.loads(self.clipData.GetData())
quoteData = cPickle.loads(self.quoteData.GetData())
# Dropping Transcript Text onto a Collection, Quote, Clip, or Snapshot creates a Regular Clip.
# See if the Drop Target is the correct Node Type. The type comparison was added to get this working on the Mac.
if (isinstance(clipData, ClipDragDropData)) and \
((self.dropData.nodetype == 'CollectionNode') or \
(self.dropData.nodetype == 'QuoteNode') or \
(self.dropData.nodetype == 'ClipNode') or \
(self.dropData.nodetype == 'SnapshotNode')):
# If a previous drag of a Clip Creation Data Object has been cleared, the clipData.transcriptNum
# will be "0", which indicated that the current Drag is NOT a Clip Creation Data Object,
# and therefore should be processed elsewhere. If it is NOT "0", we should process it here.
if clipData.transcriptNum != 0:
CreateClip(clipData, self.dropData, self.tree, self.dropNode)
# Once the drop is done or rejected, we must clear the Clip Creation data out of the DropTarget.
# If we don't, this data will still be there if a Tree Node drag occurs, and there is no way in that
# circumstance to know which of the dragged objects to process! Clearing avoids that problem.
self.ClearClipData()
# Dropping Document Text onto a Collection, Quote, Clip, or Snapshot creates a Regular Quote.
# See if the Drop Target is the correct Node Type. The type comparison was added to get this working on the Mac.
if (isinstance(quoteData, QuoteDragDropData)) and \
((self.dropData.nodetype == 'CollectionNode') or \
(self.dropData.nodetype == 'QuoteNode') or \
(self.dropData.nodetype == 'ClipNode') or \
(self.dropData.nodetype == 'SnapshotNode')):
# If a previous drag of a Quote Creation Data Object has been cleared, the quoteData.documentNum
# will be "0", which indicated that the current Drag is NOT a Quote Creation Data Object,
# and therefore should be processed elsewhere. If it is NOT "0", we should process it here.
if quoteData.documentNum != 0:
CreateQuote(quoteData, self.dropData, self.tree, self.dropNode)
# Once the drop is done or rejected, we must clear the Quote Creation data out of the DropTarget.
# If we don't, this data will still be there if a Tree Node drag occurs, and there is no way in that
# circumstance to know which of the dragged objects to process! Clearing avoids that problem.
self.ClearClipData()
# Dropping Transcript Text onto a Keyword Group creates a Keyword.
elif (type(clipData) == type(ClipDragDropData())) and \
(clipData.plainText != '') and \
(self.dropData.nodetype == 'KeywordGroupNode'):
# Create a new Keyword Object with the desired KWG and KW values
kw = Keyword.Keyword()
kw.keywordGroup = self.tree.GetItemText(self.dropNode)
# While the Clipboard's Plain Text has TIME CODES in it ...
while (clipData.plainText.find(u'\xa4') > -1) and \
(clipData.plainText.find('>', clipData.plainText.find(u'\xa4')) > 0):
# ... remove the time codes and the time code data
clipData.plainText = clipData.plainText[:clipData.plainText.find(u'\xa4')] + \
clipData.plainText[clipData.plainText.find('>', clipData.plainText.find(u'\xa4')) + 1:]
# If there's still a time code, the data must have been truncated before the ">" terminator.
if (clipData.plainText.find(u'\xa4') > -1):
# Remove it from the end of the string.
clipData.plainText = clipData.plainText[:clipData.plainText.find(u'\xa4')]
# Limit the keyword length to 85 characters!
kw.keyword = clipData.plainText[:85]
# Create the Keyword Properties Dialog Box to Add a Keyword
dlg = KeywordPropertiesForm.EditKeywordDialog(None, -1, kw)
# 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 Keyword Properties Dialog Box and get the data from the user
kw = dlg.get_input()
# If the user pressed OK ...
if kw != None:
# Try to save the data from the form
kw.db_save()
# Add the new Keyword to the tree
self.tree.add_Node('KeywordNode', (_('Keywords'), kw.keywordGroup, kw.keyword), 0, kw.keywordGroup)
# Now let's communicate with other Transana instances if we're in Multi-user mode
if not TransanaConstants.singleUserVersion:
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage("AK %s >|< %s" % (kw.keywordGroup, kw.keyword))
# 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 TransanaExceptions.SaveError, e:
# 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()
# Destroy the Keyword Dialog
dlg.Destroy()
# Clear the Clip Data
self.ClearClipData()
# Dropping Document Text onto a Keyword Group creates a Keyword.
elif (type(quoteData) == type(QuoteDragDropData())) and \
(quoteData.plainText != '') and \
(self.dropData.nodetype == 'KeywordGroupNode'):
# print "DragAndDropObjects.DataTreeDropTarget.OnDrop(): Drop Document Text onto Keyword Group should create a keyword!"
# print quoteData
# print
# Create a new Keyword Object with the desired KWG and KW values
kw = Keyword.Keyword()
kw.keywordGroup = self.tree.GetItemText(self.dropNode)
# While the Clipboard's Plain Text has TIME CODES in it ...
# (If the Document was imported from an exported Transcript, it *could* have time codes!!
while (quoteData.plainText.find(u'\xa4') > -1) and \
(quoteData.plainText.find('>', quoteData.plainText.find(u'\xa4')) > 0):
# ... remove the time codes and the time code data
quoteData.plainText = quoteData.plainText[:quoteData.plainText.find(u'\xa4')] + \
quoteData.plainText[quoeData.plainText.find('>', quoteData.plainText.find(u'\xa4')) + 1:]
# If there's still a time code, the data must have been truncated before the ">" terminator.
if (quoteData.plainText.find(u'\xa4') > -1):
# Remove it from the end of the string.
quoteData.plainText = quoteData.plainText[:quoteData.plainText.find(u'\xa4')]
# Limit the keyword length to 85 characters!
kw.keyword = quoteData.plainText[:85]
# Create the Keyword Properties Dialog Box to Add a Keyword
dlg = KeywordPropertiesForm.EditKeywordDialog(None, -1, kw)
# 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 Keyword Properties Dialog Box and get the data from the user
kw = dlg.get_input()
# If the user pressed OK ...
if kw != None:
# Try to save the data from the form
kw.db_save()
# Add the new Keyword to the tree
self.tree.add_Node('KeywordNode', (_('Keywords'), kw.keywordGroup, kw.keyword), 0, kw.keywordGroup)
# Now let's communicate with other Transana instances if we're in Multi-user mode
if not TransanaConstants.singleUserVersion:
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage("AK %s >|< %s" % (kw.keywordGroup, kw.keyword))
# 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 TransanaExceptions.SaveError, e:
# 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()
# Destroy the Keyword Dialog
dlg.Destroy()
# Clear the Quote Data
self.ClearQuoteData()
# Dropping Transcript Text onto a Keyword creates a Quick Clip.
# If a previous drag of a Clip Creation Data Object has been cleared, the clipData.transcriptNum
# will be "0", which indicated that the current Drag is NOT a Clip Creation Data Object,
# and therefore should be processed elsewhere. If it is NOT "0", we should process it here.
elif (type(clipData) == type(ClipDragDropData())) and \
(clipData.transcriptNum != 0) and \
(self.dropData.nodetype == 'KeywordNode'):
# Pass the accumulated data to the CreateQuickClip method, which is in the DragAndDropObjects module
# because drag and drop is an alternate way to create a Quick Clip.
CreateQuickClip(clipData, self.dropData.parent, self.tree.GetItemText(self.dropNode), self.tree)
# Once the drop is done, we must clear the Clip Creation data out of the DropTarget.
# If we don't, this data will still be there if a Tree Node drag occurs, and there is no way in that
# circumstance to know which of the dragged objects to process! Clearing avoids that problem.
self.ClearClipData()
# Dropping Document Text onto a Keyword creates a Quick Quote.
# If a previous drag of a Quote Creation Data Object has been cleared, the QuoteData.documentNum
# will be "0", which indicated that the current Drag is NOT a QUote Creation Data Object,
# and therefore should be processed elsewhere. If it is NOT "0", we should process it here.
elif (type(quoteData) == type(QuoteDragDropData())) and \
(quoteData.documentNum != 0) and \
(self.dropData.nodetype == 'KeywordNode'):
# Pass the accumulated data to the CreateQuickQuote method, which is in the DragAndDropObjects module
# because drag and drop is an alternate way to create a Quick Quote.
CreateQuickQuote(quoteData, self.dropData.parent, self.tree.GetItemText(self.dropNode), self.tree)
# Once the drop is done, we must clear the Clip Creation data out of the DropTarget.
# If we don't, this data will still be there if a Tree Node drag occurs, and there is no way in that
# circumstance to know which of the dragged objects to process! Clearing avoids that problem.
self.ClearQuoteData()
else:
# If the Drop target is not valid, we prevent the drop process by altering the wxDropResult (dragResult)
dragResult = wx.DragNone
# Reset the cursor, regardless of whether the drop succeeded or failed.
self.tree.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
except:
# Reset the cursor, regardless of whether the drop succeeded or failed.
self.tree.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
(exType, exValue) = sys.exc_info()[:2]
# If an expection occurs here, it's no big deal. Forget about it.
pass
# Returning this value allows us to confirm or veto the drop request
return dragResult
class ClipDragDropData(object):
""" This object contains all the data that needs to be transferred in order to create a Clip
from a selection in a Transcript. """
def __init__(self, transcriptNum=0, episodeNum=0, clipStart=0, clipStop=0, text='', plainText='', videoCheckboxData=[]):
""" ClipDragDropData Objects require the following parameters:
transcriptNum The Transcript Number of the originating Transcript
episodeNum The Episode the originating Transcript is attached to
clipStart The starting Time Code for the Clip
clipStop the ending Time Code for the Clip
text the Text for the Clip, in XML format
videoCheckboxData the Video Checkbox information from the Video Window. """
self.transcriptNum = transcriptNum
self.episodeNum = episodeNum
self.clipStart = clipStart
self.clipStop = clipStop
self.text = text
self.plainText = plainText
self.videoCheckboxData = videoCheckboxData
def __repr__(self):
str = 'ClipDragDropData Object:\n'
str = str + 'transcriptNum = %s\n' % self.transcriptNum
str = str + 'episodeNum = %s\n' % self.episodeNum
str = str + 'clipStart = %s\n' % Misc.time_in_ms_to_str(self.clipStart)
str = str + 'clipStop = %s\n' % Misc.time_in_ms_to_str(self.clipStop)
str = str + 'text = %s\n' % self.text
str += 'plainText = %s\n\n' % self.plainText
str += 'videoCheckboxData = %s\n\n' % self.videoCheckboxData
return str
class QuoteDragDropData(object):
""" This object contains all the data that needs to be transferred in order to create a Quote
from a selection in a Document. """
def __init__(self, documentNum=0, sourceQuote=0, startChar=0, endChar=0, text='', plainText=''):
""" QuoteDragDropData Objects require the following parameters:
documentNum The Document Number of the originating Document
sourceQuote The Number of the Quote this is taken from, if it is from a Quote
startChar The starting character for the quote
endChar The ending character for the Quote
text the Text for the Quote, in XML format. """
self.documentNum = documentNum
self.sourceQuote = sourceQuote
self.startChar = startChar
self.endChar = endChar
self.text = text
self.plainText = plainText
def __repr__(self):
str = 'QuoteDragDropData Object:\n'
str += 'documentNum = %s\n' % self.documentNum
str += 'sourceQuote = %s\n' % self.sourceQuote
str += 'startChar = %s\n' % self.startChar
str += 'endChar = %s\n' % self.endChar
str += 'text = %s\n' % self.text
str += 'plainText = %s\n\n' % self.plainText
return str
def CreateClip(clipData, dropData, tree, dropNode):
""" This method handles the creation of a Clip Object in the Transana Database """
# Set the "continue" flag to True (used to redisplay the dialog if an exception is raised)
contin = True
# Create a new Clip Object
tempClip = Clip.Clip()
# We need to know if the Clip is coming from an Episode or another Clip.
# We can determine that by looking at the transcript passed in the ClipData
# To save time here, we can skip loading the actual transcript text, which can take time once we start dealing with images!
tempTranscript = Transcript.Transcript(clipData.transcriptNum, skipText=True)
# If we are working from an Episode Transcript ...
if tempTranscript.clip_num == 0:
# Get the Episode Number from the clipData Object
tempClip.episode_num = clipData.episodeNum
# Get the Transcript Number from the clipData Object
trNum = clipData.transcriptNum
# If we are working from a Clip Transcript ...
else:
sourceClip = Clip.Clip(tempTranscript.clip_num)
# Get the Episode Number from the sourceClip Object
tempClip.episode_num = sourceClip.episode_num
# Get the source transcript number from the clip transcript
trNum = sourceClip.transcripts[0].source_transcript
# Get the Clip Start Time from the clipData Object
tempClip.clip_start = clipData.clipStart
# Check to see if the clip starts before the media file starts (due to Adjust Indexes)
if tempClip.clip_start < 0.0:
prompt = _('The starting point for a Clip cannot be before the start of the media file.')