-
Notifications
You must be signed in to change notification settings - Fork 17
/
CoreDataPropertiesForm.py
410 lines (328 loc) · 15.7 KB
/
CoreDataPropertiesForm.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
# 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 Core Data Properties Form."""
__author__ = 'David Woods <[email protected]>'
# Import Python's Internationalization Module
import gettext
# Import the CoreData Object
import CoreData
# Import Transana's Database Interface
import DBInterface
# Import the Dialogs module from which this form inherits
import Dialogs
import TransanaGlobal
# import wxPython
import wx
# import the Masked Edit Control (requires wxPython 2.4.2.4 or later)
import wx.lib.masked
# Define the Format Options for different File Types
imageOptions = ['', 'avi', 'mov', 'mp4', 'm4v', 'mpeg', 'mpeg2', 'wmv']
soundOptions = ['', 'mp3', 'wav', 'wma', 'aac']
allOptions = ['', 'avi', 'mov', 'mp3', 'mp4', 'm4v', 'mpeg', 'mpeg2', 'wav', 'wma', 'wmv', 'aac']
class CoreDataPropertiesForm(Dialogs.GenForm):
""" Form containing Core Data fields. """
def __init__(self, parent, id, title, coredata_object):
""" Initialize the Core Data Properties form """
# Set the Size of the Form
self.width = 550
self.height = 510
# Create the Base Form, based on GenForm in the Transana Dialogs module
Dialogs.GenForm.__init__(self, parent, id, title, size=(self.width, self.height), style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
useSizers = True, HelpContext='Core Data Properties')
# Preserve the initial Core Data Object sent in from the calling routine
self.obj = coredata_object
# 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)
# Media File Name
# NOTE: The otherwise unused Comment Field is used to contain the full Media File Name.
media_filename_edit = self.new_edit_box(_("Media File Name"), v1, self.obj.comment)
# Add the element to the row sizer
r1Sizer.Add(v1, 1, wx.EXPAND)
# Media File Name Field is not editable
media_filename_edit.Enable(False)
# 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 first row
r2Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v2 = wx.BoxSizer(wx.VERTICAL)
# Title
title_edit = self.new_edit_box(_("Title"), v2, self.obj.title, maxLen=255)
# Add the element to the row sizer
r2Sizer.Add(v2, 1, wx.EXPAND)
# 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 first row
r3Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v3 = wx.BoxSizer(wx.VERTICAL)
# Creator
creator_edit = self.new_edit_box(_("Creator"), v3, self.obj.creator, maxLen=255)
# Add the element to the row sizer
r3Sizer.Add(v3, 1, wx.EXPAND)
# 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)
# Subject
subject_edit = self.new_edit_box(_("Subject"), v4, self.obj.subject, maxLen=255)
# Add the element to the row sizer
r3Sizer.Add(v4, 1, wx.EXPAND)
# 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 first row
r4Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v5 = wx.BoxSizer(wx.VERTICAL)
# Description
self.description_edit = self.new_edit_box(_("Description"), v5, self.obj.description, style=wx.TE_MULTILINE, maxLen=255)
# Add the element to the row sizer
r4Sizer.Add(v5, 1, wx.EXPAND)
# Add a spacer to enforce the height of the Description item
r4Sizer.Add((0, 80))
# Add the row sizer to the main vertical sizer
mainSizer.Add(r4Sizer, 5, wx.EXPAND)
# Add a vertical spacer to the main sizer
mainSizer.Add((0, 10))
# Create a HORIZONTAL sizer for the first row
r5Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v6 = wx.BoxSizer(wx.VERTICAL)
# Publisher
publisher_edit = self.new_edit_box(_("Publisher"), v6, self.obj.publisher, maxLen=255)
# Add the element to the row sizer
r5Sizer.Add(v6, 1, wx.EXPAND)
# Add a horizontal spacer to the row sizer
r5Sizer.Add((10, 0))
# Create a VERTICAL sizer for the next element
v7 = wx.BoxSizer(wx.VERTICAL)
# Contributor
contributor_edit = self.new_edit_box(_("Contributor"), v7, self.obj.contributor, maxLen=255)
# Add the element to the row sizer
r5Sizer.Add(v7, 1, wx.EXPAND)
# 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 first row
r6Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v8 = wx.BoxSizer(wx.VERTICAL)
# Dialogs.GenForm does not provide a Masked text control, so the Date
# Field is handled differently than other fields.
# Date [label]
date_lbl = wx.StaticText(self.panel, -1, _("Date (MM/DD/YYYY)"))
# Add the element to the vertical sizer
v8.Add(date_lbl, 0, wx.BOTTOM, 3)
# Date layout
# Use the Masked Text Control (Requires wxPython 2.4.2.4 or later)
# TODO: Make Date autoformat localizable
self.date_edit = wx.lib.masked.TextCtrl(self.panel, -1, '', autoformat='USDATEMMDDYYYY/')
# Add the element to the vertical sizer
v8.Add(self.date_edit, 1, wx.EXPAND)
# If a Date is know, load it into the control
if (self.obj.dc_date != '') and (self.obj.dc_date != '01/01/0'):
self.date_edit.SetValue(self.obj.dc_date)
# Add the element to the row sizer
r6Sizer.Add(v8, 1, wx.EXPAND)
# Add a horizontal spacer to the row sizer
r6Sizer.Add((10, 0))
# Create a VERTICAL sizer for the next element
v9 = wx.BoxSizer(wx.VERTICAL)
# Type
# Define legal options for the Combo Box
options = ['', _('Image'), _('Sound')]
self.type_combo = self.new_combo_box(_("Media Type"), v9, options, self.obj.dc_type)
# Add the element to the row sizer
r6Sizer.Add(v9, 1, wx.EXPAND)
# Define a Combo Box Event. When different Types are selected, different Format options should be displayed.
wx.EVT_COMBOBOX(self, self.type_combo.GetId(), self.OnTypeChoice)
# Add a horizontal spacer to the row sizer
r6Sizer.Add((10, 0))
# Create a VERTICAL sizer for the next element
v10 = wx.BoxSizer(wx.VERTICAL)
# Format
# The Format Combo Box has different options depending on the value of Type
if self.obj.dc_type == unicode(_('Image'), 'utf8'):
options = imageOptions
elif self.obj.dc_type == unicode(_('Sound'), 'utf8'):
options = soundOptions
else:
options = allOptions
self.format_combo = self.new_combo_box(_("Format"), v10, options, self.obj.format)
# Add the element to the row sizer
r6Sizer.Add(v10, 1, wx.EXPAND)
# 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 first row
r7Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v11 = wx.BoxSizer(wx.VERTICAL)
# Identifier
identifier_edit = self.new_edit_box(_("Identifier"), v11, self.obj.id)
# Add the element to the row sizer
r7Sizer.Add(v11, 1, wx.EXPAND)
# Identifier is not editable
identifier_edit.Enable(False)
# Add a horizontal spacer to the row sizer
r7Sizer.Add((10, 0))
# Create a VERTICAL sizer for the next element
v12 = wx.BoxSizer(wx.VERTICAL)
# Source
source_edit = self.new_edit_box(_("Source"), v12, self.obj.source, maxLen=255)
# Add the element to the row sizer
r7Sizer.Add(v12, 1, wx.EXPAND)
# Add the row sizer to the main vertical sizer
mainSizer.Add(r7Sizer, 0, wx.EXPAND)
# Add a vertical spacer to the main sizer
mainSizer.Add((0, 10))
# Create a HORIZONTAL sizer for the first row
r8Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v13 = wx.BoxSizer(wx.VERTICAL)
# Language
language_edit = self.new_edit_box(_("Language"), v13, self.obj.language, maxLen=25)
# Add the element to the row sizer
r8Sizer.Add(v13, 1, wx.EXPAND)
# Add a horizontal spacer to the row sizer
r8Sizer.Add((10, 0))
# Create a VERTICAL sizer for the next element
v14 = wx.BoxSizer(wx.VERTICAL)
# Relation
relation_edit = self.new_edit_box(_("Relation"), v14, self.obj.relation, maxLen=255)
# Add the element to the row sizer
r8Sizer.Add(v14, 1, 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 HORIZONTAL sizer for the first row
r9Sizer = wx.BoxSizer(wx.HORIZONTAL)
# Create a VERTICAL sizer for the next element
v15 = wx.BoxSizer(wx.VERTICAL)
# Coverage
coverage_edit = self.new_edit_box(_("Coverage"), v15, self.obj.coverage, maxLen=255)
# Add the element to the row sizer
r9Sizer.Add(v15, 1, wx.EXPAND)
# Add a horizontal spacer to the row sizer
r9Sizer.Add((10, 0))
# Create a VERTICAL sizer for the next element
v16 = wx.BoxSizer(wx.VERTICAL)
# Rights
rights_edit = self.new_edit_box(_("Rights"), v16, self.obj.rights, maxLen=255)
# Add the element to the row sizer
r9Sizer.Add(v16, 1, wx.EXPAND)
# Add the row sizer to the main vertical sizer
mainSizer.Add(r9Sizer, 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(self.width, width), height))
# Define the minimum size for this dialog as the current size
self.SetSizeHints(max(self.width, width), height)
# Center the form on screen
TransanaGlobal.CenterOnPrimary(self)
# Set focus to Title
title_edit.SetFocus()
def OnTypeChoice(self, event):
""" This method changes the options in the Format field based on the selection made in the Type field. """
# Get the current Text Value for the Format field
currentString = self.format_combo.GetValue()
# Determine the appropriate options for the Format Combo based on the current value of the Type Field
if self.type_combo.GetStringSelection() == unicode(_('Image'), 'utf8'):
options = imageOptions
elif self.type_combo.GetStringSelection() == unicode(_('Sound'), 'utf8'):
options = soundOptions
else:
options = allOptions
# Clear the values from the Format Combo
self.format_combo.Clear()
# Insert the New Values for the Format Combo
for option in options:
self.format_combo.Append(option)
# Reset the String Value for the Format Combo to its original value
if currentString != '':
self.format_combo.SetValue(currentString)
def get_input(self):
"""Show the dialog and return the modified Core Data Object. Result
is None if user pressed the Cancel button."""
d = Dialogs.GenForm.get_input(self) # inherit parent method
if d:
self.obj.id = d[_('Identifier')]
self.obj.comment = d[_('Media File Name')]
self.obj.title = d[_('Title')]
self.obj.creator = d[_('Creator')]
self.obj.subject = d[_('Subject')]
# Description Field does not utilize Dialogs.GenForm.get_input()
self.obj.description = self.description_edit.GetValue()
self.obj.publisher = d[_('Publisher')]
self.obj.contributor = d[_('Contributor')]
# TODO: Block "Okay" if self.date_edit.IsValid() is false!
# Date Field does not utilize Dialogs.GenForm.get_input()
self.obj.dc_date = self.date_edit.GetValue()
self.obj.dc_type = d[_('Media Type')]
self.obj.format = d[_('Format')]
self.obj.source = d[_('Source')]
self.obj.language = d[_('Language')]
self.obj.relation = d[_('Relation')]
self.obj.coverage = d[_('Coverage')]
self.obj.rights = d[_('Rights')]
else:
self.obj = None
return self.obj
class AddCoreDataDialog(CoreDataPropertiesForm):
"""Dialog used when adding a new Core Data record."""
def __init__(self, parent, id):
# Create a blank Core Data Object
obj = CoreData.CoreData()
CoreDataPropertiesForm.__init__(self, parent, id, _("Add Core Data"), obj)
class EditCoreDataDialog(CoreDataPropertiesForm):
"""Dialog used when editing Core Data properties."""
def __init__(self, parent, id, coredata_object):
CoreDataPropertiesForm.__init__(self, parent, id, _("Core Data Properties"), coredata_object)