-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from geoscixyz/Patch_DCapps
Patch DCapps to work with updated version of ipywidgets
- Loading branch information
Showing
6 changed files
with
22 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,43 @@ | ||
from ipywidgets import ( | ||
interactive, VBox, HBox, Box, Widget | ||
interactive, VBox, HBox, Box, Widget, interact, interact_manual, IntSlider, FloatSlider, FloatText, ToggleButtons, fixed, Checkbox | ||
) | ||
from IPython.display import display | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
class MyApp(Box): | ||
def __init__(self, widgets, kwargs): | ||
self._kwargs = kwargs | ||
|
||
self._widgets = widgets | ||
super(MyApp, self).__init__(widgets) | ||
self.layout.display = 'flex' | ||
self.layout.flex_flow = 'column' | ||
self.layout.align_items = 'stretch' | ||
|
||
@property | ||
def kwargs(self): | ||
instanceCheck = lambda x: isinstance(x, ToggleButtons) or isinstance(x, FloatSlider) or isinstance(x, IntSlider) or isinstance(x, FloatText) or isinstance(x, fixed) or isinstance(x, Checkbox) | ||
return dict( | ||
[(key, val.value) for key, val in self._kwargs.iteritems() | ||
if isinstance(val, Widget)] | ||
if instanceCheck(val)] | ||
) | ||
|
||
def widgetify(fun, layout=None, manual=False, **kwargs): | ||
|
||
|
||
def widgetify(fun, layout=None, **kwargs): | ||
f = fun | ||
app = interactive(f, **kwargs) | ||
|
||
if manual: | ||
app = interact_manual(f, **kwargs) | ||
app = app.widget | ||
else: | ||
app = interactive(f, **kwargs) | ||
|
||
# if layout is None: | ||
# TODO: add support for changing layouts | ||
w = MyApp(app.children, kwargs) | ||
|
||
f.widget = w | ||
# defaults = #dict([(key, val.value) for key, val in kwargs.iteritems() if isinstance(val, Widget)]) | ||
app.on_displayed(f(**(w.kwargs))) | ||
app.update() | ||
#app.on_displayed(f(**(w.kwargs))) | ||
|
||
return w |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters