Skip to content

Instantly share code, notes, and snippets.

@jasongrout
Last active October 26, 2017 21:16
Show Gist options
  • Save jasongrout/39bcea2de5325bba326425a8ec4fd746 to your computer and use it in GitHub Desktop.
Save jasongrout/39bcea2de5325bba326425a8ec4fd746 to your computer and use it in GitHub Desktop.
import os
from collections import OrderedDict
from IPython.display import display
import ipywidgets as widgets
from IPython.display import clear_output
import collections
class DictTable(collections.OrderedDict):
def _repr_html_(self):
html = ["<table width=100%>"]
for key, value in self.items():
html.append("<tr>")
html.append("<td>{0}</td>".format(key))
html.append("<td>{0}</td>".format(value))
html.append("</tr>")
html.append("</table>")
return ''.join(html)
class general(object):
def listloc(self):
return DictTable([('WGS84-UTM19N', ['PERMANENT', 'UTM_user1', 'UTM_user2']),
('lonlat', ['PERMANENT', 'lonlat_user1', 'lonlat_user2']),
('nc_ll', ['PERMANENT'])
])
def environment_placeholder(self):
return DictTable([('DEBUG', '0'),
('GISBASE', '/usr/lib/grass72'),
('GISDBASE', '/home/epinux/work/data/grassdata'),
('GRASS_VERBOSE', '-1'),
('GUI', 'text'),
('LOCATION_NAME', 'WGS84-UTM19N'),
('MAPSET', 'PERMANENT')])
def wizard2(self):
self.out = widgets.Output()
self.locations = self.listloc()
self.location_options = sorted(list(self.locations.keys()))
self.locationlist = widgets.Dropdown(
options=list(self.locations.keys()),
value=list(self.locations.keys())[-1],
description='Location:',
)
self.maplist = widgets.Dropdown(
options=self.locations[self.locationlist.value],
value=list(self.locations[self.locationlist.value])[-1],
description='Mapset:',
)
self.setgisdb = widgets.Button(
description='Select',
disabled=False,
button_style='', # 'success', 'info', 'warning', 'danger' or ''
tooltip='Set GRASS LOCATION & MAPSET',
)
self.locationlist.observe(self.on_locations_change2, names='value')
self.setgisdb.on_click(self.on_button_clicked2)
display(widgets.HBox([self.locationlist, self.maplist]), widgets.VBox([self.setgisdb, self.out]))
def on_locations_change2(self, locationame):
self.maplist.options=self.locations[self.locationlist.value]
with self.out:
clear_output()
display(self.listloc())
def on_button_clicked2(self, b):
with self.out:
clear_output()
display(self.environment_placeholder())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment