class EditForm(form.EditForm): extends(form.EditForm) grok.context(IFearture) grok.require('zope2.View') fields = field.Fields(IFearture) label = _(u"modify standard parameters for Plotting the figure") fields['coordination'].widgetFactory = DataGridFieldFactory
from zope.schema.vocabulary import SimpleVocabulary from zope.schema.vocabulary import SimpleTerm from five import grok from zope.schema.interfaces import IVocabularyFactory #import unicodedata from emc.bokeh import _ source_type = [ ('inline', 'inline', _(u'inline')), ('upload', 'upload', _(u'upload')), ('reference', 'reference', _(u'reference')), ] source_type_terms = [ SimpleTerm(value, token, title) for value, token, title in source_type ] class SourceType(object): def __call__(self, context): return SimpleVocabulary(source_type_terms) grok.global_utility(SourceType, IVocabularyFactory, name="emc.bokeh.vocabulary.sourcetype") axis_type = [ ('linear', 'linear', _(u'Linear coordinate')), ('log', 'log', _(u'logarithmic coordinate')), ('datetime', 'date', _(u'Date time')),
def getData(self, source="upload", datadic=None, upload=None, reference=None): # source = self.context.source data = {'x': [], 'y': []} if source == 'inline': # this is a list,and every item of the list must be dic # datadic = self.context.coordination if datadic == None: return None for d in datadic: m = d['x'] n = d['y'] if m == None: data['x'].append(0) else: data['x'].append(m) if n == None: data['y'].append(0) else: data['y'].append(n) return data elif source == 'upload': # fo = self.context.upload reader = upload.data #split byte string to get all rows rows = reader.split('\n') #the first row is header cell,it must be same with template file's the first row. header = rows[0].split(',') if header != data_VALUES: msg = _( 'Wrong specification of the CSV file. Please correct it and retry.' ) type = 'error' IStatusMessage(self.request).addStatusMessage(msg, type=type) return None else: # data row for row in rows[1:]: line = row.split(',') #remove space line if len(line) == 2: data['x'].append(float(line[0])) data['y'].append(float(line[1])) else: continue return data # KB reference else: # rel = self.context.reference ob = reference.to_object reader = ob.file.data rows = reader.split('\n') #the first row is header cell,it must be same with template file's the first row. header = rows[0].split(',') if header != data_VALUES: msg = _( 'Wrong specification of the CSV file. Please correct it and retry.' ) type = 'error' IStatusMessage(self.request).addStatusMessage(msg, type=type) return None else: # data row for row in rows[1:]: line = row.split(',') #remove space line if len(line) == 2: data['x'].append(float(line[0])) data['y'].append(float(line[1])) else: continue return data
from zope.schema.vocabulary import SimpleVocabulary from zope.schema.vocabulary import SimpleTerm from five import grok from zope.schema.interfaces import IVocabularyFactory #import unicodedata from emc.bokeh import _ source_type=[ ('inline','inline',_(u'inline')), ('upload','upload',_(u'upload')), ('reference','reference',_(u'reference')), ] source_type_terms = [SimpleTerm(value, token, title) for value, token, title in source_type ] class SourceType(object): def __call__(self, context): return SimpleVocabulary(source_type_terms) grok.global_utility(SourceType, IVocabularyFactory, name="emc.bokeh.vocabulary.sourcetype") axis_type=[ ('linear','linear',_(u'Linear coordinate')), ('log','log',_(u'logarithmic coordinate')), ('datetime','date',_(u'Date time')), ] axis_type_terms = [SimpleTerm(value, token, title) for value, token, title in axis_type ] class AxisType(object):
class IFearture(form.Schema, IBasic): """ emc project features content type """ #标准名称 dexteritytextindexer.searchable('title') title = schema.TextLine( title=_(u"standard name"), default=u"", required=True, ) #标准描述 description = schema.TextLine( title=_(u"standard description"), default=u"", required=False, ) #图例 legend = schema.TextLine( title=_(u"a legend of the first figure"), default=u"", required=True, ) #图例 legend2 = schema.TextLine( title=_(u"a legend of the second figure"), default=u"", required=False, ) #坐标类型 x_axis_type = schema.Choice(title=_(u"x axis type"), vocabulary="emc.bokeh.vocabulary.axistype", default="linear", required=True) y_axis_type = schema.Choice(title=_(u"y axis type?"), vocabulary="emc.bokeh.vocabulary.axistype", default="linear", required=True) # 坐标名称: x_axis_label = schema.TextLine(title=_(u"x axis label"), default=u"X", required=False) y_axis_label = schema.TextLine(title=_(u"y axis label"), default=u"Y", required=False) #数据来源 source = schema.Choice(title=_( u"Where the source data that will composing the plot come from ?"), vocabulary="emc.bokeh.vocabulary.sourcetype", default="inline", required=True) source2 = schema.Choice(title=_( u"Where the source data that will composing the plot come from ?"), vocabulary="emc.bokeh.vocabulary.sourcetype", default="inline", required=False) # 图像数据字段 在线输入 form.widget(coordination=DataGridFieldFactory) coordination = schema.List( title=_(u"coordination data"), value_type=DictRow(title=_(u"coordination data row"), schema=IPlotDataSchema), required=False, ) # 图像数据字段 在线输入 form.widget(coordination2=DataGridFieldFactory) coordination2 = schema.List( title=_(u"coordination data"), value_type=DictRow(title=_(u"coordination data row"), schema=IPlotDataSchema), required=False, ) #包含图像数据的csv文件 form.widget(upload=BokehNamedFileFieldWidget) upload = NamedBlobFile( title=_(u"figure data"), description=_(u"Attach your figure data report file(csv format)."), required=False, ) #包含图像数据的csv文件 form.widget(upload2=BokehNamedFileFieldWidget) upload2 = NamedBlobFile( title=_(u"the second figure data"), description=_(u"Attach your figure data report file(csv format)."), required=False, ) # 知识库中引用 reference = RelationChoice( title=_(u"reference"), source=ObjPathSourceBinder(object_provides=IFile.__identifier__), required=False, ) # 知识库中引用,file should be csv reference2 = RelationChoice( title=_(u"reference"), source=ObjPathSourceBinder(object_provides=IFile.__identifier__), required=False, ) # 字段集 form.fieldset('secondsource', label=_(u"second chart"), fields=[ 'legend2', 'source2', 'coordination2', 'upload2', 'reference2' ])
class IPlotDataSchema(Interface): x = schema.Float(title=_(u"X Coordinate")) y = schema.Float(title=_(u"Y Coordinate"))