def new_display(self, attached=True, wid=None, height_px=600, width_px=580): if wid is not None: self.wid = str(wid) all_d = set() for r in self.get_instances(): for j in r.displays.keys(): all_d.add(j) if self.wid in all_d: print('{} exists. Enter a different id or remove current display'. format(self.wid)) return html_code = "<iframe src='{}/{}' width={} height={}></iframe>".format( self.frame_url, self.wid, width_px, height_px) self.displays[self.wid] = { 'attached': attached, 'obj': ipw.widgets.HTML(value=html_code) } if attached: display(self.displays[self.wid]['obj']) else: self.sc = Sidecar(title='{}'.format(self.wid), layout=ipw.Layout(width='580px', height='600px')) self.displays[self.wid]['obj'].on_displayed(self.handler_displayed) with self.sc: display(self.displays[self.wid]['obj']) return
def set_sidecar(title): global SIDECAR try: from sidecar import Sidecar SIDECAR = Sidecar(title=title) except: print("Warning: module sidecar not installed")
def __init__(self, width=400, height=400): self.multicanvas = MultiCanvas(4, width=width, height=height) self.turtleCanvas = self.multicanvas[3] self.sc = Sidecar(title="Turtle Screen") with self.sc: display(self.multicanvas) self.turtles = []
def display_map(self, map_output, hemisphere=None, extra_layers=True): """ Will render the UI using ipyleaflet and jupyter widgets """ self.map_output = map_output self.dc = DrawControl( circlemarker={}, polyline={}, rectangle={ "shapeOptions": { "fillColor": "#cc00cc", "color": "#cc00cc", "fillOpacity": 0.5 } }) if hemisphere is None: projection = widget_projections[self.projection.value] else: projection = widget_projections[hemisphere] # TODO: maybe there is a way to create the map in the constructor # and just update its properties to see if this is faster. self.map = Map(center=projection['center'], zoom=projection['zoom'], max_zoom=projection['max_zoom'], basemap=projection['base_map'], crs=projection['projection']) self.map.add_control(self.dc) self.map.add_control(self.layers_control) self.map.add_control(self.search_control) for ib_layer in flight_layers[self.projection.value]: self.map.add_layer(ib_layer(self.start_date, self.end_date)) if extra_layers: for layer in custom_layers[self.projection.value]: self.map.add_layer(layer) # if self.dc.last_draw['geometry'] is not None: # self.map.add_layer(GeoJSON(name='selected geometry', data=self.dc.last_draw)) self.map.layout.height = '560px' self.out.clear_output() if map_output == 'vertical': if hasattr(self, 'sc'): self.sc.clear_output() else: self.sc = Sidecar(title='Map Widget') with self.sc: display(self.out) with self.out: display(self.map) for component in self.controls: display(component) else: with self.out: display(self.map) display(self.out)
def display_controls(self, where): if where == 'vertical': if not hasattr(self, 'sc'): self.sc = Sidecar(title='Map Widget') with self.sc: for component in self.controls: display(component) else: for component in self.controls: display(component)
def show(self, viewer, title): if title not in self.sidecars: self.sidecars[title] = Sidecar(title=title, anchor=self.anchor) else: # TODO: find a better way to do this self.sidecars[title].close() self.sidecars[title].open() with self.sidecars[title]: viewer.show()
def display_credentials(self, where='horizontal'): """ renders the input controls to get the user's credentials note that theey are not enccrypted here. """ if where == 'vertical': if not hasattr(self, 'sc'): self.sc = Sidecar(title='Map Widget') with self.sc: display(self.username, self.password, self.email, self.credentials_button) else: display(self.username, self.password, self.email, self.credentials_button)
def __init__(self): self._sc = Sidecar(title='Variables') get_ipython().user_ns_hidden['widgets'] = widgets get_ipython().user_ns_hidden['NamespaceMagics'] = NamespaceMagics self.closed = False self.namespace = NamespaceMagics() self.namespace.shell = get_ipython().kernel.shell self._box = widgets.Box() self._box.layout.overflow_y = 'scroll' self._table = widgets.HTML(value='Not hooked') self._box.children = [self._table] self._ipython = get_ipython() self._ipython.events.register('post_run_cell', self._fill)
def set_sidecar(title, init=False): global SIDECAR try: from sidecar import Sidecar _has_sidecar = True except: print("Warning: module sidecar not installed") _has_sidecar = False if _has_sidecar: close_sidecar() SIDECAR = Sidecar(title=title) set_defaults(display="sidecar") if init: d = get_or_create_display(init=True)
def show_in_sidecar(self, **kwargs): """ Display the Jdaviz application in a "sidecar", which by default is a tab on the right side of the JupyterLab interface. Additional keywords not listed here are passed into the ``sidecar.Sidecar`` constructor. See `jupyterlab-sidecar <https://github.com/jupyter-widgets/jupyterlab-sidecar>`_ for the most up-to-date options. Parameters ---------- title : str, optional The title of the sidecar tab. Defaults to the name of the application; e.g., "specviz". anchor : str Where the tab should appear, by default on the right. Options are: {sidecar_anchor_values}. Returns ------- sidecar The ``sidecar.Sidecar`` object used to create the tab. Notes ----- If this method is called in the "classic" Jupyter notebook, the app will appear inline, as only lab has a mechanism to have multiple tabs. See Also -------- show_in_new_tab show_inline """ if 'title' not in kwargs: kwargs['title'] = self.app.config scar = Sidecar(**kwargs) with scar: display(self.app) return scar
def create(self): """Create the sidecar view""" self.sc = Sidecar( title="Databases-%s" % os.environ["DBJL_CLUSTER"].split("-")[-1], layout=Layout(width="300px"), ) self.refresh = Button(description="refresh") self.refresh.on_click(self.on_refresh) self.output = Output( layout=Layout( height="600px", width="320px", overflow_x="scroll", overflow_y="scroll" ) ) self.output.add_class("db-detail") self.selects = [] self.accordion = Accordion(children=[]) with self.sc: display(VBox([self.refresh, self.accordion, self.output])) self.update() self.set_css()
def create(self): """Create the sidecar view""" self.sc = Sidecar(title="DBFS-%s" % os.environ["DBJL_CLUSTER"].split("-")[-1]) self.path = "/" self.flist = Select(options=[], rows=40, disabled=False) self.flist.observe(self.on_click, names="value") self.refresh = Button(description="refresh") self.refresh.on_click(self.on_refresh) self.output = Output() self.up = Button(description="up") self.up.on_click(self.on_up) with self.sc: display( VBox([ HBox([self.up, self.refresh]), self.flist, self.output ])) self.update()
def sidebar(stuff, title='Sidebar'): sc = Sidecar(title=title) with sc: display(stuff)
#%% # Example import requests import json from sidecar import Sidecar url = 'http://127.0.0.1:8080' sidecar = Sidecar(url) artifacts = sidecar.artifacts() print('\nBlock Number: {}'.format(hex(int(artifacts['at']['height'])))) print('\nBlock Hash: {}'.format(artifacts['at']['hash'])) print('\nSpec Version: {}'.format(artifacts['specVersion'])) print('\nTx Version: {}'.format(artifacts['txVersion'])) print('\nGenesis Hash: {}'.format(artifacts['genesisHash']))
def lab_display(view): from sidecar import Sidecar with Sidecar(title='nglview'): display(view)