def _repr_html_(self): from xmle import Elem xsign = Elem("div", {'class': 'larch_head_tag'}) from .images import favicon p = xsign.elem('p', {'style': 'float:left;margin-top:6px'}) p.elem('img', { 'width': "32", 'height': "32", 'src': "data:image/png;base64,{}".format(favicon), 'style': 'float:left;position:relative;top:-3px;padding-right:0.2em;' }, tail=f" {self.appname} ") p.elem('span', {'class': 'larch_head_tag_ver'}, text=f" {self.version} ") p.elem('span', {'class': 'larch_head_tag_pth'}, text=f" {self.path} ") from .images import camsyslogo_element xsign << camsyslogo_element if 'larch' in sys.modules: from .images import georgiatechlogo_element xsign << georgiatechlogo_element if self.extra: v = '\n│'.join(sys.version.split('\n')) xsign.elem('br') xinfo = xsign.elem('div', {'class': 'larch_head_tag_more', 'style':'margin-top:10px; padding:7px'}, text=f'Python {v}') xinfo.elem('br', tail=f"EXE - {sys.executable}") xinfo.elem('br', tail=f"CWD - {os.getcwd()}") xinfo.elem('br', tail=f"PATH - ") ul = xinfo.elem('ul', {'style': 'margin-top:0; margin-bottom:0;'}) for p in sys.path: ul.elem('li', text=p) from ..util.styles import _default_css_jupyter, _tooltipped_style_css style_prefix = "<style>{}\n\n{}</style>\n".format(_default_css_jupyter, _tooltipped_style_css) return style_prefix+xsign.tostring()
def __xml__(self): from xmle import Elem, Show x = Elem('div') t = x.elem('table', style="margin-top:1px;") if len(self): tr = t.elem('tr') tr.elem('th', text="key") tr.elem('th', text='value', style='text-align:left;') for k, v in self.items(): tr = t.elem('tr') tr.elem('td', text=str(k)) try: if isinstance(v, str) and '\n' not in v and v[:1] != "#": raise ValueError() v_ = Show(v) except (AttributeError, ValueError): plaintext = pprint.pformat(v) if isinstance(v, datetime.timedelta): plaintext = str(v) if "\n" in plaintext: tr.elem('td', style='text-align:left;').elem('pre', text=plaintext) else: tr.elem('td', style='text-align:left;', text=plaintext) else: tr.elem('td', style='text-align:left;') << v_ else: tr = t.elem('tr') tr.elem('td', text="<empty>") return x
def __xml__(self): from xmle import Elem, Show x = Elem('div') t = x.elem('table', style="margin-top:1px;") if len(self): tr = t.elem('tr') tr.elem('th', text="key") tr.elem('th', text='value', style='text-align:left;') for k,v in self.items(): tr = t.elem('tr') tr.elem('td', text=str(k)) try: if isinstance(v, str) and '\n' not in v and v[:1] != "#": raise ValueError() v_ = Show(v) except (AttributeError, ValueError): plaintext = pprint.pformat(v) if isinstance(v, datetime.timedelta): plaintext = str(v) if "\n" in plaintext: tr.elem('td', style='text-align:left;').elem('pre', text=plaintext) else: tr.elem('td', style='text-align:left;', text=plaintext) else: tr.elem('td', style='text-align:left;') << v_ else: tr = t.elem('tr') tr.elem('td', text="<empty>") return x
def _repr_html_(self): from ..util.styles import _default_css_jupyter, _tooltipped_style_css style_prefix = "<style>{}\n\n{}</style>\n".format( _default_css_jupyter, _tooltipped_style_css) from xmle import Elem xsign = Elem("div", {'class': 'larch_head_tag'}) from .images import favicon p = xsign.elem('p', {'style': 'float:left;margin-top:6px'}) p.elem('img', { 'width': "32", 'height': "32", 'src': "data:image/png;base64,{}".format(favicon), 'style': 'float:left;position:relative;top:-3px;padding-right:0.2em;' }, tail=f" {self.appname} ") p.elem('span', {'class': 'larch_head_tag_ver'}, text=f" {self.version} ") if not self.minimal: p.elem('span', {'class': 'larch_head_tag_pth'}, text=f" {self.path} ") from .images import camsyslogo_element xsign << camsyslogo_element if 'larch' in sys.modules: from .images import georgiatechlogo_element xsign << georgiatechlogo_element if self.extra: v = '\n│'.join(sys.version.split('\n')) xsign.elem('br') xinfo = xsign.elem('div', { 'class': 'larch_head_tag_more', 'style': 'margin-top:10px; padding:7px' }, text=f'Python {v}') xinfo.elem('br', tail=f"EXE - {sys.executable}") xinfo.elem('br', tail=f"CWD - {os.getcwd()}") xinfo.elem('br', tail=f"PATH - ") ul = xinfo.elem('ul', {'style': 'margin-top:0; margin-bottom:0;'}) for p in sys.path: ul.elem('li', text=p) return style_prefix + xsign.tostring()
def __xml__(self): from xmle import Elem x = Elem('div') t = x.elem('table', style="margin-top:1px;") if len(self): tr = t.elem('tr') tr.elem('th', text="key") tr.elem('th', text='value', style='text-align:left;') for k, v in self.items(): tr = t.elem('tr') tr.elem('td', text=str(k)) try: v_ = v.__xml__() except AttributeError: tr.elem('td', text=str(v), style='text-align:left;') else: tr.elem('td') << v_ else: tr = t.elem('tr') tr.elem('td', text="<empty>") return x
def __xml__(self): from xmle import Elem x = Elem('div') t = x.elem('table', style="margin-top:1px;") if len(self): tr = t.elem('tr') tr.elem('th', text="key") tr.elem('th', text='value', style='text-align:left;') for k,v in self.items(): tr = t.elem('tr') tr.elem('td', text=str(k)) try: v_ = v.__xml__() except AttributeError: tr.elem('td', text=str(v), style='text-align:left;') else: tr.elem('td') << v_ else: tr = t.elem('tr') tr.elem('td', text="<empty>") return x
def utility_functions(self, subset=None, resolve_parameters=False): """ Generate an XHTML output of the utility function(s). Parameters ---------- subset : Collection, optional A collection of alternative codes to include. This only has effect if there are separate utility_co functions set by alternative. It is recommended to use this parameter if there are a very large number of alternatives, and the utility functions of most (or all) of them can be effectively communicated by showing only a few. resolve_parameters : bool, default False Whether to resolve the parameters to the current (estimated) value in the output. Returns ------- xmle.Elem """ self.unmangle() from xmle import Elem x = Elem('div') t = x.elem('table', style="margin-top:1px;", attrib={'class': 'floatinghead'}) if len(self.utility_co): # t.elem('caption', text=f"Utility Functions", # style="caption-side:top;text-align:left;font-family:Roboto;font-weight:700;" # "font-style:normal;font-size:100%;padding:0px;color:black;") # iterate over all alternatives if a dataframes is attached and lists the alternatives try: if self.dataservice is not None: alts = self.dataservice.alternative_codes() elif self.dataframes is not None: alts = self.dataframes.alternative_codes() else: alts = self.utility_co.keys() except: alts = self.utility_co.keys() t_head = t.elem('thead') tr = t_head.elem('tr') tr.elem('th', text="alt") tr.elem('th', text='formula', attrib={'style': 'text-align:left;'}) t_body = t.elem('tbody') for j in alts: if subset is None or j in subset: tr = t_body.elem('tr') tr.elem('td', text=str(j)) utilitycell = tr.elem('td', attrib={'style': 'text-align:left;'}) utilitycell.elem('div') anything = False if len(self.utility_ca): utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + " utilitycell << list( self.utility_ca.__xml__( linebreaks=True, resolve_parameters=self, value_in_tooltips=not resolve_parameters)) anything = True if j in self.utility_co: v = self.utility_co[j] if len(v): if anything: utilitycell << Elem('br') utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + " utilitycell << list( v.__xml__( linebreaks=True, resolve_parameters=self, value_in_tooltips=not resolve_parameters)) anything = True if len(self.quantity_ca): if anything: utilitycell << Elem('br') if self.quantity_scale: utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + " from .linear import ParameterRef_C utilitycell << list( ParameterRef_C(self.quantity_scale).__xml__( resolve_parameters=self, value_in_tooltips=not resolve_parameters)) utilitycell[-1].tail = (utilitycell[-1].tail or "") + " * log(" else: utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + log(" content = self.quantity_ca.__xml__( linebreaks=True, lineprefix=" ", exponentiate_parameters=True, resolve_parameters=self, value_in_tooltips=not resolve_parameters) utilitycell << list(content) utilitycell.elem('br', tail=")") else: # there is no differentiation by alternatives, just give one formula # t.elem('caption', text=f"Utility Function", # style="caption-side:top;text-align:left;font-family:Roboto;font-weight:700;" # "font-style:normal;font-size:100%;padding:0px;color:black;") tr = t.elem('tr') utilitycell = tr.elem('td', attrib={'style': 'text-align:left;'}) utilitycell.elem('div') anything = False if len(self.utility_ca): utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + " utilitycell << list( self.utility_ca.__xml__( linebreaks=True, resolve_parameters=self, value_in_tooltips=not resolve_parameters)) anything = True if len(self.quantity_ca): if anything: utilitycell << Elem('br') if self.quantity_scale: utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + " from .linear import ParameterRef_C utilitycell << list( ParameterRef_C(self.quantity_scale).__xml__( resolve_parameters=self, value_in_tooltips=not resolve_parameters)) utilitycell[-1].tail = (utilitycell[-1].tail or "") + " * log(" else: utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + log(" content = self.quantity_ca.__xml__( linebreaks=True, lineprefix=" ", exponentiate_parameters=True, resolve_parameters=self, value_in_tooltips=not resolve_parameters) utilitycell << list(content) utilitycell.elem('br', tail=")") return x
def __xml__(self, no_data=False, descriptions=True, dictionaries=False): from xmle import Elem x = Elem('div') t = x.elem('table', style="margin-top:1px;") t.elem( 'caption', text=f"<larch.{self.__class__.__name__}>", style= "caption-side:top;text-align:left;font-family:Roboto;font-weight:700;font-style:normal;font-size:100%;padding:0px;" ) # try: ident = self.ident except AttributeError: pass else: tr = t.elem('tr') tr.elem('th', text='ident') tr.elem('td', text=ident) # try: filename = self.filename except AttributeError: pass else: tr = t.elem('tr') tr.elem('th', text='file') tr.elem('td', text=truncate_path_for_display(filename)) # try: filemode = self.filemode except AttributeError: pass else: tr = t.elem('tr') tr.elem('th', text='mode') tr.elem('td', text=truncate_path_for_display(self.filemode)) # try: v_pathname = self._groupnode._v_pathname except AttributeError: pass else: if self._groupnode._v_pathname != "/": tr = t.elem('tr') tr.elem('th', text='node') tr.elem('td', text=self._groupnode._v_pathname) # try: str_shape = str(self.shape) except NoKnownShape: pass else: tr = t.elem('tr') tr.elem('th', text='shape') tr.elem('td', text=str_shape) # try: str_shape = str(self.metashape) except (NoKnownShape, AttributeError): pass else: tr = t.elem('tr') tr.elem('th', text='metashape') tr.elem('td', text=str_shape) # try: str_durable_mask = f"0x{self.durable_mask:X}" except (AttributeError): pass else: if str_durable_mask != '0x0': tr = t.elem('tr') tr.elem('th', text='durable_mask') tr.elem('td', text=str_durable_mask) # if not no_data: if len(self._groupnode._v_children): tr = t.elem('tr') tr.elem('th', text='data', style='vertical-align:top;') td = tr.elem('td') t1 = td.elem('table', cls='dictionary') t1head = t1.elem('thead') t1headr = t1head.elem('tr') t1headr.elem('th', text='name') t1headr.elem('th', text='dtype') if descriptions: t1headr.elem('th', text='description') any_sources = 0 for i in sorted(self._groupnode._v_children.keys()): try: node_dtype = self._groupnode._v_children[i].dtype except (tb.NoSuchNodeError, AttributeError): node_dtype = "<no dtype>" if i not in _reserved_names_: tr1 = t1.elem('tr') tr1.elem('td', text=i) tr1.elem('td', text=node_dtype) if descriptions: try: title = self._groupnode._v_children[ i]._v_attrs['TITLE'] except: title = "" else: tr1.elem('td', text=title) try: orig_source = self._groupnode._v_children[ i]._v_attrs['ORIGINAL_SOURCE'] except: pass else: tr1.elem('td', text=orig_source) any_sources += 1 if any_sources: t1headr.elem('th', text='source') else: tr = t.elem('tr') tr.elem('th', text='data', style='vertical-align:top;') tr.elem('td', text='<empty>') return x
def utility_functions(self, subset=None, resolve_parameters=False): """ Generate an XHTML output of the utility function(s). Parameters ---------- subset : Collection, optional A collection of alterative codes to include. This only has effect if there are seperate utility_co functions set by alternative. resolve_parameters : bool, default False Whether to resolve the parameters to the current (estimated) value in the output. Returns ------- xmle.Elem """ self.unmangle() from xmle import Elem x = Elem('div') t = x.elem('table', style="margin-top:1px;", attrib={'class':'floatinghead'}) if len(self.utility_co): # t.elem('caption', text=f"Utility Functions", # style="caption-side:top;text-align:left;font-family:Roboto;font-weight:700;" # "font-style:normal;font-size:100%;padding:0px;color:black;") t_head = t.elem('thead') tr = t_head.elem('tr') tr.elem('th', text="alt") tr.elem('th', text='formula', attrib={'style':'text-align:left;'}) t_body = t.elem('tbody') for j in self.utility_co.keys(): if subset is None or j in subset: tr = t_body.elem('tr') tr.elem('td', text=str(j)) utilitycell = tr.elem('td', attrib={'style':'text-align:left;'}) utilitycell.elem('div') anything = False if len(self.utility_ca): utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + " utilitycell << list(self.utility_ca.__xml__(linebreaks=True, resolve_parameters=self, value_in_tooltips=not resolve_parameters)) anything = True if j in self.utility_co: if anything: utilitycell << Elem('br') v = self.utility_co[j] utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + " utilitycell << list(v.__xml__(linebreaks=True, resolve_parameters=self, value_in_tooltips=not resolve_parameters)) anything = True if len(self.quantity_ca): if anything: utilitycell << Elem('br') if self.quantity_scale: utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + " from .linear import ParameterRef_C utilitycell << list(ParameterRef_C(self.quantity_scale).__xml__(resolve_parameters=self, value_in_tooltips=not resolve_parameters)) utilitycell[-1].tail = (utilitycell[-1].tail or "") + " * log(" else: utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + log(" content = self.quantity_ca.__xml__(linebreaks=True, lineprefix=" ", exponentiate_parameters=True, resolve_parameters=self, value_in_tooltips=not resolve_parameters) utilitycell << list(content) utilitycell.elem('br', tail=")") else: # there is no differentiation by alternatives, just give one formula # t.elem('caption', text=f"Utility Function", # style="caption-side:top;text-align:left;font-family:Roboto;font-weight:700;" # "font-style:normal;font-size:100%;padding:0px;color:black;") tr = t.elem('tr') utilitycell = tr.elem('td', attrib={'style':'text-align:left;'}) utilitycell.elem('div') anything = False if len(self.utility_ca): utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + " utilitycell << list(self.utility_ca.__xml__(linebreaks=True, resolve_parameters=self, value_in_tooltips=not resolve_parameters)) anything = True if len(self.quantity_ca): if anything: utilitycell << Elem('br') if self.quantity_scale: utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + " from .linear import ParameterRef_C utilitycell << list(ParameterRef_C(self.quantity_scale).__xml__(resolve_parameters=self, value_in_tooltips=not resolve_parameters)) utilitycell[-1].tail = (utilitycell[-1].tail or "") + " * log(" else: utilitycell[-1].tail = (utilitycell[-1].tail or "") + " + log(" content = self.quantity_ca.__xml__(linebreaks=True, lineprefix=" ", exponentiate_parameters=True, resolve_parameters=self, value_in_tooltips=not resolve_parameters) utilitycell << list(content) utilitycell.elem('br', tail=")") return x