Skip to content
This repository has been archived by the owner on Nov 29, 2019. It is now read-only.

Defined label_formatter parameter on Widgets #48

Merged
merged 7 commits into from
May 16, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dodo.py
Original file line number Diff line number Diff line change
@@ -21,8 +21,8 @@ def task_install_doc_dependencies():
# would not need to exist if nbsite had conda package
return {
'actions': [
'conda install -y -q -c conda-forge notebook ipython sphinx beautifulsoup4 graphviz selenium phantomjs',
'pip install nbsite sphinx_ioam_theme'],
'conda install -y -q -c conda-forge notebook ipython sphinx=1.6 beautifulsoup4 graphviz selenium phantomjs',
'pip install https://github.com/pyviz/nbsite/archive/master.zip sphinx_ioam_theme'],
'task_dep': ['install_test_dependencies']
}

2 changes: 1 addition & 1 deletion examples/user_guide/View_Parameters.ipynb
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@
" \n",
" def view(self, *args, **kwargs):\n",
" return self.element(self.amplitude*np.sin(np.linspace(0, np.pi*self.frequency)),\n",
" vdims=[hv.Dimension('y', range=(-5, 5))])(style=dict(color=self.color))\n",
" vdims=[hv.Dimension('y', range=(-5, 5))]).opts(style=dict(color=self.color))\n",
" \n",
" def event(self, **kwargs):\n",
" if not self.output or any(k in kwargs for k in ['color', 'element']):\n",
35 changes: 34 additions & 1 deletion parambokeh/__init__.py
Original file line number Diff line number Diff line change
@@ -29,6 +29,31 @@
__version__ = '0.2.1-unknown'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why we need this conditional anymore. @ceball ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure how this is in a pr about label format (I'm on my phone so can't easily see whole context), but isn't this just a case of parambokeh not having been updated to use autover yet?



class default_label_formatter(param.ParameterizedFunction):
"Default formatter to turn parameter names into appropriate widget labels."

capitalize = param.Boolean(default=True, doc="""
Whether or not the label should be capitalized.""")

replace_underscores = param.Boolean(default=True, doc="""
Whether or not underscores should be replaced with spaces.""")

overrides = param.Dict(default={}, doc="""
Allows custom labels to be specified for specific parameter
names using a dictionary where key is the parameter name and the
value is the desired label.""")

def __call__(self, pname):

if pname in self.overrides:
return self.overrides[pname]
if self.replace_underscores:
pname = pname.replace('_',' ')
if self.capitalize:
pname = pname.capitalize()
return pname


class Widgets(param.ParameterizedFunction):

callback = param.Callable(default=None, doc="""
@@ -93,6 +118,9 @@ class Widgets(param.ParameterizedFunction):
width = param.Integer(default=300, bounds=(0, None), doc="""
Width of widgetbox the parameter widgets are displayed in.""")

label_formatter = param.Callable(default=default_label_formatter, allow_None=True,
doc="Callable used to format the parameter names into widget labels.")

# Timeout if a notebook comm message is swallowed
timeout = 20000

@@ -265,7 +293,12 @@ def _make_widget(self, p_name):

kw = dict(value=value)

kw['title'] = p_name
if self.p.label_formatter is not None:
kw['title'] = self.p.label_formatter(p_name)
else:
kw['title'] = p_name

kw['name'] = p_name

if hasattr(p_obj, 'get_range') and not isinstance(kw['value'], dict):
options = named_objs(p_obj.get_range().items())
4 changes: 2 additions & 2 deletions parambokeh/widgets.py
Original file line number Diff line number Diff line change
@@ -94,10 +94,10 @@ def RangeWidget(*args, **kw):
return RangeSlider(*args, **kw)

def PlotWidget(*args, **kw):
return column(name=kw['title'])
return column(name=kw['name'])

def HTMLWidget(*args, **kw):
return Div(name=kw['title'])
return Div(name=kw['name'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely sure this is the only two cases where this change is needed?



ptype2wtype = {