forked from sanyaade-machine-learning/Transana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuWindow.py
2408 lines (2173 loc) · 133 KB
/
MenuWindow.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 file handles the Transana Menu Window and all associated logic. """
__author__ = 'David Woods <[email protected]>, Nathaniel Case, Rajas Sambhare'
DEBUG = False
if DEBUG:
print "MenuWindow DEBUG is ON!!"
# import Python's cStringIO module for fast string processing
import cStringIO
# Import Python os module
import os
# Import Python sys module
import sys
# import Python time module
import time
# Import Python's gettext module
import gettext
# import python's webbrowser module
import webbrowser
# import wxPython
import wx
# Import Transana About Box
import About
# import Transana Database Interface
import DBInterface
# import the Transana Dialogs
import Dialogs
# import Transana File Management System
import FileManagement
# Import Transana Menu Setup
import MenuSetup
# import Transana's Notes Browser
import NotesBrowser
# import Database Import
import XMLImport
# import Database Import
import XMLExport
# import the Color Configuration utility
import ColorConfig
# import Batch Waveform Generator, now called the Batch File Processor
import BatchFileProcessor
# Import Transana Options Settings
import OptionsSettings
# Import Transana's Constants
import TransanaConstants
# Import Transana Globals
import TransanaGlobal
# Import Transana's Images
import TransanaImages
if TransanaConstants.USESRTC:
import wx.richtext as richtext
# Import the RTC-based RichTextEditCtrl, needed for printing
import RichTextEditCtrl_RTC
else:
# Import the Transcript Printing Module
import TranscriptPrintoutClass
# ONLY if we're using the Multi-user version ...
if not TransanaConstants.singleUserVersion:
# ... import Transana's ChatWindow
import ChatWindow
# import Transana Record Lock Utility
import RecordLock
# import Media Conversion Tool
import MediaConvert
# Language-specific labels for the different languages.
ENGLISH_LABEL = 'English'
ARABIC_LABEL = unichr(1575) + unichr(1604) + unichr(1593) + unichr(1585) + unichr(1576) + unichr(1610) + unichr(1577) # 'Arabic'
DANISH_LABEL = 'Dansk'
GERMAN_LABEL = 'Deutsch'
GREEK_LABEL = 'English prompts, Greek data'
if 'unicode' in wx.PlatformInfo:
SPANISH_LABEL = u'Espa\u00f1ol'
else:
SPANISH_LABEL = 'Espanol'
FINNISH_LABEL = 'Finnish'
if 'unicode' in wx.PlatformInfo:
FRENCH_LABEL = u'Fran\u00e7ais'
else:
FRENCH_LABEL = 'Francais'
HEBREW_LABEL = 'Hebrew'
ITALIAN_LABEL = 'Italiano'
DUTCH_LABEL = 'Nederlands'
if 'unicode' in wx.PlatformInfo:
NORWEGIAN_BOKMAL_LABEL = u'Norv\u00e9gien Bokm\u00e5l'
NORWEGIAN_NYNORSK_LABEL = u'Norv\u00e9gien Ny-norsk'
else:
NORWEGIAN_BOKMAL_LABEL = 'Norvegien Bokmal'
NORWEGIAN_NYNORSK_LABEL = 'Norvegien Ny-norsk'
POLISH_LABEL = 'Polish'
PORTUGUESE_LABEL = 'Portuguese'
if 'unicode' in wx.PlatformInfo:
RUSSIAN_LABEL = u'\u0420\u0443\u0441\u0441\u043a\u0438\u0439'
else:
RUSSIAN_LABEL = 'Russian'
SWEDISH_LABEL = 'Svenska'
CHINESE_LABEL = unicode('\xe4\xb8\xad\xe6\x96\x87\x2d\xe7\xae\x80\xe4\xbd\x93', 'utf8') # 'Chinese - Simplified'
EASTEUROPE_LABEL = _("English prompts, Eastern European data (ISO-8859-2 encoding)")
JAPANESE_LABEL = 'English prompts, Japanese data'
KOREAN_LABEL = 'English prompts, Korean data'
class MenuWindow(wx.Frame): # wx.MDIParentFrame
"""This class contains the frame object for the Transana Menu Bar window."""
def __init__(self, parent, id, title):
"""Initialize a MenuBarFrame object."""
# Initialize the Control Object to None so its absence can be detected
self.ControlObject = None
# Initialize the height to be used for the Menu Window.
self.height = TransanaGlobal.menuHeight
if DEBUG:
print "MenuWindow.__init__():", wx.ClientDisplayRect(), wx.Display(TransanaGlobal.configData.primaryScreen).GetClientArea()
print
print "Number of Monitors:", wx.Display.GetCount()
for x in range(wx.Display.GetCount()):
print " ", x, wx.Display(x).IsPrimary(), wx.Display(x).GetGeometry(), wx.Display(x).GetClientArea()
print
# If no language has been specified, request an initial language
if TransanaGlobal.configData.language == '':
initialLanguage = self.GetLanguage(self)
if initialLanguage == ENGLISH_LABEL:
TransanaGlobal.configData.language = 'en'
elif initialLanguage == ARABIC_LABEL:
TransanaGlobal.configData.language = 'ar'
elif initialLanguage == DANISH_LABEL:
TransanaGlobal.configData.language = 'da'
elif initialLanguage == GERMAN_LABEL:
TransanaGlobal.configData.language = 'de'
# elif initialLanguage == GREEK_LABEL:
# TransanaGlobal.configData.language = 'el'
elif initialLanguage == SPANISH_LABEL:
TransanaGlobal.configData.language = 'es'
elif initialLanguage == FINNISH_LABEL:
TransanaGlobal.configData.language = 'fi'
elif initialLanguage == FRENCH_LABEL:
TransanaGlobal.configData.language = 'fr'
elif initialLanguage == HEBREW_LABEL:
TransanaGlobal.configData.language = 'he'
elif initialLanguage == ITALIAN_LABEL:
TransanaGlobal.configData.language = 'it'
elif initialLanguage == DUTCH_LABEL:
TransanaGlobal.configData.language = 'nl'
elif initialLanguage == NORWEGIAN_BOKMAL_LABEL:
TransanaGlobal.configData.language = 'nb'
elif initialLanguage == NORWEGIAN_NYNORSK_LABEL:
TransanaGlobal.configData.language = 'nn'
elif initialLanguage == POLISH_LABEL:
TransanaGlobal.configData.language = 'pl'
elif initialLanguage == PORTUGUESE_LABEL:
TransanaGlobal.configData.language = 'pt'
elif initialLanguage == RUSSIAN_LABEL:
TransanaGlobal.configData.language = 'ru'
# The single-user version on Windows needs to set the proper encoding for Russian.
## if ('wxMSW' in wx.PlatformInfo) and (TransanaConstants.singleUserVersion):
## TransanaGlobal.encoding = 'koi8_r'
elif initialLanguage == SWEDISH_LABEL:
TransanaGlobal.configData.language = 'sv'
# Chinese
elif initialLanguage == CHINESE_LABEL:
TransanaGlobal.configData.language = 'zh'
## if ('wxMSW' in wx.PlatformInfo) and (TransanaConstants.singleUserVersion):
## TransanaGlobal.encoding = TransanaConstants.chineseEncoding
# Japanese, and Korean are a special circumstance. We don't have
# translations for these languages, but want to be able to allow users to
# work in these languages. It's not possible on the Mac for now, and it
# already works on the Windows MU version. The Windows single-user version
# should work if we just add the proper encodings!
#
# NOTE: There are multiple possible encodings for these languages. I've picked
# these at random.
## elif initialLanguage == EASTEUROPE_LABEL:
## TransanaGlobal.configData.language = 'easteurope'
## if ('wxMSW' in wx.PlatformInfo) and (TransanaConstants.singleUserVersion):
## TransanaGlobal.encoding = 'iso8859_2'
## elif initialLanguage == GREEK_LABEL:
## TransanaGlobal.configData.language = 'el'
## if ('wxMSW' in wx.PlatformInfo) and (TransanaConstants.singleUserVersion):
## TransanaGlobal.encoding = 'iso8859_7'
## elif initialLanguage == JAPANESE_LABEL:
## TransanaGlobal.configData.language = 'ja'
## if ('wxMSW' in wx.PlatformInfo) and (TransanaConstants.singleUserVersion):
## TransanaGlobal.encoding = 'cp932'
## elif initialLanguage == KOREAN_LABEL:
## TransanaGlobal.configData.language = 'ko'
## if ('wxMSW' in wx.PlatformInfo) and (TransanaConstants.singleUserVersion):
## TransanaGlobal.encoding = 'cp949'
# Okay, a few notes on Internationalization (i18n) are called for here. It gets a little complicated.
#
# There is more than one way to skin a cat. There is the Python way to internationalize, using "gettext",
# and there is the wxPython way to internationalize, using wx.Locale. I've experimented with both, and
# they both seem to work. However, the Python way allows me to change languages while Transana is running,
# while the wxPython way does not. (It used to, but now it raises an exception.) On the other hand,
# the Python way does not affect strings provided by wxPython, while the wxPython way does.
# (I have yet to identify any such strings on Windows, though I think the wx.MessageDialog on Linux
# might be an example.) Some error messages are provided by embedded MySQL, and the language for these
# messages cannot be changed once the DB in initialized. A further wrinkle is that common dialogs that
# come from the OS rather than from Python or wxPython, such as the File and Print Dialogs, don't respond
# to either method of i18n. They get their language setting from the OS rather than the program.
#
# What I have chosen to do is to implement Transana's i18n using gettext, doing it the Python way so that
# users will be able to change languages on the fly. In addition, I set the wx.Locale at program start-up
# to the initial language selected by the user. In this case, when a user uses the Language Menu to
# change languages, all of the prompts supplied by Transana should reflect the change. However, prompts
# supplied by wxPython and by MySQL will not change until the user restarts Transana. At the moment, I
# don't know what any of these prompts that a user would actually see might be.
# Install gettext. Once this is done, all strings enclosed in "_()" will automatically be translated.
# gettext.install('Transana', 'locale', False)
# Define supported languages for Transana
self.presLan_en = gettext.translation('Transana', 'locale', languages=['en']) # English
# Arabic
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'ar', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_ar = gettext.translation('Transana', 'locale', languages=['ar']) # Arabic
# Danish
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'da', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_da = gettext.translation('Transana', 'locale', languages=['da']) # Danish
# German
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'de', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_de = gettext.translation('Transana', 'locale', languages=['de']) # German
# Greek
# dir = os.path.join(TransanaGlobal.programDir, 'locale', 'el', 'LC_MESSAGES', 'Transana.mo')
# if os.path.exists(dir):
# self.presLan_el = gettext.translation('Transana', 'locale', languages=['el']) # Greek
# Spanish
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'es', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_es = gettext.translation('Transana', 'locale', languages=['es']) # Spanish
# Finnish
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'fi', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_fi = gettext.translation('Transana', 'locale', languages=['fi']) # Finnish
# French
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'fr', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_fr = gettext.translation('Transana', 'locale', languages=['fr']) # French
# Hebrew
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'he', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_he = gettext.translation('Transana', 'locale', languages=['he']) # Hebrew
# Italian
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'it', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_it = gettext.translation('Transana', 'locale', languages=['it']) # Italian
# Dutch
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'nl', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_nl = gettext.translation('Transana', 'locale', languages=['nl']) # Dutch
# Norwegian Bokmal
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'nb', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_nb = gettext.translation('Transana', 'locale', languages=['nb']) # Norwegian Bokmal
# Norwegian Ny-norsk
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'nn', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_nn = gettext.translation('Transana', 'locale', languages=['nn']) # Norwegian Ny-norsk
# Polish
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'pl', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_pl = gettext.translation('Transana', 'locale', languages=['pl']) # Polish
# Portuguese
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'pt', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_pt = gettext.translation('Transana', 'locale', languages=['pt']) # Portuguese
# Russian
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'ru', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_ru = gettext.translation('Transana', 'locale', languages=['ru']) # Russian
# Swedish
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'sv', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_sv = gettext.translation('Transana', 'locale', languages=['sv']) # Swedish
# Chinese
dir = os.path.join(TransanaGlobal.programDir, 'locale', 'zh', 'LC_MESSAGES', 'Transana.mo')
if os.path.exists(dir):
self.presLan_zh = gettext.translation('Transana', 'locale', languages=['zh']) # Chinese
# We're starting to face the situation where not all the translations may be up-to-date. Let's build some checks.
# Initialize an empty variable
outofdateLanguage = ''
# Set the default prompt, which might get changed
languageErrorPrompt = "Transana's %s translation is no longer up-to-date.\nMissing prompts will be displayed in English.\n\nIf you are willing to help with this translation,\nplease contact David Woods at [email protected]." % outofdateLanguage
# Start exception handling to deal with lost languages
try:
# Install English as the initial language if no language has been specified
# NOTE: Eastern European Encoding, Greek, Japanese, Korean will use English prompts
if (TransanaGlobal.configData.language in ['', 'en', 'easteurope', 'el', 'ja', 'ko']) :
lang = wx.LANGUAGE_ENGLISH
self.presLan_en.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Arabic
elif (TransanaGlobal.configData.language == 'ar'):
outofdateLanguage = 'Arabic'
lang = wx.LANGUAGE_ARABIC
self.presLan_ar.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Danish
elif (TransanaGlobal.configData.language == 'da'):
outofdateLanguage = 'Danish'
lang = wx.LANGUAGE_DANISH
self.presLan_da.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# German
elif (TransanaGlobal.configData.language == 'de'):
outofdateLanguage = 'German'
lang = wx.LANGUAGE_GERMAN
self.presLan_de.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Greek
# elif (TransanaGlobal.configData.language == 'el'):
# outofdateLanguage = 'Greek'
# lang = wx.LANGUAGE_GREEK
# self.presLan_el.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Spanish
elif (TransanaGlobal.configData.language == 'es'):
outofdateLanguage = 'Spanish'
lang = wx.LANGUAGE_SPANISH
self.presLan_es.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Finnish
elif (TransanaGlobal.configData.language == 'fi'):
outofdateLanguage = 'Finnish'
lang = wx.LANGUAGE_FINNISH
self.presLan_fi.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# French
elif (TransanaGlobal.configData.language == 'fr'):
outofdateLanguage = 'French'
lang = wx.LANGUAGE_FRENCH
self.presLan_fr.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Hebrew
elif (TransanaGlobal.configData.language == 'he'):
outofdateLanguage = 'Hebrew'
lang = wx.LANGUAGE_HEBREW
self.presLan_he.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Italian
elif (TransanaGlobal.configData.language == 'it'):
outofdateLanguage = 'Italian'
lang = wx.LANGUAGE_ITALIAN
self.presLan_it.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Dutch
elif (TransanaGlobal.configData.language == 'nl'):
outofdateLanguage = 'Dutch'
lang = wx.LANGUAGE_DUTCH
self.presLan_nl.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Norwegian Bokmal
elif (TransanaGlobal.configData.language == 'nb'):
outofdateLanguage = 'Norwegian Bokmal'
# There seems to be a bug in GetText on the Mac when the wxLANGUAGE is set to Bokmal.
# Setting this to English seems to make little practical difference.
if 'wxMac' in wx.PlatformInfo:
lang = wx.LANGUAGE_ENGLISH
else:
lang = wx.LANGUAGE_NORWEGIAN_BOKMAL
self.presLan_nb.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Norwegian Ny-norsk
elif (TransanaGlobal.configData.language == 'nn'):
outofdateLanguage = 'Norwegian Nynorsk'
# There seems to be a bug in GetText on the Mac when the wxLANGUAGE is set to Nynorsk.
# Setting this to English seems to make little practical difference.
if 'wxMac' in wx.PlatformInfo:
lang = wx.LANGUAGE_ENGLISH
else:
lang = wx.LANGUAGE_NORWEGIAN_NYNORSK
self.presLan_nn.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Polish
elif (TransanaGlobal.configData.language == 'pl'):
outofdateLanguage = 'Polish'
lang = wx.LANGUAGE_POLISH # Polish spec causes an error message on my computer
self.presLan_pl.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Portuguese
elif (TransanaGlobal.configData.language == 'pt'):
outofdateLanguage = 'Portuguese'
lang = wx.LANGUAGE_PORTUGUESE # Polish spec causes an error message on my computer
self.presLan_pt.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Russian
elif (TransanaGlobal.configData.language == 'ru'):
outofdateLanguage = 'Russian'
lang = wx.LANGUAGE_RUSSIAN # Russian spec causes an error message on my computer
self.presLan_ru.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Swedish
elif (TransanaGlobal.configData.language == 'sv'):
outofdateLanguage = 'Swedish'
lang = wx.LANGUAGE_SWEDISH
self.presLan_sv.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Chinese
elif (TransanaGlobal.configData.language == 'zh'):
outofdateLanguage = 'Chinese - Simplified'
lang = wx.LANGUAGE_CHINESE
self.presLan_zh.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
except:
TransanaGlobal.configData.language = 'en'
TransanaGlobal.configData.SaveConfiguration()
lang = wx.LANGUAGE_ENGLISH
self.presLan_en.install() # Adding "unicode=1" here would eliminiate the need to declare translations strings at unicode() objects!!
# Change the Language Error Message
languageErrorPrompt = "Transana's %s translation is no longer up-to-date or available.\nAll prompts will be displayed in English.\n\nIf you are willing to update this translation,\nplease contact David Woods at [email protected]." % outofdateLanguage
# Due to a problem with wx.Locale on the Mac (It won't load anything but English), I'm disabling
# i18n functionality of the wxPython layer on the Mac. This code accomplishes that.
if "__WXMAC__" in wx.PlatformInfo:
lang = wx.LANGUAGE_ENGLISH
# if (TransanaGlobal.configData.language != 'en'):
# print "wxPython language selection over-ridden for the Mac"
# This provides localization for wxPython
self.locale = wx.Locale(lang) # , wx.LOCALE_LOAD_DEFAULT | wx.LOCALE_CONV_ENCODING)
# Add the Transana catalog to the Locale
self.locale.AddCatalog("Transana")
if 'wxGTK' in wx.PlatformInfo:
TransanaGlobal.configData.LayoutDirection = wx.Layout_LeftToRight
else:
# Save the Text Direction to the Configuration Data
TransanaGlobal.configData.LayoutDirection = self.locale.GetLanguageInfo(lang).LayoutDirection
# We need to reset the media type constants if we are using a Right-To-Left Language, due to a
# bug in wxWidgets 3.0.0.0's MediaCtrl, which doesn't play Media for QuickTime formats under RtL languages.
# We do this here, because layout direction isn't defined when we load the Constants!
if TransanaGlobal.configData.LayoutDirection == wx.Layout_RightToLeft:
TransanaConstants.fileTypesString = TransanaConstants.fileTypesString_RtL
TransanaConstants.fileTypesList = TransanaConstants.fileTypesList_RtL
TransanaConstants.mediaFileTypes = TransanaConstants.mediaFileTypes_RtL
if DEBUG:
print "MenuWindow.__init__(): Language: ", TransanaGlobal.configData.language, lang
if not 'wxGTK' in wx.PlatformInfo:
print "Layout Direction:", self.locale.GetLanguageInfo(lang).LayoutDirection, "LtR:", wx.Layout_LeftToRight, "RtL:", wx.Layout_RightToLeft
print
# Check to see if we have a translation, and if it is up-to-date.
# NOTE: "Fixed-Increment Time Code" works for version 2.42. "&Media Conversion" works for 2.50.
# For 2.60, let's go with "Snapshot". For 2.61, we'll use "SSL Client Key File"
# For 3.00, let's use "Libraries".
# If you update this, also update the phrase
# below in the OnOptionsLanguage method.)
if (outofdateLanguage != '') and ("Libraries" == _("Libraries")):
# If not, display an information message.
dlg = Dialogs.InfoDialog(None, languageErrorPrompt)
dlg.ShowModal()
dlg.Destroy()
# Determine which monitor to use
if TransanaGlobal.configData.primaryScreen < wx.Display.GetCount():
primaryScreen = TransanaGlobal.configData.primaryScreen
else:
primaryScreen = 0
# We need to handle the window differently on Windows vs. Mac.
# First, Windows ...
if '__WXMSW__' in wx.Platform:
screenDims = wx.Display(primaryScreen).GetClientArea() # wx.ClientDisplayRect()
self.left = screenDims[0] # + 2
self.top = screenDims[1] # + 2
self.width = screenDims[2] # - 4
# ... adjust the Menu Window to full height (grey background)
self.height = TransanaGlobal.menuHeight # screenDims[3] - 4
winstyle = wx.DEFAULT_FRAME_STYLE | wx.FRAME_NO_WINDOW_MENU
# wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.RESIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION # | wx.MAXIMIZE
# on Mac OS-X ...
elif '__WXMAC__' in wx.Platform:
screenDims = wx.Display(primaryScreen).GetClientArea() # wx.ClientDisplayRect()
self.left = screenDims[0] + 2
self.top = 1 # screenDims[1] + 2
self.width = 1 # screenDims[2] - 4
# ... adjust the Menu Window to full height (grey background)
self.height = screenDims[3] - 4
winstyle = wx.DEFAULT_FRAME_STYLE | wx.FRAME_NO_WINDOW_MENU
# Linux and who knows what else
else:
screenDims = wx.Display(primaryScreen).GetClientArea() # wx.ClientDisplayRect()
# screenDims2 = wx.Display(primaryScreen).GetGeometry()
self.left = screenDims[0]
self.top = screenDims[1]
self.width = 1 # screenDims2[2] - screenDims[0] # min(screenDims[2], 1280 - self.left)
self.height = 1 # min(screenDims[3], screenDims2[3])
winstyle = wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.RESIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION # | wx.MAXIMIZE
if DEBUG:
print "Linux:", screenDims, self.left, self.top, self.width, self.height
print
# Now create the Frame for the Menu Bar
wx.Frame.__init__(self, parent, -1, title, style=winstyle,
# wx.MDIParentFrame.__init__(self, parent, -1, title, style=winstyle,
size=(self.width, self.height), pos=(self.left, self.top))
# Set "Window Variant" to small only for Mac to use small icons
if "__WXMAC__" in wx.PlatformInfo:
self.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
# Initialize Window Layout variables (saved position and size)
self.lastSize = self.GetClientSize()
self.menuWindowLayout = None
self.visualizationWindowLayout = None
self.videoWindowLayout = None
self.transcriptWindowLayout = None
self.dataWindowLayout = None
# Initialize File Management Window
self.fileManagementWindow = None
# Define the Key Down Event Handler
self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
transanaIcon = wx.Icon("images/Transana.ico", wx.BITMAP_TYPE_ICO)
self.SetIcon(transanaIcon)
# Build the Menu System using the MenuSetup Object
self.menuBar = MenuSetup.MenuSetup()
# Define handler for File > New
wx.EVT_MENU(self, MenuSetup.MENU_FILE_NEW, self.OnFileNew)
# Define handler for File > New Database
wx.EVT_MENU(self, MenuSetup.MENU_FILE_NEWDATABASE, self.OnFileNewDatabase)
# Define handler for File > File Management
wx.EVT_MENU(self, MenuSetup.MENU_FILE_FILEMANAGEMENT, self.OnFileManagement)
# Define handler for File > Save Document
wx.EVT_MENU(self, MenuSetup.MENU_FILE_SAVE, self.OnSaveTranscript)
# Define handler for File > Save Document As
wx.EVT_MENU(self, MenuSetup.MENU_FILE_SAVEAS, self.OnSaveTranscriptAs)
# Define handler for File > Print Document
wx.EVT_MENU(self, MenuSetup.MENU_FILE_PRINTTRANSCRIPT, self.OnPrintTranscript)
# Define handler for File > Printer Setup
wx.EVT_MENU(self, MenuSetup.MENU_FILE_PRINTERSETUP, self.OnPrinterSetup)
# Define handler for File > Close All Snapshots
wx.EVT_MENU(self, MenuSetup.MENU_FILE_CLOSE_SNAPSHOTS, self.OnCloseAllSnapshots)
# Define handler for File > Close All Reports
wx.EVT_MENU(self, MenuSetup.MENU_FILE_CLOSE_REPORTS, self.OnCloseAllReports)
# Define handler for File > Exit
wx.EVT_MENU(self, MenuSetup.MENU_FILE_EXIT, self.OnFileExit)
# Define handler for Document > Undo
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_EDIT_UNDO, self.OnTranscriptUndo)
# Define handler for Document > Cut
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_EDIT_CUT, self.OnTranscriptCut)
# Define handler for Document > Copy
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_EDIT_COPY, self.OnTranscriptCopy)
# Define handler for Document > Paste
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_EDIT_PASTE, self.OnTranscriptPaste)
# Define handler for Document > Format Font
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_FONT, self.OnFormatFont)
# If we're using the Rich Text Control ...
if TransanaConstants.USESRTC:
# Define handler for Document > Format Paragraph
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_PARAGRAPH, self.OnFormatParagraph)
# Define handler for Document > Format Tabs
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_TABS, self.OnFormatTabs)
# Define handler for Document > Insert Image
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_INSERT_IMAGE, self.OnInsertImage)
# Define handler for Document > Print
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_PRINT, self.OnPrintTranscript)
# Define handler for Document > Printer Setup
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_PRINTERSETUP, self.OnPrinterSetup)
# Define handler for Document > Change Document Splitter Orientation
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_ORIENTATION, self.OnDocumentOrientation)
# Define handler for Document > Fixed-Increment Time Codes
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_AUTOTIMECODE, self.OnAutoTimeCode)
# Define handler for Document > Adjust Indexes
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_ADJUSTINDEXES, self.OnAdjustIndexes)
# Define handler for Document > Text Time Code Conversion
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_TEXT_TIMECODE, self.OnTextTimeCodeConversion)
# Define handler for Document > Close Current Transcript
wx.EVT_MENU(self, MenuSetup.MENU_TRANSCRIPT_CLOSE_CURRENT, self.OnCloseCurrentTranscript)
# Define handler for Tools > Notes Browser
wx.EVT_MENU(self, MenuSetup.MENU_TOOLS_NOTESBROWSER, self.OnNotesBrowser)
# Define handler for Tools > File Management
wx.EVT_MENU(self, MenuSetup.MENU_TOOLS_FILEMANAGEMENT, self.OnFileManagement)
# Define handler for Tools > Media Conversion
wx.EVT_MENU(self, MenuSetup.MENU_TOOLS_MEDIACONVERSION, self.OnMediaConversion)
# Define handler for Tools > Import Database
wx.EVT_MENU(self, MenuSetup.MENU_TOOLS_IMPORT_DATABASE, self.OnImportDatabase)
# Define handler for Tools > Export Database
wx.EVT_MENU(self, MenuSetup.MENU_TOOLS_EXPORT_DATABASE, self.OnExportDatabase)
# Define handler for Tools > Graphics Color Configuration
wx.EVT_MENU(self, MenuSetup.MENU_TOOLS_COLORCONFIG, self.OnColorConfig)
# Define handler for Tools > Batch Waveform Generator
wx.EVT_MENU(self, MenuSetup.MENU_TOOLS_BATCHWAVEFORM, self.OnBatchWaveformGenerator)
# Define handler for Tools > Chat Window
wx.EVT_MENU(self, MenuSetup.MENU_TOOLS_CHAT, self.OnChat)
# Define handler for Tools > Record Lock Utility
wx.EVT_MENU(self, MenuSetup.MENU_TOOLS_RECORDLOCK, self.OnRecordLock)
# Define handler for Options > Settings
wx.EVT_MENU(self, MenuSetup.MENU_OPTIONS_SETTINGS, self.OnOptionsSettings)
# Define handler for Options > Language changes
wx.EVT_MENU_RANGE(self, MenuSetup.MENU_OPTIONS_LANGUAGE_EN, MenuSetup.MENU_OPTIONS_LANGUAGE_ZH, self.OnOptionsLanguage)
# Define handler for Options > Quick Clip Mode
wx.EVT_MENU(self, MenuSetup.MENU_OPTIONS_QUICK_CLIPS, self.OnOptionsQuickClipMode)
# Define handler for Options > Show Quick Clip Warning
wx.EVT_MENU(self, MenuSetup.MENU_OPTIONS_QUICKCLIPWARNING, self.OnOptionsQuickClipWarning)
# Define handler for Options > Auto Word-tracking
wx.EVT_MENU(self, MenuSetup.MENU_OPTIONS_WORDTRACK, self.OnOptionsWordTrack)
# Define handler for Options > Auto-Arrange
wx.EVT_MENU(self, MenuSetup.MENU_OPTIONS_AUTOARRANGE, self.OnOptionsAutoArrange)
# Define handler for Options > Long Document Editing
# wx.EVT_MENU(self, MenuSetup.MENU_OPTIONS_LONGTRANSCRIPTEDIT, self.OnOptionsLongTranscriptEdit)
# Define handler for Options > Visualization Style changes
wx.EVT_MENU_RANGE(self, MenuSetup.MENU_OPTIONS_VISUALIZATION_WAVEFORM, MenuSetup.MENU_OPTIONS_VISUALIZATION_HYBRID, self.OnOptionsVisualizationStyle)
# Define handler for Options > Media Size changes
wx.EVT_MENU_RANGE(self, MenuSetup.MENU_OPTIONS_VIDEOSIZE_50, MenuSetup.MENU_OPTIONS_VIDEOSIZE_200, self.OnOptionsVideoSize)
# Define handler for Window Menu
wx.EVT_MENU(self, MenuSetup.MENU_WINDOW_ALL_MAIN, self.OnWindow)
wx.EVT_MENU(self, MenuSetup.MENU_WINDOW_ALL_SNAPSHOT, self.OnCloseAllSnapshots)
wx.EVT_MENU(self, MenuSetup.MENU_WINDOW_CLOSE_REPORTS, self.OnCloseAllReports)
wx.EVT_MENU(self, MenuSetup.MENU_WINDOW_DATA, self.OnWindow)
wx.EVT_MENU(self, MenuSetup.MENU_WINDOW_VIDEO, self.OnWindow)
wx.EVT_MENU(self, MenuSetup.MENU_WINDOW_TRANSCRIPT, self.OnWindow)
wx.EVT_MENU(self, MenuSetup.MENU_WINDOW_VISUALIZATION, self.OnWindow)
wx.EVT_MENU(self, MenuSetup.MENU_WINDOW_NOTESBROWSER, self.OnNotesBrowser)
wx.EVT_MENU(self, MenuSetup.MENU_WINDOW_CHAT, self.OnChat)
# Define handler for Help > Manual
wx.EVT_MENU(self, MenuSetup.MENU_HELP_MANUAL, self.OnHelpManual)
# Define handler for Help > Tutorial
wx.EVT_MENU(self, MenuSetup.MENU_HELP_TUTORIAL, self.OnHelpTutorial)
# Define handler for Help > Transcript Notation
wx.EVT_MENU(self, MenuSetup.MENU_HELP_NOTATION, self.OnHelpNotation)
# Define handler for Help > www.transana.org
wx.EVT_MENU(self, MenuSetup.MENU_HELP_WEBSITE, self.OnHelpWebsite)
# Define handler for Help > Fund Transana
# wx.EVT_MENU(self, MenuSetup.MENU_HELP_FUND, self.OnHelpFund)
self.SetMenuBar(self.menuBar)
# Define handler for Help > About
wx.EVT_MENU(self, MenuSetup.MENU_HELP_ABOUT, self.OnHelpAbout)
# Define a Close Event, so that if the user click the "X" on the Menu Frame, everything
# will close properly, including the Media Window.
wx.EVT_CLOSE(self, self.OnCloseWindow)
# This doesn't work for Right-To-Left languages!
if TransanaGlobal.configData.LayoutDirection == wx.Layout_LeftToRight:
MenuSetup.MENU_OPTIONS_MONITOR = []
for x in range(wx.Display.GetCount()):
MenuSetup.MENU_OPTIONS_MONITOR.append(wx.NewId())
if len(MenuSetup.MENU_OPTIONS_MONITOR) > 1:
cnt = 1
self.MenuBar.optionsmonitormenu = wx.Menu()
for x in MenuSetup.MENU_OPTIONS_MONITOR:
self.MenuBar.optionsmonitormenu.Append(x, '%d' % cnt, kind=wx.ITEM_RADIO)
cnt += 1
wx.EVT_MENU(self, x, self.OnMonitor)
self.MenuBar.optionsmenu.AppendMenu(MenuSetup.MENU_OPTIONS_MONITOR_BASE, _("Display Monitor"), self.MenuBar.optionsmonitormenu)
self.MenuBar.optionsmonitormenu.Check(MenuSetup.MENU_OPTIONS_MONITOR[TransanaGlobal.configData.primaryScreen], True)
# Initialize Menus by setting them to their initial starting point
self.ClearMenus()
# We need to know the actual menu height on Windows, as XP has the funky header option that makes the height an unknown.
if 'wxMSW' in wx.PlatformInfo:
# The difference between the actual window size and the Client Size is (surprise!) the height of the
# Header Bar and the Menu. This is exactly what we need to know.
# TransanaGlobal.menuHeight = self.GetSizeTuple()[1] - self.GetClientSizeTuple()[1]
# That worked in wxPython 2.8.x, but not in wxPython 2.9.x!!
# Determine which monitor to use and get its size and position
if TransanaGlobal.configData.primaryScreen < wx.Display.GetCount():
primaryScreen = TransanaGlobal.configData.primaryScreen
else:
primaryScreen = 0
rect = wx.Display(primaryScreen).GetClientArea() # wx.ClientDisplayRect()
# Get the SCREEN coordinates of the CLIENT WINDOW's (0, 0) position
origin = self.ClientToScreen(wx.Point(0, 0))
# This doesn't work for Right-To-Left languages!
if TransanaGlobal.configData.LayoutDirection == wx.Layout_RightToLeft:
primaryScreen = 0
origin = (8, 50)
# The Menu Height needs to be the width of the window's frame (origin[0]) to accomodate the BOTTOM
# of the window plus the height of the top of the frame and the height of the menu, but we
# need to compensate for possibly not being on the primary monitor
# minus 1 because we don't want to show the first pixel below the menu!
TransanaGlobal.menuHeight = origin[0] - rect[0] + origin[1] - rect[1] - 1
if DEBUG:
print "MenuWindow.__init__() 1 Menu Height set to:", rect, origin, TransanaGlobal.menuHeight
print
# Resize the MenuWindow based on this change!
self.SetSize((self.GetSize()[0], TransanaGlobal.menuHeight))
# Set the Minimum Size for the MDI Parent Window
self.SetSizeHints((self.GetSize()[0] * .60),self.GetSize()[1], self.GetSize()[0], self.GetSize()[1])
# Define the OnSize event. We should resize ALL Transana main windows on resizing the Menu Window!
# wx.EVT_SIZE(self, self.OnSize)
# We need to block moving the Menu Bar. This should allow that.
wx.EVT_MOVE(self, self.OnMove)
# Define an event for minimizing or restoring Transana
self.Bind(wx.EVT_ICONIZE, self.OnIconize)
if DEBUG:
print "MenuWindow.__init__(): Initial size:", self.GetSize()
# With wxPython 2.9.x, the MenuWindow can no longer accept focus through pressing the F1 key. Adding a
# useless control, which CAN recieve focus, is the only way I've found to get around this.
if 'wxMSW' in wx.PlatformInfo:
self.tmpCtrl = wx.TextCtrl(self, -1)
self.tmpCtrl.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
def OnKeyDown(self, event):
""" Handle Key Down Events """
# See if the ControlObject wants to handle the key that was pressed.
if self.ControlObject.ProcessCommonKeyCommands(event):
# If so, we're done here.
return
# If we didn't already handle the key ...
elif (event.AltDown()):
# ... pass it along to the parent control. (Leaving this out breaks Menu shortcuts!)
event.Skip()
def OnSize(self, event):
""" Handle Size Events for the MDI parent """
# Call the inherited event so the ClientSize will be correct
event.Skip()
# Compare current size to last known size to determine how much the size has changes and in what direction
changeX = self.GetClientSize()[0] - self.lastSize[0]
changeY = self.GetClientSize()[1] - self.lastSize[1]
# If there's a HORIZONTAL change ...
if (changeX != 0) and TransanaGlobal.configData.autoArrange:
# Get the Visualization Size
visRect = self.ControlObject.VisualizationWindow.GetRect()
# Get the Media Size
vidRect = self.ControlObject.VideoWindow.GetRect()
# Change the Visualization WIDTH by the horizontal change
self.ControlObject.VisualizationWindow.SetRect((visRect[0], visRect[1], visRect[2] + changeX, visRect[3]))
# Change the Media POSITION by the horizontal change
self.ControlObject.VideoWindow.SetRect((vidRect[0] + changeX, vidRect[1], vidRect[2], vidRect[3]))
# If there's a VERTICAL change ...
if (changeY != 0) and TransanaGlobal.configData.autoArrange:
# Get the Data Size
dataRect = self.ControlObject.DataWindow.GetRect()
# Get the Document Size (pick the Document window based on the REMAINDER so each Document gets change in turn!)
trRect = self.ControlObject.TranscriptWindow.GetRect() # len(self.ControlObject.TranscriptWindow)].dlg.GetRect()
# Change the HEIGHT of the Data Window
self.ControlObject.DataWindow.SetRect((dataRect[0], dataRect[1], dataRect[2], dataRect[3] + changeY))
# Change the HEIGHT of the Document Window
self.ControlObject.TranscriptWindow.dlg.SetRect((trRect[0], trRect[1], trRect[2], trRect[3] + changeY))
# Update the Last Known Size value
self.lastSize = self.GetClientSize()
def OnMove(self, event):
# We need to block moving the Menu Bar. This should allow that, except on Linux, where it causes problems in Gnome
# (and perhaps elsewhere.)
if not ('wxGTK' in wx.PlatformInfo):
self.Move(wx.Point(self.left, self.top))
def OnIconize(self, event):
""" When the Menu Window is minimized or restored, all other windows should be too! """
# Pass the instruction on to the Control Object
self.ControlObject.IconizeAll(event.Iconized())
def OnCloseAllSnapshots(self, event):
""" Handler for the Close All Snapshots menu item """
# Tell the Control Object to close all Snapshot Images
self.ControlObject.CloseAllImages()
def OnCloseWindow(self, event):
""" This code forces the Media Window to close when the "X" is used to close the Menu Bar """
# Prompt for save if Document was modified
if TransanaConstants.partialTranscriptEdit:
self.ControlObject.SaveTranscript(1, continueEditing=False)
else:
self.ControlObject.SaveTranscript(1)
# For each Shapshot Window (from the end of the list to the start) ...
while len(self.ControlObject.SnapshotWindows) > 0:
# ... close it, thus releasing any records that might be locked there.
self.ControlObject.SnapshotWindows[len(self.ControlObject.SnapshotWindows) - 1].Close()
# Tell the Control Object to close all the Reports
self.ControlObject.CloseAllReports()
# Check to see if there are Search Results Nodes
if self.ControlObject.DataWindowHasSearchNodes():
# If so, prompt the user about if they really want to exit.
# Define the Message Dialog
dlg = Dialogs.QuestionDialog(self, _('You have unsaved Search Results. Are you sure you want to exit Transana without converting them to Collections?'))
# Display the Message Dialog and capture the response
result = dlg.LocalShowModal()
# Destroy the Message Dialog
dlg.Destroy()
else:
# If no Search Results exist, it's the same as if the user requests to Exit
result = wx.ID_YES
# If the user wants to exit (or if there are no Search Results) ...
if result == wx.ID_YES:
# Signal that we're closing Transana. This allows us to avoid a problem or two on shutdown.
self.ControlObject.shuttingDown = True
# See if there's a Notes Browser open
if self.ControlObject.NotesBrowserWindow != None:
# If so, close it, which saves anything being edited.
self.ControlObject.NotesBrowserWindow.Close()
# unlock the Document Records, if any are locked
# For each Notebook Tab ... (Count backwards from the highest number!)
for tabNum in range(self.ControlObject.TranscriptWindow.nb.GetPageCount() - 1, -1, -1):
# Select the tab (needed for checking and saving documents!)
self.ControlObject.TranscriptWindow.nb.SetSelection(tabNum)
# ... for each splitter pane on the notebook tab ...
for pane in self.ControlObject.TranscriptWindow.nb.GetPage(tabNum).GetChildren():
# Activate the Panel so TranscriptModified call will be accurate
pane.ActivatePanel()
# Turn off the Line Number Timer
pane.LineNumTimer.Stop()
# If the Document has been modified ...
if pane.TranscriptModified():
x = pane.panelNum
# ... save it!
if TransanaConstants.partialTranscriptEdit:
self.ControlObject.SaveTranscript(1, transcriptToSave=x, continueEditing=False)
else:
self.ControlObject.SaveTranscript(1, transcriptToSave=x)
# If the Document is locked ...
if (pane.editor.TranscriptObj != None) and \
(pane.editor.TranscriptObj.isLocked):
# ... unlock it
pane.editor.TranscriptObj.unlock_record()
## # Close the Document Window
## pane.Close()
# If we have the multi-user version ...
if not TransanaConstants.singleUserVersion:
# ... stop the Connection Timer.
TransanaGlobal.connectionTimer.Stop()
# Save Configuration Data
TransanaGlobal.configData.SaveConfiguration()
# We need to force the Media Window to close along with all of the other windows.
# (The other windows all close automatically.)
if self.ControlObject != None:
if self.ControlObject.TranscriptWindow != None:
self.ControlObject.TranscriptWindow.Close()
if self.ControlObject.DataWindow != None:
# Close the Data Window
self.ControlObject.DataWindow.Close()
if self.ControlObject.VideoWindow != None:
self.ControlObject.VideoWindow.Close()
if self.ControlObject.VisualizationWindow != None:
self.ControlObject.VisualizationWindow.Close()
# Close the connection to the Database, if one is open
if DBInterface.is_db_open():
DBInterface.close_db()
# Terminate MySQL if using the embedded version.
# (This is slow, so should be done as late as possible, preferably after windows are closed.)
if TransanaConstants.singleUserVersion:
DBInterface.EndSingleUserDatabase()
# Alternately, if we're in the Multi-user version, we need to close the Chat Window, which
# ends the socket connection to the Transana MessageServer.
else:
# If a Chat Window exists ...
if TransanaGlobal.chatWindow != None:
# Closing the form will cause an expected Socket Loss, which should not be reported.
TransanaGlobal.chatWindow.reportSocketLoss = False
# ... close it ...
TransanaGlobal.chatWindow.OnFormClose(event)
# ... and destroy the form so Transana won't hang on closing
TransanaGlobal.chatWindow.Destroy()
# ... and set the pointer to None
TransanaGlobal.chatWindow = None
# If we are running from a BUILD instead of source code ...
if hasattr(sys, "frozen") or ('wxMac' in wx.PlatformInfo):
# Put a shutdown indicator in the Error Log
print "Transana stopped:", time.asctime()
print
# Destroy the Menu Window
self.Destroy()
# On the Mac ...
if 'wxMac' in wx.PlatformInfo:
# ... Transana is not exiting properly on OS X 10.10.3. This should ensure the program ends.
sys.exit(0)
# If the user reconsiders exiting...
else:
# If the Close Event is triggered from the Menu, the event has no Veto property.
# We should only call Veto if this is called by pressing the Frame's Close Control [X].
if event.GetId() != MenuSetup.MENU_FILE_EXIT:
# ... Veto (block) the Close event
event.Veto()
def Register(self, ControlObject=None):
""" Register a ControlObject """
# If a Control Object is registered, we need to remember it.
self.ControlObject=ControlObject
def ClearMenus(self):
# Set Menus to their initial default values
self.menuBar.filemenu.Enable(MenuSetup.MENU_FILE_SAVE, False)
# Most Document Menu items default to disabled until a Document
# is loaded
self.SetTranscriptOptions(False)
self.SetTranscriptEditOptions(False)
def SetTranscriptOptions(self, enable):
"""Enable or disable the menu options that depend on whether or not a Document is loaded."""
self.menuBar.filemenu.Enable(MenuSetup.MENU_FILE_SAVEAS, enable)
# If we have Right to Left text, we cannot enable PRINT because it doesn't work right due to wxWidgets bugs.
if TransanaGlobal.configData.LayoutDirection == wx.Layout_RightToLeft:
self.menuBar.filemenu.Enable(MenuSetup.MENU_FILE_PRINTTRANSCRIPT, False)
else:
self.menuBar.filemenu.Enable(MenuSetup.MENU_FILE_PRINTTRANSCRIPT, enable)
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_EDIT_COPY, enable)
# If we have Right to Left text, we cannot enable PRINT because it doesn't work right due to wxWidgets bugs.
if TransanaGlobal.configData.LayoutDirection == wx.Layout_RightToLeft:
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_PRINT, False)
else:
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_PRINT, enable)
def SetTranscriptEditOptions(self, enable):
"""Enable or disable the menu options that depend on whether or not
a Document is editable."""
self.menuBar.filemenu.Enable(MenuSetup.MENU_FILE_SAVE, enable)
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_EDIT_UNDO, enable)
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_EDIT_CUT, enable)
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_EDIT_PASTE, enable)
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_FONT, enable)
if TransanaConstants.USESRTC:
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_PARAGRAPH, enable)
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_TABS, enable)
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_INSERT_IMAGE, enable)
if enable and self.ControlObject.AutoTimeCodeEnableTest():
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_AUTOTIMECODE, enable)
else:
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_AUTOTIMECODE, False)
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_ADJUSTINDEXES, enable)
# If there are NO existing Time Codes ...
if enable and self.ControlObject.AutoTimeCodeEnableTest():
# ... enable Text Time Code Conversion
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_TEXT_TIMECODE, enable)
# If there are existing time codes ...
else:
# ... then we can't do Text Time Code conversion
self.menuBar.transcriptmenu.Enable(MenuSetup.MENU_TRANSCRIPT_TEXT_TIMECODE, False)
def OnFileNew(self, event):
""" Implements File New menu command """
# If a Control Object has been defined ...
if self.ControlObject != None:
# set the active Document to 0 so multiple Document will be cleared
self.ControlObject.activeTranscript = 0