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.pitch_study_app.batch_sel_win import BatchSelectionWindow
3 from ui.pitch_study_app.options_window import OptionsWindow
4 from utils.ui_utils import UIUtils
5 from utils.progress_dialog import ProgressDialog
6 import parsers.pitch_study_exporter as pitch_exporter
7 from db.bll_database import BLLDatabase
8 from data_structs.pitch_study_props import PitchStudyProps
9 import traceback
10 
11 class MainWindow():
12  def __init__(self):
14  self.props = PitchStudyProps.db_select(self.bll_db)[0]
15  self.bll_db.close()
16 
17  self.window = gtk.Window(gtk.WindowType.TOPLEVEL)
18  self.window.set_title('Pitch Study')
19  self.window.connect('destroy', lambda x: gtk.main_quit())
20  self.window.set_border_width(10)
21  self.window.set_default_size(210, 100)
22 
23  box = gtk.VBox(False, 5)
24  create_button = UIUtils.create_button('Run Batch', UIUtils.BUTTON_ICONS.RUN)
25  create_button.connect('clicked', lambda widget, data=None: BatchSelectionWindow(self.props.clips_db_path))
26  box.pack_start(create_button, False, False, 0)
27 
28  export_button = UIUtils.create_button('Export Results', UIUtils.BUTTON_ICONS.EXPORT)
29  export_button.connect('clicked', lambda widget, data=None: self._export_results())
30  box.pack_start(export_button, False, False, 0)
31 
32  options_button = UIUtils.create_button('Options', UIUtils.BUTTON_ICONS.RUN)
33  options_button.connect('clicked', lambda widget, data=None: OptionsWindow())
34  box.pack_start(options_button, False, False, 0)
35 
36  exit_button = UIUtils.create_button('Exit', UIUtils.BUTTON_ICONS.EXIT)
37  exit_button.connect('clicked', lambda widget: gtk.main_quit())
38  box.pack_start(exit_button, False, False, 0)
39 
40  self.window.add(box)
41  self.window.show_all()
42 
43  def _export_results(self):
44  folder = UIUtils.open_folder()
45  if folder is not None and not folder.endswith('\\') and not folder.endswith('/'):
46  folder += '/'
47 
48  if folder != None:
49  progress = ProgressDialog(title='Exporting Data...')
50  progress.show()
51  try:
52  pitch_exporter.export_data(self.props.clips_db_path, folder, progress.set_fraction)
53  progress.ensure_finish()
54  UIUtils.show_message_dialog('Data exported successfully.')
55 
56  except Exception as err:
57  print err
58  print traceback.format_exc()
59 
60  progress.ensure_finish()
61  UIUtils.show_message_dialog('There was an error exporting the data.\nPlease make sure the folders are not open in a Windows Explorer window.', dialog_type=gtk.MessageType.WARNING)
62 
63 
64