1 from gi.repository
import Gtk
as gtk
10 def __init__(self, action_callback, edit_output=None):
14 self.
window = gtk.Window(gtk.WindowType.TOPLEVEL)
15 self.window.set_title(
'%s Output' % (
'Edit' if self.
edit_output else 'Create'))
16 self.window.set_border_width(10)
17 self.window.set_default_size(400, 400)
24 filters_frame =
FiltersFrame(existing_filters=edit_output.filters
if edit_output
else [])
25 filters_frame.set_vexpand(
True)
27 options_frame.set_vexpand(
True)
29 vbox.pack_start(props_frame,
False,
False, 0)
32 grid.attach(filters_frame, 0, 0, 1, 1)
35 grid.attach(options_frame, 1, 0, 1, 1)
36 vbox.pack_start(grid,
True,
True, 0)
38 button_box = gtk.HButtonBox()
39 button_box.set_layout(gtk.ButtonBoxStyle.EDGE)
41 cancel_button = gtk.Button(stock=gtk.STOCK_CANCEL)
42 cancel_button.connect(
'clicked',
lambda w: self.window.destroy())
43 button_box.pack_start(cancel_button,
False,
False, 0)
45 ok_button = gtk.Button(stock=gtk.STOCK_OK)
46 button_box.pack_start(ok_button,
False,
False, 0)
47 ok_button.connect(
'clicked',
lambda w: self.
_create_output(filters_frame, options_frame))
48 vbox.pack_end(button_box,
False,
False, 0)
51 self.window.show_all()
54 props_frame = gtk.Frame(label=
'Properties')
57 name_label = gtk.Label(
'Name:')
59 self.name_entry.set_width_chars(50)
61 self.name_entry.set_text(self.edit_output.name)
64 name_label_hbox = gtk.HBox()
65 name_label_hbox.pack_start(gtk.Alignment(xalign=1, yalign=0, xscale=0, yscale=0),
True,
True, 0)
66 name_label_hbox.pack_start(name_label,
False,
False, 0)
68 sub_grid.attach(name_label_hbox, 0, 0, 1, 1)
70 name_entry_hbox = gtk.HBox()
71 name_entry_hbox.pack_start(self.
name_entry,
False,
False, 0)
73 sub_grid.attach(name_entry_hbox, 1, 0, 1, 1)
75 desc_label = gtk.Label(
'Description:')
77 self.desc_entry.set_width_chars(50)
79 self.desc_entry.set_text(self.edit_output.desc)
81 desc_label_hbox = gtk.HBox()
82 desc_label_hbox.pack_start(gtk.Alignment(xalign=1, yalign=0, xscale=0, yscale=0),
True,
True, 0)
83 desc_label_hbox.pack_start(desc_label,
False,
False, 0)
85 sub_grid.attach(desc_label_hbox, 0, 1, 1, 1)
87 desc_entry_hbox = gtk.HBox()
88 desc_entry_hbox.pack_start(self.
desc_entry,
False,
False, 0)
90 sub_grid.attach(desc_entry_hbox, 1, 1, 1, 1)
92 props_frame.add(sub_grid)
97 return self.name_entry.get_text() !=
''
100 if options_frame.validate()
and self.
_validate():
101 name = self.name_entry.get_text()
102 desc = self.desc_entry.get_text()
103 filters = filters_frame.get_filters()
104 calc = options_frame.get_output_calc()
105 chained = options_frame.get_seg_linkage()
107 output =
Output(name, desc, filters, calc, chained)
110 self.window.destroy()
113 UIUtils.show_empty_form_dialog()
116 def __init__(self, edit_output=None, label='Options'):
117 super(OptionsFrame, self).
__init__(label=label)
133 options = DBConstants.COMBO_OPTIONS[DBConstants.COMBO_GROUPS.OUTPUT_CALC_TYPES]
136 calc_cls = {options.COUNT: CountOutputCalc,
137 options.RATE: RateOutputCalc,
138 options.TIME_PERIOD: TimePeriodOutputCalc,
139 options.BREAKDOWN: BreakdownOutputCalc,
140 options.LIST: ListOutputCalc,
145 args.append(arg_tuple[1]())
147 return calc_cls(*args)
157 while is_valid
and i < len(inputs):
158 is_valid = inputs[i][0]()
164 vbox = gtk.VBox(spacing=5)
166 linkage_label = gtk.Label(
'Segment Linkage:')
167 linkage_combo = UIUtils.build_options_combo(
168 DBConstants.COMBO_GROUPS.FILTER_LINKAGE_OPTIONS,
169 include_empty_option=
False,
170 active_index=(0
if self.
edit_output and self.edit_output.chained
else 1)
173 self.
inputs_dict[
'seg_linkage'] = (
lambda: linkage_combo.get_active() >= 0,
174 lambda: linkage_combo.get_model()[linkage_combo.get_active()][1] == DBConstants.COMBO_OPTIONS[DBConstants.COMBO_GROUPS.FILTER_LINKAGE_OPTIONS].LINKED)
175 linkage_hbox = gtk.HBox()
176 linkage_hbox.pack_start(linkage_label,
True,
True, 0)
177 linkage_hbox.pack_start(linkage_combo,
True,
True, 0)
178 vbox.pack_start(linkage_hbox,
False,
False, 0)
182 grid.set_row_spacing(5)
187 for row
in range(n_rows):
188 for col
in range(n_cols):
189 cell_hbox = gtk.HBox()
191 cell_matrix.append([cell_hbox])
193 cell_matrix[row].append(cell_hbox)
196 grid.attach(cell_matrix[row][col], col, row, 1, 1)
198 output_type_label = gtk.Label(
'Output Type:')
204 output_type_combo = UIUtils.build_options_combo(DBConstants.COMBO_GROUPS.OUTPUT_CALC_TYPES, active_index)
205 output_type_combo.connect(
'changed',
lambda w: self.
_update_options_frame(cell_matrix, n_rows, n_cols, w.get_model().get(w.get_active_iter(), 1)[0]) )
207 self.
_update_options_frame( cell_matrix, n_rows, n_cols, output_type_combo.get_model().get(output_type_combo.get_active_iter(), 1)[0] )
209 self.
inputs_dict[
'calc_type'] = (
lambda: output_type_combo.get_active() > 0,
210 lambda: output_type_combo.get_model()[output_type_combo.get_active()][1])
211 output_type_hbox = gtk.HBox()
212 output_type_hbox.pack_start(output_type_label,
True,
True, 0)
213 output_type_hbox.pack_start(output_type_combo,
True,
True, 0)
215 vbox.pack_start(output_type_hbox,
False,
False, 0)
216 vbox.pack_start(gtk.HSeparator(),
False,
False, 0)
217 vbox.pack_start(grid,
True,
True, 0)
224 calc_cls = self.edit_output.output_calc.__class__
225 opts = DBConstants.COMBO_OPTIONS[DBConstants.COMBO_GROUPS.OUTPUT_CALC_TYPES]
226 val = {CountOutputCalc: opts.COUNT,
227 RateOutputCalc: opts.RATE,
228 TimePeriodOutputCalc: opts.TIME_PERIOD,
229 BreakdownOutputCalc: opts.BREAKDOWN,
230 ListOutputCalc: opts.LIST,
233 return self.
_get_combo_index(DBConstants.COMBO_GROUPS.OUTPUT_CALC_TYPES, val)
236 opts = DBConstants.COMBO_OPTIONS[combo_group]
238 enum_vals = opts.get_ordered_vals()
240 while found_index < 0
and i < len(enum_vals):
241 if enum_vals[i] == combo_val:
246 active_index = found_index
252 for row
in range(n_rows):
253 for col
in range(n_cols):
254 children = cell_matrix[row][col].get_children()
255 for child
in children:
256 cell_matrix[row][col].remove(child)
258 options = DBConstants.COMBO_OPTIONS[DBConstants.COMBO_GROUPS.OUTPUT_CALC_TYPES]
260 if sel_option_id == options.COUNT:
261 regex_label = gtk.Label(
'Search:')
262 regex_entry = gtk.Entry()
263 regex_entry.set_width_chars(30)
265 regex_entry.set_text(self.edit_output.output_calc.search_term)
267 regex_helper = UIUtils.build_regex_helper_combo(regex_entry)
269 hbox.pack_start(regex_entry,
False,
False, 0)
270 hbox.pack_start(regex_helper,
False,
False, 0)
272 cell_matrix[0][0].pack_start(regex_label,
False,
False, 0)
273 cell_matrix[0][1].pack_start(hbox,
False,
False, 0)
274 cell_matrix[0][0].show_all()
275 cell_matrix[0][1].show_all()
277 combo_label = gtk.Label(
'Calc Type:')
280 active_index = self.
_get_combo_index(DBConstants.COMBO_GROUPS.COUNT_OUTPUT_CALC_TYPES, self.edit_output.output_calc.count_type)
282 combo = UIUtils.build_options_combo(DBConstants.COMBO_GROUPS.COUNT_OUTPUT_CALC_TYPES, active_index)
283 cell_matrix[1][0].pack_start(combo_label,
False,
False, 0)
284 cell_matrix[1][1].pack_start(combo,
False,
False, 0)
285 cell_matrix[1][0].show_all()
286 cell_matrix[1][1].show_all()
288 self.
inputs_dict[
'calc_inputs'].append( (
lambda:
True,
289 lambda: regex_entry.get_text()) )
290 self.
inputs_dict[
'calc_inputs'].append( (
lambda: combo.get_active() > 0,
291 lambda: combo.get_model()[combo.get_active()][1]) )
293 elif sel_option_id == options.RATE:
294 regex_label = gtk.Label(
'Search:')
295 regex_entry = gtk.Entry()
296 regex_entry.set_width_chars(30)
298 regex_entry.set_text(self.edit_output.output_calc.search_term)
300 regex_helper = UIUtils.build_regex_helper_combo(regex_entry)
302 hbox.pack_start(regex_entry,
False,
False, 0)
303 hbox.pack_start(regex_helper,
False,
False, 0)
305 cell_matrix[0][0].pack_start(regex_label,
False,
False, 0)
306 cell_matrix[0][1].pack_start(hbox,
False,
False, 0)
307 cell_matrix[0][0].show_all()
308 cell_matrix[0][1].show_all()
310 combo_label = gtk.Label(
'Calc Type:')
313 active_index = self.
_get_combo_index(DBConstants.COMBO_GROUPS.RATE_OUTPUT_CALC_TYPES, self.edit_output.output_calc.rate_type)
315 combo = UIUtils.build_options_combo(DBConstants.COMBO_GROUPS.RATE_OUTPUT_CALC_TYPES, active_index)
316 cell_matrix[1][0].pack_start(combo_label,
False,
False, 0)
317 cell_matrix[1][1].pack_start(combo,
False,
False, 0)
318 cell_matrix[1][0].show_all()
319 cell_matrix[1][1].show_all()
321 self.
inputs_dict[
'calc_inputs'].append( (
lambda:
True,
322 lambda: regex_entry.get_text()) )
323 self.
inputs_dict[
'calc_inputs'].append( (
lambda: combo.get_active() > 0,
324 lambda: combo.get_model()[combo.get_active()][1]) )
326 elif sel_option_id == options.TIME_PERIOD:
327 regex_label = gtk.Label(
'Search:')
328 regex_entry = gtk.Entry()
329 regex_entry.set_width_chars(30)
331 regex_entry.set_text(self.edit_output.output_calc.search_term)
333 regex_helper = UIUtils.build_regex_helper_combo(regex_entry)
335 hbox.pack_start(regex_entry,
False,
False, 0)
336 hbox.pack_start(regex_helper,
False,
False, 0)
338 cell_matrix[0][0].pack_start(regex_label,
False,
False, 0)
339 cell_matrix[0][1].pack_start(hbox,
False,
False, 0)
340 cell_matrix[0][0].show_all()
341 cell_matrix[0][1].show_all()
343 self.
inputs_dict[
'calc_inputs'].append( (
lambda:
True,
344 lambda: regex_entry.get_text()) )
346 elif sel_option_id == options.BREAKDOWN:
347 row_combo_label = gtk.Label(
'Row Criteria:')
350 active_row_index = self.
_get_combo_index(DBConstants.COMBO_GROUPS.BREAKDOWN_OUTPUT_CALC_CRITERIA, self.edit_output.output_calc.row_criteria)
352 row_combo = UIUtils.build_options_combo(DBConstants.COMBO_GROUPS.BREAKDOWN_OUTPUT_CALC_CRITERIA, active_row_index)
353 cell_matrix[0][0].pack_start(row_combo_label,
False,
False, 0)
354 cell_matrix[0][1].pack_start(row_combo,
False,
False, 0)
355 cell_matrix[0][0].show_all()
356 cell_matrix[0][1].show_all()
358 col_combo_label = gtk.Label(
'Column Criteria:')
361 active_col_index = self.
_get_combo_index(DBConstants.COMBO_GROUPS.BREAKDOWN_OUTPUT_CALC_CRITERIA, self.edit_output.output_calc.col_criteria)
362 col_combo = UIUtils.build_options_combo(DBConstants.COMBO_GROUPS.BREAKDOWN_OUTPUT_CALC_CRITERIA, active_col_index)
363 cell_matrix[1][0].pack_start(col_combo_label,
False,
False, 0)
364 cell_matrix[1][1].pack_start(col_combo,
False,
False, 0)
365 cell_matrix[1][0].show_all()
366 cell_matrix[1][1].show_all()
368 self.
inputs_dict[
'calc_inputs'].append( (
lambda: row_combo.get_active() > 0,
369 lambda: row_combo.get_model()[row_combo.get_active()][1]) )
370 self.
inputs_dict[
'calc_inputs'].append( (
lambda: col_combo.get_active() > 0,
371 lambda: col_combo.get_model()[col_combo.get_active()][1]) )
373 elif sel_option_id == options.LIST:
374 regex_label = gtk.Label(
'Search:')
375 regex_entry = gtk.Entry()
376 regex_entry.set_width_chars(30)
378 regex_entry.set_text(self.edit_output.output_calc.search_term)
380 regex_helper = UIUtils.build_regex_helper_combo(regex_entry)
382 hbox.pack_start(regex_entry,
False,
False, 0)
383 hbox.pack_start(regex_helper,
False,
False, 0)
385 cell_matrix[0][0].pack_start(regex_label,
False,
False, 0)
386 cell_matrix[0][1].pack_start(hbox,
False,
False, 0)
387 cell_matrix[0][0].show_all()
388 cell_matrix[0][1].show_all()
390 grouping_cat_label = gtk.Label(
"Grouping Category:")
393 active_index = self.
_get_combo_index(DBConstants.COMBO_GROUPS.LIST_OUTPUT_CALC_CATS, self.edit_output.output_calc.cat)
394 grouping_cat_combo = UIUtils.build_options_combo(DBConstants.COMBO_GROUPS.LIST_OUTPUT_CALC_CATS, active_index)
395 cell_matrix[1][0].pack_start(grouping_cat_label,
False,
False, 0)
396 cell_matrix[1][1].pack_start(grouping_cat_combo,
False,
False, 0)
397 cell_matrix[1][0].show_all()
398 cell_matrix[1][1].show_all()
400 self.
inputs_dict[
'calc_inputs'].append( (
lambda:
True,
401 lambda: regex_entry.get_text()) )
402 self.
inputs_dict[
'calc_inputs'].append( (
lambda: grouping_cat_combo.get_active() > 0,
403 lambda: grouping_cat_combo.get_model()[grouping_cat_combo.get_active()][1]) )