forked from sanyaade-machine-learning/Transana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SnapshotWindow.py
2510 lines (2264 loc) · 129 KB
/
SnapshotWindow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (C) 2003 - 2015 The Board of Regents of the University of Wisconsin System
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
"""This module contains functions for manipulating and coding still images in Transana."""
__author__ = 'David K. Woods <[email protected]>'
DEBUG=False
if DEBUG:
print "SnapshotWindow DEBUG is ON!!"
# import wxPython
import wx
# import the FloatCanvas, FloatCanvas Resources, and FloatCanvas GUIMode module
from wx.lib.floatcanvas import FloatCanvas, Resources, GUIMode
# Import the Python os and sys modules
import os, sys
# Import Transana's Collection Object
import Collection
# import Transana's Dialogs
import Dialogs
# import Transana's Database Interface
import DBInterface
# Import Transana's Keyword Object
import KeywordObject
# import Transana's Keyword List Edit Form
import KeywordListEditForm
# import the Transana Snapshot Object
import Snapshot
# import Transana's constants
import TransanaConstants
# Import Transana Exceptions
import TransanaExceptions
# Import Transana Globals (for color objects)
import TransanaGlobal
# Import Transana images
import TransanaImages
# Define Menu constants
MENU_FILE_CLEAR = wx.NewId()
MENU_FILE_RESTORE = wx.NewId()
MENU_FILE_SHOWALLCODING = wx.NewId()
MENU_FILE_HIDEALLCODING = wx.NewId()
MENU_FILE_INSERT_IN_TRANSCRIPT = wx.NewId()
MENU_FILE_SAVE_SELECTION_AS = wx.NewId()
MENU_FILE_SAVE_WHOLE_IMAGE_AS = wx.NewId()
MENU_FILE_CLOSE_ALL = wx.NewId()
MENU_FILE_EXIT = wx.NewId()
MENU_POPUP_HIDE = wx.NewId()
MENU_POPUP_SENDTOBACK = wx.NewId()
MENU_POPUP_DELETE = wx.NewId()
class SnapshotWindow(wx.Frame):
""" This window displays still images and allows coding of those images. """
def __init__(self, parent, id, title, snapshot, showWindow=True):
# Because of problems with the wx.EVT_ACTIVATE handler, we need to track if we're in the process of closing
# this window. Initially, we're not.
self.closing = False
# Retain the parent object (a MenuWindow?)
self.parent = parent
# The Snapshot Window can get the Control Object from it's parent, which it needs.
if parent != None:
self.ControlObject = self.parent.ControlObject
else:
self.ControlObject = None
# Retain the snapshot object
self.obj = snapshot
# Retain showWindow so we don't remove HIDDEN snapshots from the Window Menu!
self.showWindow = showWindow
# Create a holder for the Coding Key popup
self.codingKeyPopup = None
# Initialize the Bitmap to None
self.theBitmap = None
# Check to see if the image file can be found
if not os.path.exists(self.obj.image_filename):
# If not, raise an exception
errmsg = unicode(_("Image file not found:\n%s"), 'utf8')
raise TransanaExceptions.ImageLoadError(errmsg % self.obj.image_filename)
# Load the image
self.bgImage = wx.Image(self.obj.image_filename)
# Make sure the image is loaded, is not corrupt
if not self.bgImage.IsOk():
# If not, raise an exception
errmsg = unicode(_("Unable to load image file:\n%s\nThere may be a problem with the file, or you may\nhave too many Snapshots open."), 'utf8')
raise TransanaExceptions.ImageLoadError(errmsg % self.obj.image_filename)
# If the image that is passed in has a defined window size ...
if self.obj.image_size[0] > 0:
# ... use that defined size
width = self.obj.image_size[0]
height = self.obj.image_size[1]
# If the image does NOT have a size ...
else:
# ... use the default image window size
width = self.__size()[0]
height = self.__size()[1]
# Initialize the Window Frame
wx.Frame.__init__(self,parent,-1, title, pos = self.__pos(), size = (width, height), style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
# Set the background to WHITE
self.SetBackgroundColour(wx.SystemSettings.GetColour(getattr(wx, 'SYS_COLOUR_MENUBAR')))
# Let's go ahead and keep the menu for non-Mac platforms
if self.showWindow and (not '__WXMAC__' in wx.PlatformInfo):
# Menu Bar
# Create a MenuBar
menuBar = wx.MenuBar()
# Build a Menu Object to go into the Menu Bar
menuFile = wx.Menu()
# Add the menu items that should appear in the File Menu
menuFile.Append(MENU_FILE_CLEAR, _("&Remove All Coding"), _("Remove all coding"))
menuFile.Append(MENU_FILE_RESTORE, _("Restore &Last Save"), _("Restore Last Save"))
menuFile.Append(MENU_FILE_SHOWALLCODING, _("&Show All Coding"), _("Show all coding"))
menuFile.Append(MENU_FILE_HIDEALLCODING, _("&Hide All Coding"), _("Hide all coding"))
menuFile.Append(MENU_FILE_INSERT_IN_TRANSCRIPT, _("&Insert Image in Transcript"), _("Insert the Coded Image into the Transcript"))
menuFile.AppendSeparator()
menuFile.Append(MENU_FILE_SAVE_SELECTION_AS, _("Save &Visible Selection As"), _("Save Visible Selection As"))
menuFile.Append(MENU_FILE_SAVE_WHOLE_IMAGE_AS, _("Save &Whole Image As"), _("Save Whole Image As"))
menuFile.AppendSeparator()
menuFile.Append(MENU_FILE_CLOSE_ALL, _("Close &All Snapshots"), _("Close All Snapshots"))
menuFile.Append(MENU_FILE_EXIT, _("&Close"), _("Close this window"))
#Place the Menu Item in the Menu Bar
menuBar.Append(menuFile, _("&File"))
# Place a Window menu in the Menu Bar
# First, create the Window menu
self.menuWindow = wx.Menu()
# Add this to the menuBar
menuBar.Append(self.menuWindow, _("Window"))
# Place the Menu Bar on the Frame
self.SetMenuBar(menuBar)
#Define Events for the Menu Items
wx.EVT_MENU(self, MENU_FILE_CLEAR, self.FileClear)
wx.EVT_MENU(self, MENU_FILE_RESTORE, self.FileRestore)
wx.EVT_MENU(self, MENU_FILE_SHOWALLCODING, self.FileRedraw)
wx.EVT_MENU(self, MENU_FILE_HIDEALLCODING, self.FileRedraw)
wx.EVT_MENU(self, MENU_FILE_INSERT_IN_TRANSCRIPT, self.OnInsertIntoTranscript)
wx.EVT_MENU(self, MENU_FILE_SAVE_SELECTION_AS, self.FileSaveSelectionAs)
wx.EVT_MENU(self, MENU_FILE_SAVE_WHOLE_IMAGE_AS, self.FileSaveAs)
wx.EVT_MENU(self, MENU_FILE_CLOSE_ALL, self.CloseAllImages)
wx.EVT_MENU(self, MENU_FILE_EXIT, self.CloseWindow)
# Bind the Close Event
self.Bind(wx.EVT_CLOSE, self.OnClose)
# Bind the Form Activate event
self.Bind(wx.EVT_ACTIVATE, self.OnEnterWindow)
# Define the Frame's Main Sizer
mainSizer = wx.BoxSizer(wx.VERTICAL)
# Create a Panel for the Frame
self.panel = wx.Panel(self, -1)
self.panel.SetBackgroundColour(wx.SystemSettings.GetColour(getattr(wx, 'SYS_COLOUR_MENUBAR')))
# Put the Panel on the Sizer
mainSizer.Add(self.panel, 9, wx.GROW, 4)
# Create a Sizer for the Panel
pnlSizer = wx.BoxSizer(wx.VERTICAL)
# Get a list of all Snapshots in the same collection
self.snapshotList = DBInterface.list_of_snapshots_by_collectionnum(self.obj.collection_num, True)
# Initialize values for Previous and Next Snapshots
self.prevSnapshot = 0
self.nextSnapshot = 0
# Determine the list index for the current Snapshot
index = self.snapshotList.index((self.obj.number, self.obj.id, self.obj.collection_num, self.obj.sort_order))
# If the current snapshot isn't the first item in the list ...
if index > 0:
# ... then remember the previous snapshot's number
self.prevSnapshot = self.snapshotList[index - 1][0]
# If the current snapshot isn't the last item in the list ...
if index < len(self.snapshotList) - 1:
# ... then remember the next snapshot's number
self.nextSnapshot = self.snapshotList[index + 1][0]
if self.showWindow:
# Create the Toolbar
self.toolbar = self.CreateToolBar () # wx.ToolBar(self.panel)
# Set the Bitmap Size for the Toolbar
self.toolbar.SetToolBitmapSize((16, 16))
# Create the Edit-Mode Tool
bmp = TransanaImages.ReadOnly16.GetBitmap()
self.editTool = self.toolbar.AddCheckTool(wx.ID_ANY, bitmap=bmp, shortHelp = _("Edit/Read-only"))
self.Bind(wx.EVT_TOOL, self.OnToolbar, self.editTool)
# Create the Pointer Tool
bmp = Resources.getPointerBitmap()
self.pointer = self.toolbar.AddRadioTool(wx.ID_ANY, bitmap=bmp, shortHelp=_("Coding Tool"))
self.Bind(wx.EVT_TOOL, self.OnToolbar, self.pointer)
# Create the Move Tool
bmp = Resources.getHandBitmap()
self.moveTool = self.toolbar.AddRadioTool(wx.ID_ANY, bitmap=bmp, shortHelp=_("Move"))
self.Bind(wx.EVT_TOOL, self.OnToolbar, self.moveTool)
# Create the Zoom In Tool
bmp = Resources.getMagPlusBitmap()
self.zoomIn = self.toolbar.AddRadioTool(wx.ID_ANY, bitmap=bmp, shortHelp=_("Zoom In"))
self.Bind(wx.EVT_TOOL, self.OnToolbar, self.zoomIn)
# Create the Zoom Out Tool
bmp = Resources.getMagMinusBitmap()
self.zoomOut = self.toolbar.AddRadioTool(wx.ID_ANY, bitmap=bmp, shortHelp=_("Zoom Out"))
self.Bind(wx.EVT_TOOL, self.OnToolbar, self.zoomOut)
# Add Edit keywords button
bmp = TransanaImages.KeywordRoot16.GetBitmap()
self.keywordTool = self.toolbar.AddTool(wx.ID_ANY, bitmap=bmp, isToggle=False, shortHelpString = _("Whole Snapshot Keywords"))
self.Bind(wx.EVT_TOOL, self.OnEditKeywords, self.keywordTool)
# Add Coding Key button
bmp = TransanaImages.Keyword16.GetBitmap()
self.codingKeyTool = self.toolbar.AddTool(wx.ID_ANY, bitmap=bmp, isToggle=False, shortHelpString = _("Show Coding Key"))
self.Bind(wx.EVT_TOOL, self.OnCodingKey, self.codingKeyTool)
# Add a Previous button
self.prevSnapBtn = self.toolbar.AddTool(wx.ID_ANY, bitmap=TransanaImages.ArtProv_BACK.GetBitmap(), isToggle=False, shortHelpString = _("Previous Snapshot"))
self.Bind(wx.EVT_TOOL, self.OnChangeSnapshot, self.prevSnapBtn)
# If there is no previous snapshot ...
if self.prevSnapshot == 0:
# ... disable the button
self.toolbar.EnableTool(self.prevSnapBtn.GetId(), False)
# If there is a next snapshot in the collection, add a Next button
self.nextSnapBtn = self.toolbar.AddTool(wx.ID_ANY, bitmap=TransanaImages.ArtProv_FORWARD.GetBitmap(), isToggle=False, shortHelpString = _("Next Snapshot"))
self.Bind(wx.EVT_TOOL, self.OnChangeSnapshot, self.nextSnapBtn)
# If there is no next snapshot ...
if self.nextSnapshot == 0:
# ... disable the button
self.toolbar.EnableTool(self.nextSnapBtn.GetId(), False)
# Use multiple Separators to create a space between cursor modes and coding tools
self.toolbar.AddSeparator()
# Get the Shapshot's Collection record
tmpCollection = Collection.Collection(self.obj.collection_num)
# Create the Keyword Group Selector
txt = wx.StaticText(self.toolbar, wx.ID_ANY, " " + _("Keyword Group:") + " ")
self.toolbar.AddControl(txt)
# Get the Keyword Groups to populate the control
choices = [''] + DBInterface.list_of_keyword_groups()
self.keyword_group_cb = wx.Choice(self.toolbar, wx.ID_ANY, choices=choices)
# If there is a Default Keyword Group ...
if (tmpCollection.keyword_group != '') and (tmpCollection.keyword_group in choices):
# ... make that the initial selection
self.keyword_group_cb.SetStringSelection(tmpCollection.keyword_group)
# If there's no default keyword group ...
elif len(choices) > 0:
# ... select the blank element
self.keyword_group_cb.Select(0)
self.toolbar.AddControl(self.keyword_group_cb)
self.keyword_group_cb.Bind(wx.EVT_CHOICE, self.OnKWGSelect)
# Create the Keyword Selector
txt = wx.StaticText(self.toolbar, wx.ID_ANY, " " + _("Keyword:") + " ")
self.toolbar.AddControl(txt)
# If we have a Keyword Group ...
if self.keyword_group_cb.GetStringSelection() != '':
# ... get that group's Keywords
choices = [''] + DBInterface.list_of_keywords_by_group(self.keyword_group_cb.GetStringSelection())
# If there's no Keyword Group ...
else:
# ... there are no Keywords to add yet.
choices = ['This keyword is used for sizing']
self.keyword_cb = wx.Choice(self.toolbar, wx.ID_ANY, choices=choices)
# In any case, select the Blank option to start
self.keyword_cb.Select(0)
self.toolbar.AddControl(self.keyword_cb)
self.keyword_cb.Bind(wx.EVT_CHOICE, self.OnKWSelect)
self.toolbar.AddSeparator()
# Create the Hide / Show Keyword button
self.kwShowHideButton = wx.Button(self.toolbar, label=_("Hide"))
self.toolbar.AddControl(self.kwShowHideButton)
self.kwShowHideButton.Bind(wx.EVT_BUTTON, self.OnKWShowHideTool)
self.kwShowHideButton.Enable(False)
# Realize the Toolbar
self.toolbar.Realize()
# Create the second Toolbar
self.toolbar2 = wx.ToolBar(self.panel)
# Set the Bitmap Size for the Toolbar
self.toolbar2.SetToolBitmapSize((16, 16))
# Create the Zoom to 100% Tool
self.zoomToFull = wx.Button(self.toolbar2, label=_("100%"))
self.toolbar2.AddControl(self.zoomToFull)
self.zoomToFull.Bind(wx.EVT_BUTTON, self.OnToolbar)
# Create the Zoom To Fit Tool
self.zoomToFit = wx.Button(self.toolbar2, label=_("Fit"))
self.toolbar2.AddControl(self.zoomToFit)
self.zoomToFit.Bind(wx.EVT_BUTTON, self.OnToolbar)
# Create the Insert Coded Image Into Transcript button
# Get the initial image for the Play / Pause button
self.pushToTranscript = wx.BitmapButton(self.toolbar2, -1, TransanaImages.Snapshot.GetBitmap(), size=(48, 24))
self.pushToTranscript.SetToolTipString(_("Insert Coded Image into Transcript"))
self.toolbar2.AddControl(self.pushToTranscript)
self.pushToTranscript.Bind(wx.EVT_BUTTON, self.OnInsertIntoTranscript)
# Use multiple Separators to create a space between cursor modes and coding tools
self.toolbar2.AddSeparator()
# Create the Color Selector
txt = wx.StaticText(self.toolbar2, wx.ID_ANY, " " + _("Color:") + " ")
self.toolbar2.AddControl(txt)
# Get the list of colors for populating the control
choices = []
# Make a dictionary for looking up the color definintions that match the color names
self.colorList = {}
# Iterate through the global Graphics Colors (which can be user-defined!)
for x in TransanaGlobal.transana_graphicsColorList:
# We need to exclude WHITE
if x[1] != (255, 255, 255):
# Get the TRANSLATED color name
tmpColorName = _(x[0])
# If the color name is a string ...
if isinstance(tmpColorName, str):
# ... convert it to unicode
tmpColorName = unicode(tmpColorName, 'utf8')
# Add the translated color name to the choice box
choices.append(tmpColorName)
# Add the color definition to the dictionary, using the translated name as the key
self.colorList[tmpColorName] = x
self.line_color_cb = wx.Choice(self.toolbar2, wx.ID_ANY, choices=choices)
# Select the first color in the choice box
self.line_color_cb.SetStringSelection(_(TransanaGlobal.keywordMapColourSet[0]))
self.toolbar2.AddControl(self.line_color_cb)
self.line_color_cb.Bind(wx.EVT_CHOICE, self.OnToolbar)
# Disable Color Selection
self.line_color_cb.Enable(False)
# Create the Shape Selection Tool
txt = wx.StaticText(self.toolbar2, wx.ID_ANY, " " + _("Code Tool:") + " ")
self.toolbar2.AddControl(txt)
self.codeShape = wx.Choice(self.toolbar2, wx.ID_ANY, choices=[_('Rectangle'), _('Ellipse'), _('Line'), _('Arrow')])
# Set the Shape to Rectangle by default
self.codeShape.SetStringSelection(_('Rectangle'))
self.toolbar2.AddControl(self.codeShape)
self.codeShape.Bind(wx.EVT_CHOICE, self.OnToolbar)
# Disable Shape Selection
self.codeShape.Enable(False)
# Create the Line Width Tool
txt = wx.StaticText(self.toolbar2, wx.ID_ANY, " " + _("Line Width:") + " ")
self.toolbar2.AddControl(txt)
self.lineSize = wx.Choice(self.toolbar2, wx.ID_ANY, choices=['1', '2', '3', '4', '5', '6'])
# Set Line Width to 3 by default
self.lineSize.SetStringSelection('3')
self.toolbar2.AddControl(self.lineSize)
self.lineSize.Bind(wx.EVT_CHOICE, self.OnToolbar)
# Disable Line Width selection
self.lineSize.Enable(False)
# Create the Line Style Tool
txt = wx.StaticText(self.toolbar2, wx.ID_ANY, " " + _("Line Style:") + " ")
self.toolbar2.AddControl(txt)
# ShortDash is indistinguishable from LongDash, at least on Windows, so I've left it out of the options here.
self.line_style_cb = wx.Choice(self.toolbar2, wx.ID_ANY, choices=[_('Solid'), _('Dot'), _('Dash'), _('Dot Dash')])
# Set line style to Solid by default
self.line_style_cb.SetStringSelection(_('Solid'))
self.toolbar2.AddControl(self.line_style_cb)
self.line_style_cb.Bind(wx.EVT_CHOICE, self.OnToolbar)
# Disable Line Style selection
self.line_style_cb.Enable(False)
self.toolbar2.AddSeparator()
# Add a Help button
self.help = wx.BitmapButton(self.toolbar2, -1, TransanaImages.ArtProv_HELP.GetBitmap(), size=(24, 24))
self.help.SetToolTipString(_("Help"))
self.toolbar2.AddControl(self.help)
self.help.Bind(wx.EVT_BUTTON, self.OnHelp)
# Realize the second Toolbar
self.toolbar2.Realize()
# If we do NOT have a Keyword Group ...
if self.keyword_group_cb.GetStringSelection() == '':
# ... clear out the items list, which was just used to size the control
self.keyword_cb.SetItems([''])
# Add the Toolbar to the Panel Sizer
pnlSizer.Add(self.toolbar2, 0, wx.ALL | wx.ALIGN_LEFT | wx.GROW, 0)
# If we're on a Mac, we need another Toolbar to handle the menu functions!
if '__WXMAC__' in wx.PlatformInfo:
# Create the second Toolbar
self.toolbar3 = wx.ToolBar(self.panel)
# Set the Bitmap Size for the Toolbar
self.toolbar3.SetToolBitmapSize((16, 16))
# Create the Remove All Keywords button
self.removeAllCodingButton = wx.Button(self.toolbar3, id=MENU_FILE_CLEAR, label=_("Remove All Coding"))
self.removeAllCodingButton.Bind(wx.EVT_BUTTON, self.FileClear)
self.toolbar3.AddControl(self.removeAllCodingButton)
# Create the Show All Keywords button
self.showAllCodingButton = wx.Button(self.toolbar3, label=_("Show All Coding"))
self.showAllCodingButton.Bind(wx.EVT_BUTTON, self.FileRedraw)
self.toolbar3.AddControl(self.showAllCodingButton)
# Create the Hide All Keywords button
self.hideAllCodingButton = wx.Button(self.toolbar3, label=_("Hide All Coding"))
self.hideAllCodingButton.Bind(wx.EVT_BUTTON, self.FileRedraw)
self.toolbar3.AddControl(self.hideAllCodingButton)
# Create the Save Visible Selection button
self.saveVisibleButton = wx.Button(self.toolbar3, label=_("Save Visible"))
self.saveVisibleButton.Bind(wx.EVT_BUTTON, self.FileSaveSelectionAs)
self.toolbar3.AddControl(self.saveVisibleButton)
# Create the Save Whole Image button
self.saveWholeImageButton = wx.Button(self.toolbar3, label=_("Save Whole Image"))
self.saveWholeImageButton.Bind(wx.EVT_BUTTON, self.FileSaveAs)
self.toolbar3.AddControl(self.saveWholeImageButton)
# German, Spanish, and French require that the supplementary Mac toolbar get split here.
if TransanaGlobal.configData.language in ['de', 'es', 'fr']:
# Realize the second Toolbar
self.toolbar3.Realize()
# Add the Toolbar to the Panel Sizer
pnlSizer.Add(self.toolbar3, 0, wx.ALL | wx.ALIGN_LEFT | wx.GROW, 0)
# Create the third Toolbar
self.toolbar4 = wx.ToolBar(self.panel)
# Set the Bitmap Size for the Toolbar
self.toolbar4.SetToolBitmapSize((16, 16))
tmpToolbar = self.toolbar4
else:
tmpToolbar = self.toolbar3
# Create the Restore Last Save button
self.restoreButton = wx.Button(tmpToolbar, label=_("Restore Last Save"))
self.restoreButton.Bind(wx.EVT_BUTTON, self.FileRestore)
tmpToolbar.AddControl(self.restoreButton)
# Italian, Dutch, and Swedish require that the supplementary Mac toolbar get split here.
if TransanaGlobal.configData.language in ['it', 'nl', 'sv']:
# Realize the second Toolbar
self.toolbar3.Realize()
# Add the Toolbar to the Panel Sizer
pnlSizer.Add(self.toolbar3, 0, wx.ALL | wx.ALIGN_LEFT | wx.GROW, 0)
# Create the third Toolbar
self.toolbar4 = wx.ToolBar(self.panel)
# Set the Bitmap Size for the Toolbar
self.toolbar4.SetToolBitmapSize((16, 16))
tmpToolbar = self.toolbar4
# Create the Close All button
self.closeAllButton = wx.Button(tmpToolbar, label=_("Close All Snapshots"))
self.closeAllButton.Bind(wx.EVT_BUTTON, self.CloseAllImages)
tmpToolbar.AddControl(self.closeAllButton)
# Create the Close button
self.closeButton = wx.BitmapButton(tmpToolbar, -1, TransanaImages.Exit.GetBitmap(), size=(24, 24))
self.closeButton.SetToolTipString(_("Close"))
self.closeButton.Bind(wx.EVT_BUTTON, self.CloseWindow)
tmpToolbar.AddControl(self.closeButton)
# Realize the final Toolbar
tmpToolbar.Realize()
# Add the Toolbar to the Panel Sizer
pnlSizer.Add(tmpToolbar, 1, wx.EXPAND | wx.ALL | wx.ALIGN_LEFT | wx.GROW, 0)
# Create a FloatCanvas for the image and coding
self.canvas = FloatCanvas.FloatCanvas(self.panel)
# Set Layout Direction to Left-to-Right to prevent image reversal in Arabic
self.canvas.SetLayoutDirection(wx.Layout_LeftToRight)
# Add the FloatCanvas to the Panel Sizer
pnlSizer.Add(self.canvas, 1, wx.EXPAND | wx.GROW, 0)
# Set the Panel Sizer on the Panel and Fit it.
self.panel.SetSizerAndFit(pnlSizer)
# The FloatCanvas ScaledBitmap object seems to run into problems when zoomed in too far. Large images raise
# an exception on Zoom In with click and Wheel zooms, as well as with selection-based zoomed. I contacted Chris
# Barker, who wrote FloatCanvas, and he suggested I try ScaledBitmap2, which requires a 2-step creation process.
# It seems to work.
# Add a Scaled Bitmap, converted from the loaded image, to the SnapshotWindow canvas
bgBitmapObj = FloatCanvas.ScaledBitmap2(self.bgImage, # wx.BitmapFromImage(self.bgImage),
(0 - (float(self.bgImage.GetWidth()) / 2.0), (float(self.bgImage.GetHeight()) / 2.0)),
Height = self.bgImage.GetHeight(),
Position = "tl")
self.canvas.AddObject(bgBitmapObj)
# Set the minimum scale to 1/20th normal size
self.canvas.MinScale = 0.05
# Set the maximum scale to 5 times normal size. (This avoids unsightly but not serious errors with large images.)
self.canvas.MaxScale = 5.0 # 3.70
if self.showWindow:
# Select the Move Tool initially
self.toolbar.ToggleTool(self.moveTool.GetId(), True)
# Set the Canvas Mode to the Move Tool initially
self.canvas.SetMode(GUIMode.GUIMove())
# Initialize the Coding Object Number to the number of existing objects
self.objectNum = len(self.obj.codingObjects)
# Initialize the variable that tracks the MouseDown position to None
self.mouseDown = None
# Initialize the variable that tracks the MouseUp position to None
self.mouseUp = None
# Initialize the Code Shape to the Rectanble
self.drawMode = 'Rectangle' # one of ['Arrow', 'Rectangle', 'Ellipse', 'Line']
# Initialize the Line Width to 3
self.lineWidth = 3
# Initialize the Line Style to Solid
self.lineStyle = 'Solid'
# if the Snapshot Window is visible ...
if self.showWindow:
# Get the initial color
color = self.colorList[self.line_color_cb.GetStringSelection()][1]
# If the window is not visible ...
else:
# ... color and self.drawColor are ignored, so we can just set it to black
color = wx.BLACK
# Initialize the Line Color to the initial color
self.drawColor = wx.Colour(color[0], color[1], color[2])
# Note that events are NOT bound initially
self.eventsAreBound = False
# Bind the FloatCanvas Events
self.BindEvents()
# Create the Status Bar (to show Coding information)
self.CreateStatusBar()
# Set the Frame's Main Sizer
self.SetSizer(mainSizer)
# Make the Frame's Sizing automatic
self.SetAutoLayout(True)
# Lay out the frame
self.Layout()
# If the snapshot that was passed in has a defined Scale ...
if self.obj.image_scale > 0.0:
# ... set the canvas' scale to the snapshot's value ...
self.canvas.Scale = self.obj.image_scale
# ... and apply the scale change to the canvas.
self.canvas.SetToNewScale(DrawFlag=True)
# If the snapshot that was passed in does NOT have a defined Scale ...
else:
# ... size the image to fit the frame
self.canvas.ZoomToBB()
# Position the image according to the snapshot object's settings
self.canvas.ViewPortCenter = [self.obj.image_coords[0], self.obj.image_coords[1]]
# If we're showing the window ...
if showWindow:
# Show the Frame
self.Show(True)
# Bring this window to the front, so it doesn't get lost on some computers
wx.CallLater(500, self.Raise)
# Draw the initial codingObjects
self.FileRedraw(None)
# Call Yield so everything gets drawn properly
wx.GetApp().Yield(True)
def AddWindowMenuItem(self, itemName, itemNumber):
""" Add an item to this Snapshot Window's Window menu """
# Let's go ahead and keep the menu for non-Mac platforms
if self.showWindow and (not '__WXMAC__' in wx.PlatformInfo):
# Get an Item ID
id = wx.NewId()
# Add the Menu Item
newItem = self.menuWindow.Append(id, itemName)
# Add the Snapshot Number to the Menu Item's Help, which isn't shown so can hold this data
newItem.SetHelp("%s" % itemNumber)
# Bind the ID to the Menu Handler
wx.EVT_MENU(self, id, self.OnWindowMenuItem)
def UpdateWindowMenuItem(self, oldName, oldNumber, newName, newNumber):
""" Update an item from this Snapshot Window's Window menu when a snapshot has been changed via Prev / Next buttons """
# Let's go ahead and keep the menu for non-Mac platforms
if self.showWindow and (not '__WXMAC__' in wx.PlatformInfo):
# Iterate through all of the Window Menu Items
for item in self.menuWindow.GetMenuItems():
# Find the item with the correct name and number
if (oldName == item.GetLabel()) and (oldNumber == int(item.GetHelp())):
# Update the Menu Label and Menu's Help (which indicates the Snapshot Number)
item.SetItemLabel(newName)
item.SetHelp("%s" % newNumber)
# We don't need to look any more
break
def OnWindowMenuItem(self, event):
""" Handle the Selection of an item in the Window Menu """
# Let's go ahead and keep the menu for non-Mac platforms
if self.showWindow and (not '__WXMAC__' in wx.PlatformInfo):
# Get the name and number of the menu item selected
itemName = self.menuWindow.GetLabel(event.GetId())
itemNumber = int(self.menuWindow.GetHelpString(event.GetId()))
# Have the Control Object select the appropriate Snapshot Window
self.ControlObject.SelectSnapshotWindow(itemName, itemNumber)
def DeleteWindowMenuItem(self, itemName, itemNumber):
""" Remove an item from this Snapshot Window's Window menu """
# Let's go ahead and keep the menu for non-Mac platforms
if self.showWindow and (not '__WXMAC__' in wx.PlatformInfo):
# Iterate through all of the Window Menu Items
for item in self.menuWindow.GetMenuItems():
# Find the item with the correct name and number
if (itemName == self.menuWindow.GetLabel(item.GetId())) and (itemNumber == int(self.menuWindow.GetHelpString(item.GetId()))):
# Delete the menu item
self.menuWindow.Delete(item.GetId())
# We don't need to look any more
break
# The FloatCanvas requires a mechanism for binding and un-binding events
def BindEvents(self):
""" Bind the FloatCanvas Events """
# If the events are not bound ...
if not self.eventsAreBound:
# Bind the FloatCanvas' Motion, LeftDown, LeftUp, RightDown, and RightUp events
self.canvas.Bind(FloatCanvas.EVT_MOTION, self.OnCanvasMotion)
self.canvas.Bind(FloatCanvas.EVT_LEFT_DOWN, self.OnCanvasLeftDown)
self.canvas.Bind(FloatCanvas.EVT_LEFT_UP, self.OnCanvasLeftUp)
self.canvas.Bind(FloatCanvas.EVT_RIGHT_DOWN, self.OnCanvasRightDown)
self.canvas.Bind(FloatCanvas.EVT_RIGHT_UP, self.OnCanvasRightUp)
# Note that the events are now bound!
self.eventsAreBound = True
def UnbindEvents(self):
""" Unbind the FloatCanvas Events """
# Bind the FloatCanvas' Motion, LeftDown, LeftUp, RightDown, and RightUp events
self.canvas.Unbind(FloatCanvas.EVT_MOTION)
self.canvas.Unbind(FloatCanvas.EVT_LEFT_DOWN)
self.canvas.Unbind(FloatCanvas.EVT_LEFT_UP)
self.canvas.Unbind(FloatCanvas.EVT_RIGHT_DOWN)
self.canvas.Unbind(FloatCanvas.EVT_RIGHT_UP)
# Note that the events are now unbound!
self.eventsAreBound = False
def OnToolbar(self, event):
""" Handle presses for many of the Toolbar's buttons """
# Get the ID of the control that triggered this event
eventID = event.GetId()
# If Edit Tool ...
if eventID == self.editTool.GetId():
# ... if we're entering EDIT mode ...
if self.editTool.IsToggled():
# Start exception handling
try:
# Remember the current Last Save Time
tmpLastSaveTime = self.obj.lastsavetime
# ... try to lock the Snapshot
self.obj.lock_record()
# If the Last Save Time was changed during the act of locking the record ...
if tmpLastSaveTime != self.obj.lastsavetime:
# ... inform the user that the Snapshot has been updated
msg = _('This Snapshot has been updated since you originally loaded it!\nYour copy of the record will be refreshed to reflect the changes.')
dlg = Dialogs.InfoDialog(self, msg)
dlg.ShowModal()
dlg.Destroy()
# Get the new Scale
self.canvas.Scale = self.obj.image_scale
# Get the new Position information
self.canvas.ViewPortCenter = [self.obj.image_coords[0], self.obj.image_coords[1]]
# resize the image window to the new Size
self.SetSize((self.obj.image_size[0], self.obj.image_size[1]))
# Re-set the Coding Object Number to the number of existing objects
self.objectNum = len(self.obj.codingObjects)
# Freeze the image
self.canvas.Freeze()
# Clear the Image (without deleting the coding)
self.FileClear(None)
# Redraw the coding
self.FileRedraw(None)
# Thaw the image
self.canvas.Thaw()
# If a Keyword has been selected ...
if (self.keyword_group_cb.GetStringSelection() != '') and (self.keyword_cb.GetStringSelection() != ''):
# ... enable the Coding Configuration tools
self.line_color_cb.Enable(True)
self.codeShape.Enable(True)
self.lineSize.Enable(True)
self.line_style_cb.Enable(True)
self.kwShowHideButton.Enable(True)
# If the current Keyword Group : Keyword selection in the interface is NOT already defined
# in the Snapshot's Keyword Styles ...
if not (self.keyword_group_cb.GetStringSelection(), self.keyword_cb.GetStringSelection()) in \
self.obj.keywordStyles.keys():
# ... then add the current Coding Configuration information to the Snapshot's Keyword Styles
self.obj.keywordStyles[(self.keyword_group_cb.GetStringSelection(), self.keyword_cb.GetStringSelection())] = \
{ 'drawMode' : self.drawMode,
'lineColorName' : self.colorList[self.line_color_cb.GetStringSelection()][0], # self.line_color_cb.GetStringSelection(),
'lineColorDef' : "#%02x%02x%02x" % self.colorList[self.line_color_cb.GetStringSelection()][1], # "#%02x%02x%02x" % TransanaGlobal.transana_colorLookup[self.line_color_cb.GetStringSelection()],
'lineWidth' : self.lineSize.GetStringSelection(),
'lineStyle' : self.lineStyle }
# Handle "RecordLockedError" exception
except TransanaExceptions.RecordLockedError, e:
# Display the Exception information to the user
TransanaExceptions.ReportRecordLockedException(_("Snapshot"), self.obj.id, e)
# Reject the attempt to go into Edit mode
self.toolbar.ToggleTool(self.editTool.GetId(), False)
# If we are LEAVING EDIT mode ...
else:
# ... save the image changes
self.LeaveEditMode()
# Disable the Coding Configuration Tools
self.line_color_cb.Enable(False)
self.codeShape.Enable(False)
self.lineSize.Enable(False)
self.line_style_cb.Enable(False)
# If the Pointer Tool is selected ...
if self.pointer.IsToggled():
# ... switch to the Move Tool ...
self.toolbar.ToggleTool(self.moveTool.GetId(), True)
# ... and switch the GUI Mode to match
self.canvas.SetMode(GUIMode.GUIMove())
# If Pointer Tool ...
elif eventID == self.pointer.GetId():
# ... set the canvas mode to GUITransana, which DRAWS
self.canvas.SetMode(GUITransana())
# If Move Tool ...
elif eventID == self.moveTool.GetId():
# ... set the canvas mode to FloatCanvas' GUIMove, which MOVES the canvas
self.canvas.SetMode(GUIMode.GUIMove())
# If Zoom In Tool ...
elif eventID == self.zoomIn.GetId():
# ... set the canvas mode to Transana's modified version of FloatCanvas' GUIZoomIn, which Zooms
self.canvas.SetMode(GUIMode.GUIZoomIn())
# If Zoom Out Tool ...
elif eventID == self.zoomOut.GetId():
# ... set the canvas mode to FloatCanvas' GUIZoomOut, which Zooms (out)
self.canvas.SetMode(GUIMode.GUIZoomOut())
# If Zoom To Fit Tool ...
elif eventID == self.zoomToFit.GetId():
# ... zoom to the canvas' Bounding Box (this accompishes the zoom) ...
self.canvas.ZoomToBB()
# ... and shift the focus to the canvas rather than the toolbar
self.canvas.SetFocus()
# If Zoom To Full Tool ...
elif eventID == self.zoomToFull.GetId():
# ... set the canvas' scale to 1 ...
self.canvas.Scale= 1
# ... and apply the scale change to the canvas.
self.canvas.SetToNewScale(DrawFlag=True)
# Set the focus to the canvas rather than the toolbar
self.canvas.SetFocus()
# If the Shape is selected ...
elif eventID == self.codeShape.GetId():
# ... set the Draw Mode to the selected shape
if self.codeShape.GetStringSelection().encode('utf8') == _('Rectangle'):
self.drawMode = 'Rectangle'
elif self.codeShape.GetStringSelection().encode('utf8') == _('Ellipse'):
self.drawMode = 'Ellipse'
elif self.codeShape.GetStringSelection().encode('utf8') == _('Line'):
self.drawMode = 'Line'
elif self.codeShape.GetStringSelection().encode('utf8') == _('Arrow'):
self.drawMode = 'Arrow'
# If the Color is selected ...
elif eventID == self.line_color_cb.GetId():
# ... get the color RGB definition for the selected color ...
color = self.colorList[self.line_color_cb.GetStringSelection()][1] # TransanaGlobal.transana_colorLookup[self.line_color_cb.GetStringSelection()]
# ... and set the Draw Color to the selected color
self.drawColor = wx.Colour(color[0], color[1], color[2])
# If the Line Width is selected ...
elif eventID == self.lineSize.GetId():
# ... set the Draw Line Width
self.lineWidth = int(self.lineSize.GetStringSelection())
# If the Line Style is selected ...
elif eventID == self.line_style_cb.GetId():
# ... set the style to None
style = None
# Translate the user's selection to the style the FloatCanvas needs
if self.line_style_cb.GetStringSelection().encode('utf8') == _('Solid'):
style = 'Solid'
elif self.line_style_cb.GetStringSelection().encode('utf8') == _('Dot'):
style = 'Dot'
elif self.line_style_cb.GetStringSelection().encode('utf8') == _('Dash'):
style = 'LongDash'
# ShortDash is indistinguishable from LongDash, at least on Windows, so it's not supported
# elif self.line_style_cb.GetStringSelection().encode('utf8') == 'Short Dash':
# style = 'ShortDash'
elif self.line_style_cb.GetStringSelection().encode('utf8') == _('Dot Dash'):
style = 'DotDash'
# If a valid Style has been selected ...
if style:
# ... set the Draw Line Style
self.lineStyle = style
# If one of the Coding Configuration controls was used ...
if eventID in [self.codeShape.GetId(), self.line_color_cb.GetId(), self.lineSize.GetId(), self.line_style_cb.GetId()]:
# ... update (or add) the current configuration to the Shapshot's Keyword Styles
self.obj.keywordStyles[(self.keyword_group_cb.GetStringSelection(), self.keyword_cb.GetStringSelection())] = \
{ 'drawMode' : self.drawMode,
'lineColorName' : self.colorList[self.line_color_cb.GetStringSelection()][0], # self.line_color_cb.GetStringSelection(),
'lineColorDef' : "#%02x%02x%02x" % self.colorList[self.line_color_cb.GetStringSelection()][1], # TransanaGlobal.transana_colorLookup[self.line_color_cb.GetStringSelection()],
'lineWidth' : self.lineSize.GetStringSelection(),
'lineStyle' : self.lineStyle }
# If there are Draw Objects ... (If there aren't, calling these lines messes up image position until the image is clicked!)
if len(self.obj.codingObjects) > 0:
# Freeze the image
self.canvas.Freeze()
# Clear the Image (without deleting coding)
self.FileClear(None)
# Redraw the coding
self.FileRedraw(None)
# Thaw the Image
self.canvas.Thaw()
def OnInsertIntoTranscript(self, event):
""" Insert the current sized & coded Snapshot into the current editable Transcript! """
# If the current transcript is in Read Only mode ...
if self.ControlObject.ActiveTranscriptReadOnly():
# ... inform the user
msg = _("The current document is not editable. The requested snapshot cannot be inserted into the document.")
msg += '\n\n' + _("To insert the snapshot into the document, press the Edit Mode button on the Document Toolbar to make the document editable.")
dlg = Dialogs.InfoDialog(self, msg)
dlg.ShowModal()
dlg.Destroy()
else:
# Create a Temporary Image File Name
filename = os.path.join(TransanaGlobal.configData.visualizationPath, 'Temp.jpg')
# Save the current selection to the temporary file
self.FileSaveSelectionAs(event, filename = filename)
# Load the TEMP file into Transcript"
self.ControlObject.TranscriptInsertImage(filename, self.obj.number)
def OnEditKeywords(self, event):
""" Edit whole snapshot keywords """
# Start Exception Handling
try:
# If the Snapshot isn't already locked ...
if not self.obj.isLocked:
# Remember the current Last Save Time
tmpLastSaveTime = self.obj.lastsavetime
# ... lock the Snapshot ...
self.obj.lock_record()
# If the Last Save Time was changed during the act of locking the record ...
if tmpLastSaveTime != self.obj.lastsavetime:
# ... inform the user that the Snapshot has been updated
msg = _('This Snapshot has been updated since you originally loaded it!\nYour copy of the record will be refreshed to reflect the changes.')
dlg = Dialogs.InfoDialog(self, msg)
dlg.ShowModal()
dlg.Destroy()
# Get the new Scale
self.canvas.Scale = self.obj.image_scale
# Get the new Position information
self.canvas.ViewPortCenter = [self.obj.image_coords[0], self.obj.image_coords[1]]
# resize the image window to the new Size
self.SetSize((self.obj.image_size[0], self.obj.image_size[1]))
# Re-set the Coding Object Number to the number of existing objects
self.objectNum = len(self.obj.codingObjects)
# Freeze the image
self.canvas.Freeze()
# Clear the Image (without deleting the coding)
self.FileClear(None)
# Redraw the coding
self.FileRedraw(None)
# Thaw the image
self.canvas.Thaw()
# ... and remember we locked it here
lockedRecord = True
# We need to refresh the Keyword List.
# See, if someone has deleted a Keyword (or Keyword Group) while this Snapshot was
# open, it could be out of date without LastSaveTime being updated!
self.obj.refresh_keywords()
# If the Snapshot IS already locked ...
else:
# ... remember that we did NOT lock it here
lockedRecord = False
# Determine the title for the KeywordListEditForm Dialog Box
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Keywords for %s"), 'utf8')
else:
prompt = _("Keywords for %s")
dlgTitle = prompt % self.obj.id
# Extract the keyword List from the Data object
kwlist = []
for kw in self.obj.keyword_list:
kwlist.append(kw)
# Create/define the Keyword List Edit Form
dlg = KeywordListEditForm.KeywordListEditForm(self, -1, dlgTitle, self.obj, kwlist)
# 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:
# if the user pressed "OK" ...
try:
# Show the Keyword List Edit Form and process it if the user selects OK
if dlg.ShowModal() == wx.ID_OK:
# Clear the local keywords list and repopulate it from the Keyword List Edit Form
kwlist = []
for kw in dlg.keywords:
kwlist.append(kw)
# Copy the local keywords list into the appropriate object
self.obj.keyword_list = kwlist
# If we locked the Snapshot here ...
if lockedRecord:
# Save the Data object
self.obj.db_save()
# Re-load the Snapshot so we don't get an error message about having an OLD copy of the Snapshot Data
self.obj = Snapshot.Snapshot(self.obj.number)
# Update the Keyword Visualization, if needed
self.ControlObject.UpdateKeywordVisualization()
# Even if this computer doesn't need to update the keyword visualization others, might need to.
if not TransanaConstants.singleUserVersion and (self.obj.episode_num != 0):
# We need to update the Episode Keyword Visualization
if DEBUG:
print 'Message to send = "UKV %s %s %s"' % ('Episode', self.obj.episode_num, 0)
if TransanaGlobal.chatWindow != None:
TransanaGlobal.chatWindow.SendMessage("UKV %s %s %s" % ('Episode', self.obj.episode_num, 0))
# 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:
# Display the Error Message, allow "continue" flag to remain true
errordlg = Dialogs.ErrorDialog(None, sys.exc_info()[1].reason)
errordlg.ShowModal()
errordlg.Destroy()
# Refresh the Keyword List, if it's a changed Keyword error
dlg.refresh_keywords()
# Highlight the first non-existent keyword in the Keywords control
dlg.highlight_bad_keyword()
# Handle other exceptions
except:
if DEBUG:
import traceback
traceback.print_exc(file=sys.stdout)
# Display the Exception Message, allow "continue" flag to remain true
if 'unicode' in wx.PlatformInfo:
# Encode with UTF-8 rather than TransanaGlobal.encoding because this is a prompt, not DB Data.
prompt = unicode(_("Exception %s: %s"), 'utf8')
else:
prompt = _("Exception %s: %s")
errordlg = Dialogs.ErrorDialog(None, prompt % (sys.exc_info()[0], sys.exc_info()[1]))
errordlg.ShowModal()
errordlg.Destroy()
# If we locked the Snapshot here ...
if lockedRecord:
# ... release the record lock
self.obj.unlock_record()
# Handle record lock exceptions
except TransanaExceptions.RecordLockedError, e:
"""Handle the RecordLockedError exception."""
TransanaExceptions.ReportRecordLockedException(_('Snapshot'), self.obj.id, e)
def OnCodingKey(self, event):
""" Display the Snapshot Coding Key """
# We need to determine what styles are visible. INitialize a variable to hold the visible styles
visibleKeywordStyles = {}
# Iterate through the coding objects ...
for x in self.obj.codingObjects.keys():
# If the current Coding Object is visible AND is not yet represented in the Visible Styles dictionary ...
if (self.obj.codingObjects[x]['visible']) and \
not ((self.obj.codingObjects[x]['keywordGroup'], self.obj.codingObjects[x]['keyword']) in visibleKeywordStyles.keys()):
# ... then add its style to the Visible Styles dictionary
visibleKeywordStyles[(self.obj.codingObjects[x]['keywordGroup'], self.obj.codingObjects[x]['keyword'])] = \
self.obj.keywordStyles[(self.obj.codingObjects[x]['keywordGroup'], self.obj.codingObjects[x]['keyword'])]
# If there is a current Coding Key Popup display ...
if self.codingKeyPopup != None:
# ... start exception handling ...
try:
# ... close the Coding Key Poup display
self.codingKeyPopup.Close()
# Ignore exceptions
except:
pass