1 from gi.repository
import Gtk
as gtk
2 from gi.repository
import Gdk
as gdk
3 from gi.repository
import GObject
as gobject
15 self.
window = gtk.Window(gtk.WindowType.TOPLEVEL)
16 self.window.set_title(
'New')
17 self.window.connect(
'destroy',
lambda w: self.window.destroy())
18 self.window.set_border_width(10)
19 self.window.set_default_size(210, 100)
28 vbox.pack_start(settings_grid,
True,
True, 0)
31 vbox.pack_start(button_box,
True,
True, 0)
34 self.window.show_all()
40 csv_label = gtk.Label(
'CSV File:')
41 csv_label.set_justify(gtk.JUSTIFY_RIGHT)
43 grid.attach(csv_label, 0, 0, 1, 1)
45 csv_entry = gtk.Entry()
46 csv_entry.set_width_chars(60)
48 grid.attach(csv_entry, 1, 0, 1, 1)
51 csv_button = gtk.Button(
'Browse')
53 grid.attach(csv_button, 2, 0, 1, 1)
54 csv_button.connect(
'clicked',
lambda w: UIUtils.browse_file(
'Select csv file', csv_entry, [UIUtils.CSV_FILE_FILTER, UIUtils.ALL_FILE_FILTER]))
56 wav_label = gtk.Label(
'Wav Folder:')
57 wav_label.set_justify(gtk.JUSTIFY_RIGHT)
59 grid.attach(wav_label, 0, 1, 1, 1)
61 wav_entry = gtk.Entry()
62 wav_entry.set_width_chars(60)
64 grid.attach(wav_entry, 1, 1, 1, 1)
67 wav_button = gtk.Button(
'Browse')
69 grid.attach(wav_button, 2, 1, 1, 1)
70 wav_button.connect(
'clicked',
lambda w: UIUtils.browse_folder(
'Select parent wav folder', wav_entry))
72 blocks_label = gtk.Label(
'Blocks per Activity:')
73 blocks_label.set_justify(gtk.JUSTIFY_RIGHT)
75 grid.attach(blocks_label, 0, 2, 1, 1)
77 spin_adj = gtk.Adjustment(value=3, lower=1, upper=1000, step_incr=1, page_incr=10)
78 blocks_spinner = gtk.SpinButton(adjustment=spin_adj)
80 grid.attach(blocks_spinner, 1, 2, 1, 1)
83 vbox = gtk.VBox(spacing=5)
85 grid.attach(vbox, 1, 3, 1, 2)
87 csv_entry.connect(
'changed',
lambda w: self.
_build_treeviews(w.get_text(), vbox))
92 button_box = gtk.HButtonBox()
93 button_box.set_layout(gtk.ButtonBoxStyle.EDGE)
95 cancel_button = gtk.Button(stock=gtk.STOCK_CANCEL, label=
'Cancel')
96 cancel_button.connect(
'clicked',
lambda w: self.window.destroy())
97 button_box.add(cancel_button)
99 ok_button = gtk.Button(stock=gtk.STOCK_OK, label=
'Run')
100 ok_button.connect(
'clicked',
lambda w: self.
run())
101 button_box.add(ok_button)
106 it = treeview.get_model().get_iter_first()
108 if treeview.get_model().get_value(it, 0)
in defaults_dict:
109 treeview.get_selection().select_iter(it)
111 it = treeview.get_model().iter_next(it)
114 if os.path.exists(filename):
116 map(
lambda child: vbox.remove(child), vbox.get_children())
121 envs_names = self.parser.get_envs_list()
123 acts_names = self.parser.get_acts_list()
126 self.
envs_treeview = UIUtils.build_multiselect_treeview(envs_names, envs_names, gobject.TYPE_STRING,
'Select Environments:')
127 self.
acts_treeview = UIUtils.build_multiselect_treeview(acts_names, acts_names, gobject.TYPE_STRING,
'Select Activities:')
130 self.envs_treeview.modify_base(gtk.StateFlags.ACTIVE, gdk.Color.parse(
'#4285F4')[1])
131 self.acts_treeview.modify_base(gtk.StateFlags.ACTIVE, gdk.Color.parse(
'#4285F4')[1])
143 'playtime - outside',
144 'playtime - general',
145 'playtime - organized'
154 csv_path = self.csv_entry.get_text()
155 wav_path = self.wav_entry.get_text()
156 blocks_per_activity = self.blocks_spinner.get_value_as_int()
159 if self.
acts_treeview and self.acts_treeview.get_selection():
160 model, sel_paths = self.acts_treeview.get_selection().get_selected_rows()
162 for path
in sel_paths:
163 it = model.get_iter(path)
164 activities.append(model.get_value(it, 0))
167 if self.
envs_treeview and self.envs_treeview.get_selection():
168 model, sel_paths = self.envs_treeview.get_selection().get_selected_rows()
170 for path
in sel_paths:
171 it = model.get_iter(path)
172 environments.append(model.get_value(it, 0))
174 is_valid = csv_path
and wav_path
and blocks_per_activity
and len(activities)
and len(environments)
185 enough_blocks, counts_str = self.parser.have_enough_blocks(check2,
False)
188 sel_test2s = self.parser.pick_rows(
190 lambda filename: UIUtils.open_file(
'Please locate %s' % (filename), filters=[UIUtils.WAV_FILE_FILTER], save_last_location=
True, cur_location=wav_path),
194 enough_blocks, counts_str = self.parser.have_enough_blocks(check2,
True)
197 if UIUtils.show_confirm_dialog(
'There are not enough unused rows left for some activities (see command window for row counts). If you proceed, the same row will be selected twice. Ok to continue?'):
198 sel_test2s = self.parser.pick_rows(
200 lambda filename: UIUtils.open_file(
'Please locate %s' % (filename), filters=[UIUtils.WAV_FILE_FILTER], save_last_location=
True, cur_location=wav_path),
205 UIUtils.show_message_dialog(
'The input file does not contain enough blocks of the specified types. Please refer to the command window for a printout of the activity counts.')
208 progress_dialog =
ProgressDialog(title=
'Setting up...', phases=[
''])
209 progress_dialog.show()
213 check2.test2s = sel_test2s
214 for i
in range(len(check2.test2s)):
215 test2 = check2.test2s[i]
216 test2.check2_id = check2.db_id
219 progress_dialog.set_fraction(float(i + 1) / float(len(check2.test2s)))
221 progress_dialog.ensure_finish()
226 self.window.destroy()
229 UIUtils.show_empty_form_dialog()