forked from sanyaade-machine-learning/Transana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigData.py
635 lines (596 loc) · 32.9 KB
/
ConfigData.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
# 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 contains Transana's Configuration Information."""
__author__ = 'David Woods <[email protected]>, Rajas Sambhare'
DEBUG = False
if DEBUG:
print "ConfigData DEBUG is ON! NOTE: THIS MUST BE RUN THROUGH IDLE for Unicode support."
# Import wxPython
import wx
# Import the Styled Text Control for a constant
from wx import stc
# import Python os module
import os
## # import Python sys module
## import sys
# Import Transana's Constants
import TransanaConstants
# Import Transana's Globals
import TransanaGlobal
# import Python's pickle module
import pickle
class ConfigData(object):
""" This module handles Transana Configuration Data, including loading and saving this data. """
def __init__(self):
""" Initialize the ConfigData Object """
# Load the data that has been stored or get default values if not stored
self.LoadConfiguration()
# Set default values for parameters that are not saved
# Video Speed of 10 is equal to normal playback speed
self.videoSpeed = 10
# Auto Arrange is enabled by default
self.autoArrange = True
# Set default values for Dialog Size values which are not saved as part of the configuration file
self.quotePropertiesSize = (680, 550)
self.clipPropertiesSize = (680, 550)
self.keywordListEditSize = (600, 385)
def __repr__(self):
""" String Representation of the data in this object. """
str = 'ConfigData Object:\n'
str = str + 'host = %s\n' % self.host
str = str + 'dbport = %s\n' % self.dbport
str = str + 'database = %s\n' % self.database
str = str + 'visualizationPath = %s\n' % self.visualizationPath
str = str + 'videoPath = %s\n' % self.videoPath
str = str + 'transcriptionSetback = %s\n' % self.transcriptionSetback
str = str + 'videoSpeed = %s\n' % self.videoSpeed
str = str + 'videoSize = %s\n' % self.videoSize
str = str + 'quickClipMode = %s\n' % self.quickClipMode
str = str + 'wordTracking = %s\n' % self.wordTracking
str = str + 'autoArrange = %s\n' % self.autoArrange
str = str + 'Visualization style = %s\n' % self.visualizationStyle
str = str + 'messageServer = %s\n' % self.messageServer
str = str + 'messageServerPort = %s\n' % self.messageServerPort
str = str + 'ssl = %s\n' % self.ssl
str = str + 'sslClientCert = %s\n' % self.sslClientCert
str = str + 'sslClientKey = %s\n' % self.sslClientKey
srt = str + 'sslMsgSrvCert = %s\n' % self.sslMsgSrvCert
str = str + 'language = %s\n\n' % self.language
str = str + 'databaseList = %s\n\n' % self.databaseList
str += 'pathsByDB = %s\n' % self.pathsByDB
str += 'pathsByDB2 = %s\n' % self.pathsByDB2
str += 'tabSize = %s\n' % self.tabSize
str += 'wordWrap = %s\n' % self.wordWrap
str += 'autoSave = %s\n' % self.autoSave
str += 'maxTranscriptImageWidth = %s\n' % self.maxTranscriptImageWidth
str = str + 'defaultFontFace = %s\n' % self.defaultFontFace
str = str + 'defaultFontSize = %s\n' % self.defaultFontSize
str = str + 'specialFontFace = %s\n' % self.specialFontFace
str = str + 'specialFontSize = %s\n' % self.specialFontSize
str += 'formatUnits = %s\n' % self.formatUnits
## str += 'transcriptScale = %s\n' % self.transcriptScale
str = str + 'keywordMapBarHeight = %s\n' % self.keywordMapBarHeight
str = str + 'keywordMapWhitespace = %s\n' % self.keywordMapWhitespace
str = str + 'keywordVisualizationBarHeight = %s\n' % self.keywordVisualizationBarHeight
str = str + 'keywordVisualizationWhitespace = %s\n' % self.keywordVisualizationWhitespace
str = str + 'seriesMapBarHeight = %s\n' % self.seriesMapBarHeight
str = str + 'seriesMapWhitespace = %s\n' % self.seriesMapWhitespace
str = str + 'keywordMapHorizontalGridLines = %s\n' % self.keywordMapHorizontalGridLines
str = str + 'keywordMapVerticalGridLines = %s\n' % self.keywordMapVerticalGridLines
str = str + 'keywordVisualizationHorizontalGridLines = %s\n' % self.keywordVisualizationHorizontalGridLines
str = str + 'keywordVisualizationVerticalGridLines = %s\n' % self.keywordVisualizationVerticalGridLines
str = str + 'seriesMapHorizontalGridLines = %s\n' % self.seriesMapHorizontalGridLines
str = str + 'seriesMapVerticalGridLines = %s\n' % self.seriesMapVerticalGridLines
str = str + 'singleLineDisplay = %s\n' % self.singleLineDisplay
str = str + 'showLegend = %s\n' % self.showLegend
str = str + 'colorOutput = %s\n' % self.colorOutput
str += 'colorAsKeywords = %s\n' % self.colorAsKeywords
str = str + 'colorConfigFilename = %s\n' % self.colorConfigFilename
str = str + 'quickClipsWarning = %s\n' % self.quickClipWarning
if 'wxMSW' in wx.PlatformInfo:
str = str + 'mediaPlayer = %s\n\n' % self.mediaPlayer
return str
def LoadConfiguration(self):
""" Load Configuration Data from Registry or Config File """
# Define the default VisualizationPath as the Transana Data Path's 'waveforms' subfolder
defaultVisualizationPath = os.path.join(self.GetDefaultProfilePath(), 'waveforms')
# Define the default DatabasePath as the Transana Data Path's 'databases' subfolder
defaultDatabaseDir = os.path.join(self.GetDefaultProfilePath(), 'databases')
# Embedded MySQL can only work with Latin-1 compatible paths. The following
# code checks to make sure the path will work, and tries a couple of
# substitutions if necessary.
try:
# First, let's see if the Database Dir is Latin-1 compatible
temp = defaultDatabaseDir.encode('latin1')
except UnicodeError:
# If not, try the Program Dir + 'database'
defaultDatabaseDir = os.path.join(TransanaGlobal.programDir, 'databases')
# Unfortunately, the Program Dir might not be Latin-1 compatible. Check that.
# for testing non-English systems
# defaultDatabaseDir = u'E:\\Video\\\u4eb2\u4eb3\u4eb2'
# print "ConfigData.LoadConfiguration(): defaultDatabaseDir overridden"
try:
# See if the new Database Dir is Latin-1 compatible
temp = defaultDatabaseDir.encode('latin1')
except UnicodeError:
# If we're still in trouble, let's build the path from scratch
if 'wxMSW' in wx.PlatformInfo:
defaultDatabaseDir = 'C:' + os.sep + 'Transana 2' + os.sep + 'databases'
else:
# Actually, I have no idea if this will work. I'd bet permissions issues will prevent it.
# But I have no way to pursue the issue further for the Mac until I find a user who's willing to help.
defaultDatabaseDir = os.path.join('Transana 2', 'databases')
# Define the Default Database Host
if TransanaConstants.singleUserVersion:
defaultHost = 'localhost'
else:
defaultHost = ''
# Default tab size is 4
self.tabSize = '4'
# Default Font Face is Courier New, a fixed-width font
self.defaultFontFace = "Courier New"
# Default Font Size is 10, reasoning that smaller is better
self.defaultFontSize = 10
# Special Font Face is Courier New, a fixed-width font
self.specialFontFace = "Courier New"
# Special Font Size is 14, reasoning that it should be 4 points larger than normal to look right
self.specialFontSize = 14
# Load the Config Data. wxConfig automatically uses the Registry on Windows and the appropriate file on Mac.
# Program Name is Transana, Vendor Name is Verception to remain compatible with Transana 1.0.
config = wx.Config('Transana', 'Verception')
# See if a version 2.0 Configuration exists, and use it if so
if config.Exists('/2.0'):
# Load Host
if TransanaConstants.singleUserVersion:
self.host = config.Read('/2.0/host', defaultHost)
else:
self.host = config.Read('/2.0/hostMU', defaultHost)
# Load Database and Database Directory(single user version only)
if TransanaConstants.singleUserVersion:
self.database = config.Read('/2.0/database', '')
self.databaseDir = config.Read('/2.0/Directories/databaseDir', defaultDatabaseDir)
else:
self.database = config.Read('/2.0/databaseMU', '')
self.databaseDir = config.Read('/2.0/Directories/databaseDir', defaultDatabaseDir)
# Load Visualization Path
self.visualizationPath = config.Read('/2.0/Directories/visualizationPath', defaultVisualizationPath)
# Load Video Root Path
self.videoPath = config.Read('/2.0/Directories/videoPath', '')
# Load Transcriber Setback setting
self.transcriptionSetback = config.ReadInt('/2.0/TranscriptionSetback', 2)
# Load Video Size setting
self.videoSize = config.ReadInt('/2.0/VideoSize', 100)
# Load the Visualization Style
self.visualizationStyle = config.Read('/2.0/visualizationStyle', 'Waveform')
# Load Quick Clip Mode setting
self.quickClipMode = config.ReadInt('/2.0/QuickClipMode', True)
# Load Auto Word-Tracking setting
self.wordTracking = config.ReadInt('/2.0/WordTracking', True)
# Load Message Server Host Setting
self.messageServer = config.Read('/2.0/MessageHost', '')
# Load Message Server Port Setting
self.messageServerPort = config.ReadInt('/2.0/MessagePort', 17595)
# Load SSL Setting
self.ssl = config.ReadInt('/2.0/SSL', 0)
# Load SSL Client Certificate File Setting
self.sslClientCert = config.Read('/2.0/SSLClientCert', '')
# Load SSL Client Key File Setting
self.sslClientKey = config.Read('/2.0/SSLClientKey', '')
# Load the SSL Message Server Certificate File Setting
self.sslMsgSrvCert = config.Read('/2.0/SSLMessageServerCertificate', '')
# Load Language Setting
self.language = config.Read('/2.0/Language', '')
# Load the Tab Size Setting
self.tabSize = config.Read('/2.0/TabSize', '4')
# Load the Word Wrap setting
self.wordWrap = config.ReadInt('/2.0/WordWrap', stc.STC_WRAP_WORD)
# Load the Auto Save setting
self.autoSave = config.ReadInt('2.0/AutoSave', True)
# Load Max Transcript Image Width
self.maxTranscriptImageWidth = config.ReadInt('2.0/MaxTranscriptImageWidth', 1)
# Load Default Font Face Setting
self.defaultFontFace = config.Read('/2.0/FontFace', self.defaultFontFace)
# Load Default Font Size Setting
self.defaultFontSize = config.ReadInt('/2.0/FontSize', self.defaultFontSize)
# Load Special Font Face Setting
self.specialFontFace = config.Read('/2.0/FontFaceSpecial', self.specialFontFace)
# Load Special Font Size Setting
self.specialFontSize = config.ReadInt('/2.0/FontSizeSpecial', self.specialFontSize)
# Load Format Units Setting
self.formatUnits = config.Read('/2.0/FormatUnits', 'in')
## # For the Transcript Scaling Factor, if we're on OS X ...
## if sys.platform == 'darwin':
## # ... default to 1.25 times normal size
## defVal = 1.25
## # Otherwise ...
## else:
## # ... use the normal size
## defVal = 1.00
## # Load the Transcript Scaling Factor
## self.transcriptScale = config.ReadFloat('/2.0/TranscriptScale', defVal)
# Load Keyword Map Bar Height Setting
self.keywordMapBarHeight = config.ReadInt('/2.0/KeywordMapBarHeight', 8)
# Load Keyword Map Whitespace Height Setting
self.keywordMapWhitespace = config.ReadInt('/2.0/KeywordMapWhitespace', 2)
# Load Keyword Visualization Bar Height Setting
self.keywordVisualizationBarHeight = config.ReadInt('/2.0/KeywordVisualizationBarHeight', 5)
# Load Keyword Visualization Whitespace Height Setting
self.keywordVisualizationWhitespace = config.ReadInt('/2.0/KeywordVisualizationWhitespace', 2)
# Load Series Map Bar Height Setting
self.seriesMapBarHeight = config.ReadInt('/2.0/SeriesMapBarHeight', 8)
# Load Series Map Whitespace Height Setting
self.seriesMapWhitespace = config.ReadInt('/2.0/SeriesMapWhitespace', 2)
# Load Keyword Map Horizontal Grid Lines Setting
self.keywordMapHorizontalGridLines = config.ReadInt('/2.0/KeywordMapHorizontalGridLines', False)
# Load Keyword Map Vertical Grid Lines Setting
self.keywordMapVerticalGridLines = config.ReadInt('/2.0/KeywordMapVerticalGridLines', False)
# Load Keyword Visualization Horizontal Grid Lines Setting
self.keywordVisualizationHorizontalGridLines = config.ReadInt('/2.0/KeywordVisualizationHorizontalGridLines', False)
# Load Keyword Visualization Vertical Grid Lines Setting
self.keywordVisualizationVerticalGridLines = config.ReadInt('/2.0/KeywordVisualizationVerticalGridLines', False)
# Load Series Map Horizontal Grid Lines Setting
self.seriesMapHorizontalGridLines = config.ReadInt('/2.0/SeriesMapHorizontalGridLines', False)
# Load Series Map Vertical Grid Lines Setting
self.seriesMapVerticalGridLines = config.ReadInt('/2.0/SeriesMapVerticalGridLines', False)
# Load the Series Map Sequence Map Single Line Setting
self.singleLineDisplay = config.ReadInt('/2.0/SeriesMapSequenceMapSingleLine', False)
# For Windows only ...
if 'wxMSW' in wx.PlatformInfo:
# ... load the Media Player selection
self.mediaPlayer = config.ReadInt('/2.0/MediaPlayer', 0)
# If no version 2.0 Config File exists, ...
else:
# See if a verion 1 config file exists, and use it's data if it does.
if config.Exists('/1.0/'):
# Load Visualization Path
self.visualizationPath = config.Read('/1.0/Directories/Waveforms', defaultVisualizationPath)
# Set default database directory
self.databaseDir = defaultDatabaseDir
# Load Message Server Host Setting
self.messageServer = config.Read('/1.0/MessageHost', '')
# Load Message Server Port Setting
self.messageServerPort = config.ReadInt('/1.0/MessagePort', 17595)
# If no Config File exists, use default settings
else:
# Set Default Visualization Path
self.visualizationPath = defaultVisualizationPath
# Set Default Database directory
self.databaseDir = defaultDatabaseDir
# There is no default Message Server Host
self.messageServer = ''
# Set Default Message Server Port
self.messageServerPort = 17595
# Set SSL Setting
self.ssl = 0
# Set SSL Client Certificate File Setting
self.sslClientCert = ''
# Set SSL Client Key File Setting
self.sslClientKey = ''
# Set the SSL Message Server Certificate File Setting
self.sslMsgSrvCert = ''
# Default Database Host
self.host = defaultHost
# Default Database
self.database = ''
# Set Default Video Root Folder
self.videoPath = ''
# Default Transcriber Setback is 2 seconds
self.transcriptionSetback = 2
# Default Video Size is 100%
self.videoSize = 100
# Default Visualization Style is Waveform
self.visualizationStyle = 'Waveform'
# Quick Clip Mode should be disabled by default
self.quickClipMode = True
# Auto Word Tracking is enabled by default
self.wordTracking = True
# Word Wrap
self.wordWrap = stc.STC_WRAP_WORD
# Auto Save
self.autoSave = True
# Max Transcript Image Width
self.maxTranscriptImageWidth = 1
# Language setting
self.language = ''
# Format Units
self.formatUnits = 'in'
## # For the Transcript Scaling Factor, if we're on OS X ...
## if sys.platform == 'darwin':
## # ... default to 1.25 times normal size
## self.transcriptScale = 1.25
## # Otherwise ...
## else:
## # ... use the normal size
## self.transcriptScale = 1.00
# Load Keyword Map Bar Height Setting
self.keywordMapBarHeight = 8
# Load Keyword Map Whitespace Height Setting
self.keywordMapWhitespace = 2
# Load Keyword Visualization Bar Height Setting
self.keywordVisualizationBarHeight = 5
# Load Keyword Visualization Whitespace Height Setting
self.keywordVisualizationWhitespace = 2
# Load Series Map Bar Height Setting
self.seriesMapBarHeight = 8
# Load Series Map Whitespace Height Setting
self.seriesMapWhitespace = 2
# Load Keyword Map Horizontal Grid Lines Setting
self.keywordMapHorizontalGridLines = False
# Load Keyword Map Vertical Grid Lines Setting
self.keywordMapVerticalGridLines = False
# Load Keyword Visualization Horizontal Grid Lines Setting
self.keywordVisualizationHorizontalGridLines = False
# Load Keyword Visualization Vertical Grid Lines Setting
self.keywordVisualizationVerticalGridLines = False
# Load Series Map Horizontal Grid Lines Setting
self.seriesMapHorizontalGridLines = False
# Load Series Map Vertical Grid Lines Setting
self.seriesMapVerticalGridLines = False
# Load the Series Map Sequence Map Single Line Setting
self.singleLineDisplay = False
# For Windows only ...
if 'wxMSW' in wx.PlatformInfo:
# ... load the Media Player selection
self.mediaPlayer = 0
# Load Port
if not TransanaConstants.singleUserVersion:
self.dbport = config.Read('/2.0/dbport', '3306')
else:
self.dbport = '3306'
# Initialize the Show Legend setting
self.showLegend = True
# Initialize Color Output Setting
self.colorOutput = True
# Initialize the colorAsKeywords setting for the Keyword Map
self.colorAsKeywords = config.ReadInt('/2.0/ColorAsKeywords', 0)
# Initialize Color Configuration Filename
self.colorConfigFilename = config.Read('/2.0/ColorConfigFilename', '')
# Load the Quick Clips Warning setting
self.quickClipWarning = config.ReadInt('/2.0/QuickClipWarning', True)
# Load the Primary Screen setting
self.primaryScreen = config.ReadInt('/2.0/PrimaryScreen', 0)
# Check for screen set to higher than current number of monitors
if self.primaryScreen >= wx.Display.GetCount():
# If so, set to main screen (0)
self.primaryScreen = 0
# Load the databaseList, if it exists
# NOTE: if using Unicode, this MUST be a String object!
if TransanaConstants.singleUserVersion:
dbList = str(config.Read('/3.0/DatabaseListSU', ''))
else:
dbList = str(config.Read('/2.0/DatabaseListMU', ''))
if DEBUG:
print "ConfigData.LoadConfiguration(): dbList = '%s'" % dbList
# The early versions (Alpha and Beta releases) used a different system. Check to see
# if we need to get the data from there!
# If dbList is empty, let's see if a pickle file exists of the database host and database combinations
if dbList == '':
if TransanaConstants.singleUserVersion:
# Name of the file for pickling the single-user Database Information
dbFile = 'TransanaDBs.pkl'
else:
# Name of the file for pickling the multi-user Database Information
dbFile = 'TransanaMUDBs.pkl'
# Add the data path to the pickle file name
dbFile = os.path.join(self.databaseDir, dbFile)
# Initialize the database list to an empty dictionary
self.databaseList = {}
# See if Database Definitions have been pickled on this computer.
if os.path.exists(dbFile):
try:
# If so, try to open it
file = open(dbFile, 'r')
# Load the Databases structure from the pickle file
self.databaseList = pickle.load(file)
except:
print "Exception in ConfigData loading Databases."
self.Databases = {}
# if the dbList from the Config files is not empty, we need to unpickle the string to restore the dictionary object
else:
self.databaseList = pickle.loads(dbList)
if DEBUG:
print "ConfigData.LoadConfiguration(): self.databaseList ="
for h in self.databaseList.keys():
for d in self.databaseList[h]:
print h, d
# Read the dictionary object that stores Path information for different databases
pathsByDB = str(config.Read('/3.0/pathsByDB', ''))
# If we get the default value of '' ...
if pathsByDB == '':
# ... then we want this variable to be an empty dictionary object
self.pathsByDB = {}
# If there is already data in the config file ...
else:
# ... we need to unpack it to make it usable.
self.pathsByDB = pickle.loads(pathsByDB)
# When converting databases, we may need OLD information from the version 2.0 pathByDB config object!
pathsByDB2 = str(config.Read('/2.0/pathsByDB', ''))
# If we get the default value of '' ...
if pathsByDB2 == '':
# ... then we want this variable to be an empty dictionary object
self.pathsByDB2 = {}
# If there is already data in the config file ...
else:
# ... we need to unpack it to make it usable.
self.pathsByDB2 = pickle.loads(pathsByDB2)
# Embedded MySQL can only work with Latin-1 compatible paths. The following
# code checks to make sure the path will work. This final check handles the situation where
# an improper path is saved in the configuration file, which is entirely possible, as the selection
# browser does no tests.
try:
# First, let's see if the Database Dir is Latin-1 compatible
temp = self.databaseDir.encode('latin1')
except UnicodeError:
# NOTE: Can't use the Dialogs.ErrorDialog here. The wxApp object hasn't been created yet.
msg = _("Illegal Database Directory specification.\nCurrent Directory replaced with\n%s.") % (defaultDatabaseDir)
print msg
self.databaseDir = defaultDatabaseDir
def SaveConfiguration(self):
""" Save Configuration Data to the Registry or a Config File. """
# The Lab version should not save configuration data ...
if TransanaConstants.labVersion:
# ... so just skip this method entirely!
return
# Save the Config Data. wxConfig automatically uses the Registry on Windows and the appropriate file on Mac.
# Program Name is Transana, Vendor Name is Verception to remain compatible with Transana 1.0.
config = wx.Config('Transana', 'Verception')
# Save the Host
if TransanaConstants.singleUserVersion:
config.Write('/2.0/host', self.host)
else:
config.Write('/2.0/hostMU', self.host)
# Load Port
if not TransanaConstants.singleUserVersion:
config.Write('/2.0/dbport', self.dbport)
# Save the Database
if TransanaConstants.singleUserVersion:
config.Write('/2.0/database', self.database)
config.Write('/2.0/Directories/databaseDir', self.databaseDir)
else:
config.Write('/2.0/databaseMU', self.database)
config.Write('/2.0/Directories/databaseDir', self.databaseDir)
# Save the Visualization Path
config.Write('/2.0/Directories/visualizationPath', self.visualizationPath)
# Save the Video Root Folder
config.Write('/2.0/Directories/videoPath', self.videoPath)
# Save the Transcriber Setback setting
config.WriteInt('/2.0/TranscriptionSetback', self.transcriptionSetback)
# Save the Video Size setting
config.WriteInt('/2.0/VideoSize', self.videoSize)
# Save the Visualization Style
config.Write('/2.0/visualizationStyle', self.visualizationStyle)
# Save the Quick Clip Mode setting
config.WriteInt('/2.0/QuickClipMode', self.quickClipMode)
# Save the Auto Word Tracking setting
config.WriteInt('/2.0/WordTracking', self.wordTracking)
# Save the Message Server Host
config.Write('/2.0/MessageHost', self.messageServer)
# Save the Message Server Port
config.WriteInt('/2.0/MessagePort', self.messageServerPort)
# Save the SSL Setting
config.WriteInt('/2.0/SSL', self.ssl)
# Save the SSL Client Certificate File
config.Write('/2.0/SSLClientCert', self.sslClientCert)
# Save the SSL Client Certificate Key
config.Write('/2.0/SSLClientKey', self.sslClientKey)
config.Write('/2.0/SSLMessageServerCertificate', self.sslMsgSrvCert)
# Save the Language setting
config.Write('/2.0/Language', self.language)
# NOTE: Video Speed, Auto-Arrange, and Waveform Quickload are NOT saved to the config file.
# We decided it was better to have them reset to default values when the program is restarted.
if DEBUG:
print "ConfigData.SaveConfiguration(): self.databaseList ="
for h in self.databaseList.keys():
for d in self.databaseList[h]['dbList']:
print h, d
# Save the list of Databases this user has used as a string by pickling it
tmpDbList = pickle.dumps(self.databaseList)
if DEBUG:
print "ConfigData.SaveConfiguration(): tmpDbList = '%s'" % tmpDbList
if TransanaConstants.singleUserVersion:
config.Write('/3.0/DatabaseListSU', tmpDbList)
else:
config.Write('/2.0/DatabaseListMU', tmpDbList)
# To save the dictionary of paths for different databases, we must first pickle it
tmpPathsByDB = pickle.dumps(self.pathsByDB)
# Now we can save it to the config file/registry
config.Write('/3.0/pathsByDB', tmpPathsByDB)
# Save Tab Size setting
config.Write('/2.0/TabSize', self.tabSize)
# Save the Word Wrap setting
config.WriteInt('/2.0/WordWrap', self.wordWrap)
# Save the AutoSave Setting
config.WriteInt('/2.0/AutoSave', self.autoSave)
# Save the Max Transcript Image Width Setting
config.WriteInt('/2.0/MaxTranscriptImageWidth', self.maxTranscriptImageWidth)
# Save Default Font Face Setting
config.Write('/2.0/FontFace', self.defaultFontFace)
# Save Default Font Size Setting
config.WriteInt('/2.0/FontSize', self.defaultFontSize)
# Save Special Font Face Setting
config.Write('/2.0/FontFaceSpecial', self.specialFontFace)
# Save Special Font Size Setting
config.WriteInt('/2.0/FontSizeSpecial', self.specialFontSize)
# Save Format Units Setting
config.Write('/2.0/FormatUnits', self.formatUnits)
## # Save the Transcript Scaling Factor
## config.WriteFloat('/2.0/TranscriptScale', self.transcriptScale)
# Save Keyword Map Bar Height Setting
config.WriteInt('/2.0/KeywordMapBarHeight', self.keywordMapBarHeight)
# Save Keyword Map Whitespace Setting
config.WriteInt('/2.0/KeywordMapWhitespace', self.keywordMapWhitespace)
# Save Keyword Visualization Bar Height Setting
config.WriteInt('/2.0/KeywordVisualizationBarHeight', self.keywordVisualizationBarHeight)
# Save Keyword Visualization Whitespace Setting
config.WriteInt('/2.0/KeywordVisualizationWhitespace', self.keywordVisualizationWhitespace)
# Save Series Map Bar Height Setting
config.WriteInt('/2.0/SeriesMapBarHeight', self.seriesMapBarHeight)
# Save Series Map Whitespace Setting
config.WriteInt('/2.0/SeriesMapWhitespace', self.seriesMapWhitespace)
# Save Keyword Map Horizontal Grid Lines Setting
config.WriteInt('/2.0/KeywordMapHorizontalGridLines', self.keywordMapHorizontalGridLines)
# Save Keyword Map Vertical Grid Lines Setting
config.WriteInt('/2.0/KeywordMapVerticalGridLines', self.keywordMapVerticalGridLines)
# Save Keyword Visualization Horizontal Grid Lines Setting
config.WriteInt('/2.0/KeywordVisualizationHorizontalGridLines', self.keywordVisualizationHorizontalGridLines)
# Save Keyword Visualization Vertical Grid Lines Setting
config.WriteInt('/2.0/KeywordVisualizationVerticalGridLines', self.keywordVisualizationVerticalGridLines)
# Save Series Map Horizontal Grid Lines Setting
config.WriteInt('/2.0/SeriesMapHorizontalGridLines', self.seriesMapHorizontalGridLines)
# Save Series Map Vertical Grid Lines Setting
config.WriteInt('/2.0/SeriesMapVerticalGridLines', self.seriesMapVerticalGridLines)
# Save the Series Map Sequence Map Single Line Setting
config.WriteInt('/2.0/SeriesMapSequenceMapSingleLine', self.singleLineDisplay)
# Save the Keyword Map's colorAsKeywords setting
config.WriteInt('/2.0/ColorAsKeywords', self.colorAsKeywords)
# Save Color Configuration Filename
config.Write('/2.0/ColorConfigFilename', self.colorConfigFilename)
# Save the Quick Clips Warning setting
config.WriteInt('/2.0/QuickClipWarning', self.quickClipWarning)
# For Windows only ...
if 'wxMSW' in wx.PlatformInfo:
# ... save the Media Player selection
config.WriteInt('/2.0/MediaPlayer', self.mediaPlayer)
# if the current primary display is valid ...
if self.primaryScreen < wx.Display.GetCount():
# ... save the Primary Screen setting
config.WriteInt('/2.0/PrimaryScreen', self.primaryScreen)
def GetDefaultProfilePath(self):
""" Query the operating system and get the default path for user data. """
# Initialize the default Profile Path to None
defaultProfilePath = None
# Try to get the proper Profile Path from the OS.
if "__WXMSW__" in wx.Platform:
# Define a wx.StandardPaths object
sp = wx.StandardPaths.Get()
# Get the user's document directory
defaultProfilePath = sp.GetDocumentsDir()
elif "__WXMAC__" in wx.Platform:
# Mac OS/X should use HOME, which generally points to
# /Users/USERNAME
defaultProfilePath = os.getenv("HOME")
else: # Assuming that getenv("HOME") returns something useful
defaultProfilePath = os.getenv("HOME")
# I think the above fails for Windows 98 and Windows Me. So if we don't get
# something from the above, let's fall back to using the Program Directory here.
if defaultProfilePath == None:
defaultProfilePath = TransanaGlobal.programDir
else:
defaultProfilePath = os.path.join(defaultProfilePath, 'Transana 2')
# for testing non-English systems
# defaultProfilePath = u'E:\\Video\\\u4eb2\u4eb3\u4eb2'
# print "ConfigData.GetDefaultProfilePath() overridden"
return defaultProfilePath