def __init__(self, window_provider): title = "Create Synthetic Datafile" super().__init__(title, window_provider) def window_provider(title): return self.window.internal_renderer self.form = FormController(window_provider) def dist_options_provider(): from datafiles.distribution import all_distributions distributions = {} for d in all_distributions: distributions[d] = d return distributions dist_select = Select(True, dist_options_provider) dist_section = Section("Distribution", dist_select) self.form.add_element('dist', dist_section) self.form.add_element('samples', Section("Samples", Input(True, int, 1500))) self.form.add_element('break1', SectionBreak()) all_params = {} for dist, params in param_map.items(): for p in params: if p not in all_params.keys(): inp = Input(True, myfloat, 1) self.form.add_element(p, Section(p, inp)) all_params[p] = inp self.form.add_element('break2', SectionBreak()) self.form.add_element('loc', Section("Mean", Input(True, myfloat, 0))) self.form.add_element('scale', Section("Standard deviation", Input(True, nfloat, 2))) def on_dist_change(old_value, new_value, is_valid=True): for inp in all_params.values(): inp.disappear() if new_value is not None: for p in param_map[new_value]: all_params[p].changed() all_params[p].show() dist_select.on_change(on_dist_change) on_dist_change(None, None) self.submitted = False cancel = self.form.get_button('cancel', "Cancel", self.remove) submit = self.form.get_button('submit', "Submit", self.submit) self.form.set_action_button('cancel', cancel) self.form.set_action_button('submit', submit) self.form.add_element('buttons', DoubleSection(submit, cancel)) self.form.start()
def get_all_inputs(datafile_select): parameters = {} parameters['population_method'] = Select(True, { 'auto': "Auto", 'manual': "Manual" }, 0) parameters['bins_method'] = Select( True, { 'auto': "Auto", 'fd': "Freedman Diacosis", 'doane': "Doane", 'scott': "Scott", 'stone': "Stone", 'rice': "Rice", 'sturges': "Sturges", 'sqrt': "Square root", 'manual': "Manual" }, 0) parameters['neighbors_method'] = Select(True, { 'auto': "Auto", 'manual': "Manual" }, 0) parameters['bins'] = Input(False, nint, 9) parameters['bin_population'] = Input(False, nfloat, 9) parameters['neighbors'] = Input(False, nfloat, 9) parameters['kernel'] = Select(True, {'gaussian': "Gaussian"}) parameters['bandwidth'] = Input(True, pfloat, "1.0") def on_bins_method_change(old_value, new_value, is_valid): if new_value == "manual": parameters['bins'].reset() else: parameters['bins'].disable() parameters['bins'].set_value("Disabled") def on_population_method_change(old_value, new_value, is_valid): if new_value == "manual": parameters['bin_population'].reset() else: parameters['bin_population'].disable() parameters['bin_population'].set_value("Disabled") def on_neighbors_method_change(old_value, new_value, is_valid): if new_value == "manual": parameters['neighbors'].reset() else: parameters['neighbors'].disable() parameters['neighbors'].set_value("Disabled") parameters['bins_method'].on_change(on_bins_method_change) parameters['population_method'].on_change(on_population_method_change) parameters['neighbors_method'].on_change(on_neighbors_method_change) return parameters
def __init__(self, window_provider): title = "Set RNG seed" super().__init__(title, window_provider) def window_provider(title): return self.window.internal_renderer self.form = FormController(window_provider) seed = self.s.get('seed') if seed is None: seed = '' self.form.add_element('seed', Section("Seed", Input(True, nonenint, seed))) self.submitted = False cancel = self.form.get_button('cancel', "Cancel", self.remove) submit = self.form.get_button('submit', "Submit", self.submit) self.form.set_action_button('cancel', cancel) self.form.set_action_button('submit', submit) self.form.add_element('buttons', DoubleSection(submit, cancel)) self.form.start()
def __init__(self, name, input_from, input_to): self.input_from = input_from self.input_to = input_to self.input_to.value = self.input_to.value self.input_step = Input(True, pfloat, 1) section_from = Section("From", input_from) section_to = Section("To", input_to) inputs_section = DoubleSection(section_from, section_to) step_section = Section("Steps", self.input_step) step_section = DoubleSection(Section(name, None), step_section) self.sections = {0: step_section, 1: inputs_section} self.cursor = VListCursor(self.sections) self.init_form_object(1)
def __init__(self, window_provider): title = "Run repeated experiment" super().__init__(title, window_provider) def window_provider(title): return self.window.internal_renderer self.form = FormController(window_provider) iterations_input = Section("Iterations", Input(True, pint, 100)) self.form.add_element('iterations', iterations_input) self.form.add_element('break1', SectionBreak()) def dist_options_provider(): from datafiles.distribution import all_distributions distributions = {} for d in all_distributions: distributions[d] = d return distributions dist_select = Select(True, dist_options_provider) dist_section = Section("Distribution", dist_select) self.form.add_element('dist', dist_section) self.form.add_element('samples', Section("Samples", Input(True, int, 1500))) self.form.add_element('break1', SectionBreak()) all_params = {} for dist, params in param_map.items(): for p in params: if p not in all_params.keys(): inp = Input(True, myfloat, 1) self.form.add_element(p, Section(p, inp)) all_params[p] = inp self.form.add_element('break2', SectionBreak()) self.form.add_element('loc', Section("Mean", Input(True, myfloat, 0))) self.form.add_element( 'scale', Section("Standard deviation", Input(True, nfloat, 2))) def on_dist_change(old_value, new_value, is_valid=True): for inp in all_params.values(): inp.disappear() if new_value is not None: for p in param_map[new_value]: all_params[p].changed() all_params[p].show() dist_select.on_change(on_dist_change) on_dist_change(None, None) def get_estimator_options(): keys = Estimators.get_all() options = {} for key in keys: options[key] = key.get_name() options['all'] = "All" return options estimator_select = Section("Estimator", Select(True, get_estimator_options)) self.form.add_element('estimator', estimator_select) self.form.add_element('break3', SectionBreak()) min_parameters = Estimators.get_all_inputs(None) max_parameters = Estimators.get_all_inputs(None) names = Estimators.get_all_input_names() simple_parameters = ['bins_method', 'kernel'] range_parameters = ['neighbors', 'bins', 'bin_population', 'bandwidth'] for p in simple_parameters: self.form.add_element(p, Section(names[p], min_parameters[p])) for p in range_parameters: self.form.add_element( p, RangeSection(names[p], min_parameters[p], max_parameters[p])) def on_estimator_change(old_value, new_value, is_valid=True): for inp in min_parameters.values(): inp.disappear() for inp in max_parameters.values(): inp.disappear() if new_value is not None and type(new_value) != str: for p in new_value.get_parameters(): min_parameters[p].show() min_parameters[p].reset() min_parameters[p].changed() max_parameters[p].show() max_parameters[p].reset() cur_value = max_parameters[p].get_value() if type(cur_value) != str and cur_value is not None: max_parameters[p].set_value(cur_value * 100) max_parameters[p].changed() estimator_select.inp.on_change(on_estimator_change) on_estimator_change(None, None) cancel = self.form.get_button('cancel', "Cancel", self.remove) submit = self.form.get_button('submit', "Submit", self.submit) self.form.set_action_button('cancel', cancel) self.form.set_action_button('submit', submit) self.form.add_element('buttons', DoubleSection(submit, cancel)) self.form.start()
class RangeSection(FormObject): def __init__(self, name, input_from, input_to): self.input_from = input_from self.input_to = input_to self.input_to.value = self.input_to.value self.input_step = Input(True, pfloat, 1) section_from = Section("From", input_from) section_to = Section("To", input_to) inputs_section = DoubleSection(section_from, section_to) step_section = Section("Steps", self.input_step) step_section = DoubleSection(Section(name, None), step_section) self.sections = {0: step_section, 1: inputs_section} self.cursor = VListCursor(self.sections) self.init_form_object(1) def set_value(self, value): pass def unfocus(self): super().unfocus() self.sections[0].unfocus() self.sections[1].unfocus() def visible(self): return self.input_from.visible() and self.input_to.visible( ) and self.input_step.visible() def focus(self): super().focus() def enable(self): super().enable() self.sections[0].enable() self.sections[1].enable() def disable(self): super().disable() self.sections[0].disable() self.sections[1].disable() def show(self): super().show() self.sections[0].show() self.sections[1].show() def hide(self): super().hide() self.sections[0].hide() self.sections[1].hide() def disappear(self): super().disappear() self.sections[0].disappear() self.sections[1].disappear() def is_valid(self): return self.sections[0].is_valid() and self.sections[1].is_valid() def on_change(self, on_change_func): pass def get_value(self): return { 'step': self.input_step.get_value(), 'from': self.input_from.get_value(), 'to': self.input_to.get_value() } def input(self, key): return self.cursor.input(key) def render(self, renderer): def renderer_provider(index, pos_y, cursor, item): if pos_y is None: pos_y = 0 return pos_y, Renderer(1, 0, pos_y, 0, renderer) self.cursor.render(renderer_provider) return 2