def add_figure_widget(self, image_data, title='', caption = '', pvals=None, colors=None): children = [i for i in self.unsaved.children] if len(title) > 0: title = title + '.' if len(caption) > 0: caption = ' ' + caption html_str = '<b>'+title+'</b>' + caption html_widget = HTML(value=html_str) save_button = Button(description='Save Figure') save_button.image_data = image_data save_button.title = title save_button.caption = caption save_button.on_click(self.save_unsaved_figure) save_button.pvals = pvals save_button.colors = colors close_button = Button(description='Remove Figure') close_button.on_click(self.remove_unsaved_figure) restore_pvals = Button(description='Restore Parameter Values') restore_pvals.pvals = pvals if pvals is None: restore_pvals.visible = False if old_ipython is True: image_widget = Image() image_widget.value = image_data tab_widget = VBox(children=[image_widget, html_widget]) if colors is not None: html_widgets = self.colorbar_tabs(colors) tab_widget.description='Figure' tab_widget = Tab(children=[tab_widget]+html_widgets) else: image_widget = self._image_widget_new(image_data, colors=colors) tab_widget = VBox(children=[image_widget, html_widget]) toggle = Button(description='Hide') restore_pvals.on_click(self.restore_figure_pvals) if old_ipython is True: wi = Popup(children=[close_button, save_button, tab_widget, restore_pvals]) else: contents = VBox(children=[close_button, save_button, tab_widget, restore_pvals]) contents.width = '100%' wi = Popup(children=[contents]) wi.border = '1px solid black' save_button.wi = wi close_button.wi = wi children.append(wi) self.unsaved.children = children if colors is not None: if old_ipython is True: tab_widget.set_title(0, 'Figure') tab_widget.set_title(1, 'Colorbar')
def create_plot_widget(self): controller = self.controller options = self.controller.options if controller.ds is None: return xaxis = controller.defaults('xaxis') if xaxis is None: xaxis = controller.ds.independent_variables[0] yaxis = controller.defaults('yaxis') if yaxis is None: yaxis = controller.ds.independent_variables[1] center = controller.defaults('center_axes') range_x = controller.defaults('range_x') range_y = controller.defaults('range_y') xlabel = Dropdown( description='* X-Axis', values=controller.ds.independent_variables, options=controller.ds.independent_variables, value=xaxis) ylabel = Dropdown( description='* Y-Axis', values=['None'] + controller.ds.independent_variables, options=['None'] + controller.ds.independent_variables, value=yaxis) xmin = FloatText(description='* X-Min', value=range_x[0]) xmax = FloatText(description='* X-Max', value=range_x[1]) ymin = FloatText(description='* Y-Min', value=range_y[0]) ymax = FloatText(description='* Y-Max', value=range_y[1]) center_axes = Checkbox(description='Center Axes', value=center) boundaries = Checkbox(description='Draw Boundaries', value=False) plot_type = Dropdown(description='* Plot Type', values=self.widget_types, options=self.widget_types, value='Design Space (interactive)') title_widget = Text(description='Title') caption_widget = Textarea(description='Caption') included = controller.defaults('included_cases') if included is None: included = [] if isinstance(included, list) is False: included = [included] included_widget = Textarea(description='Only Cases', value=', '.join(included)) wi = VBox(children=[xlabel, ylabel, plot_type, xmin, xmax, ymin, ymax, center_axes, boundaries, title_widget, caption_widget, included_widget]) for i in [xlabel, ylabel, plot_type]: i.on_trait_change(self.update_field, 'value') plot_type.widget_container = wi button = Button(value=False, description='Add Plot') button.on_click(self.make_plot) button.xlabel = xlabel button.ylabel = ylabel button.xmin = xmin button.xmax = xmax button.ymin = ymin button.ymax = ymax button.center_axes = center_axes button.boundaries = boundaries button.plot_type = plot_type button.title = title_widget button.caption = caption_widget button.included = included_widget button.wi = wi self.title = title_widget self.caption = caption_widget self.boundaries = boundaries self.plot_type = plot_type self.xlabel = xlabel self.ylabel = ylabel self.ymin = ymin self.ymax = ymax self.xmin = xmin self.xmax = xmax add_plot = VBox(description='Add Plot', children=[wi, self.plot_data, button]) self.update_plot_widget('value', 'Design Space (Interactive)') return ('Create Plot', add_plot)