Baby Language Lab Scripts
A collection of data processing tools.
 All Classes Namespaces Files Functions Variables Pages
main_window.py
Go to the documentation of this file.
1 from gi.repository import Gtk as gtk
2 from ui.splitter_app.options_window import OptionsWindow
3 from utils.ui_utils import UIUtils
4 from utils.progress_dialog import ProgressDialog
5 from parsers.trs_splitter import TRSMerger
6 
7 class MainWindow():
8  def __init__(self):
9  self.window = gtk.Window(gtk.WindowType.TOPLEVEL)
10  self.window.set_title('TRS Splitter')
11  self.window.connect('destroy', lambda w: gtk.main_quit())
12  self.window.set_border_width(10)
13  self.window.set_default_size(150, 100)
14 
15  box = gtk.VBox(False, 5)
16  split_button = UIUtils.create_button('Split File', UIUtils.BUTTON_ICONS.SPLIT)
17  split_button.connect('clicked', lambda w: self.split_file())
18  box.pack_start(split_button, False, False, 0)
19  split_button.show()
20 
21  merge_button = UIUtils.create_button('Merge Files', UIUtils.BUTTON_ICONS.MERGE)
22  merge_button.connect('clicked', lambda w: self.merge_files())
23  box.pack_start(merge_button, False, False, 0)
24  merge_button.show()
25 
26  exit_button = UIUtils.create_button('Exit', UIUtils.BUTTON_ICONS.EXIT)
27  exit_button.connect('clicked', lambda w: gtk.main_quit())
28  box.pack_start(exit_button, False, False, 0)
29  exit_button.show()
30 
31  self.window.add(box)
32  box.show()
33  self.window.show()
34 
35  def split_file(self):
36  filename = UIUtils.open_file('Select trs file', [UIUtils.TRS_FILE_FILTER, UIUtils.ALL_FILE_FILTER])
37 
38  dest_folder = None
39  if filename:
40  dialog = gtk.FileChooserDialog(title='Select Folder for Split Files',
41  action=gtk.FileChooserAction.SELECT_FOLDER,
42  buttons=(gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL, gtk.STOCK_OPEN, gtk.ResponseType.OK))
43  dialog.set_default_response(gtk.ResponseType.OK)
44 
45  response = dialog.run()
46  if response == gtk.ResponseType.OK:
47  dest_folder = dialog.get_filename()
48  OptionsWindow(filename, dest_folder)
49 
50  dialog.destroy()
51 
52  def merge_files(self):
53  dialog = gtk.FileChooserDialog(title='Select Folder Containing Split Files',
54  action=gtk.FileChooserAction.SELECT_FOLDER,
55  buttons=(gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL, gtk.STOCK_OPEN, gtk.ResponseType.OK))
56  dialog.set_default_response(gtk.ResponseType.OK)
57 
58  response = dialog.run()
59  if response == gtk.ResponseType.OK:
60  src_folder = dialog.get_filename()
61  dialog.destroy()
62 
63  progress_dialog = ProgressDialog(title='Merging files', phases=['Merging TRS files...'])
64  progress_dialog.show()
65  merger = TRSMerger(src_folder)
66  merger.merge(progress_dialog.set_fraction)
67 
68  else:
69  dialog.destroy()