def add_datasets_to_plot(self, datasets, plot, undolist=None):
        """
        Adds the given Datasets to Dataset to the Plot object.
        
        >>> add_datasets_to_plot( [ds1,ds2], plot )

        Returns the Plot object.
        """
        if undolist is None:
            undolist = self.journal
        
        # make sure we are talking about an iterable object
        if not isinstance( datasets, (list,tuple) ):
            datasets = [datasets]

        ul = UndoList().describe("Add Datasets to Plot")

        try:
            layer = plot.layers[0]
        except KeyError:
            layer = Layer(type='lineplot2d')
            
        for dataset in datasets:
            dataset = self.get_dataset(dataset)
            line = Line(source=dataset, label = dataset.key)
            ulist.append( layer.lines, line, undolist=ul )

        uwrap.emit_last(self.plot, "changed", undolist=ul)
        undolist.append( ul )
        
        return plot
    def check_out(self, undolist=[]):

        # TOOD: make sure we are finished with editing the treeview
        
        ul = UndoList().describe("Set Line Property")

        model = self.treeview.get_model()
        model_lines = []

        def get_column(column, default=None):
            """
            Returns the value of the specified column from the model, or if
            it is an empty string, returns the default value given.
            """
            rv = model.get_value(treeiter, column)
            if isinstance(rv, basestring) and len(rv) == 0:
                return default
            else:
                return rv
        
        n=0        
        treeiter = model.get_iter_first()
        while treeiter:
            # Is this row an existing line or a new one?
            line = model.get_value(treeiter, self.COL_LINE)
            if line in self.layer.lines:
                # existing line
                source_key = model.get_value(treeiter, self.COL_SOURCE_KEY)
                if not source_key:
                    source = None
                else:
                    source = self.app.project.get_dataset(source_key, default=None)
                        
                uwrap.smart_set(line,
                          'visible', get_column(self.COL_VISIBLE),
                         'label', get_column(self.COL_LABEL),
                         'style', get_column(self.COL_STYLE),
                         'marker', get_column(self.COL_MARKER),
                         'width', get_column(self.COL_WIDTH),
                         'source', source,
                         'cx', get_column(self.COL_CX),
                         'cy', get_column(self.COL_CY),
                         'row_first', get_column(self.COL_ROW_FIRST),
                         'row_last', get_column(self.COL_ROW_LAST),
                         'cxerr', get_column(self.COL_CXERR),
                         'cyerr', get_column(self.COL_CYERR),
                         undolist=ul)
            else:
                ulist.append( self.layer.lines, line, undolist=ul )

            model_lines.append(line)
            treeiter = model.iter_next(treeiter)
            n+=1

        # now we need to check if we have removed any lines
        for line in self.layer.lines:
            if line not in model_lines:
                ulist.remove( self.layer.lines, line, undolist=ul)
            
        undolist.append(ul)
示例#3
0
    def on_new(self, sender):
        label = objects.TextLabel(text="newlabel")
        self.edit(label)
        project = self.get_data("project")

        ul = UndoList().describe("New label.")
        ulist.append(self.layer.labels, label, undolist=ul)
        uwrap.emit_last(self.layer, "notify::labels", updateinfo={"add": label}, undolist=ul)
        project.journal.append(ul)
示例#4
0
 def on_new(self, sender):
     self.check_layer()
     
     label = objects.TextLabel(text='newlabel')
     self.edit(label)
     project = self.get_data('project')
         
     ul = UndoList().describe("New label.")
     ulist.append(self.layer.labels, label, undolist=ul)
     uwrap.emit_last(self.layer, "notify::labels",
                     updateinfo={'add' : label},
                     undolist=ul)
     project.journal.append(ul)
    def add_plots(self, plots, undolist=None):
        if undolist is None:
            undolist = self.journal

        if len(plots) == 0:
            undolist.append(NullUndo())

        ul = UndoList()
        ul.describe("Append Plots to Project")

        for plot in plots:
            new_key = pdict.unique_key(self.plots, plot.key)
            if new_key != plot.key:
                uwrap.set(plot, 'key', new_key, undolist=ul)
            ulist.append(self.plots, plot, undolist=ul)

        undolist.append(ul)

        cli_logger.info("Added %d plot(s)." % len(plots) )
    def add_datasets(self, datasets, undolist=None):
        if undolist is None:
            undolist = self.journal

        if len(datasets) == 0:
            undolist.append(NullUndo())
            return
        
        ul = UndoList()
        ul.describe("Append Dataset to Project")

        for dataset in datasets:
            new_key = pdict.unique_key(self.datasets, dataset.key)
            if new_key != dataset.key:
                uwrap.set(dataset, 'key', new_key, undolist=ul)
            ulist.append( self.datasets, dataset, undolist=ul )

        undolist.append(ul)
        
        cli_logger.info("Added %d dataset(s)." % len(datasets) )
    def add_experimental_plot(self, project, undolist=None):

        if undolist is None:
            undolist = project.journal

        ul = UndoList().describe("Experimental Plot")

        ds = Dataset()
        ds.key = pdict.unique_key(project.datasets, "exp_ds")
        ds.data = Table(colcount=2, rowcount=5)
        ds.data[0] = [1,2,3,4,5]
        ds.data[1] = [1,4,9,16,25]

        ds2 = Dataset()
        ds2.key = pdict.unique_key(project.datasets, "exp_ds2")
        ds2.data = Table(colcount=2, rowcount=4)
        ds2.data[0] = [10,17,3,8]
        ds2.data[1] = [1,89,48,1]

        ulist.append( project.datasets, ds, undolist=ul )
        ulist.append( project.datasets, ds2, undolist=ul )                

        plot = Plot()
        plot.key = pdict.unique_key(project.plots, "exp_plot")
        layer1 = Layer(type="line2d",
                       lines=[Line(source=ds,cx=0,cy=1), Line(source=ds2)],
                       x=0.0, y=0.0, width=1.0, height=0.5)
        layer2 = Layer(type="line2d",
                       lines=[Line(source=ds2,cx=0,cy=1)],
                       x=0.0, y=0.5, width=1.0, height=0.5)
        plot.layers = [layer1, layer2]
#        plot.layers.arrange(rowcount=1, colcount=2)
        
        ulist.append( project.plots, plot, undolist=ul )

        uwrap.emit_last(project.datasets, "changed")
        undolist.append(ul)