-
Notifications
You must be signed in to change notification settings - Fork 17
/
NotePropertiesForm.py
317 lines (264 loc) · 12.2 KB
/
NotePropertiesForm.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
# Copyright (C) 2003 - 2015 The Board of Regents of the University of Wisconsin System
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
""" This module implements the Note Properties form. """
__author__ = 'David Woods <[email protected]>, Nathaniel Case <[email protected]>'
import TransanaConstants
import TransanaGlobal
import DBInterface
import Dialogs
import KWManager
import Misc
import Library
import Document
import Episode
import Transcript
import Collection
import Quote
import Clip
import Snapshot
import Note
import wx
import string
class NotePropertiesForm(Dialogs.GenForm):
"""Form containing Note fields."""
def __init__(self, parent, id, title, note_object):
# Make the Keyword Edit List resizable by passing wx.RESIZE_BORDER style
Dialogs.GenForm.__init__(self, parent, id, title, size=(400, 260), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
useSizers = True, HelpContext='Notes') # 'Notes' is the Help Context for Notes. There is no entry for Note Properties at this time
self.obj = note_object
seriesID = ''
episodeID = ''
transcriptID = ''
collectionID = ''
clipID = ''
snapshotID = ''
documentID = ''
quoteID = ''
if (self.obj.series_num != 0) and (self.obj.series_num != None):
tempLibrary = Library.Library(self.obj.series_num)
seriesID = tempLibrary.id
elif (self.obj.episode_num != 0) and (self.obj.episode_num != None):
tempEpisode = Episode.Episode(self.obj.episode_num)
episodeID = tempEpisode.id
tempLibrary = Library.Library(tempEpisode.series_num)
seriesID = tempLibrary.id
elif (self.obj.transcript_num != 0) and (self.obj.transcript_num != None):
# To save time here, we can skip loading the actual transcript text, which can take time once we start dealing with images!
tempTranscript = Transcript.Transcript(self.obj.transcript_num, skipText=True)
transcriptID = tempTranscript.id
tempEpisode = Episode.Episode(tempTranscript.episode_num)
episodeID = tempEpisode.id
tempLibrary = Library.Library(tempEpisode.series_num)
seriesID = tempLibrary.id
elif (self.obj.collection_num != 0) and (self.obj.collection_num != None):
tempCollection = Collection.Collection(self.obj.collection_num)
collectionID = tempCollection.GetNodeString()
elif (self.obj.clip_num != 0) and (self.obj.clip_num != None):
# We can skip loading the Clip Transcript to save load time
tempClip = Clip.Clip(self.obj.clip_num, skipText=True)
clipID = tempClip.id
tempCollection = Collection.Collection(tempClip.collection_num)
collectionID = tempCollection.GetNodeString()
elif (self.obj.snapshot_num != 0) and (self.obj.snapshot_num != None):
tempSnapshot = Snapshot.Snapshot(self.obj.snapshot_num)
snapshotID = tempSnapshot.id
tempCollection = Collection.Collection(tempSnapshot.collection_num)
collectionID = tempCollection.GetNodeString()
elif (self.obj.document_num != 0) and (self.obj.document_num != None):
tempDocument = Document.Document(self.obj.document_num)
documentID = tempDocument.id
tempLibrary = Library.Library(tempDocument.library_num)
seriesID = tempLibrary.id
elif (self.obj.quote_num != 0) and (self.obj.quote_num != None):
tempQuote = Quote.Quote(num=self.obj.quote_num, skipText=True)
quoteID = tempQuote.id
tempCollection = Collection.Collection(tempQuote.collection_num)
collectionID = tempCollection.GetNodeString()
# Create the form's main VERTICAL sizer
mainSizer = wx.BoxSizer(wx.VERTICAL)
# Create a HORIZONTAL sizer for the first row
r1Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v1 = wx.BoxSizer(wx.VERTICAL)
# Note ID
id_edit = self.new_edit_box(_("Note ID"), v1, self.obj.id, maxLen=100)
# Add the element to the sizer
r1Sizer.Add(v1, 1, wx.EXPAND)
# Add the row sizer to the main vertical sizer
mainSizer.Add(r1Sizer, 0, wx.EXPAND)
# Add a vertical spacer to the main sizer
mainSizer.Add((0, 10))
# Create a HORIZONTAL sizer for the next row
r2Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v2 = wx.BoxSizer(wx.VERTICAL)
# Library ID
seriesID_edit = self.new_edit_box(_("Library ID"), v2, seriesID)
# Add the element to the row sizer
r2Sizer.Add(v2, 1, wx.EXPAND)
seriesID_edit.Enable(False)
# Add the row sizer to the main vertical sizer
mainSizer.Add(r2Sizer, 0, wx.EXPAND)
# Add a vertical spacer to the main sizer
mainSizer.Add((0, 10))
# Create a HORIZONTAL sizer for the next row
r3Sizer = wx.BoxSizer(wx.HORIZONTAL)
if TransanaConstants.proVersion:
# Create a VERTICAL sizer for the next element
v9 = wx.BoxSizer(wx.VERTICAL)
# Document ID
documentID_edit = self.new_edit_box(_("Document ID"), v9, documentID)
# Add the element to the row sizer
r3Sizer.Add(v9, 1, wx.EXPAND)
documentID_edit.Enable(False)
# Add a horizontal spacer to the row sizer
r3Sizer.Add((10, 0))
# Create a VERTICAL sizer for the next element
v3 = wx.BoxSizer(wx.VERTICAL)
# Episode ID
episodeID_edit = self.new_edit_box(_("Episode ID"), v3, episodeID)
# Add the element to the row sizer
r3Sizer.Add(v3, 1, wx.EXPAND)
episodeID_edit.Enable(False)
# Add a horizontal spacer to the row sizer
r3Sizer.Add((10, 0))
# Create a VERTICAL sizer for the next element
v4 = wx.BoxSizer(wx.VERTICAL)
# Transcript ID
transcriptID_edit = self.new_edit_box(_("Transcript ID"), v4, transcriptID)
# Add the element to the row sizer
r3Sizer.Add(v4, 1, wx.EXPAND)
transcriptID_edit.Enable(False)
# Add the row sizer to the main vertical sizer
mainSizer.Add(r3Sizer, 0, wx.EXPAND)
# Add a vertical spacer to the main sizer
mainSizer.Add((0, 10))
# Create a HORIZONTAL sizer for the next row
r5Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v5 = wx.BoxSizer(wx.VERTICAL)
# Collection ID
collectionID_edit = self.new_edit_box(_("Collection ID"), v5, collectionID)
# Add the element to the row sizer
r5Sizer.Add(v5, 2, wx.EXPAND)
collectionID_edit.Enable(False)
# Add the row sizer to the main vertical sizer
mainSizer.Add(r5Sizer, 0, wx.EXPAND)
# Add a vertical spacer to the main sizer
mainSizer.Add((0, 10))
# Create a HORIZONTAL sizer for the next row
r6Sizer = wx.BoxSizer(wx.HORIZONTAL)
if TransanaConstants.proVersion:
# Create a VERTICAL sizer for the next element
v7 = wx.BoxSizer(wx.VERTICAL)
# Quote ID
quoteID_edit = self.new_edit_box(_("Quote ID"), v7, quoteID)
# Add the element to the row sizer
r6Sizer.Add(v7, 1, wx.EXPAND)
quoteID_edit.Enable(False)
# Add a horizontal spacer to the row sizer
r6Sizer.Add((10, 0))
# Create a VERTICAL sizer for the next element
v6 = wx.BoxSizer(wx.VERTICAL)
# Clip ID
clipID_edit = self.new_edit_box(_("Clip ID"), v6, clipID)
# Add the element to the row sizer
r6Sizer.Add(v6, 1, wx.EXPAND)
clipID_edit.Enable(False)
if TransanaConstants.proVersion:
# Add a horizontal spacer to the row sizer
r6Sizer.Add((10, 0))
# Create a VERTICAL sizer for the next element
v8 = wx.BoxSizer(wx.VERTICAL)
# Snapshot ID
snapshotID_edit = self.new_edit_box(_("Snapshot ID"), v8, snapshotID)
# Add the element to the row sizer
r6Sizer.Add(v8, 1, wx.EXPAND)
snapshotID_edit.Enable(False)
# Add the row sizer to the main vertical sizer
mainSizer.Add(r6Sizer, 0, wx.EXPAND)
# Add a vertical spacer to the main sizer
mainSizer.Add((0, 10))
# Create a HORIZONTAL sizer for the next row
r8Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v8 = wx.BoxSizer(wx.VERTICAL)
# Comment layout
noteTaker_edit = self.new_edit_box(_("Note Taker"), v8, self.obj.author, maxLen=100)
# Add the element to the row sizer
r8Sizer.Add(v8, 2, wx.EXPAND)
# Add the row sizer to the main vertical sizer
mainSizer.Add(r8Sizer, 0, wx.EXPAND)
# Add a vertical spacer to the main sizer
mainSizer.Add((0, 10))
# Create a sizer for the buttons
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
# Add the buttons
self.create_buttons(sizer=btnSizer)
# Add the button sizer to the main sizer
mainSizer.Add(btnSizer, 0, wx.EXPAND)
# If Mac ...
if 'wxMac' in wx.PlatformInfo:
# ... add a spacer to avoid control clipping
mainSizer.Add((0, 2))
# Set the PANEL's main sizer
self.panel.SetSizer(mainSizer)
# Tell the PANEL to auto-layout
self.panel.SetAutoLayout(True)
# Lay out the Panel
self.panel.Layout()
# Lay out the panel on the form
self.Layout()
# Resize the form to fit the contents
self.Fit()
# Get the new size of the form
(width, height) = self.GetSizeTuple()
# Reset the form's size to be at least the specified minimum width
self.SetSize(wx.Size(max(400, width), height))
# Define the minimum size for this dialog as the current size, and define height as unchangeable
self.SetSizeHints(max(400, width), height, -1, height)
# Center the form on screen
TransanaGlobal.CenterOnPrimary(self)
# Set focus to the Note ID
id_edit.SetFocus()
def get_input(self):
"""Custom input routine."""
# Inherit base input routine
gen_input = Dialogs.GenForm.get_input(self)
if gen_input:
self.obj.id = gen_input[_('Note ID')]
self.obj.author = gen_input[_('Note Taker')]
else:
self.obj = None
return self.obj
class AddNoteDialog(NotePropertiesForm):
"""Dialog used when adding a new Note."""
def __init__(self, parent, id, seriesNum=0, episodeNum=0, transcriptNum=0, collectionNum=0, clipNum=0, snapshotNum=0, documentNum=0, quoteNum=0):
obj = Note.Note()
obj.author = DBInterface.get_username()
obj.series_num = seriesNum
obj.episode_num = episodeNum
obj.transcript_num = transcriptNum
obj.collection_num = collectionNum
obj.clip_num = clipNum
obj.snapshot_num = snapshotNum
obj.document_num = documentNum
obj.quote_num = quoteNum
NotePropertiesForm.__init__(self, parent, id, _("Add Note"), obj)
class EditNoteDialog(NotePropertiesForm):
"""Dialog used when editing Note properties."""
def __init__(self, parent, id, note_object):
NotePropertiesForm.__init__(self, parent, id, _("Note Properties"), note_object)