def view(self, view_name, title=None, width=None, height=None, scrollable=True): """ Adds a viewable panel. :param view: The panel to show in this golden layout sub section. :param title: The text to show at the top of the panel. :param width: Initial width. :param height: Initial height. """ # pn.config.js_files.update(fig_panel.js_files) # We need to register every panel with a unique name such that after # composing the jinja2 template, we can add them (see compose function). # It seems that these unique names cannot start with a number or they cannot be referenced directly # Therefore, currently tmpl.main.append cannot be used as this generates fig_panel = self.main_controller.views[view_name] panel_ID = "ID" + str(id(fig_panel)) title = default_label_formatter(title or getattr(fig_panel, "name", None)) fig_panel.update() # intialize item = pn.Row(fig_panel.panel, sizing_mode="stretch_both") # Place figure in layout self.panels[panel_ID] = item title_str = "title: '%s'," % str( title) if title is not None else "title: ''," width_str = "width: %s," % str(width) if width is not None else "" height_str = "height: %s," % str(height) if height is not None else "" scroll_str = "css_classes: ['lm_content_noscroll']" if not scrollable else "" # scroll_str = "css_classes: ['overflow-y: hidden !important']" # this doesnt work # scroll_str = "overflow: 'hidden'," #if not scrollable else "" settings = title_str + height_str + width_str + scroll_str return self.VIEW % (panel_ID, settings)
def redraw(self): # create new widgets if self.n_levels <= 0: n_levels = len(self._names) + self.n_levels else: n_levels = self.n_levels self.widgets = { name: pn.widgets.Select(name=default_label_formatter(name)) for name in self._names[:n_levels] } # todo perhaps do self.param.add_parameter? self.selectors = list(self.widgets.values()) for selector in self.selectors: selector.param.watch(self._selector_changed, ["value"], onlychanged=True) options = list(self.index.get_level_values(0).unique()) if self.empty_select: # todo use Nonetype? -> allow_none kwarg for Select? options = ["None"] + options self.selectors[0].options = options self.selectors[0].value = options[0] self.redrawn = True
def test_default_label_formatter(self): assert default_label_formatter('a_b_C') == 'A b C'
def __init__(self, **params): super().__init__(**params) name = default_label_formatter(self.field) self.widget = self._widget.from_param(self.param.value, name=name) self.update() # populate options