def linked_image(obj, check=True): if check and maintype(obj) != 'image': raise ValueError('type mismatch: {0} and image'.format(maintype(obj))) return HTML.a( HTML.img(src=bitstream_url(obj, 'web'), class_='image'), href=bitstream_url(obj), title="View image ({0})".format(format_size(obj.jsondata.get('size', 0))))
def cc_link(req, license_url, button='regular'): if license_url == 'https://en.wikipedia.org/wiki/Public_domain': license_url = 'https://creativecommons.org/publicdomain/zero/1.0/' # pragma: no cover license_url = URL(license_url) if license_url.host() != 'creativecommons.org': return comps = license_url.path().split('/') if len(comps) < 3: return # pragma: no cover known = { 'zero': 'Public Domain', 'by': 'Creative Commons Attribution License', 'by-nc': 'Creative Commons Attribution-NonCommercial License', 'by-nc-nd': 'Creative Commons Attribution-NonCommercial-NoDerivatives License', 'by-nc-sa': 'Creative Commons Attribution-NonCommercial-ShareAlike License', 'by-nd': 'Creative Commons Attribution-NoDerivatives License', 'by-sa': 'Creative Commons Attribution-ShareAlike License'} if comps[2] not in known: return icon = 'cc-' + comps[2] + ('-small' if button == 'small' else '') + '.png' img_attrs = dict( alt=known[comps[2]], src=req.static_url('clld:web/static/images/' + icon)) height, width = (15, 80) if button == 'small' else (30, 86) img_attrs.update(height=height, width=width) return HTML.a(HTML.img(**img_attrs), href=license_url, rel='license')
def cc_link(req, license_url, button="regular"): if license_url == "http://en.wikipedia.org/wiki/Public_domain": license_url = "http://creativecommons.org/publicdomain/zero/1.0/" license_url = URL(license_url) if license_url.host() != "creativecommons.org": return comps = license_url.path().split("/") if len(comps) < 3: return # pragma: no cover known = { "zero": "Public Domain", "by": "Creative Commons Attribution License", "by-nc": "Creative Commons Attribution-NonCommercial License", "by-nc-nd": "Creative Commons Attribution-NonCommercial-NoDerivatives License", "by-nc-sa": "Creative Commons Attribution-NonCommercial-ShareAlike License", "by-nd": "Creative Commons Attribution-NoDerivatives License", "by-sa": "Creative Commons Attribution-ShareAlike License", } if comps[2] not in known: return icon = "cc-" + comps[2] + ("-small" if button == "small" else "") + ".png" img_attrs = dict(alt=known[comps[2]], src=req.static_url("clld:web/static/images/" + icon)) height, width = (15, 80) if button == "small" else (30, 86) img_attrs.update(height=height, width=width) return HTML.a(HTML.img(**img_attrs), href=license_url, rel="license")
def get_legends(self): if len(self.layers) > 1: items = [] total = 0 repr_attrs = dict(class_='pull-right stay-open', style="padding-right: 10px;") for layer in self.layers: representation = '' if hasattr(layer, 'representation'): total += layer.representation representation = HTML.span(str(layer.representation), **repr_attrs) items.append([ HTML.label( HTML.input( class_="stay-open", type="checkbox", checked="checked", onclick=helpers.JS_CLLD.mapToggleLayer( self.eid, layer.id, helpers.JS("this"))), getattr(layer, 'marker', ''), layer.name, class_="checkbox inline stay-open", style="margin-left: 5px; margin-right: 5px;", ), representation, ]) if total: items.append(HTML.span(HTML.b(str(total)), **repr_attrs)) yield Legend( self, 'layers', items, label='Legend', stay_open=True, item_attrs=dict(style='clear: right')) items = [] for size in [15, 20, 30, 40]: attrs = dict(name="iconsize", value=str(size), type="radio") if size == self.options.get('icon_size', 30): attrs['checked'] = 'checked' items.append(HTML.label( HTML.input(onclick=helpers.JS_CLLD.mapResizeIcons(self.eid), **attrs), HTML.img( height=str(size), width=str(size), src=self.req.registry.getUtility(IIcon, 'cff6600').url(self.req)), class_="radio", style="margin-left: 5px; margin-right: 5px;")) yield Legend( self, 'iconsize', items, label='Icon size') item = lambda layer: HTML.a( layer.name, onclick='return %s;' % helpers.JS_CLLD.mapShowGeojson(self.eid, layer.id), href=layer.data if isinstance(layer.data, string_types) else '#') yield Legend( self, 'geojson', map(item, self.layers), label='GeoJSON', pull_right=True)
def format(self, item): if not item.gbif_url: return '' return HTML.a(HTML.img( width='20', src=self.dt.req.static_url('acc:static/gbif.png')), item.gbif_name, href=item.gbif_url)
def linked_image(obj, check=True): if check and maintype(obj) != 'image': raise ValueError('type mismatch: {0} and image'.format(maintype(obj))) return HTML.a( HTML.img(src=bitstream_url(obj, 'web'), class_='image'), href=bitstream_url(obj), title="View image ({0})".format(format_size(obj.jsondata.get('size', 0))))
def get_legends(self): if len(self.layers) > 1: items = [] total = 0 repr_attrs = dict(class_='pull-right stay-open', style="padding-right: 10px;") for layer in self.layers: representation = '' if hasattr(layer, 'representation'): total += layer.representation representation = HTML.span(str(layer.representation), **repr_attrs) items.append([ HTML.label( HTML.input( class_="stay-open", type="checkbox", checked="checked", onclick=helpers.JS_CLLD.mapToggleLayer( self.eid, layer.id, helpers.JS("this"))), getattr(layer, 'marker', ''), layer.name, class_="checkbox inline stay-open", style="margin-left: 5px; margin-right: 5px;", ), representation, ]) if total: items.append(HTML.span(HTML.b(str(total)), **repr_attrs)) yield Legend( self, 'layers', items, label='Legend', stay_open=True, item_attrs=dict(style='clear: right')) items = [] for size in [15, 20, 30, 40]: attrs = dict(name="iconsize", value=str(size), type="radio") if size == self.options.get('icon_size', 30): attrs['checked'] = 'checked' items.append(HTML.label( HTML.input(onclick=helpers.JS_CLLD.mapResizeIcons(self.eid), **attrs), HTML.img( height=str(size), width=str(size), src=self.req.registry.getUtility(IIcon, 'cff6600').url(self.req)), class_="radio", style="margin-left: 5px; margin-right: 5px;")) yield Legend( self, 'iconsize', items, label='Icon size') item = lambda layer: HTML.a( layer.name, onclick='return %s;' % helpers.JS_CLLD.mapShowGeojson(self.eid, layer.id), href=layer.data if isinstance(layer.data, basestring) else '#') yield Legend( self, 'geojson', map(item, self.layers), label='GeoJSON', pull_right=True)
def concepticon_link(request, concept): return HTML.a(HTML.img( src=request.static_url('lexibank:static/concepticon_logo.png'), height=20, width=30), title='corresponding concept set at Concepticon', href=concept.concepticon_url)
def cc_link(req, license_url, button='regular'): if license_url == 'https://en.wikipedia.org/wiki/Public_domain': license_url = 'https://creativecommons.org/publicdomain/zero/1.0/' license_url = URL(license_url) if license_url.host() != 'creativecommons.org': return comps = license_url.path().split('/') if len(comps) < 3: return # pragma: no cover known = { 'zero': 'Public Domain', 'by': 'Creative Commons Attribution License', 'by-nc': 'Creative Commons Attribution-NonCommercial License', 'by-nc-nd': 'Creative Commons Attribution-NonCommercial-NoDerivatives License', 'by-nc-sa': 'Creative Commons Attribution-NonCommercial-ShareAlike License', 'by-nd': 'Creative Commons Attribution-NoDerivatives License', 'by-sa': 'Creative Commons Attribution-ShareAlike License'} if comps[2] not in known: return icon = 'cc-' + comps[2] + ('-small' if button == 'small' else '') + '.png' img_attrs = dict( alt=known[comps[2]], src=req.static_url('clld:web/static/images/' + icon)) height, width = (15, 80) if button == 'small' else (30, 86) img_attrs.update(height=height, width=width) return HTML.a(HTML.img(**img_attrs), href=license_url, rel='license')
def layers(spec, size, zindex=0): # pragma: no cover import requests app, pid, url = spec def normalize(geojson): for f in geojson['features']: f['properties']['icon_size'] = size f['properties']['zindex'] = zindex if f['geometry']['coordinates'][0] > 180: f['geometry']['coordinates'][0] = f['geometry']['coordinates'][0] - 360 return geojson geojson = requests.get(url + '.geojson').json() id_ = '-'.join([app, pid]) if geojson['properties']['domain'] and not geojson['features']: for de in geojson['properties']['domain']: yield Layer( '-'.join([id_, de['id']]), '%s: %s - %s' % (app, geojson['properties']['name'], de['name']), normalize( requests.get(url + '.geojson?domainelement=' + de['id']).json()), size=size, link=url, marker=HTML.img(src=de['icon'], width=size, height=size)) else: yield Layer( id_, '%s: %s' % (app, geojson['properties']['name']), normalize(geojson), size=size, link=url, domain=geojson['properties']['domain'])
def make_item(label, icon): return HTML.span( HTML.img( width=16, height=16, src=self.req.static_url('clld:web/static/icons/%s.png' % icon)), HTML.span(label, style='padding-left:5px'), style='padding-left:5px')
def legend_items(req): for type, label in [('recipient', 'recipient language'), ('donor', 'donor languoid')]: yield HTML.label(HTML.img(src=icon_url(req, type), height='20', width='20'), literal(' ' + label), style='margin-left: 1em; margin-right: 1em;')
def concepticon_link(request, meaning): return HTML.a( HTML.img( src=request.static_url('dictionaria:static/concepticon_logo.png'), height=20, width=30), title='corresponding concept set at Concepticon', href=meaning.concepticon_url)
def get_layers(self): for layer in self.data['layers']: yield Layer( layer['properties']['number'], layer['properties']['name'], layer, marker=HTML.img(src=self.value_map[layer['properties']['number']]['icon'], height=20, width=20), representation=len(layer['features']))
def concepticon_link(request, meaning): return HTML.a( HTML.img( src=request.static_url('dictionaria:static/concepticon_logo.png'), height=20, width=30), title='corresponding concept set at Concepticon', href=meaning.concepticon_url)
def get_layers(self): for de in self.ctx.domain: if de.languages: yield Layer( de.id, de.name, GeoJsonCombinationDomainElement(de).render(de, self.req, dump=False), marker=HTML.img(src=de.icon.url(self.req), height='20', width='20')) if self.ctx.multiple: # yield another layer which can be used to mark languages with multiple # values, because this may not be visible when markers are stacked on top # of each other. icon_url = self.req.registry.getUtility(IIcon, 'tff0000').url(self.req) yield Layer( '__multiple__', 'Languages with multiple values', GeoJsonMultiple(None).render(self.ctx.multiple, self.req, dump=False), marker=HTML.img(src=icon_url, height='20', width='20'))
def get_layers(self): for spec in self.value_map.values(): geojson = GeoJsonApicsWals(spec).render(self.ctx, self.req, dump=False) yield Layer( spec['number'], spec['name'], geojson, marker=HTML.img(src=spec['icon'], height=20, width=20), representation=len(geojson['features']))
def format(self, item): item = self.get_obj(item) return HTML.span( HTML.img(width='20', src=svg.data_url(svg.icon(item.jsondata['icon']))), ' ', HTML.a(item.family_name, href="http://glottolog.org/resource/languoid/id/" + item.family_id), style="white-space: nowrap;")
def concepticon_link(request, concept): if not concept.concepticon_id: return '' return HTML.a( HTML.img( src=request.static_url('dogonlanguages:static/concepticon_logo.png'), height=20, width=30), title='corresponding concept set at Concepticon', href=concept.concepticon_url)
def format_frequency(req, obj, marker=None, height='20', width='20'): if not obj.frequency or obj.frequency == 100: return '' res = 'Frequency: %s%%' % round(obj.frequency, 1) marker = marker or req.registry.queryUtility(interfaces.IFrequencyMarker) if marker: url = marker(obj, req) if url: return HTML.img(src=url, height=height, width=width, alt=res, title=res) return res
def tsammalex_link(request, concept): if not concept.tsammalex_taxon: return '' return HTML.a( HTML.img( src=request.static_url('dogonlanguages:static/tsamma.png'), height=20, width=30), title='corresponding taxon at Tsammalex', href=concept.tsammalex_url)
def link(href, label, img, alt=None): return HTML.li( HTML.a( HTML.img(src=req.static_url('glottolog3:static/' + img), height="20", width="20", alt=alt or label), ' ', label, href=href, target="_blank", title=label, ))
def gbs_link(source, pages=None): """Format Google-Books information for source as HTML.""" if not source or not source.google_book_search_id or not source.jsondata.get("gbs"): return "" if source.jsondata["gbs"]["accessInfo"]["viewability"] in ["NO_PAGES"]: return "" pg = "PP1" if pages: match = re.search("(?P<startpage>[0-9]+)", pages) if match: pg = "PA" + match.group("startpage") return HTML.a( HTML.img(src="https://www.google.com/intl/en/googlebooks/images/" "gbs_preview_button1.gif"), href="http://books.google.com/books?id=%s&lpg=PP1&pg=%s" % (source.google_book_search_id, pg), )
def gbs_link(source, pages=None): if not source.google_book_search_id or not source.jsondata or not source.jsondata.get('gbs'): return '' if source.jsondata['gbs']['accessInfo']['viewability'] in ['NO_PAGES']: return '' pg = 'PP1' if pages: match = re.search('(?P<startpage>[0-9]+)', pages) if match: pg = 'PA' + match.group('startpage') return HTML.a( HTML.img(src="https://www.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif"), href="http://books.google.com/books?id=%s&lpg=PP1&pg=%s" % ( source.google_book_search_id, pg) )
def value_li(l): return ( HTML.img(height="20", width="20", src=self.icon_map[l.pk]), literal(' '), languoid_link(self.req, l), literal(' '), HTML.label(HTML.input( type="checkbox", onclick="GLOTTOLOG3.filterMarkers(this);", class_="checkbox inline", checked="checked", value=str(l.pk)), class_="checkbox inline", title="click to toggle markers"), )
def value_li(l): return ( HTML.img(height="20", width="20", src=self.icon_map[l.pk]), literal(' '), languoid_link(self.req, l), literal(' '), HTML.label( HTML.input( type="checkbox", onclick="GLOTTOLOG3.filterMarkers(this);", class_="checkbox inline", checked="checked", value=str(l.pk)), class_="checkbox inline", title="click to toggle markers"), )
def icons(req, param): icon_map = req.registry.settings['icons'] print "yes" print icon_map td = lambda spec: HTML.td( HTML.img( src=req.static_url('clld:web/static/icons/' + icon_map[spec] + '.png'), ##src=req.static_url('lsi:static/icons/' + icon_map[spec] + '.png'), height='20', width='20'), onclick='LSI.reload({"%s": "%s"})' % (param, spec)) rows = [ HTML.tr(*map(td, icons)) for c, icons in groupby(sorted(icon_map.keys()), lambda spec: spec[0]) ] return HTML.div( HTML.table(HTML.tbody(*rows), class_="table table-condensed"), button('Close', **{'data-dismiss': 'clickover'}))
def get_images(self, image_type='thumbnail', width='50', req=None): if not self.files or not req: # pragma: no cover return '' res = [] for k, f in self.files.items(): if image_type in ['web', 'thumbnail']: if image_type == 'web' and f.mime_type.startswith('video'): image_type = 'thumbnail' res.append( HTML.a( HTML.img( src=cdstar.bitstream_url(f, image_type), width='%spx' % (width) if width else 'auto', class_='image_%s' % (image_type), ), href='%s/%s' % (req.route_url('images'), f.id), title=f.name, target='_new', )) return ''.join(res)
def map_marker_img(req, obj, marker=None, height='20', width='20'): marker = marker or req.registry.getUtility(interfaces.IMapMarker) url = marker(obj, req) if url: return HTML.img(src=url, height=height, width=width) return ''
def marker_img(src, **kw): kw.setdefault('height', MARKER_IMG_DIM) kw.setdefault('width', MARKER_IMG_DIM) return HTML.img(src=src, **kw)
def logo(req, width='20'): return HTML.img( src=req.static_url('clld:web/static/images/glottolog.png'), width=width, style="margin-top: -2px")
def map_marker_img(req, obj, marker=None, height='20', width='20'): url = map_marker_url(req, obj, marker=marker) if url: return HTML.img(src=url, height=height, width=width) return ''
def marker_img(src, **kw): kw.setdefault("height", MARKER_IMG_DIM) kw.setdefault("width", MARKER_IMG_DIM) return HTML.img(src=src, **kw)
def marker_img(src, **kw): kw.setdefault('height', MARKER_IMG_DIM) kw.setdefault('width', MARKER_IMG_DIM) return HTML.img(src=src, **kw)
def legend_items(req): for type, label in [('recipient', 'recipient language'), ('donor', 'donor languoid')]: yield HTML.label( HTML.img(src=icon_url(req, type), height='20', width='20'), literal(' ' + label), style='margin-left: 1em; margin-right: 1em;')
def format(self, item): item = self.get_obj(item) for f in item.iterfiles(): if maintype(f) == 'image': return HTML.img(src=bitstream_url(f, type_='thumbnail')) return ''
def format(self, item): item = self.get_obj(item) for f in item._files: if maintype(f) == 'image': return HTML.img(src=bitstream_url(f, type_='thumbnail')) return ''
def concepticon_link(request, concept): return HTML.a( HTML.img(src=request.static_url("lexibank:static/concepticon_logo.png"), height=20, width=30), title="corresponding concept set at Concepticon", href=concept.concepticon_url, )
def img(spec): return HTML.img( src=self.icon_map[spec], height='20', width='20', style='margin-left: 0.5em;')
def ipa_vowels(req, segments): segments[0] = ('separator', u'•', 'segment-separator', None, False, None) div_specs = [ # high (4, -29, 125, [87, 54, 53, 0, 55, 88]), (4, 135, 60, [62, 0]), (4, 264, 110, [66, 0, 67, 68, 93]), # lowered high (35, 80, 60, [56, 0]), (35, 221, 60, [0, 69]), # higher mid (71, 12, 90, [89, 58, 57, 0]), (71, 283, 90, [0, 70, 71, 94]), # mid (98, 182, 60, [63]), # lower mid (135, 55, 90, [90, 60, 59, 0]), (135, 282, 90, [0, 72, 86, 95]), # raised low (166, 96, 60, [91, 61, 0]), # low (198, 100, 90, [92, 65, 64, 0]), (198, 247, 60, [96, 73, 0]), ] divs = [ HTML.div( *[HTML.span(parameter_link(req, symbol, vs or p), class_=class_, title=name) for name, symbol, class_, p, exists, vs in [segments[i] for i in content]], style="top:%spx; left:%spx; width:%spx;" % (top, left, width), class_='segment-container') for top, left, width, content in div_specs] def wm_url(path): return '//upload.wikimedia.org/wikipedia/commons/thumb/4/4f/'\ 'Blank_vowel_trapezoid.svg' + path diagram = HTML.div( HTML.img( height="224", width="320", alt="Blank vowel trapezoid.svg", src=wm_url("/320px-Blank_vowel_trapezoid.svg.png"), srcset=', '.join([ wm_url('/480px-Blank_vowel_trapezoid.svg.png 1.5x'), wm_url('/640px-Blank_vowel_trapezoid.svg.png 2x')]), ), HTML.div( HTML.table( HTML.tbody(HTML.tr(HTML.td(*divs))), style="position:relative; width:320px; height:224px; text-align:center; " "background:transparent; font-size:131%;", ), style="background:transparent; position:absolute; top:0px; left:0px;", ), style="position:relative;", ) return HTML.table( HTML.tbody( HTML.tr( HTML.td(' '), HTML.td( HTML.span( 'front', style="position:relative; left:-0.4em; font-weight: bold;"), style="width:64px;"), HTML.td( 'near-front', style="width:62px; font-weight: bold;"), HTML.td( 'central', style="width:64px; font-weight: bold;"), HTML.td( 'near-back', style="width:62px; font-weight: bold;"), HTML.td( 'back', style="width:64px; font-weight: bold;"), style="text-align: center;", ), HTML.tr( HTML.td( 'high', style="height:32px; text-align:right; font-weight: bold;"), HTML.td( diagram, style="height:210px; padding-left: 30px;", colspan="5", rowspan="7"), ), HTML.tr(HTML.td('', style="height:32px; text-align:right;")), HTML.tr(HTML.td( 'higher-mid', style="height:32px; text-align:right; font-weight: bold;")), HTML.tr(HTML.td( 'mid', style="height:32px; text-align:right; font-weight: bold;")), HTML.tr(HTML.td( 'lower-mid', style="height:32px; text-align:right; font-weight: bold;")), HTML.tr(HTML.td('', style="height:32px; text-align:right;")), HTML.tr(HTML.td( 'low', style="height:32px; text-align:right; font-weight: bold;")), ), style="line-height:1.4em; background:transparent; margin:0em auto 0em auto;", cellspacing="0")
def logo(req, width='20'): return HTML.img(src=req.static_url('clld:web/static/images/concepticon.png'), width=width)