Пример #1
0
class CanvasItem(object):
    def __init__(self,params,defaults=None):
        self.params = PropertyTree()
        if not defaults is None:
            self.params.update(defaults)
        if isinstance(params,PropertyTree):
            self.params.update(params)
        elif isinstance(params,dict):
            self.params.update(PropertyTree(init=params))
        self.params.lock()
Пример #2
0
class CanvasItem(object):
    def __init__(self, params, defaults=None):
        self.params = PropertyTree()
        if not defaults is None:
            self.params.update(defaults)
        if isinstance(params, PropertyTree):
            self.params.update(params)
        elif isinstance(params, dict):
            self.params.update(PropertyTree(init=params))
        self.params.lock()
Пример #3
0
class CurveScene(object):
    def __init__(self,params):
        self.params = PropertyTree(init={"size": (400,250),
                                         "view":(0.0,0.0,0.0,0.0),
                                         "left_margin":15,
                                         "right_margin":10,
                                         "top_margin":10,
                                         "bottom_margin":15,
                                         "use_antialiasing":True,
                                         "log_scale_y":False,
                                         "fg_color":(255,255,255,255),
                                         "bg_color":(0,0,0,255)})
        self.params.update(params)
        self.params.lock()
        self.items = []
        self.active_view = "scene"
        self.__setup()
    def __setup(self):
        self.__add_bg()
        if self.params.has_property("grid"):
            self.items.append(PlotGrid(self.params.grid,self))
        if self.params.has_property("axes"):
            self.items.append(PlotAxes(self.params.axes,self))
        for p in self.params.plots:
            self.items.append(Plots.create(self,p))
        if self.params.has_property("labels"):
            self.items.append(PlotLabels(self.params.labels,self))
        for i in self.params.annotations:
            self.items.append(Annotations.create(i))
    def __add_bg(self):
        mgns = self.margins()
        w = 100 + int(mgns[0] + mgns[1])
        h = 100 + int(mgns[2] + mgns[3])
        bg = Rect({"x":-mgns[0],"y":-mgns[3],
                  "w":w,"h":h,"color":self.params.bg_color})
        self.items.append(bg)
    def __add_plot(self,params):
        pass
    def __add_annotation(self,params):
        pass
    def aspect_ratio(self):
        return float(self.params.size[1])/float(self.params.size[0])
    def margins(self):
        return [self.params.left_margin,self.params.right_margin,
                self.params.bottom_margin, self.params.top_margin]
    def render(self,ofname):
        mgns =self.margins()
        w = 100 + int(mgns[0] + mgns[1])
        h = 100 + int(mgns[2] + mgns[3])
        view = (-mgns[0],-mgns[3],w,h)
        Canvas.render(self.items,self.params.size,ofname,view)
    def set_scene_viewport(self,painter):
        if not self.active_view == "regular":
            if self.active_view == "curve":
                painter.restore()
            mgns =self.margins()
            w = 100 + int(mgns[0] + mgns[1])
            h = 100 + int(mgns[2] + mgns[3])
            view = (-mgns[0],-mgns[3],w,h)
            painter.setWindow(-mgns[0],-mgns[3],w,h)
            self.active_view = "scene"
    def set_curve_viewport(self,painter):
        if not self.active_view == "curve":
            mgns =self.margins()
            w = 100 + int(mgns[0] + mgns[1])
            h = 100 + int(mgns[2] + mgns[3])
            view = (-mgns[0],-mgns[3],w,h)
            painter.setWindow(-mgns[0],-mgns[3],w,h);
            xmin, xmax,ymax,ymin= self.params.view
            if self.params.log_scale_y:
                ymin = log10(ymin);
                ymax = log10(ymax);
            xdiff = xmax - xmin;
            ydiff = ymax - ymin;
            painter.save()
            painter.scale(100.0/xdiff,100.0/ydiff)
            painter.translate(-xmin,-ymin)
            self.active_view="curve"
    def set_regular_viewport(self,painter):
        if not self.active_view == "regular":
            if self.active_view == "curve":
                painter.restore()
            sz = self.params.size
            painter.setWindow(0,0,sz[0],sz[1])
            self.active_view = "regular"
Пример #4
0
class CurveScene(object):
    def __init__(self, params):
        self.params = PropertyTree(
            init={
                "size": (400, 250),
                "view": (0.0, 0.0, 0.0, 0.0),
                "left_margin": 15,
                "right_margin": 10,
                "top_margin": 10,
                "bottom_margin": 15,
                "use_antialiasing": True,
                "log_scale_y": False,
                "fg_color": (255, 255, 255, 255),
                "bg_color": (0, 0, 0, 255)
            })
        self.params.update(params)
        self.params.lock()
        self.items = []
        self.active_view = "scene"
        self.__setup()

    def __setup(self):
        self.__add_bg()
        if self.params.has_property("grid"):
            self.items.append(PlotGrid(self.params.grid, self))
        if self.params.has_property("axes"):
            self.items.append(PlotAxes(self.params.axes, self))
        for p in self.params.plots:
            self.items.append(Plots.create(self, p))
        if self.params.has_property("labels"):
            self.items.append(PlotLabels(self.params.labels, self))
        for i in self.params.annotations:
            self.items.append(Annotations.create(i))

    def __add_bg(self):
        mgns = self.margins()
        w = 100 + int(mgns[0] + mgns[1])
        h = 100 + int(mgns[2] + mgns[3])
        bg = Rect({
            "x": -mgns[0],
            "y": -mgns[3],
            "width": w,
            "height": h,
            "color": self.params.bg_color
        })
        self.items.append(bg)

    def __add_plot(self, params):
        pass

    def __add_annotation(self, params):
        pass

    def aspect_ratio(self):
        return float(self.params.size[1]) / float(self.params.size[0])

    def margins(self):
        return [
            self.params.left_margin, self.params.right_margin,
            self.params.bottom_margin, self.params.top_margin
        ]

    def render(self, ofname):
        mgns = self.margins()
        w = 100 + int(mgns[0] + mgns[1])
        h = 100 + int(mgns[2] + mgns[3])
        view = (-mgns[0], -mgns[3], w, h)
        Canvas.render(self.items, self.params.size, ofname, view)

    def set_scene_viewport(self, painter):
        if not self.active_view == "regular":
            if self.active_view == "curve":
                painter.restore()
            mgns = self.margins()
            w = 100 + int(mgns[0] + mgns[1])
            h = 100 + int(mgns[2] + mgns[3])
            view = (-mgns[0], -mgns[3], w, h)
            painter.setWindow(-mgns[0], -mgns[3], w, h)
            self.active_view = "scene"

    def set_curve_viewport(self, painter):
        if not self.active_view == "curve":
            mgns = self.margins()
            w = 100 + int(mgns[0] + mgns[1])
            h = 100 + int(mgns[2] + mgns[3])
            view = (-mgns[0], -mgns[3], w, h)
            painter.setWindow(-mgns[0], -mgns[3], w, h)
            xmin, xmax, ymax, ymin = self.params.view
            if self.params.log_scale_y:
                ymin = log10(ymin)
                ymax = log10(ymax)
            xdiff = xmax - xmin
            ydiff = ymax - ymin
            painter.save()
            painter.scale(100.0 / xdiff, 100.0 / ydiff)
            painter.translate(-xmin, -ymin)
            self.active_view = "curve"

    def set_regular_viewport(self, painter):
        if not self.active_view == "regular":
            if self.active_view == "curve":
                painter.restore()
            sz = self.params.size
            painter.setWindow(0, 0, sz[0], sz[1])
            self.active_view = "regular"