Skip to content

Commit

Permalink
Various minor fixes (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Mar 29, 2019
1 parent 913eebf commit 1486a41
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
6 changes: 5 additions & 1 deletion panel/io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ def sig_exit(*args, **kwargs):

def do_stop(*args, **kwargs):
server.io_loop.stop()
signal.signal(signal.SIGINT, sig_exit)

try:
signal.signal(signal.SIGINT, sig_exit)
except ValueError:
pass # Can't use signal on a thread

if start:
server.start()
Expand Down
2 changes: 1 addition & 1 deletion panel/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def _process_links(cls, root_view, root_model):
for link, src, tgt in found:
cb = cls._callbacks[type(link)]
if src is None or (getattr(link, '_requires_target', False)
and tgt is None):
and tgt is None):
continue
callbacks.append(cb(root_model, link, src, tgt))
return callbacks
Expand Down
1 change: 0 additions & 1 deletion panel/models/vtk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export class VTKPlotView extends HTMLBoxView {
delete state.vtkCamera;
delete state.viewPlaneNormal;
this.model.camera = state;
this.model.properties.camera.change.emit();
this._setting = false;
}
}
Expand Down
24 changes: 18 additions & 6 deletions panel/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ def hashable(x):

def isIn(obj, objs):
"""
Checks if the object is in the list of objects, unlike the ``in``
Python operator this will check only for identity not equality.
Checks if the object is in the list of objects safely.
"""
return any(o is obj for o in objs)
for o in objs:
if o is obj:
return True
try:
if o == obj:
return True
except:
pass
return False


def indexOf(obj, objs):
Expand All @@ -42,9 +49,14 @@ def indexOf(obj, objs):
list.index method this function only checks for identity not
equality.
"""
indexes = [i for i, o in enumerate(objs) if o is obj]
if indexes:
return indexes[0]
for i, o in enumerate(objs):
if o is obj:
return i
try:
if o == obj:
return i
except:
pass
raise ValueError('%s not in list' % obj)


Expand Down
2 changes: 1 addition & 1 deletion panel/viewable.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def _repr_mimebundle_(self, include=None, exclude=None):
model = self.get_root(doc, comm)
if config.embed:
embed_state(self, model, doc,
json=config.json,
json=config.embed_json,
save_path=config.embed_save_path,
load_path=config.embed_load_path)
return render_model(model)
Expand Down
24 changes: 24 additions & 0 deletions panel/widgets/tests/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ def test_select_list_constructor():
assert select.options == ['A', 1]


def test_select_float_option_with_equality():
opts = {'A': 3.14, '1': 2.0}
select = Select(options=opts, value=3.14, name='Select')
assert select.value == 3.14

select.value = 2
assert select.value == 2.0

select.value = 3.14
assert select.value == 3.14


def test_select_text_option_with_equality():
opts = {'A': 'ABC', '1': 'DEF'}
select = Select(options=opts, value='DEF', name='Select')
assert select.value == 'DEF'

select.value = 'ABC'
assert select.value == 'ABC'

select.value = 'DEF'
assert select.value == 'DEF'


def test_select(document, comm):
opts = {'A': 'a', '1': 1}
select = Select(options=opts, value=opts['1'], name='Select')
Expand Down

0 comments on commit 1486a41

Please sign in to comment.