Skip to content

Commit

Permalink
Merge pull request #74 from geoscixyz/Patch_DCapps
Browse files Browse the repository at this point in the history
Patch DCapps to work with updated version of ipywidgets
  • Loading branch information
lheagy committed May 30, 2017
2 parents 5498195 + 034120a commit b4c0b25
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 12 deletions.
22 changes: 14 additions & 8 deletions em_examples/Base.py
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
2 changes: 1 addition & 1 deletion em_examples/DCWidgetPlate2_5D.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ def PLOT(survey,A,B,M,N,dx,dz,xc,zc,rotAng,rhohalf,rhoplate,Field,Type,Scale):
ax[1].set_xlim([-40.,40.])
ax[1].set_ylim([-40.,5.])
# ax[1].set_aspect('equal')
# plt.show()
plt.show()
# return fig, ax


Expand Down
2 changes: 1 addition & 1 deletion em_examples/DCWidgetPlate_2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ def plot_Surface_Potentials(survey,A,B,M,N,dx,dz,xc,zc,rotAng,rhohalf,rhoplate,F
ax[1].set_xlim([-40.,40.])
ax[1].set_ylim([-40.,5.])
ax[1].set_aspect('equal')
# plt.show()
plt.show()
# return fig, ax


Expand Down
4 changes: 3 additions & 1 deletion em_examples/DCWidgetResLayer2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from scipy.constants import epsilon_0
import copy

from ipywidgets import interact, IntSlider, FloatSlider, FloatText, ToggleButtons
from ipywidgets import interact, IntSlider, FloatSlider, FloatText, ToggleButtons

from .Base import widgetify

Expand Down Expand Up @@ -692,6 +692,8 @@ def plot_Surface_Potentials(survey,A,B,M,N,zcLayer,dzLayer,xc,zc,r,rhoHalf,rhoLa
ax[1].set_ylim([-40.,5.])
ax[1].set_aspect('equal')

plt.show()


def ResLayer_app():
app = widgetify(plot_Surface_Potentials,
Expand Down
2 changes: 2 additions & 0 deletions em_examples/DCWidgetResLayer2_5D.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ def PLOT(survey,A,B,M,N,zcLayer,dzLayer,xc,zc,r,rhohalf,rholayer,rhoTarget,Field
ax[1].set_ylim([ymin,ymax])
ax[1].set_aspect('equal')

plt.show()


def ResLayer_app():
app = widgetify(PLOT,
Expand Down
2 changes: 1 addition & 1 deletion em_examples/DC_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def plot_Surface_Potentials(survey,A,B,M,N,r,xc,yc,rhohalf,rhocyl,Field,Type,Sca
ax[1].set_ylim([ymin,ymax])
ax[1].set_aspect('equal')

# plt.show()
plt.show()
# return fig, ax

def cylinder_app():
Expand Down

0 comments on commit b4c0b25

Please sign in to comment.