diff --git a/src/graph/app.py b/src/graph_ZCA/app.py copy from src/graph/app.py copy to src/graph_ZCA/app.py --- a/src/graph/app.py +++ b/src/graph_ZCA/app.py @@ -1,13 +1,17 @@ -from zope.interface import Interface + from zope.interface import implements -from graph.components import BaseComponent, Image -from graph.interfaces import IAxis, IViewBox +from graph_ZCA.components import BaseComponent, Image, Axis, AxisComponent, ViewBox +from graph_ZCA.interfaces import IAxis, IViewBox, IBaseComponent + +from zope.component import getGlobalSiteManager, adapts + +gsm = getGlobalSiteManager() -class IPlotImage(Interface): +class IPlotImage(IBaseComponent): """ - Componante to plot a 2d graph of a given image + Component to plot a 2d graph of a given image """ @@ -17,31 +21,39 @@ class PlotImage( BaseComponent): """ implements(IPlotImage) - def __init__(self, parent, image): + def __init__(self, parent): super(PlotImage, self).__init__(parent) - self.image = image - self.x_axis = IAxis(self) - self.x_axis.orientation='bottom' - self.x_axis.start=0 - self.x_axis.end=8 + + self.vb = ViewBox(self)() - self.y_axis = IAxis(self) - self.y_axis.orientation='left' - self.y_axis.start=-5 - self.y_axis.end=3 + x_axis = Axis(self.vb)() + x_axis.orientation='bottom' + x_axis.start=0 + x_axis.end=8 - self.vb = IViewBox(self) + y_axis = Axis(self.vb)() + y_axis.orientation='left' + y_axis.start=-5 + y_axis.end=3 - self.vb.addItem( self.x_axis ) - self.vb.addItem( self.y_axis ) - self.vb.addItem( self.image ) + + self.vb.addItem( x_axis ) + self.vb.addItem( y_axis ) def render(self): return self.vb.render() +class NewAxisComponent(AxisComponent): + adapts(IViewBox) -image = Image(None, None) -plot = PlotImage( None, image) +gsm.registerAdapter(NewAxisComponent) + +image_data = [1,2,3,4] + +plot = PlotImage( None) +image = Image(plot.vb)(image_data) +plot.vb.addItem(image) + print( plot.render())