4 from gi.repository
import Gtk
as gtk
5 from gi.repository
import WebKit
as webkit
14 self.
window = gtk.Window(gtk.WindowType.TOPLEVEL)
15 self.window.set_title(
'Transcription Verifier')
16 self.window.connect(
'destroy',
lambda w: self.window.destroy())
17 self.window.set_default_size(270, 210)
18 self.window.set_resizable(
True)
21 file1_grid = gtk.Grid()
22 file1_frame = gtk.Frame(label=
'File 1')
24 file1_name_label = gtk.Label(
'Transcriber Name:')
25 file1_name_entry = gtk.Entry()
26 file1_name_entry.set_width_chars(20)
27 file1_label = gtk.Label(
'Path:')
28 file1_entry = gtk.Entry()
29 file1_entry.set_width_chars(50)
30 file1_browse_button = gtk.Button(
'Browse')
31 file1_browse_button.connect(
'clicked',
lambda w: UIUtils.browse_file(
'Select File 1', file1_entry, [UIUtils.TRS_FILE_FILTER]))
32 file1_grid.attach(file1_name_label, 0, 0, 1, 1)
33 file1_grid.attach(file1_name_entry, 1, 0, 1, 1)
34 file1_grid.attach(file1_label, 0, 1, 1, 1)
35 file1_grid.attach(file1_entry, 1, 1, 1, 1)
36 file1_grid.attach(file1_browse_button, 2, 1, 1, 1)
38 file1_frame.add(file1_grid)
39 vbox.pack_start(file1_frame,
True,
True, 0)
41 file2_grid = gtk.Grid()
42 file2_frame = gtk.Frame(label=
'File 2')
44 file2_name_label = gtk.Label(
'Transcriber Name:')
45 file2_name_entry = gtk.Entry()
46 file2_name_entry.set_width_chars(20)
47 file2_label = gtk.Label(
'Path:')
48 file2_entry = gtk.Entry()
49 file2_entry.set_width_chars(50)
50 file2_browse_button = gtk.Button(
'Browse')
51 file2_browse_button.connect(
'clicked',
lambda w: UIUtils.browse_file(
'Select File 2', file2_entry, [UIUtils.TRS_FILE_FILTER]))
52 file2_grid.attach(file2_name_label, 0, 2, 1, 1)
53 file2_grid.attach(file2_name_entry, 1, 2, 1, 1)
54 file2_grid.attach(file2_label, 0, 3, 1, 1)
55 file2_grid.attach(file2_entry, 1, 3, 1, 1)
56 file2_grid.attach(file2_browse_button, 2, 3, 1, 1)
58 file2_frame.add(file2_grid)
59 vbox.pack_start(file2_frame,
True,
True, 0)
65 file1_name_entry.grab_focus()
67 button_box = gtk.HButtonBox()
68 button_box.set_layout(gtk.ButtonBoxStyle.EDGE)
69 cancel_button = gtk.Button(stock=gtk.STOCK_CANCEL, label=
'Cancel')
70 cancel_button.connect(
'clicked',
lambda w: self.window.destroy())
71 button_box.add(cancel_button)
73 ok_button = gtk.Button(stock=gtk.STOCK_OK, label=
'Ok')
74 ok_button.connect(
'clicked',
lambda w: self.
_check_input(
75 file1_entry.get_text(),
76 file2_entry.get_text(),
77 file1_name_entry.get_text(),
78 file2_name_entry.get_text())
80 button_box.add(ok_button)
82 vbox.pack_start(button_box,
True,
True, 0)
85 self.window.show_all()
87 def _check_input(self, file1_path, file2_path, file1_name, file2_name):
88 if file1_path
and file2_path:
90 for path
in [file1_path, file2_path]:
91 if not os.path.exists(path):
92 bad_paths.append(path)
95 message =
'The following files could not be located.\n'
96 for path
in bad_paths:
97 message +=
'\n- %s' % (path)
98 message +=
'\n\nPlease double-check the paths and try again.'
99 UIUtils.show_message_dialog(message)
102 self.
_compare(file1_path, file2_path, file1_name, file2_name)
105 UIUtils.show_message_dialog(
'Please select two files.')
107 def _compare(self, file1_path, file2_path, file1_name, file2_name):
108 self.window.set_sensitive(
False)
109 paths = [file1_path, file2_path]
111 dialog =
ProgressDialog(
'Processing Files...', [
'Parsing trs file %d...' % (i + 1)
for i
in range(len(paths))] + [
'Comparing files...',
'Generating output...'])
114 for i
in range(len(paths)):
116 progress_update_fcn=dialog.set_fraction,
118 remove_bad_trans_codes=
False
120 segs.append(file_segs)
127 html = difflib.HtmlDiff().make_file(*desc_strs, fromdesc=file1_name, todesc=file2_name, context=
True, numlines=0)
130 html = html.replace(
'font-family:Courier;',
'')
133 dialog.ensure_finish()
135 self.window.destroy()
140 for i
in range(len(segs)):
143 for utter
in seg.utters:
146 dialog.set_fraction(float(i) / float(len(segs)))
147 descs.append(file_descs)
156 if utter.speaker.speaker_codeinfo:
157 speaker_cd = utter.speaker.speaker_codeinfo.get_code()
161 desc_str =
'%s [%s - %s]' % ( speaker_cd, BackendUtils.get_time_str(utter.start), BackendUtils.get_time_str(utter.end))
163 desc_str +=
' %s' % (utter.lena_notes)
164 if utter.trans_phrase:
165 desc_str +=
' %s' % (utter.trans_phrase)
167 desc_str +=
' |%s|' % (
'|'.join(utter.lena_codes))
168 if utter.trans_codes:
169 if not utter.lena_codes:
171 desc_str +=
'%s|' % (
'|'.join(utter.trans_codes))