PK!?AAhtmlviewer/__init__.pyfrom .pagination import PagedViewer from .core import view_table PK!p$$htmlviewer/core.pyfrom jinja2 import Environment, PackageLoader from uuid import uuid4 import os from threading import Timer from IPython.display import IFrame env = Environment( loader=PackageLoader('htmlviewer', 'templates') ) def generate_html(data, **kwargs): rowHeader = kwargs.get('rowHeader', None) colHeader = [] for record in data: for k in record.keys(): if k not in colHeader: if k == rowHeader: colHeader.insert(0, k) else: colHeader.append(k) config = { 'colHeader': colHeader, 'data': data, 'maxColWidth': 200, 'maxRowHeight': 500, } config.update(kwargs) template = env.get_template('viewer.html') return template.render(config=config) def view_table(data, width=1000, height=500, filename=None, autodelete=True, **kwargs): # A TemporaryFile does not work with Jupyter Notebook if filename is None: filename = str(uuid4()) + '.html' try: with open(filename, 'w') as f: f.write(generate_html(data=data, width=width, height=height, **kwargs)) return IFrame(filename, width=width, height=height) finally: if autodelete: Timer(5, os.unlink, args=[filename]).start() PK!htmlviewer/pagination.pyfrom IPython.display import display import math from .core import view_table class PagedViewer: chunk_size = 10 page_number = 0 def __init__(self, records, chunk_size=10, **kwargs): self.records = list(records) self.chunk_size = chunk_size self.viewer_kwargs = kwargs @property def page_count(self): return math.ceil(self.record_count / self.chunk_size) @property def record_count(self): return len(self.records) def __len__(self): return self.record_count def _repr_html_(self): display(self.view()) return '' def view(self, page_number=None, start=None): """Choose a page number to view Keyword Arguments: page_number {int >= -1} -- Page number to view (default: {self.page_number}) start {int} -- Sequence of the record to start viewing (default: {None}) Returns: Viewer function object """ if page_number is None: page_number = self.page_number elif page_number == -1: page_number = self.page_count - 1 self.page_number = page_number if start is None: start = page_number * self.chunk_size return view_table(self.records[start: start + self.chunk_size], **self.viewer_kwargs) def next(self): """Shows the next page Returns: Viewer function object """ if len(self.records) < (self.page_number + 1) * self.chunk_size: self.page_number = 0 else: self.page_number += 1 return self.view() def previous(self): """Show the previous page Returns: Viewer function object """ self.page_number -= 1 if self.page_number < 0: self.page_number = self.page_count - 1 return self.view() def first(self): """Shows the first page Returns: Viewer function object """ return self.view(0) def last(self): """Shows the last page Returns: Viewer function object """ return self.view(-1) PK!,htmlviewer/templates/colResizable-1.6.min.js// colResizable 1.6 - a jQuery plugin by Alvaro Prieto Lauroba http://www.bacubacu.com/colresizable/ !function(t){var e,i=t(document),r=t("head"),o=null,s={},d=0,n="id",a="px",l="JColResizer",c="JCLRFlex",f=parseInt,h=Math,p=navigator.userAgent.indexOf("Trident/4.0")>0;try{e=sessionStorage}catch(g){}r.append("");var u=function(e,i){var o=t(e);if(o.opt=i,o.mode=i.resizeMode,o.dc=o.opt.disabledColumns,o.opt.disable)return w(o);var a=o.id=o.attr(n)||l+d++;o.p=o.opt.postbackSafe,!o.is("table")||s[a]&&!o.opt.partialRefresh||("e-resize"!==o.opt.hoverCursor&&r.append(""),o.addClass(l).attr(n,a).before('
'),o.g=[],o.c=[],o.w=o.width(),o.gc=o.prev(),o.f=o.opt.fixed,i.marginLeft&&o.gc.css("marginLeft",i.marginLeft),i.marginRight&&o.gc.css("marginRight",i.marginRight),o.cs=f(p?e.cellSpacing||e.currentStyle.borderSpacing:o.css("border-spacing"))||2,o.b=f(p?e.border||e.currentStyle.borderLeftWidth:o.css("border-left-width"))||1,s[a]=o,v(o))},w=function(t){var e=t.attr(n),t=s[e];t&&t.is("table")&&(t.removeClass(l+" "+c).gc.remove(),delete s[e])},v=function(i){var r=i.find(">thead>tr:first>th,>thead>tr:first>td");r.length||(r=i.find(">tbody>tr:first>th,>tr:first>th,>tbody>tr:first>td, >tr:first>td")),r=r.filter(":visible"),i.cg=i.find("col"),i.ln=r.length,i.p&&e&&e[i.id]&&m(i,r),r.each(function(e){var r=t(this),o=-1!=i.dc.indexOf(e),s=t(i.gc.append('
')[0].lastChild);s.append(o?"":i.opt.gripInnerHtml).append('
'),e==i.ln-1&&(s.addClass("JCLRLastGrip"),i.f&&s.html("")),s.bind("touchstart mousedown",J),o?s.addClass("JCLRdisabledGrip"):s.removeClass("JCLRdisabledGrip").bind("touchstart mousedown",J),s.t=i,s.i=e,s.c=r,r.w=r.width(),i.g.push(s),i.c.push(r),r.width(r.w).removeAttr("width"),s.data(l,{i:e,t:i.attr(n),last:e==i.ln-1})}),i.cg.removeAttr("width"),i.find("td, th").not(r).not("table th, table td").each(function(){t(this).removeAttr("width")}),i.f||i.removeAttr("width").addClass(c),C(i)},m=function(t,i){var r,o,s=0,d=0,n=[];if(i){if(t.cg.removeAttr("width"),t.opt.flush)return void(e[t.id]="");for(r=e[t.id].split(";"),o=r[t.ln+1],!t.f&&o&&(t.width(o*=1),t.opt.overflow&&(t.css("min-width",o+a),t.w=o));d*{cursor:"+n.opt.dragCursor+"!important}"),a.addClass(n.opt.draggingClass),o=a,n.c[d.i].l)for(var f,h=0;h
PK!՗-htmlviewer/templates/viewer.jsString.prototype.hashCode = function() { var hash = 0, i, chr; if (this.length === 0) return hash; for (i = 0; i < this.length; i++) { chr = this.charCodeAt(i); hash = ((hash << 5) - hash) + chr; hash |= 0; // Convert to 32bit integer } return hash; }; Object.keys(config).forEach(key=>{ if(key.charAt(key.length - 1) === 's'){ config[key.slice(0, -1)] = config[key] } }); $(function () { $('.table').colResizable({ liveDrag: true, resizeMode: 'overflow', onDrag: ()=>{ const $body = $('body'); const maxWidth = $(this).width(); if($body.width() < maxWidth){ $body.width(maxWidth); } } }); // $('body').removeAttr('style'); }); makeTable(config); function makeTable(config){ const colHeader = config.colHeader; let table = document.createElement('table'); table.className = 'table table-striped table-bordered'; let thead = document.createElement('thead'); let tr = document.createElement('tr'); colHeader.forEach(key=>{ let th = document.createElement('th'); th.scope = 'col'; th.id = 'col' + key.hashCode(); switch(whatIsIt(config.maxColWidth)){ case "Object": th.style.maxWidth = config.maxColWidth[key] + 'px'; break; case "string": th.style.maxWidth = config.maxColWidth; break; case "number": th.style.maxWidth = config.maxColWidth + 'px'; break; } switch(whatIsIt(config.minColWidth)){ case "Object": th.style.minWidth = config.minColWidth[key] + 'px'; break; case "string": th.style.minWidth = config.minColWidth; break; case "number": th.style.minWidth = config.minColWidth + 'px'; break; default: th.style.minWidth = key.length + 'em'; } if (config.colWidth[key]){ th.style.maxWidth = (screen.width / 2) + 'px'; } th.innerHTML = key; tr.appendChild(th); }); thead.appendChild(tr); table.appendChild(thead); let tbody = document.createElement('tbody'); config.data.forEach(record=>{ let tr = document.createElement('tr'); colHeader.forEach(key=>{ let td = document.createElement('td'); let wrapped = document.createElement('div'); wrapped.className = 'wrapped' let wrapper = document.createElement('div'); wrapper.className = 'wrapper' wrapper.appendChild(wrapped); td.appendChild(wrapper); switch(whatIsIt(record[key])){ case "Object": wrapped.innerHTML = '
' + JSON.stringify(record[key], null, 2) + '
'; break; case "Array": wrapped.innerHTML = '
' + JSON.stringify(record[key]) + '
'; break; case "number": wrapped.textContent = record[key]; break; case "string": switch(whatIsIt(config.renderer)){ case "Object": if (config.renderer[key] === 'html') { wrapped.innerHTML = record[key]; } else { wrapped.textContent = record[key]; } break; case "string": if (config.renderer === 'html') { wrapped.innerHTML = record[key]; } else { wrapped.textContent = record[key]; } break; default: wrapped.textContent = record[key]; } break; default: if(record[key]) wrapped.textContent = record[key]; } tr.appendChild(td); }); tbody.appendChild(tr); }); table.appendChild(tbody); document.getElementById('tableArea').appendChild(table); let style = document.createElement('style'); document.head.appendChild(style); style.sheet.insertRule(` .wrapper { max-height: ${config.maxRowHeight}px; } `, 0); let totalWidth = 0; colHeader.forEach(key=>{ if (config.colWidth[key]){ document.getElementById('col' + key.hashCode()).style.width = config.colWidth[key] + 'px'; totalWidth += config.colWidth[key]; } else { totalWidth += document.getElementById('col' + key.hashCode()).clientWidth; } }); document.getElementById('body').style.width = totalWidth + 'px'; } function whatIsIt(object) { var arrayConstructor = [].constructor; var objectConstructor = {}.constructor; if (object === null) { return "null"; } else if (object === undefined) { return "undefined"; } else if (object.constructor === arrayConstructor) { return "Array"; } else if (object.constructor === objectConstructor) { return "Object"; } else { return typeof object; } } PK! ::"htmlviewer-0.1.6.dist-info/LICENSEMIT License Copyright (c) 2018 Pacharapol Withayasakpunt Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. PK!H WX htmlviewer-0.1.6.dist-info/WHEEL A н#Z."jm)Afb~ڠO68oF04UhoAf f4=4h0k::wXPK!H0` #htmlviewer-0.1.6.dist-info/METADATAVn8}WL][v\$ i!A-HxIYlF7`sΙ!uf fhL m}aJs)z %X&&K͘"Un{dPdU (eA0 KA$Mʎf 3n&0Ph.8"WqCr&3i\(dQD\J9٘1coc>a? nrmz Cfy!4^`|nЃ}#a#),h7oY)ӑ5mD Äi 9˰GF?r&ق@rz~݇ X\~/|̳$\yz4pswT/F4|;S+82MycڀeK3ivYb9eř cN75dY|>Y^nmA_h]rOrφ,/v%/siRM'J`d"<˥282zûOw7OnNMxaFU+ی==A|YWPBSom7H0Ķ4`orYz_{Nп06΂eVT~~@[;'dD_yl&NN gELL1j_a)Ŋ@;˂f%}#gg'ݟ+e\aɎT3'ې^EKb"f7(N`0?0Yw\-ة<.)ΤP*K(T2!y18:HXΎZ|Ky̚0czӕq_mg [;1$K~zҺ(i4kJlj̗v;,GY*:=H皷v`dfυ۹H9O70ɘս;Y7˜BE-U@Yl.+T=Q=!$Hj8W:*EEs~QeQ7PK!?AAhtmlviewer/__init__.pyPK!p$$uhtmlviewer/core.pyPK!htmlviewer/pagination.pyPK!,htmlviewer/templates/colResizable-1.6.min.jsPK!wZZ%htmlviewer/templates/viewer.cssPK!Qnn i'htmlviewer/templates/viewer.htmlPK!՗-+htmlviewer/templates/viewer.jsPK! ::"Ahtmlviewer-0.1.6.dist-info/LICENSEPK!H WX Ehtmlviewer-0.1.6.dist-info/WHEELPK!H0` #+Fhtmlviewer-0.1.6.dist-info/METADATAPK!HsX !Jhtmlviewer-0.1.6.dist-info/RECORDPK I]M