def display(self): '''This method serves the Component class and the make_html function defined in the cmf_models module. It returns an html description of self and writes a plot to 'eos.jpg'. ''' # Write file named eos.jpg fig = plt.figure('eos',figsize=(7,5)) ax = fig.add_subplot(1,1,1) ax.set_xlabel(r'$x/{\rm cm}$') ax.set_ylabel(r'$f/{\rm dyn}$') x = np.linspace(.4,4,100) y = self(x) ax.plot(x,y) fig.savefig('eos.jpg', format='jpg') # Make an html formated return value html = oneliner.p(''' Table of coefficients for spline representation of force as a function of position along the barrel''') html += oneliner.p(self.get_c().__str__()) html += oneliner.p(''' Plot of force as a function of position along the barrel''') html += oneliner.img( width=700, height=500, alt='plot of eos', src='eos.jpg') return html
def generateHTMLTable(columnNames,table_type,countTD=1): snippet = markup.page() titles = columnNames['labels'] inputids = columnNames['columns'] snippet.table(width="100%") if countTD == 1: for i in range(len(titles)): snippet.tr() snippet.td(oneliner.p(titles[i]),align='center') snippet.td(oneliner.input(id=(inputids[i]+table_type)),align='center') snippet.tr.close() snippet.tr() snippet.td(style='padding-top: 10px;',align="center") snippet.td(oneliner.input(id="Cancel"+table_type,type="button",value="取消"),align='center') snippet.td(oneliner.input(id="Save"+table_type,type="button",value="保存"),align='center') snippet.tr.close() elif countTD == 3: i=0 while (i < len(titles)): snippet.tr() snippet.td(oneliner.p(titles[i]),align='left') snippet.td(oneliner.input(id=(inputids[i]+table_type)),align='left') i=i+1 if i < len(titles): snippet.td(oneliner.p(titles[i]),align='left') snippet.td(oneliner.input(id=(inputids[i]+table_type)),align='left') i=i+1 if i < len(titles): snippet.td(oneliner.p(titles[i]),align='left') snippet.td(oneliner.input(id=(inputids[i]+table_type)),align='left') snippet.tr.close() i=i+1 snippet.table.close() return str(snippet)
def html( self, # Provenance instance name, # Component name qualified by branch indices ): '''Add to html view of self. ''' from markup import oneliner import os.path # Start with a description list key return_value = oneliner.dt(name,id=name)+'\n' # Construct text for inclusion as description list value href = 'file://'+self.file # EG, "file:///absolute_path/calc.py" text = '{0}\n line {1:d}: {2}\n'.format( oneliner.a(os.path.basename(self.file),href=href), self.line_num, self.line) if self.text != '': text += oneliner.p(self.text)+'\n' if len(self.branches) == 0: text += oneliner.p('No more provenance of {0}'.format(name))+'\n' else: text += 'Parent Components: ' for i,branch in enumerate(self.branches): name_ = '{0}.{1}'.format(name,i) text += oneliner.a(name_,href='#{0}'.format(name_))+', ' # Insert description list value return_value += oneliner.dd(text.rstrip(' ,')) # Recursion on branches for i,branch in enumerate(self.branches): return_value += branch.html('{0}.{1}'.format(name,i)) return return_value